sciveo 0.1.22__tar.gz → 0.1.23__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.
Files changed (59) hide show
  1. {sciveo-0.1.22 → sciveo-0.1.23}/PKG-INFO +5 -1
  2. {sciveo-0.1.22 → sciveo-0.1.23}/sciveo/cli.py +4 -1
  3. sciveo-0.1.23/sciveo/tools/array.py +149 -0
  4. sciveo-0.1.23/sciveo/tools/common.py +98 -0
  5. {sciveo-0.1.22 → sciveo-0.1.23}/sciveo/tools/compress.py +11 -0
  6. {sciveo-0.1.22 → sciveo-0.1.23}/sciveo/tools/crypto.py +11 -0
  7. sciveo-0.1.23/sciveo/tools/http.py +134 -0
  8. sciveo-0.1.23/sciveo/tools/os.py +67 -0
  9. sciveo-0.1.23/sciveo/tools/simple_counter.py +112 -0
  10. sciveo-0.1.23/sciveo/tools/synchronized.py +160 -0
  11. sciveo-0.1.23/sciveo/version.py +2 -0
  12. {sciveo-0.1.22 → sciveo-0.1.23}/sciveo.egg-info/PKG-INFO +5 -1
  13. {sciveo-0.1.22 → sciveo-0.1.23}/sciveo.egg-info/SOURCES.txt +5 -0
  14. sciveo-0.1.23/sciveo.egg-info/requires.txt +79 -0
  15. {sciveo-0.1.22 → sciveo-0.1.23}/setup.py +23 -15
  16. sciveo-0.1.22/sciveo/tools/synchronized.py +0 -59
  17. sciveo-0.1.22/sciveo/version.py +0 -2
  18. sciveo-0.1.22/sciveo.egg-info/requires.txt +0 -15
  19. {sciveo-0.1.22 → sciveo-0.1.23}/README.md +0 -0
  20. {sciveo-0.1.22 → sciveo-0.1.23}/sciveo/__init__.py +0 -0
  21. {sciveo-0.1.22 → sciveo-0.1.23}/sciveo/api/__init__.py +0 -0
  22. {sciveo-0.1.22 → sciveo-0.1.23}/sciveo/api/base.py +0 -0
  23. {sciveo-0.1.22 → sciveo-0.1.23}/sciveo/api/upload.py +0 -0
  24. {sciveo-0.1.22 → sciveo-0.1.23}/sciveo/common/__init__.py +0 -0
  25. {sciveo-0.1.22 → sciveo-0.1.23}/sciveo/common/configuration.py +0 -0
  26. {sciveo-0.1.22 → sciveo-0.1.23}/sciveo/common/model.py +0 -0
  27. {sciveo-0.1.22 → sciveo-0.1.23}/sciveo/common/optimizers.py +0 -0
  28. {sciveo-0.1.22 → sciveo-0.1.23}/sciveo/common/sampling.py +0 -0
  29. {sciveo-0.1.22 → sciveo-0.1.23}/sciveo/content/__init__.py +0 -0
  30. {sciveo-0.1.22 → sciveo-0.1.23}/sciveo/content/dataset.py +0 -0
  31. {sciveo-0.1.22 → sciveo-0.1.23}/sciveo/content/experiment.py +0 -0
  32. {sciveo-0.1.22 → sciveo-0.1.23}/sciveo/content/project.py +0 -0
  33. {sciveo-0.1.22 → sciveo-0.1.23}/sciveo/content/runner.py +0 -0
  34. {sciveo-0.1.22 → sciveo-0.1.23}/sciveo/monitoring/__init__.py +0 -0
  35. {sciveo-0.1.22 → sciveo-0.1.23}/sciveo/monitoring/monitor.py +0 -0
  36. {sciveo-0.1.22 → sciveo-0.1.23}/sciveo/monitoring/start.py +0 -0
  37. {sciveo-0.1.22 → sciveo-0.1.23}/sciveo/network/__init__.py +0 -0
  38. {sciveo-0.1.22 → sciveo-0.1.23}/sciveo/network/camera.py +0 -0
  39. {sciveo-0.1.22 → sciveo-0.1.23}/sciveo/network/sniffer.py +0 -0
  40. {sciveo-0.1.22 → sciveo-0.1.23}/sciveo/network/tools.py +0 -0
  41. {sciveo-0.1.22 → sciveo-0.1.23}/sciveo/tools/__init__.py +0 -0
  42. {sciveo-0.1.22 → sciveo-0.1.23}/sciveo/tools/configuration.py +0 -0
  43. {sciveo-0.1.22 → sciveo-0.1.23}/sciveo/tools/daemon.py +0 -0
  44. {sciveo-0.1.22 → sciveo-0.1.23}/sciveo/tools/formating.py +0 -0
  45. {sciveo-0.1.22 → sciveo-0.1.23}/sciveo/tools/hardware.py +0 -0
  46. {sciveo-0.1.22 → sciveo-0.1.23}/sciveo/tools/logger.py +0 -0
  47. {sciveo-0.1.22 → sciveo-0.1.23}/sciveo/tools/random.py +0 -0
  48. {sciveo-0.1.22 → sciveo-0.1.23}/sciveo/tools/remote.py +0 -0
  49. {sciveo-0.1.22 → sciveo-0.1.23}/sciveo/tools/timers.py +0 -0
  50. {sciveo-0.1.22 → sciveo-0.1.23}/sciveo.egg-info/dependency_links.txt +0 -0
  51. {sciveo-0.1.22 → sciveo-0.1.23}/sciveo.egg-info/entry_points.txt +0 -0
  52. {sciveo-0.1.22 → sciveo-0.1.23}/sciveo.egg-info/top_level.txt +0 -0
  53. {sciveo-0.1.22 → sciveo-0.1.23}/setup.cfg +0 -0
  54. {sciveo-0.1.22 → sciveo-0.1.23}/test/test_compress.py +0 -0
  55. {sciveo-0.1.22 → sciveo-0.1.23}/test/test_configuration.py +0 -0
  56. {sciveo-0.1.22 → sciveo-0.1.23}/test/test_crypto.py +0 -0
  57. {sciveo-0.1.22 → sciveo-0.1.23}/test/test_monitoring.py +0 -0
  58. {sciveo-0.1.22 → sciveo-0.1.23}/test/test_runner.py +0 -0
  59. {sciveo-0.1.22 → sciveo-0.1.23}/test/test_sampling.py +0 -0
