vnai 2.1.7__tar.gz → 2.1.8__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,20 +1,20 @@
1
- Metadata-Version: 2.4
2
- Name: vnai
3
- Version: 2.1.7
4
- Summary: Vnstock Analytics Interface
5
- Author-email: Vnstock Analytics Team <support@vnstocks.com>
6
- License: proprietary
7
- Project-URL: Homepage, https://vnstocks.com
8
- Classifier: Programming Language :: Python :: 3
9
- Classifier: Operating System :: OS Independent
10
- Classifier: Development Status :: 4 - Beta
11
- Classifier: Intended Audience :: Developers
12
- Classifier: Topic :: Software Development :: Libraries :: Python Modules
13
- Requires-Python: >=3.7
14
- Description-Content-Type: text/markdown
15
- Requires-Dist: requests>=2.25.0
16
- Requires-Dist: psutil>=5.8.0
17
- Provides-Extra: dev
18
- Requires-Dist: pytest>=6.0.0; extra == "dev"
19
-
20
- # VnAI
1
+ Metadata-Version: 2.4
2
+ Name: vnai
3
+ Version: 2.1.8
4
+ Summary: Vnstock Analytics Interface
5
+ Author-email: Vnstock Analytics Team <support@vnstocks.com>
6
+ License: proprietary
7
+ Project-URL: Homepage, https://vnstocks.com
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: Operating System :: OS Independent
10
+ Classifier: Development Status :: 4 - Beta
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
13
+ Requires-Python: >=3.7
14
+ Description-Content-Type: text/markdown
15
+ Requires-Dist: requests>=2.25.0
16
+ Requires-Dist: psutil>=5.8.0
17
+ Provides-Extra: dev
18
+ Requires-Dist: pytest>=6.0.0; extra == "dev"
19
+
20
+ # VnAI
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "vnai"
7
- version = "2.1.7"
7
+ version = "2.1.8"
8
8
  description = "Vnstock Analytics Interface"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.7"
