stream_sim module
- class stream_sim.DataLoader(*args, **kwargs)[source]
Bases:
object
Singleton DataLoader class for loading and retrieving data in batches.
This class provides functionality to load data and retrieve it in batches, maintaining a singleton instance throughout the application.
- df
The underlying data in a pandas DataFrame.
- Type:
pandas.DataFrame
- batch_size
The size of each data batch.
- Type:
int
- row_ind
The current row index.
- Type:
int
- stream_sim.fetch_sensor_data()[source]
Fetches sensor data from the data loader and returns it as a JSON response.
- Returns:
A JSON response containing the fetched sensor data.
- Return type:
Response
- stream_sim.get_data(config)[source]
Retrieves the data from either a database table or a CSV file based on the configuration.
- Parameters:
config (dict) – Configuration dictionary containing the ‘DATA_TYPE’, ‘DATASET’ path, ‘IDs’, and ‘START_TIME’, DB_TABLE, DATE_TIME_COL.
- Returns:
Data retrieved from the database table or CSV file.
- Return type:
result (pandas.DataFrame)
- stream_sim.get_db_engine()[source]
Returns a SQLAlchemy engine for connecting to the database.
- Returns:
SQLAlchemy engine object.
- Return type:
engine (sqlalchemy.engine.base.Engine)
- stream_sim.get_ids()[source]
Retrieves the target IDs.
- Returns:
List of IDs or None if not specified in the config.
- Return type:
list or None
- stream_sim.get_query_result(query, db_conn, params=[])[source]
Executes a SQL query on the database connection and returns the result as a Pandas DataFrame.
- Parameters:
query (str) – SQL query to be executed.
db_conn (sqlalchemy.engine.base.Connection) – Database connection object.
params (list, optional) – Parameters to be passed to the SQL query. Defaults to [].
- Returns:
Result of the SQL query as a Pandas DataFrame.
- Return type:
result (pandas.DataFrame)
- stream_sim.get_series_from_db(db_conn, table_name, ids=None, id_column=None, start_time=None)[source]
Retrieves the series data for specific IDs from the database starting from the specified time.
- Parameters:
db_conn (sqlalchemy.engine.base.Connection) – Database connection object.
table_name (str) – Name of the table to retrieve the series data from.
ids (list or None, optional) – IDs for which to retrieve the series data. Defaults to None.
id_column (str or None, optional) – Name of the ID column in the database table. Defaults to None.
start_time (str or None, optional) – Start time from which to retrieve the series data. Defaults to None.
- Returns:
Result of the SQL query as a Pandas DataFrame.
- Return type:
result (pandas.DataFrame)