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
find_latest ¶
find_latest(fulltext_filters: dict[str, str] | None = None, generic_filter: dict[str, Any] | None = None) -> Cursor
Find 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.
May raise SnapshotCollectionError if query is invalid.
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: dict[str, str] | None = None, generic_filter: dict[str, Any] | None = None) -> int
Count latest snapshots of given etype.
See find_latest
for more information.
Returns only count of documents matching generic_filter and fulltext_filters.
Note that this method may take much longer than find_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: datetime | None = None, t2: datetime | None = None, skip: int = 0, limit: int = 0) -> 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
|
datetime | None
|
left value of time interval (inclusive) |
None
|
t2
|
datetime | None
|
right value of time interval (inclusive) |
None
|
skip
|
int
|
number of snapshots to skip |
0
|
limit
|
int
|
max number of snapshots to return, |
0
|
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
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 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 | |
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 {}.
find_latest ¶
find_latest(entity_type: str, fulltext_filters: dict[str, str] | None = None, generic_filter: dict[str, Any] | None = None) -> Cursor
Find 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.
May raise SnapshotCollectionError if query is invalid.
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: dict[str, str] | None = None, generic_filter: dict[str, Any] | None = None) -> int
Count latest snapshots of given etype.
see find_latest
for more information.
Returns only count of documents matching generic_filter and fulltext_filters.
Note that this method may take much longer than find_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: datetime | None = None, t2: datetime | None = None, skip: int = 0, limit: int = 0) -> 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
|
datetime | None
|
left value of time interval (inclusive) |
None
|
t2
|
datetime | None
|
right value of time interval (inclusive) |
None
|
skip
|
int
|
number of snapshots to skip |
0
|
limit
|
int
|
max number of snapshots to return, |
0
|
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.