traveltimes_prediction.support_files package

Submodules

traveltimes_prediction.support_files.extrapolating_cache module

class traveltimes_prediction.support_files.extrapolating_cache.ExtrapolatingCache(maxsize=10)[source]

Bases: object

Class - cache for caching of values, has ability to extrapolate using cached values.

empty()[source]

Method for investigating if the self._cache is empty or not

Returns:boolean
get(x=None)[source]

Method for extrapolating the values from the cache.

Parameters:x (int) – ‘x’ index for extrapolation
Returns:float - interpolated value
put(item)[source]

Method for inserting the values to cache.

Parameters:item (number) –
Returns:

traveltimes_prediction.support_files.fields_definitions module

class traveltimes_prediction.support_files.fields_definitions.ColumnNames[source]

Bases: object

AVG_VELOCITY = 'avg_velocity'
CALC_TIME = 'calculation_time'
FEAT_DAY = 'day_of_week'
FEAT_FRIDAY = 'friday'
FEAT_MONDAY = 'monday'
FEAT_THURSDAY = 'thursday'
FEAT_TIME = 'time_of_day'
FEAT_TIME_BIN = 'time_bin'
FEAT_TT_BCK = 'bck_prediction_tt'
FEAT_TT_MATCH = 'tt_matches'
FEAT_TT_UNMATCHED = 'tt_count_unmatched'
FEAT_TUESDAY = 'tuesday'
FEAT_WEDNESDAY = 'wednesday'
FEAT_WEEKEND = 'weekend'
FEAT_det1_COUNT = 'det1_count'
FEAT_det1_OCCUPANCY = 'det1_occupancy'
FEAT_det1_VELOCITY = 'det1_velocity'
FEAT_det2_COUNT = 'det2_count'
NORM_COUNT = 'norm_count'
TOTAL_OCCUPANCY = 'total_occupancy'
class traveltimes_prediction.support_files.fields_definitions.ColumnNamesRaw[source]

Bases: object

CALC_TIME = 'calculation_time'
LP_FULL_ENC = 'lp_full_enc'
SENSOR_NAME = 'sensor_name'
TT_CALCULATED = 'tt_calculated'
TT_LP_MATCH = 'match_tt'
TT_LP_UNMATCHED = 'unmatched_counter'
class traveltimes_prediction.support_files.fields_definitions.ColumnNamesRawFiveMin[source]

Bases: object

CALC_TIME = 'calculation_time'
COUNT = 'detection_count'
LP_COUNT = 'lp_count'
OCCUPANCY = 'occupancy'
OUTPUT_SECTION = 'output_section'
SENSOR_NAME = 'sensor_name'
TT_CALCULATED = 'tt_calculated'
TT_REAL = 'tt_real'
VELOCITY = 'velocity_avg'
class traveltimes_prediction.support_files.fields_definitions.MessageCodes[source]

Bases: object

DATA_AGGREGATION_FAILED = -4
DATA_NOT_IN_DB = -2
FEATURE_ENGINEERING_FAILED = -5
MODEL_NOT_IN_DB = -1
PREDICTION_SUCCESSFUL = 1
PREDICTION_UNSUCCESSFUL = -3
RESULT_EXTRAPOLATED = -6
TOO_HIGH_TRAVELTIME = -7

traveltimes_prediction.support_files.helpers module

traveltimes_prediction.support_files.helpers.array_append(arr_base, arr_new, stack='v')[source]

Function for appending of the numpy array.

Parameters:
  • arr_base (np.array) –
  • arr_new (np.array) –
  • stack (char) – The stacking dimension - horizontal (‘h’) or vertical (‘v’)
Returns:

np.array

traveltimes_prediction.support_files.helpers.check_params(func)[source]

Decorator for checking the method`s/function`s input parameters - if they are not empty or None.

Parameters:func
Returns:
traveltimes_prediction.support_files.helpers.chunkify(l, n)[source]

Method for cutting huge list into more smaller lists.

Parameters:
  • l (list) –
  • n (int) – Number of lists to be created.
Returns:

traveltimes_prediction.support_files.helpers.compress(s)[source]

Function for compression of string.

Parameters:s (string) –
Returns:Encoded string – binary.
traveltimes_prediction.support_files.helpers.convert_params(func)[source]

Decorator for conversion of the method`s/function`s input parameters - pd.DataFrame -> np.ndarray

Parameters:func
Returns:
traveltimes_prediction.support_files.helpers.dataframe_append(df_base, df_new)[source]

Function for appending of the dataframes.

Parameters:
  • df_base (pd.DataFrame) –
  • df_new (pd.DataFrame) –
Returns:

pd.DataFrame

traveltimes_prediction.support_files.helpers.decompress(c)[source]

Function for decompression of binary coded string.

Parameters:c (string) –
Returns:Decoded binary string – ascii.
traveltimes_prediction.support_files.helpers.impute(array, columns, invalid_val)[source]

Function for imputation of the numpy array - replacing invalid values.

Parameters:
  • array (np.array) –
  • columns (list) – Indices of columns.
  • invalid_val (number) – Identifier of the invalid number.
Returns:

tuple (imputed array, confidence - ratio of count of imputed elements to the size of the original array)

traveltimes_prediction.support_files.helpers.index(a, x)[source]

Binary search, lookup of the leftmost value exactly equal to x

Parameters:
  • a (np.array) –
  • x (number) –
Returns:

number

traveltimes_prediction.support_files.helpers.merge_inner_lists(list_of_lists)[source]

Function for merging of the inner lists creating one list of all elements.

Parameters:list_of_lists (list) – list of lists or tuples
Returns:list
traveltimes_prediction.support_files.helpers.merge_to_nearest(df1, df2)[source]

Function for merging of the pd.DataFrames according to their Datetime indices.

Parameters:
  • df1 (pd.DataFrame) –
  • df2 (pd.DataFrame) –
Returns:

pd.DataFrame

traveltimes_prediction.support_files.helpers.partition_interval(time_interval, delta_hours=12)[source]

Function for partitioning the time_interval to list of dicts - shorter intervals

Parameters:
  • time_interval (dict) – dict of datetimes -> {‘from’: datetime, ‘to’: datetime}
  • delta_hours (int) –
Returns:

list of dicts - [{‘from’: datetime, ‘to’: datetime}, ...]

traveltimes_prediction.support_files.helpers.subtract_time_intervals(new, saved)[source]

Function for the subtracting of the intervals, A-B.

Parameters:
  • new (dict) – A, format {‘from’: datetime, ‘to’: datetime}
  • saved (dict) – B, format {‘from’: datetime, ‘to’: datetime}
Returns:

dict {‘from’: datetime, ‘to’: datetime}

traveltimes_prediction.support_files.my_queue module

class traveltimes_prediction.support_files.my_queue.MyQueue(maxsize, *args, **kwargs)[source]

Bases: list

push(item)[source]

Method for inserting elements to queue.

Parameters:item (number) – Number to be inserted to queue.
Returns:self

Module contents