@@ -1,10 +1,14 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: sciveo
3
- Version: 0.1.22
3
+ Version: 0.1.23
4
4
  Description-Content-Type: text/markdown
5
5
  Provides-Extra: mon
6
6
  Provides-Extra: net
7
+ Provides-Extra: media
8
+ Provides-Extra: media-server
9
+ Provides-Extra: media-ml
7
10
  Provides-Extra: all
11
+ Provides-Extra: media-all
8
12
 
9
13
  # SCIVEO - ML/AI and Scientific tools
10
14
 
@@ -24,7 +24,7 @@ def main():
24
24
  config = GlobalConfiguration.get()
25
25
 
26
26
  parser = argparse.ArgumentParser(description='sciveo CLI')
27
- parser.add_argument('command', choices=['init', 'monitor', 'scan'], help='Command to execute')
27
+ parser.add_argument('command', choices=['init', 'monitor', 'scan', 'media-server'], help='Command to execute')
28
28
  parser.add_argument('--period', type=int, default=120, help='Period in seconds')
29
29
  parser.add_argument('--block', type=bool, default=True, help='Block flag')
30
30
  parser.add_argument('--auth', type=str, default=config['secret_access_key'], help='Auth secret access key')
@@ -53,6 +53,9 @@ def main():
53
53
  fp.write(line + '\n')
54
54
  else:
55
55
  info(f"init, [{base_path}] already there")
56
+ elif args.command == 'media-server':
57
+ from sciveo.media.pipelines.server import __START_SCIVEO_MEDIA_SERVER__
58
+ __START_SCIVEO_MEDIA_SERVER__()
56
59
  else:
57
60
  warning(args.command, "not implemented")
58
61
 
