scruby 0.9.0__py3-none-any.whl → 0.17.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.
scruby/__init__.py CHANGED
@@ -1,21 +1,29 @@
1
- """A fast key-value storage library.
2
-
3
- Scruby is a fast key-value storage asynchronous library that provides an
4
- ordered mapping from string keys to string values.
5
- The library uses fractal-tree addressing.
6
-
7
- The database consists of collections.
8
- The maximum size of the one collection is 16**8=4294967296 branches,
9
- each branch can store one or more keys.
10
-
11
- The value of any key in collection can be obtained in 8 steps,
12
- thereby achieving high performance.
13
-
14
- In the future, to search by value of key, the use of a quantum loop is supposed.
15
- """
16
-
17
- from __future__ import annotations
18
-
19
- __all__ = ("Scruby",)
20
-
21
- from scruby.db import Scruby
1
+ """Asynchronous library for building and managing a hybrid database, by scheme of key-value.
2
+
3
+ The library uses fractal-tree addressing and
4
+ the search for documents based on the effect of a quantum loop.
5
+
6
+ The database consists of collections.
7
+ The maximum size of the one collection is 16**8=4294967296 branches,
8
+ each branch can store one or more keys.
9
+
10
+ The value of any key in collection can be obtained in 8 steps,
11
+ thereby achieving high performance.
12
+
13
+ The effectiveness of the search for documents based on a quantum loop,
14
+ requires a large number of processor threads.
15
+ """
16
+
17
+ from __future__ import annotations
18
+
19
+ __all__ = ("Scruby",)
20
+
21
+ import logging
22
+
23
+ from scruby.db import Scruby
24
+
25
+ logging.basicConfig(
26
+ level=logging.INFO,
27
+ datefmt="%Y-%m-%d %H:%M:%S",
28
+ format="[%(asctime)s.%(msecs)03d] %(module)10s:%(lineno)-3d %(levelname)-7s - %(message)s",
29
+ )
scruby/aggregation.py ADDED
@@ -0,0 +1,148 @@
1
+ """Aggregation classes."""
2
+
3
+ from __future__ import annotations
4
+
5
+ __all__ = (
6
+ "Average",
7
+ "Counter",
8
+ "Max",
9
+ "Min",
10
+ "Sum",
11
+ )
12
+
13
+ from decimal import ROUND_HALF_EVEN, Decimal
14
+ from typing import Any
15
+
16
+
17
+ class Average:
18
+ """Aggregation class for calculating the average value.
19
+
20
+ Args:
21
+ precision: The accuracy of rounding. `By default = .00`
22
+ rounding: Rounding mode. `By default = ROUND_HALF_EVEN`
23
+ """
24
+
25
+ def __init__( # noqa: D107
26
+ self,
27
+ precision: str = ".00",
28
+ rounding: str = ROUND_HALF_EVEN,
29
+ ) -> None:
30
+ self.value = Decimal()
31
+ self.counter = 0
32
+ self.precision = precision
33
+ self.rounding = rounding
34
+
35
+ def set(self, number: int | float) -> None:
36
+ """Add value.
37
+
38
+ Args:
39
+ number: Current value (int | float).
40
+ """
41
+ self.value += Decimal(str(number))
42
+ self.counter += 1
43
+
44
+ def get(self) -> Decimal:
45
+ """Get arithmetic average value.
46
+
47
+ Returns:
48
+ Number (Decimal) - Average value.
49
+ """
50
+ return (self.value / Decimal(str(self.counter))).quantize(
51
+ exp=Decimal(self.precision),
52
+ rounding=self.rounding,
53
+ )
54
+
55
+
56
+ class Counter:
57
+ """Aggregation class for calculating the number of documents.
58
+
59
+ Args:
60
+ limit: The maximum counter value.
61
+ """
62
+
63
+ def __init__(self, limit: int = 1000) -> None: # noqa: D107
64
+ self.limit = limit
65
+ self.counter = 0
66
+
67
+ def check(self) -> bool:
68
+ """Check the condition of the counter.
69
+
70
+ Returns:
71
+ Boolean value. If `True`, the maximum value is achieved.
72
+ """
73
+ return self.counter >= self.limit
74
+
75
+ def next(self) -> None:
76
+ """Increment the counter on one."""
77
+ self.counter += 1
78
+
79
+
80
+ class Max:
81
+ """Aggregation class for calculating the maximum value."""
82
+
83
+ def __init__(self) -> None: # noqa: D107
84
+ self.value: Any = 0
85
+
86
+ def set(self, number: int | float) -> None:
87
+ """Add value.
88
+
89
+ Args:
90
+ number: Current value.
91
+ """
92
+ if number > self.value:
93
+ self.value = number
94
+
95
+ def get(self) -> Any:
96
+ """Get maximum value.
97
+
98
+ Returns:
99
+ Number (int|float) - Maximum value.
100
+ """
101
+ return self.value
102
+
103
+
104
+ class Min:
105
+ """Aggregation class for calculating the minimum value."""
106
+
107
+ def __init__(self) -> None: # noqa: D107
108
+ self.value: Any = 0
109
+
110
+ def set(self, number: int | float) -> None:
111
+ """Add value.
112
+
113
+ Args:
114
+ number: Current value.
115
+ """
116
+ if self.value == 0 or number < self.value:
117
+ self.value = number
118
+
119
+ def get(self) -> Any:
120
+ """Get minimum value.
121
+
122
+ Returns:
123
+ Number (int|float) - Minimum value.
124
+ """
125
+ return self.value
126
+
127
+
128
+ class Sum:
129
+ """Aggregation class for calculating sum of values."""
130
+
131
+ def __init__(self) -> None: # noqa: D107
132
+ self.value = Decimal()
133
+
134
+ def set(self, number: int | float) -> None:
135
+ """Add value.
136
+
137
+ Args:
138
+ number: Current value.
139
+ """
140
+ self.value += Decimal(str(number))
141
+
142
+ def get(self) -> Decimal:
143
+ """Get sum of values.
144
+
145
+ Returns:
146
+ Number (int|float) - Sum of values.
147
+ """
148
+ return self.value
scruby/constants.py CHANGED
@@ -1,31 +1,31 @@
1
- """Constant variables.
2
-
3
- The module contains the following variables:
4
-
5
- - `DB_ROOT` - Path to root directory of database. `By default = "ScrubyDB"` (*in root of project*).
6
- - `LENGTH_REDUCTION_HASH` - The length of the hash reduction on the left side.
7
- - `0` - 4294967296 branches in collection (by default).
8
- - `2` - 16777216 branches in collectionю
9
- - `4` - 65536 branches in collectionю
10
- - `6` - 256 branches in collection (main purpose is tests).
11
- """
12
-
13
- from __future__ import annotations
14
-
15
- __all__ = (
16
- "DB_ROOT",
17
- "LENGTH_REDUCTION_HASH",
18
- )
19
-
20
- from typing import Literal
21
-
22
- # Path to root directory of database
23
- # By default = "ScrubyDB" (in root of project).
24
- DB_ROOT: str = "ScrubyDB"
25
-
26
- # The length of the hash reduction on the left side.
27
- # 0 = 4294967296 branches in collection (by default).
28
- # 2 = 16777216 branches in collectionю
29
- # 4 = 65536 branches in collectionю
30
- # 6 = 256 branches in collection (main purpose is tests).
31
- LENGTH_REDUCTION_HASH: Literal[0, 2, 4, 6] = 0
1
+ """Constant variables.
2
+
3
+ The module contains the following variables:
4
+
5
+ - `DB_ROOT` - Path to root directory of database. `By default = "ScrubyDB"` (*in root of project*).
6
+ - `HASH_REDUCE_LEFT` - The length of the hash reduction on the left side.
7
+ - `0` - 4294967296 branches in collection (by default).
8
+ - `2` - 16777216 branches in collectionю
9
+ - `4` - 65536 branches in collectionю
10
+ - `6` - 256 branches in collection (main purpose is tests).
11
+ """
12
+
13
+ from __future__ import annotations
14
+
15
+ __all__ = (
16
+ "DB_ROOT",
17
+ "HASH_REDUCE_LEFT",
18
+ )
19
+
20
+ from typing import Literal
21
+
22
+ # Path to root directory of database
23
+ # By default = "ScrubyDB" (in root of project).
24
+ DB_ROOT: str = "ScrubyDB"
25
+
26
+ # The length of the hash reduction on the left side.
27
+ # 0 = 4294967296 branches in collection (by default).
28
+ # 2 = 16777216 branches in collectionю
29
+ # 4 = 65536 branches in collectionю
30
+ # 6 = 256 branches in collection (main purpose is tests).
31
+ HASH_REDUCE_LEFT: Literal[0, 2, 4, 6] = 0