heurist-api 0.1.4__py3-none-any.whl → 0.2.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 heurist-api might be problematic. Click here for more details.
- heurist/cli/parse_log.py +22 -0
- heurist/log/__init__.py +2 -0
- heurist/log/iterator.py +16 -0
- heurist/log/model.py +42 -0
- {heurist_api-0.1.4.dist-info → heurist_api-0.2.0.dist-info}/METADATA +1 -1
- {heurist_api-0.1.4.dist-info → heurist_api-0.2.0.dist-info}/RECORD +9 -5
- {heurist_api-0.1.4.dist-info → heurist_api-0.2.0.dist-info}/entry_points.txt +1 -0
- {heurist_api-0.1.4.dist-info → heurist_api-0.2.0.dist-info}/WHEEL +0 -0
- {heurist_api-0.1.4.dist-info → heurist_api-0.2.0.dist-info}/licenses/LICENSE +0 -0
heurist/cli/parse_log.py
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import click
|
|
2
|
+
import csv
|
|
3
|
+
from heurist.log import yield_log_blocks, LogDetail
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
log_detail_fieldnames = list(LogDetail.__annotations__.keys())
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
@click.command()
|
|
10
|
+
@click.argument("csvfile", type=click.Path())
|
|
11
|
+
@click.option("-l", "--log-file", required=None, default="validation.log")
|
|
12
|
+
def cli(csvfile, log_file):
|
|
13
|
+
with open(log_file) as f, open(csvfile, "w") as of:
|
|
14
|
+
writer = csv.DictWriter(of, fieldnames=log_detail_fieldnames)
|
|
15
|
+
writer.writeheader()
|
|
16
|
+
lines = f.readlines()
|
|
17
|
+
for block in yield_log_blocks(lines):
|
|
18
|
+
writer.writerow(block.__dict__)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
if __name__ == "__main__":
|
|
22
|
+
cli()
|
heurist/log/__init__.py
ADDED
heurist/log/iterator.py
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
from typing import Generator
|
|
2
|
+
|
|
3
|
+
from .model import LogDetail
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def yield_log_blocks(lines: list[str]) -> Generator[LogDetail, None, None]:
|
|
7
|
+
line_iterator = iter(lines)
|
|
8
|
+
l1 = next(line_iterator, None)
|
|
9
|
+
while l1 is not None:
|
|
10
|
+
if l1 and not l1.startswith("\t"):
|
|
11
|
+
l2 = next(line_iterator)
|
|
12
|
+
l3 = next(line_iterator)
|
|
13
|
+
l4 = next(line_iterator)
|
|
14
|
+
l5 = next(line_iterator)
|
|
15
|
+
yield LogDetail.load_lines(l1, l2, l3, l4, l5)
|
|
16
|
+
l1 = next(line_iterator, None)
|
heurist/log/model.py
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
from dataclasses import dataclass
|
|
2
|
+
import re
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
@dataclass
|
|
6
|
+
class LogDetail:
|
|
7
|
+
time: str
|
|
8
|
+
level: str
|
|
9
|
+
recType: int
|
|
10
|
+
recID: int
|
|
11
|
+
rule: str
|
|
12
|
+
problem: str
|
|
13
|
+
|
|
14
|
+
@classmethod
|
|
15
|
+
def load_lines(cls, *block_lines) -> "LogDetail":
|
|
16
|
+
l1, l2, l3, l4, l5 = block_lines
|
|
17
|
+
for indented_line in [l2, l3, l4, l5]:
|
|
18
|
+
assert indented_line.startswith("\t")
|
|
19
|
+
return LogDetail(
|
|
20
|
+
time=cls.parse_time(l1),
|
|
21
|
+
level=cls.parse_level(l1),
|
|
22
|
+
recType=cls.parse_number(l2),
|
|
23
|
+
recID=cls.parse_number(l3),
|
|
24
|
+
rule=l4.removeprefix("\t").strip(),
|
|
25
|
+
problem=l5.removeprefix("\t").strip(),
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
@staticmethod
|
|
29
|
+
def parse_number(line) -> int:
|
|
30
|
+
parts = line.split()
|
|
31
|
+
suffix: str = parts[-1]
|
|
32
|
+
number = suffix.removesuffix("]")
|
|
33
|
+
return int(number)
|
|
34
|
+
|
|
35
|
+
@staticmethod
|
|
36
|
+
def parse_time(l1: str) -> str:
|
|
37
|
+
parts = l1.split(" - ")
|
|
38
|
+
return parts[0].strip()
|
|
39
|
+
|
|
40
|
+
@staticmethod
|
|
41
|
+
def parse_level(l1: str) -> str:
|
|
42
|
+
return re.search(r"[A-Z]+", l1).group(0).strip()
|
|
@@ -10,11 +10,15 @@ heurist/api/utils.py,sha256=DT-BrdF7O2lmFSduRYOecx302dAlLWQTYgr2V9JoDYI,643
|
|
|
10
10
|
heurist/cli/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
11
11
|
heurist/cli/__main__.py,sha256=QG2gJG7zD3YIDRqbIp2MzTqPxqGLZ77RHCRYZ58SSjg,5975
|
|
12
12
|
heurist/cli/load.py,sha256=kU8nTSJMl6ynz6FguhE_xdqJwQFijjsRerQGRtWil5s,1903
|
|
13
|
+
heurist/cli/parse_log.py,sha256=9KjstOOjJsAiB6fTIQxxiNKpRxLg-2DB4qbKvScDhIc,623
|
|
13
14
|
heurist/cli/records.py,sha256=yKK3XIZrU1szo6X-HmGjZpD0IKk3a3rd3Kkyrg5AYGE,1345
|
|
14
15
|
heurist/cli/schema.py,sha256=Dg8NcSdI7Xb6r-dkUC_razXlZNtxSG0x7awsr1m8Mcw,2766
|
|
15
16
|
heurist/database/__init__.py,sha256=JvQCGCi84AXUSIPCu4cTOqT_yZGDLmZFAUdsHDLbpKI,79
|
|
16
17
|
heurist/database/basedb.py,sha256=0MKfQOKTBDCc6qcl8BGl5OIpSA7SYgmfcKXCBVWBPes,4200
|
|
17
18
|
heurist/database/database.py,sha256=rJPhGA4158eoIwe13QsSGZ8929dkRxMTesRRlMrn1tI,4057
|
|
19
|
+
heurist/log/__init__.py,sha256=9zYSx-jKp7GBnlS8qMWYqah3FnhqcTrebVVcn79ghFM,101
|
|
20
|
+
heurist/log/iterator.py,sha256=nmpW3QQfwToADD4zffAm5iFyIUMFT56LRORdThYRoqE,519
|
|
21
|
+
heurist/log/model.py,sha256=U04rKbKva8dk6gTtEJdbYw-li0JVUjLYm8I8gyoWxuM,1085
|
|
18
22
|
heurist/models/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
19
23
|
heurist/models/dynamic/__init__.py,sha256=dFUNGMugaOAkec6uhDxkUVrmGkR5dr1fTd8X_TprRyU,77
|
|
20
24
|
heurist/models/dynamic/annotation.py,sha256=FOkldKT5u2XWBk7DxXbrgRf8X_G3N5FEfr-rOTLq-Eg,4749
|
|
@@ -73,8 +77,8 @@ mock_data/geo/single.py,sha256=gbk_gOLfVlJuU3MhjY2Lu14bs9-FbZmNtevpiw9jArk,79867
|
|
|
73
77
|
mock_data/resource/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
74
78
|
mock_data/resource/repeated.py,sha256=Nf3nIL596pLVbKo20sQm5UITwBzqf-IHFzE_m2UCLbw,788
|
|
75
79
|
mock_data/resource/single.py,sha256=SXVri1MM8UaJw7GejMEJ6seNEnMksdw_WKiOxQOdVFs,411
|
|
76
|
-
heurist_api-0.
|
|
77
|
-
heurist_api-0.
|
|
78
|
-
heurist_api-0.
|
|
79
|
-
heurist_api-0.
|
|
80
|
-
heurist_api-0.
|
|
80
|
+
heurist_api-0.2.0.dist-info/METADATA,sha256=yen3I0sbV3Z81AXdBCsxlGAO0QWJ9m68eHelXCvkMrg,25177
|
|
81
|
+
heurist_api-0.2.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
82
|
+
heurist_api-0.2.0.dist-info/entry_points.txt,sha256=37KBvqofapLaKDPFrcYxv_rfUM9H08Mbe6mxNdd_Xno,93
|
|
83
|
+
heurist_api-0.2.0.dist-info/licenses/LICENSE,sha256=I-54yLrknPCOovDISUXGa5h-vkUgiB-1Gz2tT7Q9B8I,20137
|
|
84
|
+
heurist_api-0.2.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|