ga-api-client 0.3.2__tar.gz → 0.6.5__tar.gz

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.
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.4
2
2
  Name: ga-api-client
3
- Version: 0.3.2
3
+ Version: 0.6.5
4
4
  Classifier: Programming Language :: Python :: 3
5
5
  Classifier: License :: OSI Approved :: MIT License
6
6
  Classifier: Operating System :: OS Independent
@@ -10,6 +10,8 @@ License-File: LICENSE
10
10
  Requires-Dist: pandas>=1.4
11
11
  Requires-Dist: aiohttp>=3.8
12
12
  Requires-Dist: cryptography>=36.0
13
+ Requires-Dist: async-timeout>=5.0
14
+ Dynamic: license-file
13
15
 
14
16
  # GenieAnalytics Python Client
15
17
 
@@ -21,6 +23,19 @@ This package is the official Python client to access GenieAnalytics API server.
21
23
  pip install ga-api-client
22
24
  ```
23
25
 
26
+ ## Linter
27
+ - flake8
28
+ ```
29
+ pip install flake8
30
+ flake8 --max-complexity=10 --max-line-length=127 .
31
+ ```
32
+
33
+ - mypy
34
+ ```
35
+ pip install mypy
36
+ mypy .
37
+ ```
38
+
24
39
  ## Import Modules
25
40
 
26
41
  ```python
@@ -8,6 +8,19 @@ This package is the official Python client to access GenieAnalytics API server.
8
8
  pip install ga-api-client
9
9
  ```
10
10
 
11
+ ## Linter
12
+ - flake8
13
+ ```
14
+ pip install flake8
15
+ flake8 --max-complexity=10 --max-line-length=127 .
16
+ ```
17
+
18
+ - mypy
19
+ ```
20
+ pip install mypy
21
+ mypy .
22
+ ```
23
+
11
24
  ## Import Modules
12
25
 
13
26
  ```python
@@ -0,0 +1,8 @@
1
+ from .ga_api_client import System, Tenant, Repository, pprint
2
+ from .hyper_log_log import HyperLogLog
3
+ from .rate import Rate
4
+ from .capture import CaptureMin, CaptureMax, CaptureAnyMin, CaptureAnyMax
5
+ from .std import Std
6
+ from .average import Average
7
+ from .tdigest import TDigest
8
+ from .field_tree import FieldTable, field_table
@@ -0,0 +1,27 @@
1
+ import math
2
+
3
+ class Average:
4
+ def __init__(self, arg=[0, 0]):
5
+ self._sum = arg[0]
6
+ self._count = arg[1]
7
+ def __add__(self, other):
8
+ return Average([self._sum + other._sum, self._count + other._count])
9
+
10
+ def __radd__(self, other):
11
+ return Average([self._sum + other._sum, self._count + other._count])
12
+
13
+ def __iadd__(self, other):
14
+ self._sum += other._sum
15
+ self._count += other._count
16
+ return self
17
+
18
+ def __str__(self):
19
+ return f'{self.value()}'
20
+
21
+ def __repr__(self):
22
+ return f'$avg(sum={self._sum}, count={self._count})'
23
+
24
+ def value(self):
25
+ if self._count == 0:
26
+ return math.nan
27
+ return self._sum / self._count
@@ -0,0 +1,99 @@
1
+ from datetime import datetime, timezone
2
+ class CaptureBase:
3
+ def __init__(self, value=None, time=None):
4
+ # 如果 value 是列表,則分配 _v 和 _t
5
+ if isinstance(value, list):
6
+ time = value[0]
7
+ self._v = value[1]
8
+ else:
9
+ self._v = value
10
+
11
+ # convert _v to datetime object
12
+ self._v = self._parse_datetime(self._v)
13
+
14
+ # convert _t to datetime object
15
+ self._t = self._parse_datetime(time)
16
+
17
+ if self._t is None:
18
+ self._t = datetime.fromtimestamp(0, tz=timezone.utc)
19
+
20
+
21
+ def _parse_datetime(self, date_str):
22
+ if isinstance(date_str, str) and date_str.startswith('d:'):
23
+ try:
24
+ dt = datetime.strptime(date_str[2:-1], "%Y-%m-%dT%H:%M:%S.%f")
25
+ return dt.replace(tzinfo=timezone.utc)
26
+ except ValueError as e:
27
+ raise ValueError(f"Invalid datetime format: {date_str}") from e
28
+ return date_str
29
+
30
+ def compare(self, other):
31
+ raise NotImplementedError("Subclasses must implement `compare` method.")
32
+
33
+ def __add__(self, other):
34
+ if self._t is None:
35
+ return self.__class__([other._v, other._t])
36
+ if other._t is None:
37
+ return self.__class__([self._v, self._t])
38
+ return self.compare(other)
39
+
40
+ def __radd__(self, other):
41
+ return self + other
42
+
43
+ def __iadd__(self, other):
44
+ if self._t is None:
45
+ self._v = other._v
46
+ self._t = other._t
47
+ elif other._t is not None:
48
+ result = self.compare(other)
49
+ self._v = result._v
50
+ self._t = result._t
51
+ return self
52
+
53
+ def __str__(self):
54
+ return f'{self._v}'
55
+
56
+ def __repr__(self):
57
+ return f'{self.__class__.__name__}(v={repr(self._v)}, t={repr(self._t)})'
58
+
59
+
60
+ class CaptureAnyMin(CaptureBase):
61
+ def compare(self, other):
62
+ print(repr(self), repr(other))
63
+ if self._t is None:
64
+ return self.__class__([other._t, other._v])
65
+ elif other._t is None:
66
+ return self.__class__([self._t, self._v])
67
+ elif self._t < other._t:
68
+ return self.__class__([self._t, self._v])
69
+ return self.__class__([other._t, other._v])
70
+
71
+
72
+ class CaptureAnyMax(CaptureBase):
73
+ def compare(self, other):
74
+ print(repr(self), repr(other))
75
+ if self._t is None:
76
+ return self.__class__([other._t, other._v])
77
+ elif other._t is None:
78
+ return self.__class__([self._t, self._v])
79
+ elif self._t > other._t:
80
+ return self.__class__([self._t, self._v])
81
+ return self.__class__([other._t, other._v])
82
+
83
+
84
+ class CaptureMin(CaptureBase):
85
+ def compare(self, other):
86
+ if self._v is None:
87
+ return self.__class__([other._t, other._v ])
88
+ elif other._v is None:
89
+ return self.__class__([self._t, self._v])
90
+ return self.__class__([self._t, min(self._v, other._v)])
91
+
92
+
93
+ class CaptureMax(CaptureBase):
94
+ def compare(self, other):
95
+ if self._v is None:
96
+ return self.__class__([other._t, other._v ])
97
+ elif other._v is None:
98
+ return self.__class__([self._t, self._v])
99
+ return self.__class__([self._t, max(self._v, other._v)])