@@ -1,4 +1,4 @@
1
- [egg_info]
2
- tag_build =
3
- tag_date = 0
4
-
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,240 @@
1
+ # vnai/__init__.py
2
+ # Main entry point for vnai package
3
+
4
+ import os
5
+ import pathlib
6
+ import json
7
+ import time
8
+ import threading
9
+ import functools
10
+ from datetime import datetime
11
+
12
+ # Import core functionality
13
+ from vnai.beam.quota import guardian, optimize
14
+ from vnai.beam.metrics import collector, capture
15
+ from vnai.beam.pulse import monitor
16
+ from vnai.flow.relay import conduit
17
+ from vnai.flow.queue import buffer
18
+ from vnai.scope.profile import inspector
19
+ from vnai.scope.state import tracker, record
20
+ import vnai.scope.promo
21
+ from vnai.scope.promo import present
22
+
23
+ # Constants for terms and conditions
24
+ TC_VAR = "ACCEPT_TC"
25
+ TC_VAL = "tôi đồng ý"
26
+ TC_PATH = pathlib.Path.home() / ".vnstock" / "id" / "terms_agreement.txt"
27
+
28
+ TERMS_AND_CONDITIONS = """
29
+ Khi tiếp tục sử dụng Vnstock, bạn xác nhận rằng bạn đã đọc, hiểu và đồng ý với Chính sách quyền riêng tư và Điều khoản, điều kiện về giấy phép sử dụng Vnstock.
30
+
31
+ Chi tiết:
32
+ - Giấy phép sử dụng phần mềm: https://vnstocks.com/docs/tai-lieu/giay-phep-su-dung
33
+ - Chính sách quyền riêng tư: https://vnstocks.com/docs/tai-lieu/chinh-sach-quyen-rieng-tu
34
+ """
35
+
36
+ class Core:
37
+ """Core functionality for system optimization"""
38
+
39
+ def __init__(self):
40
+ """Initialize core"""
41
+ self.initialized = False
42
+ self.webhook_url = None
43
+ self.init_time = datetime.now().isoformat()
44
+ self.home_dir = pathlib.Path.home()
45
+ self.project_dir = self.home_dir / ".vnstock"
46
+ self.id_dir = self.project_dir / 'id'
47
+ self.terms_file_path = TC_PATH
48
+ self.system_info = None
49
+
50
+ # Create necessary directories
51
+ self.project_dir.mkdir(exist_ok=True)
52
+ self.id_dir.mkdir(exist_ok=True)
53
+
54
+ # Auto-initialize
55
+ self.initialize()
56
+
57
+ def initialize(self):
58
+ """Initialize the system"""
59
+ if self.initialized:
60
+ return True
61
+
62
+ # Check terms acceptance
63
+ if not self._check_terms():
64
+ self._accept_terms()
65
+
66
+ # Set up vnstock environment
67
+ from vnai.scope.profile import inspector
68
+ inspector.setup_vnstock_environment()
69
+
70
+ # Display content during initialization
71
+ from vnai.scope.promo import ContentManager
72
+ manager = ContentManager()
73
+ # Chỉ hiện ads nếu chắc chắn là free user
74
+ if manager.is_paid_user is False and getattr(manager, 'license_checked', False):
75
+ present()
76
+
77
+ # Record initialization
78
+ record("initialization", {"timestamp": datetime.now().isoformat()})
79
+
80
+ # Get system information ONCE and store it in the class
81
+ self.system_info = inspector.examine()
82
+
83
+ # Queue system data with optimal structure
84
+ conduit.queue({
85
+ "type": "system_info",
86
+ "data": {
87
+ "commercial": inspector.detect_commercial_usage(),
88
+ "packages": inspector.scan_packages()
89
+ }
90
+ }, priority="high")
91
+
92
+ self.initialized = True
93
+ return True
94
+
95
+ def _check_terms(self):
96
+ """Check if terms have been accepted"""
97
+ return os.path.exists(self.terms_file_path)
98
+
99
+ def _accept_terms(self):
100
+ """Record terms acceptance"""
101
+ # Get system information
102
+ system_info = inspector.examine()
103
+
104
+ # Auto-accept terms
105
+ if TC_VAR in os.environ and os.environ[TC_VAR] == TC_VAL:
106
+ response = TC_VAL
107
+ else:
108
+ # For non-interactive environments, accept by default
109
+ response = TC_VAL
110
+ os.environ[TC_VAR] = TC_VAL
111
+
112
+ # Store the acceptance with hardware info
113
+ now = datetime.now()
114
+ signed_agreement = (
115
+ f"Người dùng có mã nhận dạng {system_info['machine_id']} đã chấp nhận "
116
+ f"điều khoản & điều kiện sử dụng Vnstock lúc {now}\n"
117
+ f"---\n\n"
118
+ f"THÔNG TIN THIẾT BỊ: {json.dumps(system_info, indent=2)}\n\n"
119
+ f"Đính kèm bản sao nội dung bạn đã đọc, hiểu rõ và đồng ý dưới đây:\n"
120
+ f"{TERMS_AND_CONDITIONS}"
121
+ )
122
+
123
+ # Store the acceptance
124
+ with open(self.terms_file_path, "w", encoding="utf-8") as f:
125
+ f.write(signed_agreement)
126
+
127
+ # Create the environment.json file that vnstock expects
128
+ env_file = self.id_dir / "environment.json"
129
+ env_data = {
130
+ "accepted_agreement": True,
131
+ "timestamp": now.isoformat(),
132
+ "machine_id": system_info['machine_id']
133
+ }
134
+
135
+ with open(env_file, "w") as f:
136
+ json.dump(env_data, f)
137
+
138
+ return True
139
+
140
+ def status(self):
141
+ """Get system status"""
142
+ return {
143
+ "initialized": self.initialized,
144
+ "health": monitor.report(),
145
+ "metrics": tracker.get_metrics()
146
+ # Environment information available via self.system_info
147
+ }
148
+
149
+ def configure_privacy(self, level="standard"):
150
+ """Configure privacy settings"""
151
+ from vnai.scope.state import tracker
152
+ return tracker.setup_privacy(level)
153
+
154
+
155
+ # Create singleton instance
156
+ core = Core()
157
+
158
+ # Backward support
159
+ def tc_init():
160
+ return core.initialize()
161
+
162
+ def setup():
163
+ """Setup vnai"""
164
+ return core.initialize()
165
+
166
+ def optimize_execution(resource_type="default"):
167
+ """Decorator for optimizing function execution"""
168
+ return optimize(resource_type)
169
+
170
+ def agg_execution(resource_type="default"):
171
+ """Decorator for aggregating function execution"""
172
+ return optimize(resource_type, ad_cooldown=1500, content_trigger_threshold=100000)
173
+
174
+ def measure_performance(module_type="function"):
175
+ """Decorator for measuring function performance"""
176
+ return capture(module_type)
177
+
178
+ def accept_license_terms(terms_text=None):
179
+ """Accept license terms and conditions"""
180
+ if terms_text is None:
181
+ terms_text = TERMS_AND_CONDITIONS
182
+
183
+ # Get system information
184
+ system_info = inspector.examine()
185
+
186
+ # Record acceptance
187
+ terms_file = pathlib.Path.home() / ".vnstock" / "id" / "terms_agreement.txt"
188
+ os.makedirs(os.path.dirname(terms_file), exist_ok=True)
189
+
190
+ with open(terms_file, "w", encoding="utf-8") as f:
191
+ f.write(f"Terms accepted at {datetime.now().isoformat()}\n")
192
+ f.write(f"System: {json.dumps(system_info)}\n\n")
193
+ f.write(terms_text)
194
+
195
+ return True
196
+
197
+ def accept_vnstock_terms():
198
+ """Accept vnstock terms and create necessary files"""
199
+ # Get system information
200
+ from vnai.scope.profile import inspector
201
+ system_info = inspector.examine()
202
+
203
+ # Create necessary directories
204
+ home_dir = pathlib.Path.home()
205
+ project_dir = home_dir / ".vnstock"
206
+ project_dir.mkdir(exist_ok=True)
207
+ id_dir = project_dir / 'id'
208
+ id_dir.mkdir(exist_ok=True)
209
+
210
+ # Create environment.json file that vnstock looks for
211
+ env_file = id_dir / "environment.json"
212
+ env_data = {
213
+ "accepted_agreement": True,
214
+ "timestamp": datetime.now().isoformat(),
215
+ "machine_id": system_info['machine_id']
216
+ }
217
+
218
+ try:
219
+ with open(env_file, "w") as f:
220
+ json.dump(env_data, f)
221
+ print("Vnstock terms accepted successfully.")
222
+ return True
223
+ except Exception as e:
224
+ print(f"Error accepting terms: {e}")
225
+ return False
226
+
227
+ def configure_privacy(level="standard"):
228
+ """Configure privacy level for analytics data"""
229
+ from vnai.scope.state import tracker
230
+ return tracker.setup_privacy(level)
231
+
232
+ def check_commercial_usage():
233
+ """Check if running in commercial environment"""
234
+ from vnai.scope.profile import inspector
235
+ return inspector.detect_commercial_usage()
236
+
237
+ def authenticate_for_persistence():
238
+ """Authenticate to Google Drive for persistent settings (Colab only)"""
239
+ from vnai.scope.profile import inspector
240
+ return inspector.get_or_create_user_id()
@@ -1,3 +1,5 @@
1
- from vnai.beam.quota import guardian, optimize
2
- from vnai.beam.metrics import collector, capture
1
+ # vnai/beam/__init__.py
2
+
3
+ from vnai.beam.quota import guardian, optimize
4
+ from vnai.beam.metrics import collector, capture
3
5
  from vnai.beam.pulse import monitor