atomicshop 2.15.2__py3-none-any.whl → 2.15.3__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 CHANGED
@@ -1,4 +1,4 @@
1
1
  """Atomic Basic functions and classes to make developer life easier"""
2
2
 
3
3
  __author__ = "Den Kras"
4
- __version__ = '2.15.2'
4
+ __version__ = '2.15.3'
@@ -1,12 +1,12 @@
1
1
  import os
2
2
  import datetime
3
3
  import json
4
- from typing import Union
4
+ from typing import Union, Literal
5
5
 
6
6
  from .statistic_analyzer_helper import analyzer_helper, moving_average_helper
7
7
  from .. import filesystem, domains, datetimes, urls
8
8
  from ..basics import dicts
9
- from ..file_io import tomls, xlsxs, jsons
9
+ from ..file_io import tomls, xlsxs, jsons, csvs
10
10
  from ..wrappers.loggingw import reading
11
11
  from ..print_api import print_api
12
12
 
@@ -350,7 +350,8 @@ def deviation_calculator_by_moving_average_main(
350
350
  top_bottom_deviation_percentage: float,
351
351
  get_deviation_for_last_day_only: bool = False,
352
352
  summary: bool = False,
353
- output_json_file_path: str = None
353
+ output_file_path: str = None,
354
+ output_file_type: Literal['json', 'csv'] = 'json'
354
355
  ) -> Union[list, None]:
355
356
  """
356
357
  This function is the main function for the moving average calculator.
@@ -375,7 +376,8 @@ def deviation_calculator_by_moving_average_main(
375
376
  to 2021-01-05.
376
377
  :param summary: bool, if True, Only the summary will be generated without all the numbers that were used
377
378
  to calculate the averages and the moving average data.
378
- :param output_json_file_path: string, if None, no json file will be written.
379
+ :param output_file_path: string, if None, no file will be written.
380
+ :param output_file_type: string, the type of the output file. 'json' or 'csv'.
379
381
  -----------------------------
380
382
  :return: the deviation list of dicts.
381
383
 
@@ -397,6 +399,9 @@ def deviation_calculator_by_moving_average_main(
397
399
  sys.exit(main())
398
400
  """
399
401
 
402
+ if output_file_type not in ['json', 'csv']:
403
+ raise ValueError(f'output_file_type must be "json" or "csv", not [{output_file_type}]')
404
+
400
405
  statistics_file_path: str = f'{statistics_file_directory}{os.sep}{STATISTICS_FILE_NAME}'
401
406
 
402
407
  def convert_data_value_to_string(value_key: str, list_index: int) -> None:
@@ -414,29 +419,41 @@ def deviation_calculator_by_moving_average_main(
414
419
  )
415
420
 
416
421
  if deviation_list:
417
- if output_json_file_path:
418
- for deviation_list_index, deviation in enumerate(deviation_list):
419
- convert_data_value_to_string('request_sizes', deviation_list_index)
420
- convert_data_value_to_string('response_sizes', deviation_list_index)
421
- convert_value_to_string('ma_data', deviation_list_index)
422
-
423
- print_api(f'Deviation Found, saving to file: {output_json_file_path}', color='blue')
424
- jsons.write_json_file(deviation_list, output_json_file_path, use_default_indent=True)
425
-
426
422
  if summary:
427
423
  summary_deviation_list: list = []
428
424
  for deviation in deviation_list:
425
+ value = deviation.get('value', None)
426
+ ma_value = deviation.get('ma_value', None)
427
+ if not value or not ma_value:
428
+ total_entries_averaged = None
429
+ else:
430
+ total_entries_averaged = deviation['data']['count']
431
+
429
432
  summary_deviation_list.append({
430
433
  'day': deviation['day'],
431
434
  'host': deviation['host'],
432
435
  'message': deviation['message'],
433
- 'value': deviation['value'],
434
- 'ma_value': deviation['ma_value'],
435
- 'total_entries_averaged': deviation['data']['count']
436
+ 'value': deviation.get('value', None),
437
+ 'ma_value': deviation.get('ma_value', None),
438
+ 'total_entries_averaged': total_entries_averaged
436
439
  })