@@ -0,0 +1,149 @@
1
+ #
2
+ # Pavlin Georgiev, Softel Labs
3
+ #
4
+ # This is a proprietary file and may not be copied,
5
+ # distributed, or modified without express permission
6
+ # from the owner. For licensing inquiries, please
7
+ # contact pavlin@softel.bg.
8
+ #
9
+ # 2024
10
+ #
11
+
12
+ import numpy as np
13
+ import copy
14
+
15
+
16
+ def split_sized(arr, chunk_size, residual=True):
17
+ result = []
18
+ num_sets = int(len(arr) / chunk_size)
19
+ from_idx = 0
20
+ to_idx = 0
21
+ for i in range(num_sets):
22
+ to_idx = from_idx + chunk_size
23
+ result.append(arr[from_idx:to_idx])
24
+ from_idx = to_idx
25
+
26
+ if residual:
27
+ result.append(arr[from_idx:])
28
+
29
+ return result
30
+
31
+
32
+ def split_ratios(arr, ratios=[0.75, 0.20, 0.05]):
33
+ if sum(ratios) != 1.0:
34
+ raise Exception("invalid ratios sum: {}".format(sum(ratios)))
35
+
36
+ ratios_idx = []
37
+ current_id = 0
38
+ for r in ratios:
39
+ ratios_idx.append(current_id)
40
+ current_id += int(len(arr) * r)
41
+
42
+ result = []
43
+ for i in range(1, len(ratios_idx)):
44
+ result.append(arr[ratios_idx[i - 1] : ratios_idx[i]])
45
+ result.append(arr[ratios_idx[i]:])
46
+
47
+ return result
48
+
49
+
50
+ def split_dataset(arr, ratios={"train": 0.85, "val": 0.10, "test": 0.05}):
51
+ ratios_keys = []
52
+ ratios_values = []
53
+ for k, v in ratios.items():
54
+ ratios_keys.append(k)
55
+ ratios_values.append(v)
56
+
57
+ split_keys = split_ratios(arr, ratios_values)
58
+
59
+ dataset = {}
60
+ for i, k in enumerate(ratios_keys):
61
+ dataset[k] = split_keys[i]
62
+ return dataset
63
+
64
+
65
+ def copy_dict_values(src, dst, keys):
66
+ for k in keys:
67
+ if k in src:
68
+ dst[k] = src[k]
69
+
70
+
71
+ """
72
+ Search d2 keys into d1, when found, merge these keys recursive into the section found.
73
+ """
74
+ def merge_dicts(d1, d2):
75
+ for k, v in d1.items():
76
+ if k in d2:
77
+ if isinstance(v, dict):
78
+ merge_dicts(v, d2[k])
79
+ else:
80
+ d1[k] = d2[k]
81
+ else:
82
+ if isinstance(v, dict):
83
+ merge_dicts(v, d2)
84
+ return d1
85
+
86
+ def merge_dicts2(d1, d2, r={}):
87
+ for k, v in d1.items():
88
+ r[k] = copy.deepcopy(v)
89
+ if k in d2:
90
+ if isinstance(v, dict):
91
+ merge_dicts2(v, d2[k], r[k])
92
+ else:
93
+ d1[k] = d2[k]
94
+ r[k] = copy.deepcopy(d2[k])
95
+ else:
96
+ if isinstance(v, dict):
97
+ merge_dicts2(v, d2, r[k])
98
+ else:
99
+ for k2, v2 in d2.items():
100
+ if k2 not in d1:
101
+ r[k2] = copy.deepcopy(v2)
102
+ return r
103
+
104
+
105
+ def split_sized(arr, chunk_size, residual=True):
106
+ result = []
107
+ num_sets = int(len(arr) / chunk_size)
108
+ from_idx = 0
109
+ to_idx = 0
110
+ for i in range(num_sets):
111
+ to_idx = from_idx + chunk_size
112
+ result.append(arr[from_idx:to_idx])
113
+ from_idx = to_idx
114
+
115
+ if residual:
116
+ result.append(arr[from_idx:])
117
+
118
+ return result
119
+
120
+ def split_ratios(arr, ratios=[0.75, 0.20, 0.05]):
121
+ if sum(ratios) != 1.0:
122
+ raise Exception("invalid ratios sum: {}".format(sum(ratios)))
123
+
124
+ ratios_idx = []
125
+ current_id = 0
126
+ for r in ratios:
127
+ ratios_idx.append(current_id)
128
+ current_id += int(len(arr) * r)
129
+
130
+ result = []
131
+ for i in range(1, len(ratios_idx)):
132
+ result.append(arr[ratios_idx[i - 1] : ratios_idx[i]])
133
+ result.append(arr[ratios_idx[i]:])
134
+
135
+ return result
136
+
137
+ def split_dataset(arr, ratios={"train": 0.85, "val": 0.10, "test": 0.05}):
138
+ ratios_keys = []
139
+ ratios_values = []
140
+ for k, v in ratios.items():
141
+ ratios_keys.append(k)
142
+ ratios_values.append(v)
143
+
144
+ split_keys = split_ratios(arr, ratios_values)
145
+
146
+ dataset = {}
147
+ for i, k in enumerate(ratios_keys):
148
+ dataset[k] = split_keys[i]
149
+ return dataset
@@ -0,0 +1,98 @@
1
+ #
2
+ # Pavlin Georgiev, Softel Labs
3
+ #
4
+ # This is a proprietary file and may not be copied,
5
+ # distributed, or modified without express permission
6
+ # from the owner. For licensing inquiries, please
7
+ # contact pavlin@softel.bg.
8
+ #
9
+ # 2024
10
+ #
11
+
12
+ import re
13
+ import datetime
14
+ import os
15
+ import os.path
16
+ import json
17
+ import cv2
18
+ import skvideo.io
19
+
20
+ from sciveo.tools.logger import *
21
+
22
+
23
+ def get_resize_resoulution(FH, FW, max_dim):
24
+ if FH <= max_dim:
25
+ debug("get_resize_resoulution", [FH, FW], max_dim)
26
+ return FH, FW
27
+ h = max_dim
28
+ w = int(FW * h / FH)
29
+ if w % 2 == 1:
30
+ w += 1
31
+ return h, w
32
+
33
+ def get_frame_resolution_max_dim(frame, max_dim):
34
+ FH = frame.shape[0]
35
+ FW = frame.shape[1]
36
+
37
+ if FH > FW:
38
+ return get_resize_resoulution(FH, FW, max_dim)
39
+ else:
40
+ w, h = get_resize_resoulution(FW, FH, max_dim)
41
+ return h, w
42
+
43
+ def get_frame_resolution(frame, h):
44
+ FH = frame.shape[0]
45
+ FW = frame.shape[1]
46
+ return get_resize_resoulution(FH, FW, h)
47
+
48
+
49
+ class VideoWriterBase:
50
+ def __init__(self, local_video_path, w=640):
51
+ self.local_video_path = local_video_path
52
+ self.w = w
53
+ self.draw_frame = True
54
+
55
+ def use_frame_draw(self):
56
+ return self.draw_frame
57
+
58
+ def write(self, frame, detections=None):
59
+ pass
60
+
61
+ def close(self):
62
+ pass
63
+
64
+ class VideoWriterDummy(VideoWriterBase):
65
+ def __init__(self, local_video_path, w=640):
66
+ super().__init__(local_video_path, w)
67
+ debug("init", self.local_video_path)
68
+
69
+ def write(self, frame, detections=None):
70
+ pass
71
+
72
+ def close(self):
73
+ debug("close", self.local_video_path)
74
+ pass
75
+
76
+ class VideoWriterFFMPEG(VideoWriterBase):
77
+ def __init__(self, local_video_path, w=640, crf='35', aux_params={}):
78
+ super().__init__(local_video_path, w)
79
+
80
+ output_params = {'-vcodec':'libx264', '-crf':crf, '-preset':'medium', '-vf':'format=yuv420p', '-profile:v':'baseline', '-level':'3.0'}
81
+ output_params = {**output_params, **aux_params}
82
+ info(self.local_video_path, output_params)
83
+ self.out = skvideo.io.FFmpegWriter(self.local_video_path, outputdict=output_params)
84
+
85
+ def write(self, frame, detections=None):
86
+ self.out.writeFrame(frame[:,:,::-1])
87
+
88
+ def close(self):
89
+ self.out.close()
90
+ debug("closed", self.local_video_path)
91
+
92
+ @staticmethod
93
+ def new(local_video_path, w=640, crf='35'):
94
+ if int(os.environ.setdefault('PRODUCTION_MODE', "1")):
95
+ result = VideoWriterFFMPEG(local_video_path, w, crf)
96
+ else:
97
+ result = VideoWriterDummy(local_video_path, w)
98
+ return result
@@ -1,3 +1,14 @@
1
+ #
2
+ # Pavlin Georgiev, Softel Labs
3
+ #
4
+ # This is a proprietary file and may not be copied,
5
+ # distributed, or modified without express permission
6
+ # from the owner. For licensing inquiries, please
7
+ # contact pavlin@softel.bg.
8
+ #
9
+ # 2024
10
+ #
11
+
1
12
  import json
