Utilities

Module for utilities that can be used throughout library

ec3.ec3_utils.get_displayname_category_dict(category_tree)

Get a dictionary with display names as the keys and ids as the values

Parameters

category_tree (dict) – This should be a nested dictionary of all or part of the category tree

Returns

Dictionary with display names as keys (ex: {‘Ready Mix’: ‘6991a61b52b24e59b1244fe9dee59e9b’})

Return type

dict

ec3.ec3_utils.get_masterformat_category_dict(category_tree)

Get a dictionary with masterformat codes as the keys and ids as the values

Parameters

category_tree (dict) – This should be a nested dictionary of all or part of the category tree

Returns

Dictionary with masterformat codes as keys (ex: {‘03 00 00 Concrete’: ‘484df282d43f4b0e855fad6b351ce006’})

Return type

dict

ec3.ec3_utils.postal_to_latlong(postal_code, country_code='US')

Converts postal code to latitude and longitude returned as array. Refer to pgeocode documentation for supported country codes. If not found, then coordinates for Null Island are returned (0,0).

Parameters
  • postal_code (int) – postal code

  • country_code (str, optional) – Two letter country code. Defaults to ‘US’.

Returns

A tuple containing a float (latitude) and a float (longitude)

ec3.ec3_utils.recursive_dict_list_return(dict_item, key_name, out_keys, outlist=[])

Recursively loops through a nested json/dictionary based on the key name

This is intended for where the key_name may occur at multiple levels of nesting. For example, the “subcategories” key occurs at multiple levels of the EC3 categories tree. Using this function allows you to return a flattened list of dictionaries with the desired keys defined in the “out_keys” argument.

Parameters
  • dict_item (dict) – Dictionary with nested data to crawl through

  • key_name (str) – Name of key to crawl through nested dictionary

  • out_keys (list[str]) – List of key names to return

  • outlist (list, optional) – List to return (can be left empty if starting a new list)

Returns

List of dictionaries with keys provided in out_keys

Return type

list