437
440
 
438
441
  deviation_list = summary_deviation_list
439
442
 
443
+ if output_file_path:
444
+ if not summary:
445
+ for deviation_list_index, deviation in enumerate(deviation_list):
446
+ convert_data_value_to_string('request_sizes', deviation_list_index)
447
+ convert_data_value_to_string('response_sizes', deviation_list_index)
448
+ convert_value_to_string('ma_data', deviation_list_index)
449
+
450
+ print_api(f'Deviation Found, saving to file: {output_file_path}', color='blue')
451
+
452
+ if output_file_type == 'csv':
453
+ csvs.write_list_to_csv(output_file_path, deviation_list)
454
+ elif output_file_type == 'json':
455
+ jsons.write_json_file(deviation_list, output_file_path, use_default_indent=True)
456
+
440
457
  return deviation_list
441
458
 
442
459
  return None
@@ -7,6 +7,10 @@ from ... import filesystem, datetimes
7
7
  from ...file_io import csvs
8
8
 
9
9
 
10
+ class LogReaderTimeCouldntBeFoundInFileNameError(Exception):
11
+ pass
12
+
13
+
10
14
  def get_logs_paths(
11
15
  log_files_directory_path: str = None,
12
16
  log_file_path: str = None,
@@ -95,6 +99,13 @@ def get_logs_paths(
95
99
  if timestamp_float and timestamp_float > latest_timestamp:
96
100
  latest_timestamp = timestamp_float
97
101
 
102
+ # Check timestamps, if more than 1 file is None, then the function that gets the date from the file name
103
+ # didn't work properly, probably because of the string datetime format or the filenames.
104
+ none_timestamps = [single_file['last_modified'] for single_file in logs_files].count(None)
105
+ if none_timestamps > 1:
106
+ raise LogReaderTimeCouldntBeFoundInFileNameError(
107
+ 'The date pattern could not be found in the file name. Check the date pattern and the file names.')
108
+
98
109
  # Now, there should be a file that doesn't have the string date pattern in the file name.
99
110
  # We will add one day to the latest date that we found and assign to that file path.
100
111
  for file_index, single_file in enumerate(logs_files):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: atomicshop
3
- Version: 2.15.2
3
+ Version: 2.15.3
4
4
  Summary: Atomic functions and classes to make developer life easier
5
5
  Author: Denis Kras
6
6
  License: MIT License
@@ -1,4 +1,4 @@
1
- atomicshop/__init__.py,sha256=YjtioQo2yCdlVopAxK5ML-3qjCBp2BtnyqJLsu5hSYI,123
1
+ atomicshop/__init__.py,sha256=aCesTJoNLZUFzz58NTSDXvO_WoEVSNiCYUamRk5wgJs,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
@@ -128,7 +128,7 @@ atomicshop/mitm/initialize_engines.py,sha256=YnXPK1UKrmULnfL4zLo2LOpKWq-aGKzc9p3
128
128
  atomicshop/mitm/initialize_mitm_server.py,sha256=j1yMUbHsnFh9l5rFiUgBQA0mRZqREOKviP0frRzYikM,14611
129
129
  atomicshop/mitm/message.py,sha256=u2U2f2SOHdBNU-6r1Ik2W14ai2EOwxUV4wVfGZA098k,1732
130
130
  atomicshop/mitm/shared_functions.py,sha256=PaK_sbnEA5zo9k2ktEOKLmvo-6wRUunxzSNRr41uXIQ,1924
131
- atomicshop/mitm/statistic_analyzer.py,sha256=FdUmKVmDZp0-2ohBVwubG9v0wz8Wb-NIi50Qk8BR85E,22913
131
+ atomicshop/mitm/statistic_analyzer.py,sha256=w3mqvnfh68zW78bcIyw1Au4DimSu9dbNlqoG7jP--fM,23750
132
132
  atomicshop/mitm/engines/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
133
133
  atomicshop/mitm/engines/create_module_template.py,sha256=tRjVSm1sD6FzML71Qbuwvita0qsusdFGm8NZLsZ-XMs,4853
134
134
  atomicshop/mitm/engines/create_module_template_example.py,sha256=X5xhvbV6-g9jU_bQVhf_crZmaH50LRWz3bS-faQ18ds,489
@@ -244,7 +244,7 @@ atomicshop/wrappers/loggingw/formatters.py,sha256=7XUJvlB0CK4DCkEp8NTL0S0dkyrZD0
244
244
  atomicshop/wrappers/loggingw/handlers.py,sha256=yFYBeTkxnpmtlauoH3ZEFEHUYQYu9YL-ycd9sYTvOl4,16928
245
245
  atomicshop/wrappers/loggingw/loggers.py,sha256=DHOOTAtqkwn1xgvLHSkOiBm6yFGNuQy1kvbhG-TDog8,2374
246
246
  atomicshop/wrappers/loggingw/loggingw.py,sha256=lo4OZPXCbYZi3GqpaaJSs9SOGFfqD2EgHzzTK7f5IR4,11275
247
- atomicshop/wrappers/loggingw/reading.py,sha256=b4-ibM5WwjEOanvHY3hIsu9-4b2RAdPYiCxvl7745fk,17521
247
+ atomicshop/wrappers/loggingw/reading.py,sha256=ZgFbmQdStLg2nlgzJEznsvEP0r63ki_2RRwsNnggLDI,18148
248
248
  atomicshop/wrappers/mongodbw/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
249
249
  atomicshop/wrappers/mongodbw/infrastructure.py,sha256=tHqtt__yKGtj24CT5AIk0V0k9t1p_PjezFExXRmmmcA,1517
250
250
  atomicshop/wrappers/mongodbw/install_mongodb.py,sha256=dik6tpXws4FaQN_-u8s-yn5Z1InHROV7k1WhFA8eu4M,6617
@@ -294,8 +294,8 @@ atomicshop/wrappers/socketw/socket_server_tester.py,sha256=AhpurHJmP2kgzHaUbq5ey
294
294
  atomicshop/wrappers/socketw/socket_wrapper.py,sha256=aXBwlEIJhFT0-c4i8iNlFx2It9VpCEpsv--5Oqcpxao,11624
295
295
  atomicshop/wrappers/socketw/ssl_base.py,sha256=k4V3gwkbq10MvOH4btU4onLX2GNOsSfUAdcHmL1rpVE,2274
296
296
  atomicshop/wrappers/socketw/statistics_csv.py,sha256=t3dtDEfN47CfYVi0CW6Kc2QHTEeZVyYhc57IYYh5nmA,826
297
- atomicshop-2.15.2.dist-info/LICENSE.txt,sha256=lLU7EYycfYcK2NR_1gfnhnRC8b8ccOTElACYplgZN88,1094
298
- atomicshop-2.15.2.dist-info/METADATA,sha256=mAbT1nfgZ4Tj46GcfHsaEw8vnvZnt3ygZxipKe9aUco,10502
299
- atomicshop-2.15.2.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
300
- atomicshop-2.15.2.dist-info/top_level.txt,sha256=EgKJB-7xcrAPeqTRF2laD_Np2gNGYkJkd4OyXqpJphA,11
301
- atomicshop-2.15.2.dist-info/RECORD,,
297
+ atomicshop-2.15.3.dist-info/LICENSE.txt,sha256=lLU7EYycfYcK2NR_1gfnhnRC8b8ccOTElACYplgZN88,1094
298
+ atomicshop-2.15.3.dist-info/METADATA,sha256=0Fx6JFpY55KI4OpSnfP220ErQEvXv5RX4kcJKAvmCpI,10502
299
+ atomicshop-2.15.3.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
300
+ atomicshop-2.15.3.dist-info/top_level.txt,sha256=EgKJB-7xcrAPeqTRF2laD_Np2gNGYkJkd4OyXqpJphA,11
301
+ atomicshop-2.15.3.dist-info/RECORD,,