2
13
  import gzip
3
14
  import base64
@@ -1,3 +1,14 @@
1
+ #
2
+ # Pavlin Georgiev, Softel Labs
3
+ #
4
+ # This is a proprietary file and may not be copied,
5
+ # distributed, or modified without express permission
6
+ # from the owner. For licensing inquiries, please
7
+ # contact pavlin@softel.bg.
8
+ #
9
+ # 2024
10
+ #
11
+
1
12
  import json
2
13
  import base64
3
14
  from Crypto.Cipher import AES
@@ -0,0 +1,134 @@
1
+ #
2
+ # Pavlin Georgiev, Softel Labs
3
+ #
4
+ # This is a proprietary file and may not be copied,
5
+ # distributed, or modified without express permission
6
+ # from the owner. For licensing inquiries, please
7
+ # contact pavlin@softel.bg.
8
+ #
9
+ # 2024
10
+ #
11
+
12
+ import json
13
+ from urllib import request, parse
14
+ from urllib.error import HTTPError
15
+ import requests
16
+
17
+ from sciveo.tools.logger import *
18
+ from sciveo.tools.synchronized import ListQueue
19
+
20
+
21
+ def POST_JSON(url, data_json, headers={}, timeout=30):
22
+ result = False
23
+ try:
24
+ #debug("POST", url, data_json, headers)
25
+ response = requests.post(url, json=data_json, headers=headers, timeout=timeout)
26
+ result = response.json()
27
+ debug("POST", result)
28
+ except HTTPError as e:
29
+ error(e, data_json)
30
+ except Exception as e:
31
+ error(e, data_json)
32
+ return result
33
+
34
+ def POST(url, data, headers={}, timeout=30):
35
+ result = False
36
+ try:
37
+ debug("POST", url, data, headers)
38
+ data = parse.urlencode(data).encode("utf-8")
39
+ resp = request.urlopen(request.Request(url, data=data, headers=headers), timeout=timeout)
40
+ result = json.loads(resp.read())
41
+ debug("POST", resp.status, result)
42
+ except HTTPError as e:
43
+ error(e, data)
44
+ except Exception as e:
45
+ error(e, data)
46
+ return result
47
+
48
+ def GET(url, headers={}, timeout=30):
49
+ result = False
50
+ try:
51
+ # debug("GET", url)
52
+ response = requests.get(url, headers=headers, timeout=timeout)
53
+ result = response.json()
54
+ # debug("GET", result)
55
+ except HTTPError as e:
56
+ error(e)
57
+ except Exception as e:
58
+ error(e)
59
+ return result
60
+
61
+
62
+ class HTTPQueueSynchronized:
63
+ _queue = None
64
+
65
+ @staticmethod
66
+ def queue():
67
+ if HTTPQueueSynchronized._queue is None:
68
+ HTTPQueueSynchronized._queue = ListQueue("HTTPQueue")
69
+ return HTTPQueueSynchronized._queue
70
+
71
+ @staticmethod
72
+ def size():
73
+ return HTTPQueueSynchronized.queue().size()
74
+
75
+ @staticmethod
76
+ def get(url,
77
+ url_prefix="{}/api/v1".format(os.environ.get('API_BASE_URL', 'api.smiveo.com')),
78
+ access_token=os.environ.get('AUTH_KEY_SENSORS_API', "none")
79
+ ):
80
+ debug("HTTPQueueSynchronized::GET", url)
81
+ try:
82
+ url = url_prefix + url
83
+ url = HTTPQueueSynchronized.url_append(url, {"access_token": access_token})
84
+ HTTPQueueSynchronized.queue().push({"method": "GET", "url": url, "data": None})
85
+ except Exception as e:
86
+ error(e, "HTTPQueueSynchronized::GET", url)
87
+
88
+ @staticmethod
89
+ def post(url, data,
90
+ url_prefix="{}/api/v1".format(os.environ.get('API_BASE_URL', 'api.smiveo.com')),
91
+ access_token=os.environ.get('AUTH_KEY_SENSORS_API', "none")
92
+ ):
93
+ debug("HTTPQueueSynchronized::POST", url, data)
94
+ try:
95
+ url = url_prefix + url
96
+ data["access_token"] = access_token
97
+ HTTPQueueSynchronized.queue().push({"method": "POST", "url": url, "data": parse.urlencode(data).encode("utf-8")})
98
+ except Exception as e:
99
+ error(e, "HTTPQueueSynchronized::POST", url, data)
100
+
101
+ @staticmethod
102
+ def pop(block=True, timeout=None, retries=5):
103
+ req = HTTPQueueSynchronized.queue().pop(timeout=timeout)
104
+ try:
105
+ while(retries > 0):
106
+ if HTTPQueueSynchronized.save(req["method"], req["url"], req["data"]):
107
+ break
108
+ retries -= 1
109
+ except Exception as e:
110
+ error(e, "HTTPQueueSynchronized::POP")
111
+
112
+ @staticmethod
113
+ def url_append(url, url_args):
114
+ for k, v in url_args.items():
115
+ if "?" in url:
116
+ and_token = "&"
117
+ else:
118
+ and_token = "?"
119
+ url += "{}{}={}".format(and_token, k, v)
120
+ return url
121
+
122
+ @staticmethod
123
+ def save(method, url, data, timeout=10):
124
+ try:
125
+ debug("HTTPQueueSynchronized", method, url, data)
126
+ resp = request.urlopen(request.Request(url, data=data), timeout=timeout)
127
+ debug("HTTPQueueSynchronized", resp.status, resp.read())
128
+ except HTTPError as e:
129
+ error(e, "HTTPQueueSynchronized::HTTPError", method, url, data)
130
+ return False
131
+ except Exception as e:
132
+ error(e, "HTTPQueueSynchronized::Exception", method, url, data)
133
+ return False
134
+ return True
@@ -0,0 +1,67 @@
1
+ #
2
+ # Pavlin Georgiev, Softel Labs
3
+ #
4
+ # This is a proprietary file and may not be copied,
5
+ # distributed, or modified without express permission
6
+ # from the owner. For licensing inquiries, please
7
+ # contact pavlin@softel.bg.
8
+ #
9
+ # 2024
10
+ #
11
+
12
+ import os
13
+ import sys
14
+ import time
15
+ from sciveo.tools.logger import *
16
+
17
+ def mkdirs(path):
18
+ if not os.path.exists(path):
19
+ os.makedirs(path)
20
+ # else:
21
+ # debug("mkdirs", path, "exists")
22
+
23
+ def file_makedirs(file_path):
24
+ return mkdirs(os.path.dirname(file_path))
25
+
26
+ def touched(path):
27
+ try:
28
+ last_touched = time.time() - os.path.getmtime(path)
29
+ except Exception:
30
+ last_touched = sys.maxsize
31
+ return last_touched
32
+
33
+ def rm_file(local_path, tag=""):
34
+ try:
35
+ os.remove(local_path)
36
+ debug(tag, "RM", local_path)
37
+ except FileNotFoundError as e:
38
+ exception(e, tag, local_path)
39
+ except Exception as e:
40
+ exception(e, tag, local_path)
41
+
42
+ def file_name_split(file_path):
43
+ directory, file_name = os.path.split(file_path)
44
+ name, extension = os.path.splitext(file_name)
45
+ return name, extension
46
+
47
+ def add_suffix_to_filename(file_path, siffix):
48
+ directory, file_name = os.path.split(file_path)
49
+ name, extension = os.path.splitext(file_name)
50
+ new_file_name = f"{name}-{siffix}{extension}"
51
+ new_file_path = os.path.join(directory, new_file_name)
52
+ return new_file_path
53
+
54
+ def replace_extension_to_filename(file_path, new_ext):
55
+ directory, file_name = os.path.split(file_path)
56
+ name, extension = os.path.splitext(file_name)
57
+ new_file_name = f"{name}.{new_ext}"
58
+ new_file_path = os.path.join(directory, new_file_name)
59
+ return new_file_path
60
+
61
+ def run_system_cmd(cmd):
62
+ try:
63
+ debug("SYSTEM start [", cmd, "]")
64
+ os.system(cmd)
65
+ debug("SYSTEM finished [", cmd, "]")
66
+ except Exception as e:
67
+ exception(e, "SYSTEM FAILED [", cmd, "]")
@@ -0,0 +1,112 @@
1
+ #
2
+ # Pavlin Georgiev, Softel Labs
3
+ #
4
+ # This is a proprietary file and may not be copied,
5
+ # distributed, or modified without express permission
6
+ # from the owner. For licensing inquiries, please
7
+ # contact pavlin@softel.bg.
8
+ #
9
+ # 2024
10
+ #
11
+
12
+ import time
13
+ import sys
14
+ from datetime import datetime
15
+
16
+
17
+ class SimpleCounter:
18
+ def __init__(self, count):
19
+ self.counter = 0
20
+ self.current_count = 0
21
+ self.count = count
22
+
23
+ def run(self):
24
+ self.counter += 1
25
+ self.current_count += 1
26
+ if self.current_count >= self.count:
27
+ self.current_count = 0
28
+
29
+ return self.current_count == 0
30
+
31
+ def reset(self):
32
+ self.current_count = 0
33
+
34
+
35
+ class RunCounter(SimpleCounter):
36
+ def __init__(self, count, fn):
37
+ super().__init__(count)
38
+ self.fn = fn
39
+
40
+ def run(self):
41
+ if super().run():
42
+ self.fn()
43
+
44
+
45
+ class Timer:
46
+ def __init__(self):
47
+ self.start()
48
+
49
+ def start(self):
50
+ self.start_at = time.time()
51
+
52
+ def stop(self):
53
+ self.end_at = time.time()
54
+ return self.elapsed()
55
+
56
+ def elapsed(self):
57
+ return self.end_at - self.start_at
58
+
59
+
60
+ class TimerDateTime:
61
+ def __init__(self):
62
+ self.start()
63
+
64
+ def start(self):
65
+ self.start_at = datetime.now()
66
+
67
+ def stop(self):
68
+ self.end_at = datetime.now()
69
+ return self.elapsed()
70
+
71
+ def elapsed(self):
72
+ return (self.end_at - self.start_at).total_seconds()
73
+
74
+
75
+ class TimerExpire(Timer):
76
+ def __init__(self, expiry_period):
77
+ super().__init__()
78
+ self.expiry_period = expiry_period
79
+
80
+ def finished(self):
81
+ return self.stop() > self.expiry_period
82
+
83
+
84
+ class SimpleStat:
85
+ def __init__(self):
86
+ self.stat = {"min": sys.float_info.max, "max": - sys.float_info.max, "sum": 0, "count": 0, "mean": 0}
87
+
88
+ def __dict__(self):
89
+ return self.stat
90
+
91
+ def __str__(self):
92
+ return "{}".format(self.stat)
93
+
94
+ def __repr__(self):
95
+ return self.__str__()
96
+
97
+ def set(self, val):
98
+ if self.stat["min"] > val:
99
+ self.stat["min"] = val
100
+ if self.stat["max"] < val:
101
+ self.stat["max"] = val
102
+ self.stat["sum"] += val
103
+ self.stat["count"] += 1
104
+ self.stat["mean"] = self.stat["sum"] / self.stat["count"]
105
+
106
+
107
+ class ProcessedStatTimer(Timer):
108
+ def __call__(self, num_processed):
109
+ elapsed = self.stop()
110
+ pps = round(num_processed / elapsed, 1)
111
+ elapsed = round(elapsed, 1)
112
+ return elapsed, pps
@@ -0,0 +1,160 @@
1
+ #
2
+ # Pavlin Georgiev, Softel Labs
3
+ #
4
+ # This is a proprietary file and may not be copied,
5
+ # distributed, or modified without express permission
6
+ # from the owner. For licensing inquiries, please
7
+ # contact pavlin@softel.bg.
8
+ #
9
+ # 2024
10
+ #
11
+
12
+ import threading
13
+ import uuid
14
+ import copy
15
+ import json
16
+ import datetime
17
+
18
+ from sciveo.tools.logger import *
19
+
20
+
21
+ class BaseSynchronized:
22
+ def __init__(self, tag=""):
23
+ self.lock_data = threading.Lock()
24
+ if tag:
25
+ tag += "-"
26
+ self._guid = "guid-{}{}-{}".format(tag, datetime.datetime.now().strftime("%Y-%m-%d"), str(uuid.uuid4()).replace("-", ""))
27
+
28
+ def guid(self):
29
+ with self.lock_data:
30
+ return self._guid
31
+
32
+
33
+ class ListQueue(BaseSynchronized):
34
+ def __init__(self, tag=""):
35
+ super().__init__(tag)
36
+ self.cv = threading.Condition()
37
+ self.data = []
38
+
39
+ def size(self):
40
+ with self.cv:
41
+ return len(self.data)
42
+
43
+ def get_data(self):
44
+ with self.cv:
45
+ return copy.deepcopy(self.data)
46
+
47
+ def push(self, data):
48
+ with self.cv:
49
+ self.data.append(data)
50
+ self.cv.notify()
51
+
52
+ def pop(self, timeout=None):
53
+ with self.cv:
54
+ self.cv.wait_for(predicate=lambda: len(self.data) > 0, timeout=timeout)
55
+ if len(self.data) > 0:
56
+ return self.data.pop(0)
57
+ else:
58
+ raise Exception(f"{type(self).__name__}::POP empty after timeout {timeout}")
59
+
60
+
61
+ class CounterSynchronized(BaseSynchronized):
62
+ def __init__(self, tag=""):
63
+ super().__init__(tag)
64
+ self.data_sync = {}
65
+
66
+ def inc(self, k):
67
+ with self.lock_data:
68
+ self.data_sync.setdefault(k, 0)
69
+ self.data_sync[k] += 1
70
+
71
+ def dec(self, k):
72
+ with self.lock_data:
73
+ self.data_sync.setdefault(k, 0)
74
+ self.data_sync[k] -= 1
75
+
76
+ def data(self):
77
+ with self.lock_data:
78
+ return copy.deepcopy(self.data_sync)
79
+
80
+
81
+ class CallbackSynchronized(BaseSynchronized):
82
+ def __init__(self, tag=""):
83
+ super().__init__(tag)
84
+ self.callbacks = {}
85
+
86
+ def hook(self, name, action):
87
+ with self.lock_data:
88
+ self.callbacks.setdefault(name, []).append(action)
89
+ debug(self._guid, "hooked", name, action, self.callbacks)
90
+
91
+ def __call__(self, name, data):
92
+ with self.lock_data:
93
+ for callback in self.callbacks.setdefault(name, []):
94
+ try:
95
+ callback(data)
96
+ except Exception as e:
97
+ exception([self], e, name, callback, data)
98
+
99
+
100
+ class DataSynchronized(BaseSynchronized):
101
+ def __init__(self, tag=""):
102
+ super().__init__(tag)
103
+ self.data_sync = {}
104
+
105
+ def size(self):
106
+ with self.lock_data:
107
+ return len(self.data_sync)
108
+
109
+ def set_one(self, key, value):
110
+ with self.lock_data:
111
+ self.data_sync[key] = value
112
+
113
+ def set(self, data):
114
+ with self.lock_data:
115
+ for k, v in data.items():
116
+ self.data_sync[k] = v
117
+
118
+ def setdefault(self, data):
119
+ with self.lock_data:
120
+ for k, v in data.items():
121
+ self.data_sync.setdefault(k, v)
122
+
123
+ def get(self, key):
124
+ with self.lock_data:
125
+ return self.data_sync.get(key, None)
126
+
127
+ def pop(self, key):
128
+ result = None
129
+ with self.lock_data:
130
+ try:
131
+ result = self.data_sync.pop(key)
132
+ except Exception as e:
133
+ result = None
134
+ return result
135
+
136
+ def keys(self):
137
+ with self.lock_data:
138
+ return self.data_sync.keys()
139
+
140
+ def data(self):
141
+ with self.lock_data:
142
+ return copy.deepcopy(self.data_sync)
143
+
144
+ @staticmethod
145
+ def fix_dict(data, list_to_json=[]):
146
+ fixed_data = {}
147
+ for k, v in data.items():
148
+ if type(v) == str:
149
+ v = v.replace("+", " ")
150
+ if k in list_to_json:
151
+ v = v.replace("\'", "\"")
152
+ v = json.loads(v)
153
+ fixed_data[k] = v
154
+ return fixed_data
155
+
156
+ @staticmethod
157
+ def data2json(data, keys):
158
+ for key in keys:
159
+ if key in data:
160
+ data[key] = json.loads(data[key].replace("+", " ").replace("\'", "\"").replace("True", "true").replace("False", "false"))
@@ -0,0 +1,2 @@
1
+
2
+ __version__ = '0.1.23'
@@ -1,10 +1,14 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: sciveo
3
- Version: 0.1.22
3
+ Version: 0.1.23
4
4
  Description-Content-Type: text/markdown
