ecpi.common.params.tools_params module

Section author: ECLAIRs GP team

Manage spreadsheet format, tools conversion for string value

Summary

Classes:

SpreadSheetToParams

Extract parameters value from spreadsheet to dictionary

Class diagram:

Functions:

add_double_quote_in_list_string

Automaton adding double quote in string list for each element, example

cfgparser_to_dicttyped

Convert config parser object with section to typed dictionary

dictstr_2_dicttyped

Convert a dictionary where all values are a string to typed dictionary if conversion is possible with json.loads() function

dictstr_highlevel_to_dicttyped

Convert high level dictionary (ie with different component) where value are string to typed dictionary

remove_list_from_value

Remove list from value and used the first element.

select_column_gen

skip_column_func for get_sheet() function

spreadsheet_to_dict

Extraction a dictionary from spreadsheet file.

Reference

class SpreadSheetToParams(pars_file, col_key, col_value)[source]

Bases: object

Extract parameters value from spreadsheet to dictionary

get_params_str()[source]

Extract all parameters in all sheet where col_key, col_value are present

get_params_typed()[source]
add_double_quote_in_list_string(str_list, rm_space=False)[source]
Automaton adding double quote in string list for each element, example
  • ‘[[abb,e,1],[c,3.14]]’

returns
  • ‘[[“abb”,”e”,”1”],[“c”,”3.14”]]’

…note::

Motivation: with double quote we can apply json.loads() function to convert string list in list.

Parameters
  • str_list (str) – representation of a list as a string

  • rm_space (bool) – remove space character before processing

cfgparser_to_dicttyped(cfg, section)[source]

Convert config parser object with section to typed dictionary

Parameters
  • cfg (dict) – object configparser with section where values are string

  • section (str) – section name to convert

Returns

typed dictionary

dictstr_2_dicttyped(dict_str)[source]

Convert a dictionary where all values are a string to typed dictionary if conversion is possible with json.loads() function

Motivation: python library configparser gives value as string

Parameters

dict_str (dict) – dict where values are string

Returns

typed dictionary

dictstr_highlevel_to_dicttyped(dict_hl)[source]

Convert high level dictionary (ie with different component) where value are string to typed dictionary

Example of dict_hl:
{‘CALI’: {‘array_2D_number’: ‘[[0,10],[30,40]]’,

‘array_enum’: ‘[a,b,c]’, ‘par_number’: ‘10.9’},

‘DPCO’: {‘par_path’: ‘d2’}}

return value
{‘CALI’: {‘array_2D_number’: [[0, 10], [30, 40]],

‘array_enum’: [‘a’, ‘b’, ‘c’], ‘par_number’: 10.9},

‘DPCO’: {‘par_path’: ‘d2’} }

Parameters

dict_hl (dict) – high level dictionary with different sections

Returns

typed dictionary

remove_list_from_value(p_dict)[source]

Remove list from value and used the first element. Empty list are removed of dictionary

Motivationget_sheet() function of pyexcel returns always a list as value, example:

{‘par_enum’: [‘i1’], ‘par_path’: [‘i2’]}

so this function returns:

{‘par_enum’: ‘i1’, ‘par_path’: ‘i2’}

Parameters

p_dict (dict) – dictionary with list as value.

select_column_gen(current_index, start, limit=- 1)[source]

skip_column_func for get_sheet() function

Parameters
  • current_index (int) –

  • start (int) –

  • limit (int) –

spreadsheet_to_dict(pars_file, sheet_name, l_column_key_val)[source]

Extraction a dictionary from spreadsheet file.

Parameters
  • pars_file (str) – path and name file parameters

  • sheet_name (str) –

  • l_column_key_val (list) – list with 2 values : key index, value index