vnai 2.1.0__tar.gz → 2.1.1__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
1
  Metadata-Version: 2.4
2
2
  Name: vnai
3
- Version: 2.1.0
3
+ Version: 2.1.1
4
4
  Summary: System optimization and resource management toolkit
5
5
  Author-email: Vnstock HQ <support@vnstocks.com>
6
6
  License: MIT
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "vnai"
7
- version = "2.1.0"
7
+ version = "2.1.1"
8
8
  description = "System optimization and resource management toolkit"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.7"
@@ -1,12 +1,13 @@
1
- _K='success'
2
- _J='buffer_size'
3
- _I='request'
4
- _H='rate_limit'
1
+ _L='success'
2
+ _K='buffer_size'
3
+ _J='request'
4
+ _I='rate_limit'
5
+ _H='args'
5
6
  _G='execution_time'
6
7
  _F='timestamp'
7
- _E=False
8
- _D='error'
9
- _C=True
8
+ _E=True
9
+ _D=False
10
+ _C='error'
10
11
  _B=None
11
12
  _A='function'
12
13
  import sys,time,threading
@@ -18,7 +19,7 @@ class Collector:
18
19
  with cls._lock:
19
20
  if cls._instance is _B:cls._instance=super(Collector,cls).__new__(cls);cls._instance._initialize()
20
21
  return cls._instance
21
- def _initialize(self):self.metrics={_A:[],_H:[],_I:[],_D:[]};self.thresholds={_J:50,'error_threshold':.1,'performance_threshold':5.};self.function_count=0;self.colab_auth_triggered=_E;self.max_metric_length=200;self._last_record_time={};self.min_interval_per_type=.5
22
+ def _initialize(self):self.metrics={_A:[],_I:[],_J:[],_C:[]};self.thresholds={_K:50,'error_threshold':.1,'performance_threshold':5.};self.function_count=0;self.colab_auth_triggered=_D;self.max_metric_length=200;self._last_record_time={};self.min_interval_per_type=.5;self._recent_hashes=[];self._sending_metrics=_D
22
23
  def record(self,metric_type,data,priority=_B):
23
24
  A='high'
24
25
  if not isinstance(data,dict):data={'value':str(data)}
@@ -26,7 +27,7 @@ class Collector:
26
27
  if metric_type!='system_info':data.pop('system',_B);from vnai.scope.profile import inspector;data['machine_id']=inspector.fingerprint()
27
28
  now=time.time();last_time=self._last_record_time.get(metric_type,0)
28
29
  if now-last_time<self.min_interval_per_type and priority!=A:return
29
- self._last_record_time[metric_type]=now;data_hash=hashlib.md5(json.dumps(data,sort_keys=_C).encode()).hexdigest()
30
+ self._last_record_time[metric_type]=now;data_hash=hashlib.md5(json.dumps(data,sort_keys=_E).encode()).hexdigest()
30
31
  if data_hash in self._recent_hashes and priority!=A:return
31
32
  self._recent_hashes.append(data_hash)
32
33
  if metric_type in self.metrics:
@@ -35,31 +36,38 @@ class Collector:
35
36
  else:self.metrics[_A].append(data)
36
37
  if metric_type==_A:
37
38
  self.function_count+=1
38
- if self.function_count>10 and not self.colab_auth_triggered and'google.colab'in sys.modules:self.colab_auth_triggered=_C;threading.Thread(target=self._trigger_colab_auth,daemon=_C).start()
39
- if sum(len(metric_list)for metric_list in self.metrics.values())>=self.thresholds[_J]:self._send_metrics()
40
- if priority==A or metric_type==_D:self._send_metrics()
39
+ if self.function_count>10 and not self.colab_auth_triggered and'google.colab'in sys.modules:self.colab_auth_triggered=_E;threading.Thread(target=self._trigger_colab_auth,daemon=_E).start()
40
+ if sum(len(metric_list)for metric_list in self.metrics.values())>=self.thresholds[_K]:self._send_metrics()
41
+ if priority==A or metric_type==_C:self._send_metrics()
41
42
  def _trigger_colab_auth(self):