5
5
  Provides-Extra: mon
6
6
  Provides-Extra: net
7
+ Provides-Extra: media
8
+ Provides-Extra: media-server
9
+ Provides-Extra: media-ml
7
10
  Provides-Extra: all
11
+ Provides-Extra: media-all
8
12
 
9
13
  # SCIVEO - ML/AI and Scientific tools
10
14
 
@@ -30,15 +30,20 @@ sciveo/network/camera.py
30
30
  sciveo/network/sniffer.py
31
31
  sciveo/network/tools.py
32
32
  sciveo/tools/__init__.py
33
+ sciveo/tools/array.py
34
+ sciveo/tools/common.py
33
35
  sciveo/tools/compress.py
34
36
  sciveo/tools/configuration.py
35
37
  sciveo/tools/crypto.py
36
38
  sciveo/tools/daemon.py
37
39
  sciveo/tools/formating.py
38
40
  sciveo/tools/hardware.py
41
+ sciveo/tools/http.py
39
42
  sciveo/tools/logger.py
43
+ sciveo/tools/os.py
40
44
  sciveo/tools/random.py
41
45
  sciveo/tools/remote.py
46
+ sciveo/tools/simple_counter.py
42
47
  sciveo/tools/synchronized.py
43
48
  sciveo/tools/timers.py
