opensampl.load_data
Main functionality for loading data into the database
create_new_tables(*, _config, create_schema=True, session=None)
Use the ORM definition to create all tables, optionally creating the schema as well
Source code in opensampl/load_data.py
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 |
|
load_probe_metadata(*, vendor, probe_key, data, _config, session=None)
Write object to table
Source code in opensampl/load_data.py
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 |
|
load_time_data(probe_key, metric_type, reference_type, data, _config, compound_key=None, strict=True, session=None)
Write time data to probe_data table
Parameters:
Name | Type | Description | Default |
---|---|---|---|
probe_key
|
ProbeKey
|
ProbeKey object |
required |
metric_type
|
MetricType
|
MetricType object |
required |
reference_type
|
ReferenceType
|
ReferenceType object |
required |
data
|
DataFrame
|
pandas dataframe with time and value columns |
required |
_config
|
BaseConfig
|
BaseSettings object, automatically filled by route wrapper |
required |
compound_key
|
Optional[dict[str, Any]]
|
UUID for the reference if reference type is compound |
None
|
strict
|
bool
|
If true, raises error if any of the data parts (reference/metric/etc) not found. If false, creates new probe. Default: True |
True
|
session
|
Optional[Session]
|
SQLAlchemy session |
None
|
Source code in opensampl/load_data.py
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
|
write_to_table(table, data, _config, if_exists='update', session=None)
Write object to table with configurable behavior for handling conflicts.
table: Name of the table to write to
data: Dictionary of column names and values to write
_config: BaseSettings object, automatically filled by route wrapper
if_exists: How to handle conflicts with existing entries. One of:
- 'update': Only update fields that are provided and non-default (default)
- 'error': Raise an error if entry exists
- 'replace': Replace all non-primary-key fields with new values
- 'ignore': Skip if entry exists
session: Optional SQLAlchemy session
ValueError: If table not found or invalid on_conflict value
SQLAlchemyError: For database errors
Source code in opensampl/load_data.py
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
|