utils module

utils.access_by_path(dictionary, path_parts)[source]

Access the dictionary by the provided list of keys/indices.

Parameters:
  • dictionary -- dict, list

  • path_parts -- list

utils.after_point(s)[source]

Extracts string after finding '.'

Parameters:

s -- str

Returns:

str

utils.after_underscore(s)[source]

Extracts string after finding '_'

Parameters:

s -- str

Returns:

str

utils.convert_to_timestamp(date_input)[source]

Converts date_input into timestamp.

Parameters:

date_input -- datetime, str

Returns:

float

utils.extract_date(d)[source]

Returns only date-part in string, from datetime object.

Parameters:

d -- datetime

Returns:

str

utils.extract_time(dt)[source]

Extracts and returns the time portion from a datetime object as a string (HH:MM:SS).

Parameters:

d -- datetime

Returns:

str

utils.find_closest_index(new_time, target_hour, target_minute, target_second=0)[source]

Finds the index of the sample in new_time closest to the given hour and minute.

Parameters:
  • new_time -- datetime.datetime, target date

  • target_hour -- int/float

  • target_minute -- int/float

  • target_second -- int/float

Returns:

int, if the target time is out of bounds return None.

utils.find_key_path(dictionary, target_key, path='')[source]

Recursively finds and prints the path of a key in a nested dictionary (including lists).

Parameters:
  • dictionary -- dict, list

  • target_key -- int/str

  • path -- str, optional. Looks for target_key in dictionary[path] ex.: path = '[key1][key2]'

Returns:

list, names of all paths that lead to target_key

utils.full_date2str(d)[source]

Converts datetime object to full date string

Parameters:

d -- datetime.datetime

Returns:

str

utils.get_timestamp_from_dt(dt_string)[source]

Parses a datetime string and returns a timestamp of the time portion.

Parameters:

dt_string -- str

Returns:

float

utils.parse_datetime(string)[source]

Converts string into datetime.datetime object.

Parameters:

string -- str, "%Y-%m-%dT%H:%M:%S.%fZ" OR "%Y-%m-%dT%H:%M:%SZ" OR "%Y-%m-%d %H:%M:%S"

Returns:

datetime.datetime object

utils.parse_path(path)[source]

Convert the string path into a list of keys and indices. Example: '[key1][key2]' --> [key1,key2]

Parameters:

path -- str

Returns:

list

utils.parse_time(string)[source]

Converts time string into datetime.datetime object.

Parameters:

string -- str, "%H:%M:%S"

Returns:

datetime.datetime object

utils.read_event_file(filename)[source]

Reads a text file and returns a list of (hour, minute, second, event) tuples. If seconds are not provided, they default to 0.

Parameters:

filename -- str, must be path/file.txt

Returns:

list

utils.read_lines(filename)[source]

Converts txt file into dictionary, with firts line being key.

Parameters:

filename -- str, must be path/file.txt

Returns:

dict

utils.resource_path(*parts)[source]
utils.string2numbers(string)[source]

Converts string with numbers separated by ',' (TicksInMs) into a np.array. Example: '1,2,3,,4,6,7' --> np.array([1,2,3,4,6,7])

Parameters:

string -- str

Returns:

np.ndarray