44
49
  test/test_compress.py
@@ -0,0 +1,79 @@
1
+ numpy>=0.0.0
2
+ requests>=0.0.0
3
+
4
+ [all]
5
+ psutil>=0.0.0
6
+ netifaces>=0.0.0
7
+ scapy>=0.0.0
8
+
9
+ [media]
10
+ scikit-learn
11
+ scipy
12
+ scikit-video
13
+ scikit-image
14
+ pycryptodome
15
+ exifread
16
+ qrcode[pil]
17
+ boto3
18
+ pandas
19
+ pika
20
+ regex
21
+ matplotlib
22
+ joblib
23
+ tqdm
24
+ ffmpeg-python
25
+ opencv-python-headless
26
+ opencv-contrib-python-headless
27
+
28
+ [media-all]
29
+ psutil>=0.0.0
30
+ netifaces>=0.0.0
31
+ scapy>=0.0.0
32
+ scikit-learn
33
+ scipy
34
+ scikit-video
35
+ scikit-image
36
+ pycryptodome
37
+ exifread
38
+ qrcode[pil]
39
+ boto3
40
+ pandas
41
+ pika
42
+ regex
43
+ matplotlib
44
+ joblib
45
+ tqdm
46
+ ffmpeg-python
47
+ opencv-python-headless
48
+ opencv-contrib-python-headless
49
+ fastapi
50
+ uvicorn[standard]
51
+ tensorflow
52
+ keras
53
+ torch
54
+ torchvision
55
+ diffusers
56
+ transformers
57
+ accelerate
58
+ annoy
59
+
60
+ [media-ml]
61
+ tensorflow
62
+ keras
63
+ torch
64
+ torchvision
65
+ diffusers
66
+ transformers
67
+ accelerate
68
+ annoy
69
+
70
+ [media-server]
71
+ fastapi
72
+ uvicorn[standard]
73
+
74
+ [mon]
75
+ psutil>=0.0.0
76
+
77
+ [net]
78
+ netifaces>=0.0.0
79
+ scapy>=0.0.0
@@ -12,6 +12,28 @@
12
12
  from setuptools import setup, find_packages
