dp3.database.database ¶
MongoHostConfig ¶
Bases: BaseModel
MongoDB host.
MongoStandaloneConfig ¶
Bases: BaseModel
MongoDB standalone configuration.
MongoReplicaConfig ¶
Bases: BaseModel
MongoDB replica set configuration.
MongoConfig ¶
Bases: BaseModel
Database configuration.
EntityDatabase ¶
EntityDatabase(db_conf: HierarchicalDict, model_spec: ModelSpec, num_processes: int, elog: Optional[EventGroupType] = None)
MongoDB database wrapper responsible for whole communication with database server. Initializes database schema based on database configuration.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
db_conf |
HierarchicalDict
|
configuration of database connection (content of database.yml) |
required |
model_spec |
ModelSpec
|
ModelSpec object, configuration of data model (entities and attributes) |
required |
num_processes |
int
|
number of worker processes |
required |
Source code in dp3/database/database.py
register_on_entity_delete ¶
register_on_entity_delete(f_one: Callable[[str, str], None], f_many: Callable[[str, list[str]], None])
Registers function to be called when entity is forcibly deleted.
Source code in dp3/database/database.py
update_schema ¶
Checks whether schema saved in database is up-to-date and updates it if necessary.
Will NOT perform any changes in master collections on conflicting model changes. Any such changes must be performed via the CLI.
As this method modifies the schema collection, it should be called only by the main worker.
Source code in dp3/database/database.py
await_updated_schema ¶
Checks whether schema saved in database is up-to-date and awaits its update by the main worker on mismatch.
insert_datapoints ¶
Inserts datapoint to raw data collection and updates master record.
Raises DatabaseError when insert or update fails.
Source code in dp3/database/database.py
238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 |
|
update_master_records ¶
Replace master records of etype
:eid
with the provided records
.
Raises DatabaseError when update fails.
Source code in dp3/database/database.py
extend_ttl ¶
Extends TTL of given etype
:eid
by ttl_tokens
.
Source code in dp3/database/database.py
remove_expired_ttls ¶
Removes expired TTL of given etype
:eid
.
Source code in dp3/database/database.py
delete_eids ¶
Delete master record and all snapshots of etype
:eids
.
Source code in dp3/database/database.py
delete_eid ¶
Delete master record and all snapshots of etype
:eid
.
Source code in dp3/database/database.py
delete_old_dps ¶
Delete old datapoints from master collection.
Periodically called for all etype
s from HistoryManager.
Source code in dp3/database/database.py
delete_link_dps ¶
Delete link datapoints from master collection.
Called from LinkManager for deleted entities.
Source code in dp3/database/database.py
delete_many_link_dps ¶
delete_many_link_dps(etypes: list[str], affected_eids: list[list[str]], attr_names: list[str], eids_to: list[list[str]]) -> None
Delete link datapoints from master collection.
Called from LinkManager for deleted entities, when deleting multiple entities.
Source code in dp3/database/database.py
get_master_record ¶
Get current master record for etype/eid.
If doesn't exist, returns {}.
Source code in dp3/database/database.py
ekey_exists ¶
get_master_records ¶
Get cursor to current master records of etype.
Source code in dp3/database/database.py
get_worker_master_records ¶
get_worker_master_records(worker_index: int, worker_cnt: int, etype: str, query_filter: dict = None, **kwargs) -> pymongo.cursor.Cursor
Get cursor to current master records of etype.
Source code in dp3/database/database.py
get_latest_snapshot ¶
Get latest snapshot of given etype/eid.
If doesn't exist, returns {}.
Source code in dp3/database/database.py
get_latest_snapshots ¶
get_latest_snapshots(etype: str, fulltext_filters: Optional[dict[str, str]] = None) -> tuple[pymongo.cursor.Cursor, int]
Get latest snapshots of given etype
.
This method is useful for displaying data on web.
Returns only documents matching fulltext_filters
(dictionary attribute - fulltext filter).
These filters are interpreted as regular expressions.
Only string values may be filtered this way. There's no validation that queried attribute
can be fulltext filtered.
Only plain and observation attributes with string-based data types can be queried.
Array and set data types are supported as well as long as they are not multi value
at the same time.
If you need to filter EIDs, use attribute eid
.
Also returns total document count (after filtering).
May raise DatabaseError
if query is invalid.
Source code in dp3/database/database.py
get_snapshots ¶
get_snapshots(etype: str, eid: str, t1: Optional[datetime] = None, t2: Optional[datetime] = None) -> pymongo.cursor.Cursor
Get all (or filtered) snapshots of given eid
.
This method is useful for displaying eid
's history on web.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
etype |
str
|
entity type |
required |
eid |
str
|
id of entity, to which data-points correspond |
required |
t1 |
Optional[datetime]
|
left value of time interval (inclusive) |
None
|
t2 |
Optional[datetime]
|
right value of time interval (inclusive) |
None
|
Source code in dp3/database/database.py
get_value_or_history ¶
get_value_or_history(etype: str, attr_name: str, eid: str, t1: Optional[datetime] = None, t2: Optional[datetime] = None) -> dict
Gets current value and/or history of attribute for given eid
.
Depends on attribute type: - plain: just (current) value - observations: (current) value and history stored in master record (optionally filtered) - timeseries: just history stored in master record (optionally filtered)
Returns dict with two keys: current_value
and history
(list of values).
Source code in dp3/database/database.py
estimate_count_eids ¶
Estimates count of eid
s in given etype
Source code in dp3/database/database.py
save_snapshot ¶
Saves snapshot to specified entity of current master document.
Source code in dp3/database/database.py
save_snapshots ¶
Saves a list of snapshots of current master documents.
All snapshots must belong to same entity type.
Source code in dp3/database/database.py
save_metadata ¶
Saves snapshot to specified entity of current master document.
Source code in dp3/database/database.py
get_observation_history ¶
get_observation_history(etype: str, attr_name: str, eid: str, t1: datetime = None, t2: datetime = None, sort: int = None) -> list[dict]
Get full (or filtered) history of observation attribute.
This method is useful for displaying eid
's history on web.
Also used to feed data into get_timeseries_history()
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
etype |
str
|
entity type |
required |
attr_name |
str
|
name of attribute |
required |
eid |
str
|
id of entity, to which data-points correspond |
required |
t1 |
datetime
|
left value of time interval (inclusive) |
None
|
t2 |
datetime
|
right value of time interval (inclusive) |
None
|
sort |
int
|
sort by timestamps - 0: ascending order by t1, 1: descending order by t2, None: don't sort |
None
|
Returns: list of dicts (reduced datapoints)
Source code in dp3/database/database.py
get_timeseries_history ¶
get_timeseries_history(etype: str, attr_name: str, eid: str, t1: datetime = None, t2: datetime = None, sort: int = None) -> list[dict]
Get full (or filtered) history of timeseries attribute. Outputs them in format:
This method is useful for displayingeid
's history on web.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
etype |
str
|
entity type |
required |
attr_name |
str
|
name of attribute |
required |
eid |
str
|
id of entity, to which data-points correspond |
required |
t1 |
datetime
|
left value of time interval (inclusive) |
None
|
t2 |
datetime
|
right value of time interval (inclusive) |
None
|
sort |
int
|
sort by timestamps - |
None
|
Returns: list of dicts (reduced datapoints) - each represents just one point at time
Source code in dp3/database/database.py
get_distinct_val_count ¶
Counts occurences of distinct values of given attribute in snapshots.
Returns dictionary mapping value -> count.
Works for all plain and observation data types except dict
and json
.
Source code in dp3/database/database.py
get_raw ¶
Get raw datapoints where t1
is in <after
, before
).
If plain
is True
, then all plain datapoints will be returned (default).
Source code in dp3/database/database.py
delete_old_raw_dps ¶
Delete raw datapoints older than before
.
Deletes all plain datapoints if plain
is True
(default).
Source code in dp3/database/database.py
delete_old_snapshots ¶
Delete old snapshots.
Periodically called for all etype
s from HistoryManager.
Source code in dp3/database/database.py
get_module_cache ¶
Return a persistent cache collection for given module name.
Module name is determined automatically, but you can override it.
Source code in dp3/database/database.py
get_estimated_entity_count ¶
Get count of entities of given type.
get_caller_id ¶
Returns the name of the caller method's class, or function name if caller is not a method.