dp3.database.snapshots ¶
TypedSnapshotCollection ¶
TypedSnapshotCollection(db: Database, entity_type: str, db_config: MongoConfig, model_spec: ModelSpec, snapshots_config: dict)
Bases: ABC
Snapshot collection handler with eid type awareness.
Source code in dp3/database/snapshots.py
get_latest_one ¶
Get latest snapshot of given eid.
If doesn't exist, returns {}.
Source code in dp3/database/snapshots.py
get_latest ¶
get_latest(fulltext_filters: Optional[dict[str, str]] = None, generic_filter: Optional[dict[str, Any]] = None) -> tuple[Cursor, int]
Get latest snapshots of given etype
.
This method is useful for displaying data on web.
Returns only documents matching generic_filter
and fulltext_filters
(dictionary attribute - fulltext filter).
Fulltext 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, ensure the EID is string, then use attribute eid
.
Otherwise, use generic filter.
Generic filter allows filtering using generic MongoDB query (including $and
, $or
,
$lt
, etc.).
For querying non-JSON-native types, you can use magic strings, such as
"$$IPv4{<ip address>}"
for IPv4 addresses. The full spec with examples is in the
magic strings module.
Generic and fulltext filters are merged - fulltext overrides conflicting keys.
Also returns total document count (after filtering).
May raise SnapshotCollectionError
if query is invalid.
Source code in dp3/database/snapshots.py
find_latest ¶
find_latest(fulltext_filters: Optional[dict[str, str]] = None, generic_filter: Optional[dict[str, Any]] = None) -> Cursor
Find latest snapshots of given etype
.
See get_latest
for more information.
Returns only documents matching generic_filter
and fulltext_filters
,
does not count them.
Source code in dp3/database/snapshots.py
count_latest ¶
count_latest(fulltext_filters: Optional[dict[str, str]] = None, generic_filter: Optional[dict[str, Any]] = None) -> int
Count latest snapshots of given etype
.
See get_latest
for more information.
Returns only count of documents matching generic_filter
and fulltext_filters
.
Note that this method may take much longer than get_latest
on larger databases,
as it does count all documents, not just return the first few.
Source code in dp3/database/snapshots.py
get_by_eid ¶
get_by_eid(eid: AnyEidT, t1: Optional[datetime] = None, t2: Optional[datetime] = None) -> Union[Cursor, CommandCursor]
Get all (or filtered) snapshots of given eid
.
This method is useful for displaying eid
's history on web.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
eid
|
AnyEidT
|
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/snapshots.py
get_distinct_val_count ¶
Counts occurrences 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/snapshots.py
save_one ¶
Saves snapshot to specified entity of current master document.
Will move snapshot to oversized snapshots if the maintained bucket is too large.
Source code in dp3/database/snapshots.py
save_many ¶
Saves a list of snapshots of current master documents.
All snapshots must belong to same entity type.
Will move snapshots to oversized snapshots if the maintained bucket is too large.
For better understanding, see save()
.
Source code in dp3/database/snapshots.py
507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 |
|
delete_old ¶
Delete old snapshots.
Periodically called from HistoryManager.
Source code in dp3/database/snapshots.py
delete_eid ¶
Delete all snapshots of eid
.
Source code in dp3/database/snapshots.py
delete_eids ¶
Delete all snapshots of eids
.
Source code in dp3/database/snapshots.py
BinaryEidSnapshots ¶
BinaryEidSnapshots(db: Database, entity_type: str, db_config: MongoConfig, model_spec: ModelSpec, snapshots_config: dict)
Bases: TypedSnapshotCollection
, ABC
Source code in dp3/database/snapshots.py
SnapshotCollectionContainer ¶
SnapshotCollectionContainer(db: Database, db_config: MongoConfig, model_spec: ModelSpec, snapshots_config: dict)
Container for all required snapshot collections, exposing the public interface.
Source code in dp3/database/snapshots.py
save_one ¶
Save snapshot to specified entity of current master document.
save_many ¶
Saves a list of snapshots of current master documents.
All snapshots must belong to same entity type.
Source code in dp3/database/snapshots.py
get_latest_one ¶
Get latest snapshot of given eid.
If doesn't exist, returns {}.
get_latest ¶
get_latest(entity_type: str, fulltext_filters: Optional[dict[str, str]] = None, generic_filter: Optional[dict[str, Any]] = None) -> tuple[Cursor, int]
Get latest snapshots of given etype
.
This method is useful for displaying data on web.
Returns only documents matching generic_filter
and fulltext_filters
(dictionary attribute - fulltext filter).
Fulltext 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, ensure the EID is string, then use attribute eid
.
Otherwise, use generic filter.
Generic filter allows filtering using generic MongoDB query (including $and
, $or
,
$lt
, etc.).
For querying non-JSON-native types, you can use magic strings, such as
"$$IPv4{<ip address>}"
for IPv4 addresses. The full spec with examples is in the
magic strings module.
Generic and fulltext filters are merged - fulltext overrides conflicting keys.
Also returns total document count (after filtering).
May raise SnapshotCollectionError
if query is invalid.
Source code in dp3/database/snapshots.py
find_latest ¶
find_latest(entity_type: str, fulltext_filters: Optional[dict[str, str]] = None, generic_filter: Optional[dict[str, Any]] = None) -> Cursor
Find latest snapshots of given etype
.
see get_latest
for more information.
Returns only documents matching generic_filter
and fulltext_filters
,
does not count them.
Source code in dp3/database/snapshots.py
count_latest ¶
count_latest(entity_type: str, fulltext_filters: Optional[dict[str, str]] = None, generic_filter: Optional[dict[str, Any]] = None) -> int
Count latest snapshots of given etype
.
see get_latest
for more information.
Returns only count of documents matching generic_filter
and fulltext_filters
.
Note that this method may take much longer than get_latest
on larger databases,
as it does count all documents, not just return the first few.
Source code in dp3/database/snapshots.py
get_by_eid ¶
get_by_eid(entity_type: str, eid: AnyEidT, t1: Optional[datetime] = None, t2: Optional[datetime] = None) -> Union[Cursor, CommandCursor]
Get all (or filtered) snapshots of given eid
.
This method is useful for displaying eid
's history on web.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
entity_type
|
str
|
name of entity type |
required |
eid
|
AnyEidT
|
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/snapshots.py
get_distinct_val_count ¶
Counts occurrences 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/snapshots.py
delete_old ¶
Delete old snapshots, may raise SnapshotCollectionError
.
Periodically called from HistoryManager. Returns: number of deleted snapshots.