13
13
  from sciveo.version import __version__
14
14
 
15
+ extras_require = {
16
+ 'mon': [
17
+ 'psutil>=0.0.0',
18
+ ],
19
+ 'net': [
20
+ 'netifaces>=0.0.0',
21
+ 'scapy>=0.0.0',
22
+ ],
23
+ 'media': [
24
+ 'scikit-learn', 'scipy', 'scikit-video', 'scikit-image', 'pycryptodome', 'exifread', 'qrcode[pil]',
25
+ 'boto3', 'pandas', 'pika', 'regex', 'matplotlib', 'joblib', 'tqdm',
26
+ 'ffmpeg-python', 'opencv-python-headless', 'opencv-contrib-python-headless',
27
+ ],
28
+ 'media-server': ['fastapi', 'uvicorn[standard]'],
29
+ 'media-ml': [
30
+ 'tensorflow', 'keras', 'torch', 'torchvision', 'diffusers', 'transformers', 'accelerate', 'annoy',
31
+ ]
32
+ }
33
+
34
+ extras_require['all'] = extras_require['mon'] + extras_require['net']
35
+ extras_require['media-all'] = extras_require['all'] + extras_require['media'] + extras_require['media-server'] + extras_require['media-ml']
36
+
15
37
  setup(
16
38
  name='sciveo',
17
39
  version=__version__,
@@ -22,21 +44,7 @@ setup(
22
44
  ],
23
45
  long_description=open('README.md').read(),
24
46
  long_description_content_type='text/markdown',
25
- extras_require={
26
- 'mon': [
27
- 'psutil>=0.0.0',
28
- ],
29
- 'net': [
30
- 'netifaces>=0.0.0',
31
- 'scapy>=0.0.0',
32
- ],
33
- 'all': [
34
- 'psutil>=0.0.0',
35
- 'netifaces>=0.0.0',
36
- 'scapy>=0.0.0',
37
- 'pycryptodome>=0.0.0'
38
- ]
39
- },
47
+ extras_require=extras_require,
40
48
  py_modules=['sciveo'],
41
49
  entry_points={
42
50
  'console_scripts': [
@@ -1,59 +0,0 @@
1
- #
2
- # Pavlin Georgiev, Softel Labs
3
- #
4
- # This is a proprietary file and may not be copied,
5
- # distributed, or modified without express permission
6
- # from the owner. For licensing inquiries, please
7
- # contact pavlin@softel.bg.
8
- #
9
- # 2023
10
- #
11
-
12
- import threading
13
- import uuid
14
- import copy
15
- import json
16
- import datetime
17
-
18
- from sciveo.tools.logger import *
19
-
20
-
21
- class BaseSynchronized:
22
- def __init__(self, tag=""):
23
- self.lock_data = threading.Lock()
24
- if tag:
25
- tag += "-"
26
- self._guid = "guid-{}{}-{}".format(tag, datetime.datetime.now().strftime("%Y-%m-%d"), str(uuid.uuid4()).replace("-", ""))
27
-
28
- def guid(self):
29
- with self.lock_data:
30
- return self._guid
31
-
32
-
33
- class ListQueue(BaseSynchronized):
34
- def __init__(self, tag=""):
35
- super().__init__(tag)
36
- self.cv = threading.Condition()
37
- self.data = []
38
-
39
- def size(self):
40
- with self.cv:
41
- return len(self.data)
42
-
43
- def get_data(self):
44
- with self.cv:
45
- return copy.deepcopy(self.data)
46
-
47
- def push(self, data):
48
- with self.cv:
49
- self.data.append(data)
50
- self.cv.notify()
51
-
52
- def pop(self, timeout=None):
53
- with self.cv:
54
- self.cv.wait_for(predicate=lambda: len(self.data) > 0, timeout=timeout)
55
- if len(self.data) > 0:
56
- return self.data.pop(0)
57
- else:
58
- raise Exception(f"{type(self).__name__}::POP empty after timeout {timeout}")
59
-
@@ -1,2 +0,0 @@
1
-
2
- __version__ = '0.1.22'
@@ -1,15 +0,0 @@
1
- numpy>=0.0.0
2
- requests>=0.0.0
3
-
4
- [all]
5
- psutil>=0.0.0
6
- netifaces>=0.0.0
7
- scapy>=0.0.0
8
- pycryptodome>=0.0.0
9
-
10
- [mon]
11
- psutil>=0.0.0
12
-
13
- [net]
14
- netifaces>=0.0.0
15
- scapy>=0.0.0
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes