scruby 0.15.0__py3-none-any.whl → 0.15.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 CHANGED
@@ -4,37 +4,53 @@ from __future__ import annotations
4
4
 
5
5
  __all__ = (
6
6
  "Average",
7
+ "Counter",
7
8
  "Max",
8
9
  "Min",
9
10
  "Sum",
10
11
  )
11
12
 
13
+ from decimal import ROUND_HALF_EVEN, Decimal
12
14
  from typing import Any
13
15
 
14
16
 
15
17
  class Average:
16
- """Aggregation class for calculating the average value."""
18
+ """Aggregation class for calculating the average value.
17
19
 
18
- def __init__(self) -> None: # noqa: D107
19
- self.value = 0.0
20
- self.counter = 0.0
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
21
34
 
22
35
  def set(self, number: int | float) -> None:
23
36
  """Add value.
24
37
 
25
38
  Args:
26
- number: Current value.
39
+ number: Current value (int | float).
27
40
  """
28
- self.value += float(number)
29
- self.counter += 1.0
41
+ self.value += Decimal(str(number))
42
+ self.counter += 1
30
43
 
31
- def get(self) -> float:
44
+ def get(self) -> Decimal:
32
45
  """Get arithmetic average value.
33
46
 
34
47
  Returns:
35
- Number (int|float) - Average value.
48
+ Number (Decimal) - Average value.
36
49
  """
37
- return self.value / self.counter
50
+ return (self.value / Decimal(str(self.counter))).quantize(
51
+ exp=Decimal(self.precision),
52
+ rounding=self.rounding,
53
+ )
38
54
 
39
55
 
40
56
  class Counter:
@@ -44,7 +60,7 @@ class Counter:
44
60
  limit: The maximum counter value.
45
61
  """
46
62
 
47
- def __init__(self, limit: int = 1000) -> None:
63
+ def __init__(self, limit: int = 1000) -> None: # noqa: D107
48
64
  self.limit = limit
49
65
  self.counter = 0
50
66
 
@@ -113,7 +129,7 @@ class Sum:
113
129
  """Aggregation class for calculating sum of values."""
114
130
 
115
131
  def __init__(self) -> None: # noqa: D107
116
- self.value: Any = 0
132
+ self.value = Decimal()
117
133
 
118
134
  def set(self, number: int | float) -> None:
119
135
  """Add value.
@@ -121,9 +137,9 @@ class Sum:
121
137
  Args:
122
138
  number: Current value.
123
139
  """
124
- self.value += number
140
+ self.value += Decimal(str(number))
125
141
 
126
- def get(self) -> Any:
142
+ def get(self) -> Decimal:
127
143
  """Get sum of values.
128
144
 
129
145
  Returns:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: scruby
3
- Version: 0.15.0
3
+ Version: 0.15.1
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
@@ -1,10 +1,10 @@
1
1
  scruby/__init__.py,sha256=GOVcjXmcOEDBbJQJDJlQq-x3M-VGJaMSN278EXsl2po,884
2
- scruby/aggregation.py,sha256=x_9ZJQHJHDISxRvddS5A2Hb0saIcfPTh1Veyf2KgX8A,2919
2
+ scruby/aggregation.py,sha256=_SUo9gL9yrtr94F-BNaBpuMkEfxtxtcvuOUqw7Ryygs,3466
3
3
  scruby/constants.py,sha256=3LZfcxcuRqwzoB0-iogLMjKBZRdxfWJmTbyPwVRhQgY,1007
4
4
  scruby/db.py,sha256=FNW_o2JDd_RnGpOdsEfSubMH8kcO7CSoej52y9vJwnc,25769
5
5
  scruby/errors.py,sha256=aHQri4LNcFVQrSHwjyzb1fL8O49SwjYEU4QgMOo4uyA,622
6
6
  scruby/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
7
- scruby-0.15.0.dist-info/METADATA,sha256=0-3PkQkRh7wCbeXnYaqvmE_BPeiKx3CrWT2VpC_CBPc,10925
8
- scruby-0.15.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
9
- scruby-0.15.0.dist-info/licenses/LICENSE,sha256=2zZINd6m_jNYlowdQImlEizyhSui5cBAJZRhWQURcEc,1095
10
- scruby-0.15.0.dist-info/RECORD,,
7
+ scruby-0.15.1.dist-info/METADATA,sha256=shka5n94xxvbJ8FHWvMryCvzpEmrWyJ6Z2xzS4A0o9g,10925
8
+ scruby-0.15.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
9
+ scruby-0.15.1.dist-info/licenses/LICENSE,sha256=2zZINd6m_jNYlowdQImlEizyhSui5cBAJZRhWQURcEc,1095
10
+ scruby-0.15.1.dist-info/RECORD,,