json_importer module¶
-
class
json_importer.
JsonImporter
(file_path: str, samples_label: str, structure_label: str, variables_label: str, time_key: str, variables_key: str, array_indx: int)¶ Bases:
abstract_importer.AbstractImporter
Implements the abstracts methods of AbstractImporter and adds all the necessary methods to process and prepare the data in json ext. with the following structure: [0]
- Parameters
file_path (string) – the path of the file that contains tha data to be imported
samples_label (string) – the reference key for the samples in the trajectories
structure_label (string) – the reference key for the structure of the network data
variables_label (string) – the reference key for the cardinalites of the nodes data
time_key (string) – the key used to identify the timestamps in each trajectory
variables_key (string) – the key used to identify the names of the variables in the net
array_indx (int) – the index of the outer JsonArray to exctract the data from
- _df_samples_list
a Dataframe list in which every dataframe contains a trajectory
-
build_sorter
(sample_frame: pandas.core.frame.DataFrame) → List¶ Implements the abstract method build_sorter of the
AbstractImporter
for this dataset
-
clear_data_frame_list
() → None¶ Removes all values present in the dataframes in the list
_df_samples_list
.
-
dataset_id
() → object¶ If the original dataset contains multiple dataset, this method returns a unique id to identify the current dataset
-
import_data
() → None¶ Implements the abstract method of
AbstractImporter
-
import_sampled_cims
(raw_data: List, indx: int, cims_key: str) → Dict¶ Imports the synthetic CIMS in the dataset in a dictionary, using variables labels as keys for the set of CIMS of a particular node.
- Parameters
raw_data (List) – List of Dicts
indx (int) – The index of the array from which the data have to be extracted
cims_key (string) – the key where the json object cims are placed
- Returns
a dictionary containing the sampled CIMS for all the variables in the net
- Return type
Dictionary
-
import_structure
(raw_data: List) → pandas.core.frame.DataFrame¶ Imports in a dataframe the data in the list raw_data at the key
_structure_label
- Parameters
raw_data (List) – List of Dicts
- Returns
Dataframe containg the starting node a ending node of every arc of the network
- Return type
pandas.Dataframe
-
import_trajectories
(raw_data: List) → List¶ Imports the trajectories from the list of dicts
raw_data
.- Parameters
raw_data (List) – List of Dicts
- Returns
List of dataframes containing all the trajectories
- Return type
List
-
import_variables
(raw_data: List) → pandas.core.frame.DataFrame¶ Imports the data in
raw_data
at the key_variables_label
.- Parameters
raw_data (List) – List of Dicts
- Returns
Datframe containg the variables simbolic labels and their cardinalities
- Return type
pandas.Dataframe
-
normalize_trajectories
(raw_data: List, indx: int, trajectories_key: str) → List¶ Extracts the trajectories in
raw_data
at the indexindex
at the keytrajectories key
.- Parameters
raw_data (List) – List of Dicts
indx (int) – The index of the array from which the data have to be extracted
trajectories_key (string) – the key of the trajectories objects
- Returns
A list of daframes containg the trajectories
- Return type
List
-
one_level_normalizing
(raw_data: List, indx: int, key: str) → pandas.core.frame.DataFrame¶ Extracts the one-level nested data in the list
raw_data
at the indexindx
at the keykey
.- Parameters
raw_data (List) – List of Dicts
indx (int) – The index of the array from which the data have to be extracted
key (string) – the key for the Dicts from which exctract data
- Returns
A normalized dataframe
- Return type
pandas.Datframe
-
read_json_file
() → List¶ Reads the JSON file in the path self.filePath
- Returns
The contents of the json file
- Return type
List