timescale
mainsequence.client.data_sources_interfaces.timescale
direct_data_from_db(local_metadata, connection_uri, start_date=None, great_or_equal=True, less_or_equal=True, end_date=None, columns=None, unique_identifier_list=None, unique_identifier_range_map=None)
Connects directly to the DB without passing through the ORM to speed up calculations.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
metadata
|
dict
|
Metadata containing table and column details. |
required |
connection_config
|
dict
|
Connection configuration for the database. |
required |
start_date
|
datetime
|
The start date for filtering. If None, no lower bound is applied. |
None
|
great_or_equal
|
bool
|
Whether the start_date filter is inclusive (>=). Defaults to True. |
True
|
less_or_equal
|
bool
|
Whether the end_date filter is inclusive (<=). Defaults to True. |
True
|
end_date
|
datetime
|
The end date for filtering. If None, no upper bound is applied. |
None
|
columns
|
list
|
Specific columns to select. If None, all columns are selected. |
None
|
Returns:
Type | Description |
---|---|
DataFrame
|
Data from the table as a pandas DataFrame, optionally filtered by date range. |
direct_table_update(metadata, serialized_data_frame, overwrite, grouped_dates, table_is_empty, time_series_orm_db_connection=None, use_chunks=True, num_threads=4)
Updates the database table with the given DataFrame.
Parameters: - table_name: Name of the database table. - serialized_data_frame: DataFrame containing the data to insert. - overwrite: If True, existing data in the date range will be deleted before insertion. - time_index_name: Name of the time index column. - index_names: List of index column names. - table_is_empty: If True, the table is empty. - time_series_orm_db_connection: Database connection string. - use_chunks: If True, data will be inserted in chunks using threads. - num_threads: Number of threads to use when use_chunks is True.
filter_by_assets_ranges(table_name, asset_ranges_map, index_names, data_source, column_types)
Query time series data dynamically based on asset ranges.
Args:
table_name (str): The name of the table to query.
asset_ranges_map (dict): A dictionary where keys are asset symbols and values are dictionaries containing:
- 'start_date' (datetime): The start date of the range.
- 'start_date_operand' (str): The SQL operand for the start date (e.g., '>=' or '>').
- 'end_date' (datetime or None): The end date of the range.
index_names (list): List of column names to set as the DataFrame index.
data_source: A data source object with a method get_connection_uri()
to get the database connection URI.
Returns: pd.DataFrame: A Pandas DataFrame with the queried data, indexed by the specified columns.
process_and_update_table(serialized_data_frame, local_metadata, grouped_dates, data_source, index_names, time_index_name, overwrite=False, JSON_COMPRESSED_PREFIX=None)
Process a serialized DataFrame, handle overwriting, and update a database table.
Args:
serialized_data_frame (pd.DataFrame): The DataFrame to process and update.
metadata (DynamicTableMetaData): Metadata about the table, including table configuration.
grouped_dates (list): List of grouped dates to assist with the update.
data_source (object): A data source object with a get_connection_uri
method.
index_names (list): List of index column names.
time_index_name (str): The name of the time index column.
overwrite (bool): Whether to overwrite the table or not.
JSON_COMPRESSED_PREFIX (list): List of prefixes to identify JSON-compressed columns.
Returns: None