ts_core.config.parser module

Excel Configuration Parser Internals

This module handles all of the excel configuration parsing.

Guidelines on excel sheet formatting is as follows:

Column A Column B Column C Column E Column F
SUMO Attribute SUMO File where this attribute resides Category name Units column Value fot this attr

Attributes can only be read from Row 3 and below (MIN_ROW)

Only the first 1000 rows can have any attributes (MAX_ROW)

Current supported tabs: * Vehicle Type Customization * General Settings * Intersection Definition * Branch Settings

Current supported Intersection Types: * Cross * T * Y

Cross intersection has been tested.

get_input_from_row(sheet, row_num, cols=1)[source]

Retrieves the input from the row and returns a tuple of all the relevant data

Parameters:
  • sheet (The sheet to read) –
  • row_num (The row number to use) –
  • cols (The number of columns to the RIGHT of row_num to return) –
Returns:

formatted as (sumo_file, sumo_attribute, units, user_val1, user_val2…)

Return type:

Tupple containing the data -

parse_branches(sheet, intersection_type)[source]

Parses the given sheet assuming it is the branches sheet

Fills out OUTPUT_DICT with all information needed to parse the branches of the intersection.

Parameters:
  • sheet (openpyxl sheet - The General Branches Settings tab) –
  • intersection_type
Returns:

Return type:

None

parse_general(sheet)[source]

Parses the given sheet assuming it is the General Settings sheet

Adds parsed data to OUTPUT_DICT global variable

Parameters:sheet (openpyxl sheet - The General Settings tab) –
Returns:
Return type:String - The name of the current configuration
parse_intersection(sheet)[source]

Parses the given sheet assuming it is the Intersections sheet

Adds parsed data to OUTPUT_DICT global variable :param sheet: :type sheet: openpyxl sheet - The General Intersection Settings tab

Returns:
Return type:String - The selected intersection type. Key in ITYPE_BRANCHES
parse_stats(sheet)[source]

Parses the given sheet assuming it is the advanced customization sheet The parsed data is stored as a xml.etree.ElementTree element.

This becomes the stats file for SUMO

Parameters:sheet (The advanced customization sheet) –
Returns:
Return type:“xml.etree.ElementTree” node containing the full statistics file information
prettyprint(root, print_it=False, supress_errors=True)[source]

Attempts to create a human readable string out of a given xml STRING

Parameters:
  • root (String containing valid xml data) –
  • print_it (Tells the function whether or not it should also print out the xml) –
  • supress_errors (Tells the function to NOT print out errors if given data was invalid) –
Returns:

Return type:

String containing the formatted xml data if possible

row_has_category(sheet, row_num)[source]

Checks to see if this row starts a new category

Parameters:
  • sheet (openpyxl sheet - The sheet to use) –
  • row_num (The row to analyze) –
Returns:

  • True if there is a new category
  • False otherwise

row_has_data(sheet, row_num)[source]

Checks whether or not this row contains a user-entered value.

Parameters:
  • sheet (openpyxl sheet - The sheet to use) –
  • row_num (The row to analyze) –
Returns:

  • True if there is data to be analyzed
  • False otherwise

run_parser(excel_file_path, outpath)[source]

Main function to actually run the whole parser

Parameters:
  • excel_file_path (FULL file path to the excel sheet) –
  • outpath (File to output the temporary json file) –
Returns:

  • In order
  • 1) config_name (The name for the current configuation)
  • 2) OUTPUT_DICT (python dictionary containing all relevant information)
  • 3) Stats file xml