abstract_importer module

class abstract_importer.AbstractImporter(file_path: str)

Bases: abc.ABC

Abstract class that exposes all the necessary methods to process the trajectories and the net structure.

Parameters

file_path (str) – the file path

_concatenated_samples

Dataframe containing the concatenation of all the processed trajectories

_df_structure

Dataframe containing the structure of the network (edges)

_df_variables

Dataframe containing the nodes cardinalities

_sorter

A list containing the columns header (excluding the time column) of the _concatenated_samples

build_list_of_samples_array(data_frame: pandas.core.frame.DataFrame) → List

Builds a List containing the columns of data_frame and converts them to a numpy array.

Parameters

data_frame (pandas.Dataframe) – the dataframe from which the columns have to be extracted and converted

Returns

the resulting list of numpy arrays

Return type

List

abstract build_sorter(sample_frame: pandas.core.frame.DataFrame) → List

Initializes the _sorter class member from a trajectory dataframe, exctracting the header of the frame and keeping ONLY the variables symbolic labels, cutting out the time label in the header.

Parameters

sample_frame (pandas.DataFrame) – The dataframe from which extract the header

Returns

A list containing the processed header.

Return type

List

clear_concatenated_frame() → None

Removes all values in the dataframe concatenated_samples.

compute_row_delta_in_all_samples_frames(df_samples_list: List) → None

Calls the method compute_row_delta_sigle_samples_frame on every dataframe present in the list df_samples_list. Concatenates the result in the dataframe concatanated_samples

Parameters

df_samples_list (List) – the datframe’s list to be processed and concatenated

Warning

The Dataframe sample_frame has to follow the column structure of this header: Header of sample_frame = [Time | Variable values] The class member self._sorter HAS to be properly INITIALIZED (See class members definition doc)

Note

After the call of this method the class member concatanated_samples will contain all processed and merged trajectories

compute_row_delta_sigle_samples_frame(sample_frame: pandas.core.frame.DataFrame, columns_header: List, shifted_cols_header: List) → pandas.core.frame.DataFrame

Computes the difference between each value present in th time column. Copies and shift by one position up all the values present in the remaining columns.

Parameters
  • sample_frame (pandas.Dataframe) – the traj to be processed

  • columns_header (List) – the original header of sample_frame

  • shifted_cols_header (List) – a copy of columns_header with changed names of the contents

Returns

The processed dataframe

Return type

pandas.Dataframe

Warning

the Dataframe sample_frame has to follow the column structure of this header: Header of sample_frame = [Time | Variable values]

property concatenated_samples
abstract dataset_id() → object

If the original dataset contains multiple dataset, this method returns a unique id to identify the current dataset

property file_path
abstract import_data() → None

Imports all the trajectories, variables cardinalities, and net edges.

Warning

The class members _df_variables and _df_structure HAVE to be properly constructed as Pandas Dataframes with the following structure: Header of _df_structure = [From_Node | To_Node] Header of _df_variables = [Variable_Label | Variable_Cardinality]

Note

See :class:JsonImporter for an example of implementation of this method.

property sorter
property structure
property variables