atomicshop 3.3.17__py3-none-any.whl → 3.3.18__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 atomicshop might be problematic. Click here for more details.
- atomicshop/__init__.py +1 -1
- atomicshop/mitm/statistic_analyzer.py +7 -0
- atomicshop/mitm/statistic_analyzer_helper/moving_average_helper.py +44 -4
- {atomicshop-3.3.17.dist-info → atomicshop-3.3.18.dist-info}/METADATA +1 -1
- {atomicshop-3.3.17.dist-info → atomicshop-3.3.18.dist-info}/RECORD +8 -8
- {atomicshop-3.3.17.dist-info → atomicshop-3.3.18.dist-info}/WHEEL +0 -0
- {atomicshop-3.3.17.dist-info → atomicshop-3.3.18.dist-info}/licenses/LICENSE.txt +0 -0
- {atomicshop-3.3.17.dist-info → atomicshop-3.3.18.dist-info}/top_level.txt +0 -0
atomicshop/__init__.py
CHANGED
|
@@ -352,6 +352,7 @@ def deviation_calculator_by_moving_average(
|
|
|
352
352
|
moving_average_window_days: int = 5,
|
|
353
353
|
top_bottom_deviation_percentage: float = 0.25,
|
|
354
354
|
get_deviation_for_last_day_only: bool = False,
|
|
355
|
+
get_deviation_for_date: str = None,
|
|
355
356
|
summary: bool = False,
|
|
356
357
|
output_file_path: str = None,
|
|
357
358
|
output_file_type: Literal['json', 'csv'] = 'json',
|
|
@@ -386,6 +387,8 @@ def deviation_calculator_by_moving_average(
|
|
|
386
387
|
Files 01 to 05 will be used for moving average and the file 06 for deviation.
|
|
387
388
|
Meaning the average calculated for 2021-01-06 will be compared to the values moving average of 2021-01-01
|
|
388
389
|
to 2021-01-05.
|
|
390
|
+
:param get_deviation_for_date: string, if specified, only the specified date will be analyzed.
|
|
391
|
+
The date must be in the format of 'YYYY-MM-DD'. Example: '2021-01-06'.
|
|
389
392
|
:param summary: bool, if True, Only the summary will be generated without all the numbers that were used
|
|
390
393
|
to calculate the averages and the moving average data.
|
|
391
394
|
:param output_file_path: string, if None, no file will be written.
|
|
@@ -437,6 +440,9 @@ def deviation_calculator_by_moving_average(
|
|
|
437
440
|
if by_type not in ['host', 'url']:
|
|
438
441
|
raise ValueError(f'by_type must be "host" or "url", not [{by_type}]')
|
|
439
442
|
|
|
443
|
+
if get_deviation_for_last_day_only and get_deviation_for_date:
|
|
444
|
+
raise ValueError('Either [get_deviation_for_last_day_only] or [get_deviation_for_date] can be provided, not both.')
|
|
445
|
+
|
|
440
446
|
if statistics_file_directory:
|
|
441
447
|
statistics_file_path: str | None = f'{statistics_file_directory}{os.sep}{STATISTICS_FILE_NAME}'
|
|
442
448
|
else:
|
|
@@ -449,6 +455,7 @@ def deviation_calculator_by_moving_average(
|
|
|
449
455
|
moving_average_window_days,
|
|
450
456
|
top_bottom_deviation_percentage,
|
|
451
457
|
get_deviation_for_last_day_only,
|
|
458
|
+
get_deviation_for_date,
|
|
452
459
|
skip_total_count_less_than
|
|
453
460
|
)
|
|
454
461
|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import statistics
|
|
2
2
|
from pathlib import Path
|
|
3
3
|
from typing import Literal
|
|
4
|
+
import datetime
|
|
4
5
|
|
|
5
6
|
from ...print_api import print_api
|
|
6
7
|
from ...wrappers.loggingw import reading, consts
|
|
@@ -15,6 +16,7 @@ def calculate_moving_average(
|
|
|
15
16
|
moving_average_window_days: int = 5,
|
|
16
17
|
top_bottom_deviation_percentage: float = 0.25,
|
|
17
18
|
get_deviation_for_last_day_only: bool = False,
|
|
19
|
+
get_deviation_for_date: str = None,
|
|
18
20
|
skip_total_count_less_than: int = None,
|
|
19
21
|
print_kwargs: dict = None
|
|
20
22
|
) -> list:
|
|
@@ -29,6 +31,7 @@ def calculate_moving_average(
|
|
|
29
31
|
:param top_bottom_deviation_percentage: float, the percentage of deviation from the moving average to the top or
|
|
30
32
|
bottom.
|
|
31
33
|
:param get_deviation_for_last_day_only: bool, check the 'get_all_files_content' function.
|
|
34
|
+
:param get_deviation_for_date: str, check the 'get_all_files_content' function.
|
|
32
35
|
:param skip_total_count_less_than: integer, if the total count is less than this number, skip the deviation.
|
|
33
36
|
:param print_kwargs: dict, the print_api arguments.
|
|
34
37
|
"""
|
|
@@ -38,10 +41,15 @@ def calculate_moving_average(
|
|
|
38
41
|
if file_path and statistics_content:
|
|
39
42
|
raise ValueError('Only one of file_path or statistics_content must be provided.')
|
|
40
43
|
|
|
44
|
+
if get_deviation_for_last_day_only and get_deviation_for_date:
|
|
45
|
+
raise ValueError('Only one of get_deviation_for_last_day_only or get_deviation_for_date can be set.')
|
|
46
|
+
|
|
41
47
|
if not statistics_content:
|
|
42
48
|
statistics_content: dict = get_all_files_content(
|
|
43
49
|
file_path=file_path, moving_average_window_days=moving_average_window_days,
|
|
44
|
-
get_deviation_for_last_day_only=get_deviation_for_last_day_only,
|
|
50
|
+
get_deviation_for_last_day_only=get_deviation_for_last_day_only,
|
|
51
|
+
get_deviation_for_date=get_deviation_for_date,
|
|
52
|
+
print_kwargs=print_kwargs)
|
|
45
53
|
|
|
46
54
|
for date_string, day_dict in statistics_content.items():
|
|
47
55
|
day_dict['content_no_useless'] = get_content_without_useless(day_dict['content'])
|
|
@@ -73,6 +81,7 @@ def get_all_files_content(
|
|
|
73
81
|
file_path: str,
|
|
74
82
|
moving_average_window_days: int,
|
|
75
83
|
get_deviation_for_last_day_only: bool = False,
|
|
84
|
+
get_deviation_for_date: str = None,
|
|
76
85
|
print_kwargs: dict = None
|
|
77
86
|
) -> dict:
|
|
78
87
|
"""
|
|
@@ -83,7 +92,7 @@ def get_all_files_content(
|
|
|
83
92
|
:param get_deviation_for_last_day_only: bool, if True, only the last day will be analyzed.
|
|
84
93
|
Example: With 'moving_average_window_days=5', the last 6 days will be analyzed.
|
|
85
94
|
5 days for moving average and the last day for deviation.
|
|
86
|
-
File names example:
|
|
95
|
+
File names example the last day is 2021-01-06:
|
|
87
96
|
statistics_2021-01-01.csv
|
|
88
97
|
statistics_2021-01-02.csv
|
|
89
98
|
statistics_2021-01-03.csv
|
|
@@ -93,12 +102,24 @@ def get_all_files_content(
|
|
|
93
102
|
Files 01 to 05 will be used for moving average and the file 06 for deviation.
|
|
94
103
|
Meaning the average calculated for 2021-01-06 will be compared to the values moving average of 2021-01-01
|
|
95
104
|
to 2021-01-05.
|
|
105
|
+
:param get_deviation_for_date: str, if set, the last day is considered the date that you set here.
|
|
106
|
+
The format should be the same as in the file names, e.g. 'YYYY-MM-DD'.
|
|
96
107
|
:param print_kwargs: dict, the print_api arguments.
|
|
97
108
|
:return:
|
|
98
109
|
"""
|
|
99
110
|
|
|
111
|
+
if get_deviation_for_last_day_only and get_deviation_for_date:
|
|
112
|
+
raise ValueError('Only one of get_deviation_for_last_day_only or get_deviation_for_date can be set.')
|
|
113
|
+
|
|
100
114
|
date_format: str = consts.DEFAULT_ROTATING_SUFFIXES_FROM_WHEN['midnight']
|
|
101
115
|
|
|
116
|
+
def is_valid_date(date_str: str) -> bool:
|
|
117
|
+
try:
|
|
118
|
+
datetime.datetime.strptime(date_str, date_format)
|
|
119
|
+
return True
|
|
120
|
+
except ValueError:
|
|
121
|
+
return False
|
|
122
|
+
|
|
102
123
|
# Get all the file paths and their midnight rotations.
|
|
103
124
|
logs_paths: list[filesystem.AtomicPath] = reading.get_logs_paths(
|
|
104
125
|
log_file_path=file_path,
|
|
@@ -109,6 +130,24 @@ def get_all_files_content(
|
|
|
109
130
|
days_back_to_analyze: int = moving_average_window_days + 1
|
|
110
131
|
logs_paths = logs_paths[-days_back_to_analyze:]
|
|
111
132
|
|
|
133
|
+
if get_deviation_for_date:
|
|
134
|
+
# Check if the date format is correct.
|
|
135
|
+
if not is_valid_date(get_deviation_for_date):
|
|
136
|
+
raise ValueError(f'Date [{get_deviation_for_date}] is not in the correct format: {date_format}')
|
|
137
|
+
|
|
138
|
+
# Find the index of the date in the logs_paths list.
|
|
139
|
+
date_index: int | None = None
|
|
140
|
+
for index, log_atomic_path in enumerate(logs_paths):
|
|
141
|
+
if log_atomic_path.datetime_string == get_deviation_for_date:
|
|
142
|
+
date_index = index
|
|
143
|
+
break
|
|
144
|
+
|
|
145
|
+
if date_index is None:
|
|
146
|
+
raise ValueError(f'Date {get_deviation_for_date} not found in the log files.')
|
|
147
|
+
|
|
148
|
+
start_index: int = max(0, date_index - moving_average_window_days)
|
|
149
|
+
logs_paths = logs_paths[start_index:date_index + 1]
|
|
150
|
+
|
|
112
151
|
statistics_content: dict = {}
|
|
113
152
|
# Read each file to its day.
|
|
114
153
|
for log_atomic_path in logs_paths:
|
|
@@ -260,7 +299,7 @@ def compute_moving_averages_from_average_statistics(
|
|
|
260
299
|
|
|
261
300
|
# Create list of the last 'moving_average_window_days' days, including the current day.
|
|
262
301
|
last_x_window_days_content_list = (
|
|
263
|
-
list(average_statistics_dict.values()))[current_day-moving_average_window_days:current_day]
|
|
302
|
+
list(average_statistics_dict.values()))[current_day - moving_average_window_days:current_day]
|
|
264
303
|
|
|
265
304
|
# Compute the moving averages.
|
|
266
305
|
moving_average[day] = compute_average_for_current_day_from_past_x_days(
|
|
@@ -443,7 +482,8 @@ def find_deviation_from_moving_average(
|
|
|
443
482
|
if day_index == 0:
|
|
444
483
|
previous_day_moving_average_dict = {}
|
|
445
484
|
else:
|
|
446
|
-
previous_day_moving_average_dict = list(statistics_content.values())[day_index-1].get('moving_average',
|
|
485
|
+
previous_day_moving_average_dict = list(statistics_content.values())[day_index - 1].get('moving_average',
|
|
486
|
+
{})
|
|
447
487
|
|
|
448
488
|
# If there is no moving average for previous day continue to the next day.
|
|
449
489
|
if not previous_day_moving_average_dict:
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
atomicshop/__init__.py,sha256=
|
|
1
|
+
atomicshop/__init__.py,sha256=ZZgIypIAzAvhlg6GcAfDfISP0Pv6PTd2kCCEgIKx420,123
|
|
2
2
|
atomicshop/_basics_temp.py,sha256=6cu2dd6r2dLrd1BRNcVDKTHlsHs_26Gpw8QS6v32lQ0,3699
|
|
3
3
|
atomicshop/_create_pdf_demo.py,sha256=Yi-PGZuMg0RKvQmLqVeLIZYadqEZwUm-4A9JxBl_vYA,3713
|
|
4
4
|
atomicshop/_patch_import.py,sha256=ENp55sKVJ0e6-4lBvZnpz9PQCt3Otbur7F6aXDlyje4,6334
|
|
@@ -134,7 +134,7 @@ atomicshop/mitm/message.py,sha256=CDhhm4BTuZE7oNZCjvIZ4BuPOW4MuIzQLOg91hJaxDI,30
|
|
|
134
134
|
atomicshop/mitm/mitm_main.py,sha256=u9q4BYIhScw9W9M7AS4h217gKQXkuppOFxvprEBVPGE,39366
|
|
135
135
|
atomicshop/mitm/recs_files.py,sha256=tv8XFhYZMkBv4DauvpiAdPgvSo0Bcm1CghnmwO7dx8M,5018
|
|
136
136
|
atomicshop/mitm/shared_functions.py,sha256=0lzeyINd44sVEfFbahJxQmz6KAMWbYrW5ou3UYfItvw,1777
|
|
137
|
-
atomicshop/mitm/statistic_analyzer.py,sha256=
|
|
137
|
+
atomicshop/mitm/statistic_analyzer.py,sha256=EC9g21ocOsFzNfntV-nZHSGtrS1-Kxb0QDSGWS5FuNA,28942
|
|
138
138
|
atomicshop/mitm/engines/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
139
139
|
atomicshop/mitm/engines/create_module_template.py,sha256=PHE2pVC9JNgaIh2o7M5dFMrkdOkmIyHLoO2mdzE5BdM,5938
|
|
140
140
|
atomicshop/mitm/engines/create_module_template_main_example.py,sha256=LeQ44Rp2Gi_KbIDY_4OMS0odkSK3zFZWra_oAka5eJY,243
|
|
@@ -150,7 +150,7 @@ atomicshop/mitm/engines/__reference_general/requester___reference_general.py,sha
|
|
|
150
150
|
atomicshop/mitm/engines/__reference_general/responder___reference_general.py,sha256=5XSmvF0d6d9mPkPOGw7f9T-Cr-YoUiUTVYgBIjiKh7s,10615
|
|
151
151
|
atomicshop/mitm/statistic_analyzer_helper/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
152
152
|
atomicshop/mitm/statistic_analyzer_helper/analyzer_helper.py,sha256=pk6L1t1ea1kvlBoR9QEJptOmaX-mumhwLsP2GCKukbk,5920
|
|
153
|
-
atomicshop/mitm/statistic_analyzer_helper/moving_average_helper.py,sha256=
|
|
153
|
+
atomicshop/mitm/statistic_analyzer_helper/moving_average_helper.py,sha256=j_0_8p-6ExVbbhILMeY7RuQ3PTNjs-mB6y0wr2ie34U,23501
|
|
154
154
|
atomicshop/monitor/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
155
155
|
atomicshop/monitor/change_monitor.py,sha256=K5NlVp99XIDDPnQQMdru4BDmua_DtcDIhVAzkTOvD5s,7673
|
|
156
156
|
atomicshop/monitor/checks/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
@@ -316,8 +316,8 @@ atomicshop/wrappers/socketw/statistics_csv.py,sha256=_gA8bMX6Sw_UCXKi2y9wNAwlqif
|
|
|
316
316
|
atomicshop/wrappers/winregw/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
317
317
|
atomicshop/wrappers/winregw/winreg_installed_software.py,sha256=Qzmyktvob1qp6Tjk2DjLfAqr_yXV0sgWzdMW_9kwNjY,2345
|
|
318
318
|
atomicshop/wrappers/winregw/winreg_network.py,sha256=ih0BVNwByLvf9F_Lac4EdmDYYJA3PzMvmG0PieDZrsE,9905
|
|
319
|
-
atomicshop-3.3.
|
|
320
|
-
atomicshop-3.3.
|
|
321
|
-
atomicshop-3.3.
|
|
322
|
-
atomicshop-3.3.
|
|
323
|
-
atomicshop-3.3.
|
|
319
|
+
atomicshop-3.3.18.dist-info/licenses/LICENSE.txt,sha256=lLU7EYycfYcK2NR_1gfnhnRC8b8ccOTElACYplgZN88,1094
|
|
320
|
+
atomicshop-3.3.18.dist-info/METADATA,sha256=9i69mSa_kRBTR5_2RN1F5-rAJm7myfH7dBjI3gXBrsA,9345
|
|
321
|
+
atomicshop-3.3.18.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
322
|
+
atomicshop-3.3.18.dist-info/top_level.txt,sha256=EgKJB-7xcrAPeqTRF2laD_Np2gNGYkJkd4OyXqpJphA,11
|
|
323
|
+
atomicshop-3.3.18.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|