scruby 0.12.3__py3-none-any.whl → 0.14.0__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 ADDED
@@ -0,0 +1,129 @@
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
+
25
+ Args:
26
+ number: Current value.
27
+ """
28
+ self.value += float(number)
29
+ self.counter += 1.0
30
+
31
+ def get(self) -> float:
32
+ """Get arithmetic average value.
33
+
34
+ Returns:
35
+ Number (int|float) - Average value.
36
+ """
37
+ return self.value / self.counter
38
+
39
+
40
+ class Counter:
41
+ """Aggregation class for calculating the number of documents.
42
+
43
+ Args:
44
+ max: The maximum counter value.
45
+ """
46
+
47
+ def __init__(self, max: int = 1000) -> None:
48
+ self.max = max
49
+ self.counter = 0
50
+
51
+ def check(self) -> bool:
52
+ """Check the condition of the counter.
53
+
54
+ Returns:
55
+ Boolean value. If `True`, the maximum value is achieved.
56
+ """
57
+ self.counter += 1
58
+ return self.counter == self.max
59
+
60
+
61
+ class Max:
62
+ """Aggregation class for calculating the maximum value."""
63
+
64
+ def __init__(self) -> None: # noqa: D107
65
+ self.value: Any = 0
66
+
67
+ def set(self, number: int | float) -> None:
68
+ """Add value.
69
+
70
+ Args:
71
+ number: Current value.
72
+ """
73
+ if number > self.value:
74
+ self.value = number
75
+
76
+ def get(self) -> Any:
77
+ """Get maximum value.
78
+
79
+ Returns:
80
+ Number (int|float) - Maximum value.
81
+ """
82
+ return self.value
83
+
84
+
85
+ class Min:
86
+ """Aggregation class for calculating the minimum value."""
87
+
88
+ def __init__(self) -> None: # noqa: D107
89
+ self.value: Any = 0
90
+
91
+ def set(self, number: int | float) -> None:
92
+ """Add value.
93
+
94
+ Args:
95
+ number: Current value.
96
+ """
97
+ if self.value == 0 or number < self.value:
98
+ self.value = number
99
+
100
+ def get(self) -> Any:
101
+ """Get minimum value.
102
+
103
+ Returns:
104
+ Number (int|float) - Minimum value.
105
+ """
106
+ return self.value
107
+
108
+
109
+ class Sum:
110
+ """Aggregation class for calculating sum of values."""
111
+
112
+ def __init__(self) -> None: # noqa: D107
113
+ self.value: Any = 0
114
+
115
+ def set(self, number: int | float) -> None:
116
+ """Add value.
117
+
118
+ Args:
119
+ number: Current value.
120
+ """
121
+ self.value += number
122
+
123
+ def get(self) -> Any:
124
+ """Get sum of values.
125
+
126
+ Returns:
127
+ Number (int|float) - Sum of values.
128
+ """
129
+ return self.value
scruby/db.py CHANGED
@@ -102,8 +102,8 @@ class Scruby[T]:
102
102
 
103
103
  This method is for internal use.
104
104
  """
105
- meta_path = Path(*self.__meta_path_tuple)
106
105
  meta_json = meta.model_dump_json()
106
+ meta_path = Path(*self.__meta_path_tuple)
107
107
  await meta_path.write_text(meta_json, "utf-8")
108
108
 
109
109
  async def _counter_documents(self, step: Literal[1, -1]) -> None:
@@ -468,13 +468,13 @@ class Scruby[T]:
468
468
  leaf_path.write_bytes(orjson.dumps(new_data))
469
469
  return counter
470
470
 
471
- def find_many_and_delete(
471
+ def delete_many(
472
472
  self,
473
473
  filter_fn: Callable,
474
474
  max_workers: int | None = None,
475
475
  timeout: float | None = None,
476
476
  ) -> int:
477
- """Finds one or more documents matching the filter and deletes their.
477
+ """Delete one or more documents matching the filter.
478
478
 
479
479
  The search is based on the effect of a quantum loop.
480
480
  The search effectiveness depends on the number of processor threads.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: scruby
3
- Version: 0.12.3
3
+ Version: 0.14.0
4
4
  Summary: A fast key-value storage library.
5
5
  Project-URL: Homepage, https://github.com/kebasyaty/scruby
6
6
  Project-URL: Repository, https://github.com/kebasyaty/scruby
@@ -0,0 +1,10 @@
1
+ scruby/__init__.py,sha256=GOVcjXmcOEDBbJQJDJlQq-x3M-VGJaMSN278EXsl2po,884
2
+ scruby/aggregation.py,sha256=q84saKAP72n_VM83fEX_UY9QFz4EyVkHCVuB_1kweDQ,2833
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.14.0.dist-info/METADATA,sha256=p6ClZqXYNOcJtNHLgnYXW_CZStKogI-vgqrkmvbMn-w,10925
8
+ scruby-0.14.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
9
+ scruby-0.14.0.dist-info/licenses/LICENSE,sha256=2zZINd6m_jNYlowdQImlEizyhSui5cBAJZRhWQURcEc,1095
10
+ scruby-0.14.0.dist-info/RECORD,,
@@ -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=H70ODq0SXtEBB6iTBFA_l-fZ0L1zFq5Nb_PT3Ad2TZs,20925
4
- scruby/errors.py,sha256=aHQri4LNcFVQrSHwjyzb1fL8O49SwjYEU4QgMOo4uyA,622
5
- scruby/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
- scruby-0.12.3.dist-info/METADATA,sha256=C7rNCceHMaFezgzg4TEvUR_vOivfvGG3bpgPOQrucLg,10925
7
- scruby-0.12.3.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
8
- scruby-0.12.3.dist-info/licenses/LICENSE,sha256=2zZINd6m_jNYlowdQImlEizyhSui5cBAJZRhWQURcEc,1095
9
- scruby-0.12.3.dist-info/RECORD,,