scruby 0.12.2__py3-none-any.whl → 0.13.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of scruby might be problematic. Click here for more details.
- scruby/aggregation.py +76 -0
- scruby/db.py +18 -45
- {scruby-0.12.2.dist-info → scruby-0.13.1.dist-info}/METADATA +1 -1
- scruby-0.13.1.dist-info/RECORD +10 -0
- scruby-0.12.2.dist-info/RECORD +0 -9
- {scruby-0.12.2.dist-info → scruby-0.13.1.dist-info}/WHEEL +0 -0
- {scruby-0.12.2.dist-info → scruby-0.13.1.dist-info}/licenses/LICENSE +0 -0
scruby/aggregation.py
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"""Aggregation classes."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
__all__ = (
|
|
6
|
+
"Average",
|
|
7
|
+
"Max",
|
|
8
|
+
"Min",
|
|
9
|
+
"Sum",
|
|
10
|
+
)
|
|
11
|
+
|
|
12
|
+
from typing import Any
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class Average:
|
|
16
|
+
"""Aggregation class for calculating the average value."""
|
|
17
|
+
|
|
18
|
+
def __init__(self) -> None: # noqa: D107
|
|
19
|
+
self.value = 0.0
|
|
20
|
+
self.counter = 0.0
|
|
21
|
+
|
|
22
|
+
def set(self, number: int | float) -> None:
|
|
23
|
+
"""Add value."""
|
|
24
|
+
self.value += float(number)
|
|
25
|
+
self.counter += 1.0
|
|
26
|
+
|
|
27
|
+
def get(self) -> float:
|
|
28
|
+
"""Get arithmetic average value."""
|
|
29
|
+
return self.value / self.counter
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class Max:
|
|
33
|
+
"""Aggregation class for calculating the maximum value."""
|
|
34
|
+
|
|
35
|
+
def __init__(self) -> None: # noqa: D107
|
|
36
|
+
self.value: Any = 0
|
|
37
|
+
|
|
38
|
+
def set(self, number: int | float) -> None:
|
|
39
|
+
"""Add value."""
|
|
40
|
+
if number > self.value:
|
|
41
|
+
self.value = number
|
|
42
|
+
|
|
43
|
+
def get(self) -> Any:
|
|
44
|
+
"""Get maximum value."""
|
|
45
|
+
return self.value
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
class Min:
|
|
49
|
+
"""Aggregation class for calculating the minimum value."""
|
|
50
|
+
|
|
51
|
+
def __init__(self) -> None: # noqa: D107
|
|
52
|
+
self.value: Any = 0
|
|
53
|
+
|
|
54
|
+
def set(self, number: int | float) -> None:
|
|
55
|
+
"""Add value."""
|
|
56
|
+
if self.value == 0 or number < self.value:
|
|
57
|
+
self.value = number
|
|
58
|
+
|
|
59
|
+
def get(self) -> Any:
|
|
60
|
+
"""Get minimum value."""
|
|
61
|
+
return self.value
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
class Sum:
|
|
65
|
+
"""Aggregation class for calculating sum of values."""
|
|
66
|
+
|
|
67
|
+
def __init__(self) -> None: # noqa: D107
|
|
68
|
+
self.value: Any = 0
|
|
69
|
+
|
|
70
|
+
def set(self, number: int | float) -> None:
|
|
71
|
+
"""Add value."""
|
|
72
|
+
self.value += number
|
|
73
|
+
|
|
74
|
+
def get(self) -> Any:
|
|
75
|
+
"""Get sum of values."""
|
|
76
|
+
return self.value
|
scruby/db.py
CHANGED
|
@@ -45,7 +45,7 @@ class Scruby[T]:
|
|
|
45
45
|
self.__class_model = class_model
|
|
46
46
|
self.__db_root = constants.DB_ROOT
|
|
47
47
|
self.__hash_reduce_left = constants.HASH_REDUCE_LEFT
|
|
48
|
-
# The maximum number of
|
|
48
|
+
# The maximum number of branches.
|
|
49
49
|
match self.__hash_reduce_left:
|
|
50
50
|
case 0:
|
|
51
51
|
self.__max_branch_number = 4294967296
|
|
@@ -59,18 +59,18 @@ class Scruby[T]:
|
|
|
59
59
|
msg: str = f"{unreachable} - Unacceptable value for HASH_REDUCE_LEFT."
|
|
60
60
|
logger.critical(msg)
|
|
61
61
|
assert_never(Never(unreachable))
|
|
62
|
-
#
|
|
63
|
-
#
|
|
64
|
-
self._create_metadata()
|
|
65
|
-
|
|
66
|
-
def _create_metadata(self) -> None:
|
|
67
|
-
"""Create metadata for collection if absent.
|
|
68
|
-
|
|
69
|
-
This method is for internal use.
|
|
70
|
-
"""
|
|
62
|
+
# Caching a pati for metadata in the form of a tuple.
|
|
63
|
+
# The zero branch is reserved for metadata.
|
|
71
64
|
branch_number: int = 0
|
|
72
|
-
|
|
73
|
-
separated_hash: str = "/".join(list(
|
|
65
|
+
branch_number_as_hash: str = f"{branch_number:08x}"[constants.HASH_REDUCE_LEFT :]
|
|
66
|
+
separated_hash: str = "/".join(list(branch_number_as_hash))
|
|
67
|
+
self.__meta_path_tuple = (
|
|
68
|
+
constants.DB_ROOT,
|
|
69
|
+
class_model.__name__,
|
|
70
|
+
separated_hash,
|
|
71
|
+
"meta.json",
|
|
72
|
+
)
|
|
73
|
+
# Create metadata for collection, if required.
|
|
74
74
|
branch_path = SyncPath(
|
|
75
75
|
*(
|
|
76
76
|
self.__db_root,
|
|
@@ -87,29 +87,12 @@ class Scruby[T]:
|
|
|
87
87
|
meta_path = SyncPath(*(branch_path, "meta.json"))
|
|
88
88
|
meta_path.write_text(meta_json, "utf-8")
|
|
89
89
|
|
|
90
|
-
async def _get_meta_path(self) -> Path:
|
|
91
|
-
"""Asynchronous method for getting path to metadata of collection.
|
|
92
|
-
|
|
93
|
-
This method is for internal use.
|
|
94
|
-
"""
|
|
95
|
-
branch_number: int = 0
|
|
96
|
-
branch_number_as_hash: str = f"{branch_number:08x}"[self.__hash_reduce_left :]
|
|
97
|
-
separated_hash: str = "/".join(list(branch_number_as_hash))
|
|
98
|
-
return Path(
|
|
99
|
-
*(
|
|
100
|
-
self.__db_root,
|
|
101
|
-
self.__class_model.__name__,
|
|
102
|
-
separated_hash,
|
|
103
|
-
"meta.json",
|
|
104
|
-
),
|
|
105
|
-
)
|
|
106
|
-
|
|
107
90
|
async def _get_meta(self) -> _Meta:
|
|
108
91
|
"""Asynchronous method for getting metadata of collection.
|
|
109
92
|
|
|
110
93
|
This method is for internal use.
|
|
111
94
|
"""
|
|
112
|
-
meta_path =
|
|
95
|
+
meta_path = Path(*self.__meta_path_tuple)
|
|
113
96
|
meta_json = await meta_path.read_text()
|
|
114
97
|
meta: _Meta = self.__meta.model_validate_json(meta_json)
|
|
115
98
|
return meta
|
|
@@ -119,8 +102,8 @@ class Scruby[T]:
|
|
|
119
102
|
|
|
120
103
|
This method is for internal use.
|
|
121
104
|
"""
|
|
122
|
-
meta_path = await self._get_meta_path()
|
|
123
105
|
meta_json = meta.model_dump_json()
|
|
106
|
+
meta_path = Path(*self.__meta_path_tuple)
|
|
124
107
|
await meta_path.write_text(meta_json, "utf-8")
|
|
125
108
|
|
|
126
109
|
async def _counter_documents(self, step: Literal[1, -1]) -> None:
|
|
@@ -128,7 +111,7 @@ class Scruby[T]:
|
|
|
128
111
|
|
|
129
112
|
This method is for internal use.
|
|
130
113
|
"""
|
|
131
|
-
meta_path =
|
|
114
|
+
meta_path = Path(*self.__meta_path_tuple)
|
|
132
115
|
meta_json = await meta_path.read_text("utf-8")
|
|
133
116
|
meta: _Meta = self.__meta.model_validate_json(meta_json)
|
|
134
117
|
meta.counter_documents += step
|
|
@@ -140,17 +123,7 @@ class Scruby[T]:
|
|
|
140
123
|
|
|
141
124
|
This method is for internal use.
|
|
142
125
|
"""
|
|
143
|
-
|
|
144
|
-
branch_number_as_hash: str = f"{branch_number:08x}"[self.__hash_reduce_left :]
|
|
145
|
-
separated_hash: str = "/".join(list(branch_number_as_hash))
|
|
146
|
-
meta_path = SyncPath(
|
|
147
|
-
*(
|
|
148
|
-
self.__db_root,
|
|
149
|
-
self.__class_model.__name__,
|
|
150
|
-
separated_hash,
|
|
151
|
-
"meta.json",
|
|
152
|
-
),
|
|
153
|
-
)
|
|
126
|
+
meta_path = SyncPath(*self.__meta_path_tuple)
|
|
154
127
|
meta_json = meta_path.read_text("utf-8")
|
|
155
128
|
meta: _Meta = self.__meta.model_validate_json(meta_json)
|
|
156
129
|
meta.counter_documents += number
|
|
@@ -495,13 +468,13 @@ class Scruby[T]:
|
|
|
495
468
|
leaf_path.write_bytes(orjson.dumps(new_data))
|
|
496
469
|
return counter
|
|
497
470
|
|
|
498
|
-
def
|
|
471
|
+
def delete_many(
|
|
499
472
|
self,
|
|
500
473
|
filter_fn: Callable,
|
|
501
474
|
max_workers: int | None = None,
|
|
502
475
|
timeout: float | None = None,
|
|
503
476
|
) -> int:
|
|
504
|
-
"""
|
|
477
|
+
"""Delete one or more documents matching the filter.
|
|
505
478
|
|
|
506
479
|
The search is based on the effect of a quantum loop.
|
|
507
480
|
The search effectiveness depends on the number of processor threads.
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
scruby/__init__.py,sha256=GOVcjXmcOEDBbJQJDJlQq-x3M-VGJaMSN278EXsl2po,884
|
|
2
|
+
scruby/aggregation.py,sha256=AdVZNl9fV59pWMBQez5upQEuodAg3HIw0ixOnM8FrKg,1762
|
|
3
|
+
scruby/constants.py,sha256=3LZfcxcuRqwzoB0-iogLMjKBZRdxfWJmTbyPwVRhQgY,1007
|
|
4
|
+
scruby/db.py,sha256=OXtMqq9y6RQkHHWOgFVXqI96v7g58SIoLUq-h09WxjI,20899
|
|
5
|
+
scruby/errors.py,sha256=aHQri4LNcFVQrSHwjyzb1fL8O49SwjYEU4QgMOo4uyA,622
|
|
6
|
+
scruby/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
7
|
+
scruby-0.13.1.dist-info/METADATA,sha256=LlJPM_ZrH1yhQA7Yk0owqfigwt72Z2gRIVlDFdJ1cL4,10925
|
|
8
|
+
scruby-0.13.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
9
|
+
scruby-0.13.1.dist-info/licenses/LICENSE,sha256=2zZINd6m_jNYlowdQImlEizyhSui5cBAJZRhWQURcEc,1095
|
|
10
|
+
scruby-0.13.1.dist-info/RECORD,,
|
scruby-0.12.2.dist-info/RECORD
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
scruby/__init__.py,sha256=GOVcjXmcOEDBbJQJDJlQq-x3M-VGJaMSN278EXsl2po,884
|
|
2
|
-
scruby/constants.py,sha256=3LZfcxcuRqwzoB0-iogLMjKBZRdxfWJmTbyPwVRhQgY,1007
|
|
3
|
-
scruby/db.py,sha256=-xNn0S2fcIQoar4fYk6ER2p7dlDIeUY-BAD6LLYtFFo,21733
|
|
4
|
-
scruby/errors.py,sha256=aHQri4LNcFVQrSHwjyzb1fL8O49SwjYEU4QgMOo4uyA,622
|
|
5
|
-
scruby/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
6
|
-
scruby-0.12.2.dist-info/METADATA,sha256=YK-ZgnJEcS7y0R27hh7GTlRSAexq5H9olStIQKZL7sc,10925
|
|
7
|
-
scruby-0.12.2.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
8
|
-
scruby-0.12.2.dist-info/licenses/LICENSE,sha256=2zZINd6m_jNYlowdQImlEizyhSui5cBAJZRhWQURcEc,1095
|
|
9
|
-
scruby-0.12.2.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|