42
43
  try:from vnai.scope.profile import inspector;inspector.get_or_create_user_id()
43
44
  except:pass
44
45
  def _send_metrics(self):
45
- C='vnai';B='source';A='unknown';from vnai.flow.relay import track_function_call,track_rate_limit,track_api_request
46
+ C='vnai';B='source';A='unknown'
47
+ if self._sending_metrics:return
48
+ self._sending_metrics=_E
49
+ try:from vnai.flow.relay import track_function_call,track_rate_limit,track_api_request
50
+ except ImportError:
51
+ for metric_type in self.metrics:self.metrics[metric_type]=[]
52
+ self._sending_metrics=_D;return
46
53
  for(metric_type,data_list)in self.metrics.items():
47
54
  if not data_list:continue
48
55
  for data in data_list:
49
56
  try:
50
- if metric_type==_A:track_function_call(function_name=data.get(_A,A),source=data.get(B,C),execution_time=data.get(_G,0),success=data.get(_K,_C),error=data.get(_D),args=data.get('args'))
51
- elif metric_type==_H:track_rate_limit(source=data.get(B,C),limit_type=data.get('limit_type',A),limit_value=data.get('limit_value',0),current_usage=data.get('current_usage',0),is_exceeded=data.get('is_exceeded',_E))
52
- elif metric_type==_I:track_api_request(endpoint=data.get('endpoint',A),source=data.get(B,C),method=data.get('method','GET'),status_code=data.get('status_code',200),execution_time=data.get(_G,0),request_size=data.get('request_size',0),response_size=data.get('response_size',0))
57
+ if metric_type==_A:track_function_call(function_name=data.get(_A,A),source=data.get(B,C),execution_time=data.get(_G,0),success=data.get(_L,_E),error=data.get(_C),args=data.get(_H))
58
+ elif metric_type==_I:track_rate_limit(source=data.get(B,C),limit_type=data.get('limit_type',A),limit_value=data.get('limit_value',0),current_usage=data.get('current_usage',0),is_exceeded=data.get('is_exceeded',_D))
59
+ elif metric_type==_J:track_api_request(endpoint=data.get('endpoint',A),source=data.get(B,C),method=data.get('method','GET'),status_code=data.get('status_code',200),execution_time=data.get(_G,0),request_size=data.get('request_size',0),response_size=data.get('response_size',0))
53
60
  except Exception as e:continue
54
61
  self.metrics[metric_type]=[]
62
+ self._sending_metrics=_D
55
63
  def get_metrics_summary(self):return{metric_type:len(data_list)for(metric_type,data_list)in self.metrics.items()}
56
64
  collector=Collector()
57
65
  def capture(module_type=_A):
58
66
  def decorator(func):
59
67
  def wrapper(*args,**kwargs):
60
- start_time=time.time();success=_E;error=_B
61
- try:result=func(*args,**kwargs);success=_C;return result
62
- except Exception as e:error=str(e);raise
63
- finally:execution_time=time.time()-start_time;collector.record(module_type,{_A:func.__name__,_G:execution_time,_K:success,_D:error,_F:datetime.now().isoformat(),'args':str(args)[:100]if args else _B})
68
+ start_time=time.time();success=_D;error=_B
69
+ try:result=func(*args,**kwargs);success=_E;return result
70
+ except Exception as e:error=str(e);collector.record(_C,{_A:func.__name__,_C:error,_H:str(args)[:100]if args else _B});raise
71
+ finally:execution_time=time.time()-start_time;collector.record(module_type,{_A:func.__name__,_G:execution_time,_L:success,_C:error,_F:datetime.now().isoformat(),_H:str(args)[:100]if args else _B})
64
72
  return wrapper
65
73
  return decorator
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: vnai
3
- Version: 2.1.0
3
+ Version: 2.1.1
4
4
  Summary: System optimization and resource management toolkit
5
5
  Author-email: Vnstock HQ <support@vnstocks.com>
6
6
  License: MIT
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