nano-wait 0.0.1__tar.gz → 1.3__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.

Potentially problematic release.


This version of nano-wait might be problematic. Click here for more details.

nano_wait-1.3/PKG-INFO ADDED
@@ -0,0 +1,388 @@
1
+ Metadata-Version: 2.1
2
+ Name: nano_wait
3
+ Version: 1.3
4
+ Summary: Waiting Time Calculation for Automations Based on WiFi and PC Processing
5
+ Author: Luiz Filipe Seabra de Marco
6
+ Author-email: luizfilipeseabra@icloud.com
7
+ License: MIT License
8
+ Keywords: automation automação wifi wait
9
+ Description-Content-Type: text/markdown
10
+ License-File: LICENSE
11
+ Requires-Dist: psutil
12
+ Requires-Dist: pywifi
13
+
14
+ """
15
+ nano_wait.py
16
+
17
+ Official Nano-Wait Library: Precise and Adaptive Waiting in Python ⚡
18
+
19
+ Description: This library allows you to perform adaptive waiting based on the current performance of your computer
20
+
21
+ ### 📦 Installation
22
+
23
+
24
+ ⚠️ To download it is necessary to have two libraries to work, run in the terminal 'pip install psutil pywifi⚠️
25
+
26
+ ### Compatibility
27
+
28
+ ⚠️ Compatibility: For now it only works on Windows, we are working on it now :) ⚠️
29
+
30
+ ### Version
31
+
32
+ Version: 1.2
33
+ License: MIT
34
+
35
+ ### formulas
36
+
37
+ Formulas used in the NanoWait library:
38
+
39
+ 1) PC Score Calculation:
40
+ Evaluates how "free" your computer is based on CPU and memory usage::
41
+
42
+ cpu_score = max(0, min(10, 10 - cpu_usage / 10))
43
+
44
+ memory_score = max(0, min(10, 10 - memory_usage / 10))
45
+
46
+ pc_score = (cpu_score + memory_score) / 2
47
+
48
+ 2) Wi-Fi Score calculation:
49
+ Converts Wi-Fi signal strength (in dBm) to a scale of 0 to 10:
50
+
51
+ wifi_score = max(0, min(10, (signal_strength + 100) / 10))
52
+
53
+ Example: If the signal is -60 dBm,
54
+ wifi_score = (-60 + 100) / 10 = 4
55
+
56
+ 3) Combined Risk Score Calculation (PC + Wi-Fi):
57
+
58
+ risk_score = (pc_score + wifi_score) / 2
59
+
60
+ 4) Wi-Fi standby time (wait_wifi):
61
+
62
+ wait_time = max(1, (10 - risk_score) / speed)
63
+
64
+ 5) Waiting time without Wi-Fi (wait_n_wifi):
65
+
66
+ wait_time = max(1, (10 - pc_score) / speed)
67
+
68
+ Variable legend:
69
+
70
+ | Variable | Description |
71
+ |------------------|---------------------------------------|
72
+ | cpu_usage | Current CPU usage (%) |
73
+ | memory_usage | Current RAM usage (%) |
74
+ | signal_strength | Wi-Fi signal strength (in dBm) |
75
+ | speed | Speed factor (example: 1 to 10) |
76
+ """
77
+
78
+ import pywifi
79
+ import psutil
80
+ import time
81
+
82
+
83
+ class NanoWait:
84
+ """
85
+ Core class of the Nano-Wait library.
86
+ Allows you to calculate wait times based on the machine's current performance and Wi-Fi quality.
87
+ """
88
+
89
+ def __init__(self):
90
+ """
91
+ Initializes Wi-Fi modules, if available.
92
+ """
93
+ self.wifi = pywifi.PyWiFi()
94
+ self.interface = self.wifi.interfaces()[0]
95
+
96
+ def get_wifi_signal(self, ssid: str) -> float:7
97
+
98
+ """Returns a score from 0 to 10 based on the Wi-Fi signal strength for the given SSID.
99
+
100
+ Args:
101
+ ssid (str): Name of the Wi-Fi network to be analyzed.
102
+
103
+ Returns:
104
+ float: Wi-Fi quality rating between 0 (poor) and 10 (excellent).
105
+ """
106
+ try:
107
+ self.interface.scan()
108
+ time.sleep(2) # Wait for the scan to complete
109
+ scan_results = self.interface.scan_results()
110
+
111
+ signal_strength = -100 # Default weak signal value
112
+
113
+ for network in scan_results:
114
+ if network.ssid == ssid:
115
+ signal_strength = network.signal
116
+ break
117
+ else:
118
+ raise ValueError(f"Wi-Fi network '{ssid}' not found.")
119
+
120
+ wifi_score = max(0, min(10, (signal_strength + 100) / 10))
121
+ return wifi_score
122
+
123
+ except Exception as e:
124
+ print(f"[WiFi Error] {e}")
125
+ return 0
126
+
127
+ def get_pc_score(self) -> float:
128
+ """
129
+ Returns a score from 0 to 10 based on current CPU and RAM usage.
130
+
131
+ Returns:
132
+ float: Rating between 0 (overload) and 10 (light performance).
133
+ """
134
+ try:
135
+ cpu_usage = psutil.cpu_percent(interval=1)
136
+ memory_usage = psutil.virtual_memory().percent
137
+
138
+ cpu_score = max(0, min(10, 10 - cpu_usage / 10))
139
+ memory_score = max(0, min(10, 10 - memory_usage / 10))
140
+
141
+ pc_score = (cpu_score + memory_score) / 2
142
+ return pc_score
143
+
144
+ except Exception as e:
145
+ print(f"[PC Score Error] {e}")
146
+ return 0
147
+
148
+ def wait_wifi(self, speed: float, ssid: str) -> float:
149
+ """
150
+ Calculates the wait time based on PC performance and Wi-Fi quality.
151
+
152
+ Args:
153
+ speed (float): Speed factor. Higher values result in shorter wait times.
154
+ ssid (str): Name of the Wi-Fi network to be analyzed.
155
+
156
+ Returns:
157
+ float: Recommended wait time.
158
+ """
159
+ try:
160
+ pc_score = self.get_pc_score()
161
+ wifi_score = self.get_wifi_signal(ssid)
162
+
163
+ risk_score = (pc_score + wifi_score) / 2
164
+ wait_time = max(1, (10 - risk_score) / speed)
165
+ return wait_time
166
+
167
+ except Exception as e:
168
+ print(f"[Wait_wifi Error] {e}")
169
+ return 1
170
+
171
+ def wait_n_wifi(self, speed: float) -> float:
172
+ """
173
+ Calculates the wait time based only on the PC's performance (no Wi-Fi).
174
+
175
+ Args:
176
+ speed (float): Speed factor.
177
+
178
+ Returns:
179
+ float: Recommended wait time.
180
+ """
181
+ try:
182
+ pc_score = self.get_pc_score()
183
+ wait_time = max(1, (10 - pc_score) / speed)
184
+ return wait_time
185
+
186
+ except Exception as e:
187
+ print(f"[Error wait_n_wifi] {e}")
188
+ return 1
189
+
190
+ def nano_wait(self, t: float, use_wifi: bool = False, ssid: str = "", speed: float = 1.5) -> None:
191
+ """
192
+ Main library function. Adaptively waits for precisely t seconds.
193
+
194
+ The wait is divided between passive time (with time.sleep) and active time (status check).
195
+
196
+ Args:
197
+ t (float): Desired total wait time, in seconds.
198
+ use_wifi (bool): If True, considers the Wi-Fi network status in the analysis.
199
+ ssid (str): Wi-Fi network name (required if use_wifi=True).
200
+ speed (float): Adaptive speed. Higher values result in shorter waits.
201
+ """
202
+ try:
203
+ if use_wifi:
204
+ if not ssid:
205
+ raise ValueError("SSID required when use_wifi=True")
206
+ wait_time = self.wait_wifi(speed, ssid)
207
+ else:
208
+ wait_time = self.wait_n_wifi(speed)
209
+
210
+ t_passive = max(0, t - wait_time)
211
+ t_active = min(t, wait_time)
212
+
213
+ time.sleep(t_passive)
214
+
215
+ start = time.time()
216
+ while (time.time() - start) < t_active:
217
+ continue # Active wait — ensures accuracy at the end of the wait
218
+
219
+ except Exception as e:
220
+ print(f"[Error nano_wait] {e}")
221
+ time.sleep(t) # fallback: simple wait
222
+
223
+ # Usage examples (to put in a separate file or test interactively):
224
+
225
+ # Usage example without Wi-Fi
226
+ # import time
227
+ # from nano_wait.nano_wait import NanoWait
228
+
229
+ # automation = NanoWait()
230
+ # speeds = 10
231
+ # wait_time = automation.wait_n_wifi(speed=speeds)
232
+ # time.sleep(wait_time)
233
+
234
+ # Usage example with Wi-Fi
235
+ # ssid = "WiFiNetworkName"
236
+ # wait_time = automation.wait_wifi(speed=speeds, ssid=ssid)
237
+ # time.sleep(wait_time)
238
+
239
+ # How much more efficient would it be?
240
+ # Efficiency Comparison: NanoWait vs. Fixed Wait (Guess)
241
+
242
+ This snippet mathematically explains how much the NanoWait library can improve wait time efficiency compared to a fixed wait performed by "guessing."
243
+
244
+ ---
245
+
246
+ ## Formula for calculating adaptive wait time (NanoWait)
247
+
248
+ For Wi-Fi, the wait time is calculated by:
249
+
250
+ \[
251
+ wait\_time = \max\left(min\_wait, \frac{10 - risk\_score}{speed}\right)
252
+ \]
253
+
254
+ Where:
255
+
256
+ - \( risk\_score = \frac{pc\_score + wifi\_score}{2} \) — combined score of the computer's performance and Wi-Fi network quality (varies between 0 and 10).
257
+ - \( speed \) — configurable factor that indicates the desired speed (higher values generate shorter wait times).
258
+ - \( min\_wait \) — minimum wait time allowed (example: 0.05 seconds).
259
+
260
+ ---
261
+
262
+ ## Percentage Gain Calculation
263
+
264
+ The percentage gain in efficiency, comparing the fixed wait \( t_{fixed} \) with the adaptive wait time \( wait\_time \), is:
265
+
266
+ \[
267
+ G = \frac{t_{fixed} - wait\_time}{t_{fixed}} \times 100\%
268
+ \]
269
+
270
+ ---
271
+
272
+ ## Example Scenarios
273
+
274
+ ### Scenario A — Very Good PC and Wi-Fi
275
+
276
+ - \( pc\_score = 9 \)
277
+ - \( wifi\_score = 9 \)
278
+ - \( risk\_score = 9 \)
279
+ - \( speed = 10 \)
280
+ - \( min\_wait = 0.05 \) seconds
281
+
282
+ Calculating the wait time:
283
+
284
+ \[
285
+ wait\_time = \max(0.05, \frac{10 - 9}{10}) = \max(0.05, 0.1) = 0.1 \text{ seconds}
286
+ \]
287
+
288
+ If the fixed time is 0.2 seconds, the gain is:
289
+
290
+ \[
291
+ G = \frac{0.2 - 0.1}{0.2} \times 100\% = 50\%
292
+ \]
293
+
294
+ **Conclusion:** NanoWait halves the wait time.
295
+
296
+ ---
297
+
298
+ ### Scenario B — Reasonable PC and Poor Wi-Fi
299
+
300
+ - \( pc\_score = 5 \)
301
+ - \( wifi\_score = 3 \)
302
+ - \( risk\_score = 4 \)
303
+ - \( speed = 5 \)
304
+ - \( min\_wait = 0.05 \) seconds
305
+
306
+ Calculating the wait time:
307
+
308
+ \[
309
+ wait\_time = \max(0.05, \frac{10 - 4}{5}) = \max(0.05, 1.2) = 1.2 \text{ seconds}
310
+ \]
311
+
312
+ If the fixed time is 1 second, the gain is:
313
+
314
+ \[
315
+ G = \frac{1 - 1.2}{1} \times 100\% = -20\%
316
+ \]
317
+
318
+ **Conclusion:** Longer wait to ensure stability, which is important to avoid errors.
319
+
320
+ ---
321
+
322
+ ### Scenario C — Good PC, Average Wi-Fi
323
+
324
+ - \( pc\_score = 8 \)
325
+ - \( wifi\_score = 5 \)
326
+ - \( risk\_score = 6.5 \)
327
+ - \( speed = 10 \)
328
+ - \( min\_wait = 0.05 \) seconds
329
+
330
+ Calculating the wait time:
331
+
332
+ \[
333
+ wait\_time = \max(0.05, \frac{10 - 6.5}{10}) = \max(0.05, 0.35) = 0.35 \text{ seconds}
334
+ \]
335
+
336
+ If the fixed time is 0.5 seconds, the gain is:
337
+
338
+ \[
339
+ G = \frac{0.5 - 0.35}{0.5} \times 100\% = 30%
340
+ \]
341
+
342
+ **Conclusion:** 30% savings in total wait time.
343
+
344
+ ---
345
+ ## Summary
346
+
347
+ | Condition | Estimated Gain (%) |
348
+ |-------------------|-----------------------------------|
349
+ | Very good PC and Wi-Fi | Up to 50% reduction in wait time |
350
+ | Reasonable PC, poor Wi-Fi | Can increase the time for robustness |
351
+ | Good PC, average Wi-Fi | Approximately 20% to 35% savings |
352
+
353
+ ---
354
+
355
+ ## Practical Benefits of NanoWait
356
+
357
+ - **Adaptive time savings**: wait time decreases when the system is under stress.
358
+ - **Robustness**: time increases when the system is under stress, avoiding errors.
359
+ - **Customization**: the `speed` parameter allows you to adjust the behavior to your needs.
360
+
361
+ ---
362
+
363
+ In other words, on average, it's a 20% to 50% increase in efficiency.
364
+
365
+ ---
366
+
367
+ ### ⚠️ Error Handling
368
+
369
+ The **Nano-Wait** library is designed with robust fallback mechanisms to ensure stability, even under unexpected conditions.
370
+
371
+ #### ✅ How the library behaves in case of failures:
372
+
373
+ | Scenario | Behavior |
374
+ |---------------------------------|--------------------------------------------------------------------------|
375
+ | **Wi-Fi network not found** | Returns a Wi-Fi score of `0` and logs: `[WiFi Error]` |
376
+ | **CPU or RAM usage unavailable**| Returns a PC score of `0` and logs: `[PC Score Error]` |
377
+ | **Unexpected internal error** | Falls back to `time.sleep(t)` and logs: `[Error nano_wait]` |
378
+
379
+ #### 🔐 Why this matters:
380
+
381
+ - Ensures **safe execution** even when the system is under high load or lacks necessary permissions.
382
+ - Avoids crashes by using default behaviors in case of unexpected conditions.
383
+ - Ideal for **automation scripts** and **real-time systems** that require reliability and resilience.
384
+
385
+ ### Authors
386
+
387
+ Author: Luiz Filipe Seabra de Marco and Vitor Seabra
388
+ (and optionally the Wi-Fi network), ideal for applications that disable more intelligent waiting time control.Official Nano-Wait Library: Accurate and Adaptive Waiting in Python ⚡
@@ -0,0 +1,375 @@
1
+ """
2
+ nano_wait.py
3
+
4
+ Official Nano-Wait Library: Precise and Adaptive Waiting in Python ⚡
5
+
6
+ Description: This library allows you to perform adaptive waiting based on the current performance of your computer
7
+
8
+ ### 📦 Installation
9
+
10
+
11
+ ⚠️ To download it is necessary to have two libraries to work, run in the terminal 'pip install psutil pywifi⚠️
12
+
13
+ ### Compatibility
14
+
15
+ ⚠️ Compatibility: For now it only works on Windows, we are working on it now :) ⚠️
16
+
17
+ ### Version
18
+
19
+ Version: 1.2
20
+ License: MIT
21
+
22
+ ### formulas
23
+
24
+ Formulas used in the NanoWait library:
25
+
26
+ 1) PC Score Calculation:
27
+ Evaluates how "free" your computer is based on CPU and memory usage::
28
+
29
+ cpu_score = max(0, min(10, 10 - cpu_usage / 10))
30
+
31
+ memory_score = max(0, min(10, 10 - memory_usage / 10))
32
+
33
+ pc_score = (cpu_score + memory_score) / 2
34
+
35
+ 2) Wi-Fi Score calculation:
36
+ Converts Wi-Fi signal strength (in dBm) to a scale of 0 to 10:
37
+
38
+ wifi_score = max(0, min(10, (signal_strength + 100) / 10))
39
+
40
+ Example: If the signal is -60 dBm,
41
+ wifi_score = (-60 + 100) / 10 = 4
42
+
43
+ 3) Combined Risk Score Calculation (PC + Wi-Fi):
44
+
45
+ risk_score = (pc_score + wifi_score) / 2
46
+
47
+ 4) Wi-Fi standby time (wait_wifi):
48
+
49
+ wait_time = max(1, (10 - risk_score) / speed)
50
+
51
+ 5) Waiting time without Wi-Fi (wait_n_wifi):
52
+
53
+ wait_time = max(1, (10 - pc_score) / speed)
54
+
55
+ Variable legend:
56
+
57
+ | Variable | Description |
58
+ |------------------|---------------------------------------|
59
+ | cpu_usage | Current CPU usage (%) |
60
+ | memory_usage | Current RAM usage (%) |
61
+ | signal_strength | Wi-Fi signal strength (in dBm) |
62
+ | speed | Speed factor (example: 1 to 10) |
63
+ """
64
+
65
+ import pywifi
66
+ import psutil
67
+ import time
68
+
69
+
70
+ class NanoWait:
71
+ """
72
+ Core class of the Nano-Wait library.
73
+ Allows you to calculate wait times based on the machine's current performance and Wi-Fi quality.
74
+ """
75
+
76
+ def __init__(self):
77
+ """
78
+ Initializes Wi-Fi modules, if available.
79
+ """
80
+ self.wifi = pywifi.PyWiFi()
81
+ self.interface = self.wifi.interfaces()[0]
82
+
83
+ def get_wifi_signal(self, ssid: str) -> float:7
84
+
85
+ """Returns a score from 0 to 10 based on the Wi-Fi signal strength for the given SSID.
86
+
87
+ Args:
88
+ ssid (str): Name of the Wi-Fi network to be analyzed.
89
+
90
+ Returns:
91
+ float: Wi-Fi quality rating between 0 (poor) and 10 (excellent).
92
+ """
93
+ try:
94
+ self.interface.scan()
95
+ time.sleep(2) # Wait for the scan to complete
96
+ scan_results = self.interface.scan_results()
97
+
98
+ signal_strength = -100 # Default weak signal value
99
+
100
+ for network in scan_results:
101
+ if network.ssid == ssid:
102
+ signal_strength = network.signal
103
+ break
104
+ else:
105
+ raise ValueError(f"Wi-Fi network '{ssid}' not found.")
106
+
107
+ wifi_score = max(0, min(10, (signal_strength + 100) / 10))
108
+ return wifi_score
109
+
110
+ except Exception as e:
111
+ print(f"[WiFi Error] {e}")
112
+ return 0
113
+
114
+ def get_pc_score(self) -> float:
115
+ """
116
+ Returns a score from 0 to 10 based on current CPU and RAM usage.
117
+
118
+ Returns:
119
+ float: Rating between 0 (overload) and 10 (light performance).
120
+ """
121
+ try:
122
+ cpu_usage = psutil.cpu_percent(interval=1)
123
+ memory_usage = psutil.virtual_memory().percent
124
+
125
+ cpu_score = max(0, min(10, 10 - cpu_usage / 10))
126
+ memory_score = max(0, min(10, 10 - memory_usage / 10))
127
+
128
+ pc_score = (cpu_score + memory_score) / 2
129
+ return pc_score
130
+
131
+ except Exception as e:
132
+ print(f"[PC Score Error] {e}")
133
+ return 0
134
+
135
+ def wait_wifi(self, speed: float, ssid: str) -> float:
136
+ """
137
+ Calculates the wait time based on PC performance and Wi-Fi quality.
138
+
139
+ Args:
140
+ speed (float): Speed factor. Higher values result in shorter wait times.
141
+ ssid (str): Name of the Wi-Fi network to be analyzed.
142
+
143
+ Returns:
144
+ float: Recommended wait time.
145
+ """
146
+ try:
147
+ pc_score = self.get_pc_score()
148
+ wifi_score = self.get_wifi_signal(ssid)
149
+
150
+ risk_score = (pc_score + wifi_score) / 2
151
+ wait_time = max(1, (10 - risk_score) / speed)
152
+ return wait_time
153
+
154
+ except Exception as e:
155
+ print(f"[Wait_wifi Error] {e}")
156
+ return 1
157
+
158
+ def wait_n_wifi(self, speed: float) -> float:
159
+ """
160
+ Calculates the wait time based only on the PC's performance (no Wi-Fi).
161
+
162
+ Args:
163
+ speed (float): Speed factor.
164
+
165
+ Returns:
166
+ float: Recommended wait time.
167
+ """
168
+ try:
169
+ pc_score = self.get_pc_score()
170
+ wait_time = max(1, (10 - pc_score) / speed)
171
+ return wait_time
172
+
173
+ except Exception as e:
174
+ print(f"[Error wait_n_wifi] {e}")
175
+ return 1
176
+
177
+ def nano_wait(self, t: float, use_wifi: bool = False, ssid: str = "", speed: float = 1.5) -> None:
178
+ """
179
+ Main library function. Adaptively waits for precisely t seconds.
180
+
181
+ The wait is divided between passive time (with time.sleep) and active time (status check).
182
+
183
+ Args:
184
+ t (float): Desired total wait time, in seconds.
185
+ use_wifi (bool): If True, considers the Wi-Fi network status in the analysis.
186
+ ssid (str): Wi-Fi network name (required if use_wifi=True).
187
+ speed (float): Adaptive speed. Higher values result in shorter waits.
188
+ """
189
+ try:
190
+ if use_wifi:
191
+ if not ssid:
192
+ raise ValueError("SSID required when use_wifi=True")
193
+ wait_time = self.wait_wifi(speed, ssid)
194
+ else:
195
+ wait_time = self.wait_n_wifi(speed)
196
+
197
+ t_passive = max(0, t - wait_time)
198
+ t_active = min(t, wait_time)
199
+
200
+ time.sleep(t_passive)
201
+
202
+ start = time.time()
203
+ while (time.time() - start) < t_active:
204
+ continue # Active wait — ensures accuracy at the end of the wait
205
+
206
+ except Exception as e:
207
+ print(f"[Error nano_wait] {e}")
208
+ time.sleep(t) # fallback: simple wait
209
+
210
+ # Usage examples (to put in a separate file or test interactively):
211
+
212
+ # Usage example without Wi-Fi
213
+ # import time
214
+ # from nano_wait.nano_wait import NanoWait
215
+
216
+ # automation = NanoWait()
217
+ # speeds = 10
218
+ # wait_time = automation.wait_n_wifi(speed=speeds)
219
+ # time.sleep(wait_time)
220
+
221
+ # Usage example with Wi-Fi
222
+ # ssid = "WiFiNetworkName"
223
+ # wait_time = automation.wait_wifi(speed=speeds, ssid=ssid)
224
+ # time.sleep(wait_time)
225
+
226
+ # How much more efficient would it be?
227
+ # Efficiency Comparison: NanoWait vs. Fixed Wait (Guess)
228
+
229
+ This snippet mathematically explains how much the NanoWait library can improve wait time efficiency compared to a fixed wait performed by "guessing."
230
+
231
+ ---
232
+
233
+ ## Formula for calculating adaptive wait time (NanoWait)
234
+
235
+ For Wi-Fi, the wait time is calculated by:
236
+
237
+ \[
238
+ wait\_time = \max\left(min\_wait, \frac{10 - risk\_score}{speed}\right)
239
+ \]
240
+
241
+ Where:
242
+
243
+ - \( risk\_score = \frac{pc\_score + wifi\_score}{2} \) — combined score of the computer's performance and Wi-Fi network quality (varies between 0 and 10).
244
+ - \( speed \) — configurable factor that indicates the desired speed (higher values generate shorter wait times).
245
+ - \( min\_wait \) — minimum wait time allowed (example: 0.05 seconds).
246
+
247
+ ---
248
+
249
+ ## Percentage Gain Calculation
250
+
251
+ The percentage gain in efficiency, comparing the fixed wait \( t_{fixed} \) with the adaptive wait time \( wait\_time \), is:
252
+
253
+ \[
254
+ G = \frac{t_{fixed} - wait\_time}{t_{fixed}} \times 100\%
255
+ \]
256
+
257
+ ---
258
+
259
+ ## Example Scenarios
260
+
261
+ ### Scenario A — Very Good PC and Wi-Fi
262
+
263
+ - \( pc\_score = 9 \)
264
+ - \( wifi\_score = 9 \)
265
+ - \( risk\_score = 9 \)
266
+ - \( speed = 10 \)
267
+ - \( min\_wait = 0.05 \) seconds
268
+
269
+ Calculating the wait time:
270
+
271
+ \[
272
+ wait\_time = \max(0.05, \frac{10 - 9}{10}) = \max(0.05, 0.1) = 0.1 \text{ seconds}
273
+ \]
274
+
275
+ If the fixed time is 0.2 seconds, the gain is:
276
+
277
+ \[
278
+ G = \frac{0.2 - 0.1}{0.2} \times 100\% = 50\%
279
+ \]
280
+
281
+ **Conclusion:** NanoWait halves the wait time.
282
+
283
+ ---
284
+
285
+ ### Scenario B — Reasonable PC and Poor Wi-Fi
286
+
287
+ - \( pc\_score = 5 \)
288
+ - \( wifi\_score = 3 \)
289
+ - \( risk\_score = 4 \)
290
+ - \( speed = 5 \)
291
+ - \( min\_wait = 0.05 \) seconds
292
+
293
+ Calculating the wait time:
294
+
295
+ \[
296
+ wait\_time = \max(0.05, \frac{10 - 4}{5}) = \max(0.05, 1.2) = 1.2 \text{ seconds}
297
+ \]
298
+
299
+ If the fixed time is 1 second, the gain is:
300
+
301
+ \[
302
+ G = \frac{1 - 1.2}{1} \times 100\% = -20\%
303
+ \]
304
+
305
+ **Conclusion:** Longer wait to ensure stability, which is important to avoid errors.
306
+
307
+ ---
308
+
309
+ ### Scenario C — Good PC, Average Wi-Fi
310
+
311
+ - \( pc\_score = 8 \)
312
+ - \( wifi\_score = 5 \)
313
+ - \( risk\_score = 6.5 \)
314
+ - \( speed = 10 \)
315
+ - \( min\_wait = 0.05 \) seconds
316
+
317
+ Calculating the wait time:
318
+
319
+ \[
320
+ wait\_time = \max(0.05, \frac{10 - 6.5}{10}) = \max(0.05, 0.35) = 0.35 \text{ seconds}
321
+ \]
322
+
323
+ If the fixed time is 0.5 seconds, the gain is:
324
+
325
+ \[
326
+ G = \frac{0.5 - 0.35}{0.5} \times 100\% = 30%
327
+ \]
328
+
329
+ **Conclusion:** 30% savings in total wait time.
330
+
331
+ ---
332
+ ## Summary
333
+
334
+ | Condition | Estimated Gain (%) |
335
+ |-------------------|-----------------------------------|
336
+ | Very good PC and Wi-Fi | Up to 50% reduction in wait time |
337
+ | Reasonable PC, poor Wi-Fi | Can increase the time for robustness |
338
+ | Good PC, average Wi-Fi | Approximately 20% to 35% savings |
339
+
340
+ ---
341
+
342
+ ## Practical Benefits of NanoWait
343
+
344
+ - **Adaptive time savings**: wait time decreases when the system is under stress.
345
+ - **Robustness**: time increases when the system is under stress, avoiding errors.
346
+ - **Customization**: the `speed` parameter allows you to adjust the behavior to your needs.
347
+
348
+ ---
349
+
350
+ In other words, on average, it's a 20% to 50% increase in efficiency.
351
+
352
+ ---
353
+
354
+ ### ⚠️ Error Handling
355
+
356
+ The **Nano-Wait** library is designed with robust fallback mechanisms to ensure stability, even under unexpected conditions.
357
+
358
+ #### ✅ How the library behaves in case of failures:
359
+
360
+ | Scenario | Behavior |
361
+ |---------------------------------|--------------------------------------------------------------------------|
362
+ | **Wi-Fi network not found** | Returns a Wi-Fi score of `0` and logs: `[WiFi Error]` |
363
+ | **CPU or RAM usage unavailable**| Returns a PC score of `0` and logs: `[PC Score Error]` |
364
+ | **Unexpected internal error** | Falls back to `time.sleep(t)` and logs: `[Error nano_wait]` |
365
+
366
+ #### 🔐 Why this matters:
367
+
368
+ - Ensures **safe execution** even when the system is under high load or lacks necessary permissions.
369
+ - Avoids crashes by using default behaviors in case of unexpected conditions.
370
+ - Ideal for **automation scripts** and **real-time systems** that require reliability and resilience.
371
+
372
+ ### Authors
373
+
374
+ Author: Luiz Filipe Seabra de Marco and Vitor Seabra
375
+ (and optionally the Wi-Fi network), ideal for applications that disable more intelligent waiting time control.Official Nano-Wait Library: Accurate and Adaptive Waiting in Python ⚡
@@ -0,0 +1,388 @@
1
+ Metadata-Version: 2.1
2
+ Name: nano_wait
3
+ Version: 1.3
4
+ Summary: Waiting Time Calculation for Automations Based on WiFi and PC Processing
5
+ Author: Luiz Filipe Seabra de Marco
6
+ Author-email: luizfilipeseabra@icloud.com
7
+ License: MIT License
8
+ Keywords: automation automação wifi wait
9
+ Description-Content-Type: text/markdown
10
+ License-File: LICENSE
11
+ Requires-Dist: psutil
12
+ Requires-Dist: pywifi
13
+
14
+ """
15
+ nano_wait.py
16
+
17
+ Official Nano-Wait Library: Precise and Adaptive Waiting in Python ⚡
18
+
19
+ Description: This library allows you to perform adaptive waiting based on the current performance of your computer
20
+
21
+ ### 📦 Installation
22
+
23
+
24
+ ⚠️ To download it is necessary to have two libraries to work, run in the terminal 'pip install psutil pywifi⚠️
25
+
26
+ ### Compatibility
27
+
28
+ ⚠️ Compatibility: For now it only works on Windows, we are working on it now :) ⚠️
29
+
30
+ ### Version
31
+
32
+ Version: 1.2
33
+ License: MIT
34
+
35
+ ### formulas
36
+
37
+ Formulas used in the NanoWait library:
38
+
39
+ 1) PC Score Calculation:
40
+ Evaluates how "free" your computer is based on CPU and memory usage::
41
+
42
+ cpu_score = max(0, min(10, 10 - cpu_usage / 10))
43
+
44
+ memory_score = max(0, min(10, 10 - memory_usage / 10))
45
+
46
+ pc_score = (cpu_score + memory_score) / 2
47
+
48
+ 2) Wi-Fi Score calculation:
49
+ Converts Wi-Fi signal strength (in dBm) to a scale of 0 to 10:
50
+
51
+ wifi_score = max(0, min(10, (signal_strength + 100) / 10))
52
+
53
+ Example: If the signal is -60 dBm,
54
+ wifi_score = (-60 + 100) / 10 = 4
55
+
56
+ 3) Combined Risk Score Calculation (PC + Wi-Fi):
57
+
58
+ risk_score = (pc_score + wifi_score) / 2
59
+
60
+ 4) Wi-Fi standby time (wait_wifi):
61
+
62
+ wait_time = max(1, (10 - risk_score) / speed)
63
+
64
+ 5) Waiting time without Wi-Fi (wait_n_wifi):
65
+
66
+ wait_time = max(1, (10 - pc_score) / speed)
67
+
68
+ Variable legend:
69
+
70
+ | Variable | Description |
71
+ |------------------|---------------------------------------|
72
+ | cpu_usage | Current CPU usage (%) |
73
+ | memory_usage | Current RAM usage (%) |
74
+ | signal_strength | Wi-Fi signal strength (in dBm) |
75
+ | speed | Speed factor (example: 1 to 10) |
76
+ """
77
+
78
+ import pywifi
79
+ import psutil
80
+ import time
81
+
82
+
83
+ class NanoWait:
84
+ """
85
+ Core class of the Nano-Wait library.
86
+ Allows you to calculate wait times based on the machine's current performance and Wi-Fi quality.
87
+ """
88
+
89
+ def __init__(self):
90
+ """
91
+ Initializes Wi-Fi modules, if available.
92
+ """
93
+ self.wifi = pywifi.PyWiFi()
94
+ self.interface = self.wifi.interfaces()[0]
95
+
96
+ def get_wifi_signal(self, ssid: str) -> float:7
97
+
98
+ """Returns a score from 0 to 10 based on the Wi-Fi signal strength for the given SSID.
99
+
100
+ Args:
101
+ ssid (str): Name of the Wi-Fi network to be analyzed.
102
+
103
+ Returns:
104
+ float: Wi-Fi quality rating between 0 (poor) and 10 (excellent).
105
+ """
106
+ try:
107
+ self.interface.scan()
108
+ time.sleep(2) # Wait for the scan to complete
109
+ scan_results = self.interface.scan_results()
110
+
111
+ signal_strength = -100 # Default weak signal value
112
+
113
+ for network in scan_results:
114
+ if network.ssid == ssid:
115
+ signal_strength = network.signal
116
+ break
117
+ else:
118
+ raise ValueError(f"Wi-Fi network '{ssid}' not found.")
119
+
120
+ wifi_score = max(0, min(10, (signal_strength + 100) / 10))
121
+ return wifi_score
122
+
123
+ except Exception as e:
124
+ print(f"[WiFi Error] {e}")
125
+ return 0
126
+
127
+ def get_pc_score(self) -> float:
128
+ """
129
+ Returns a score from 0 to 10 based on current CPU and RAM usage.
130
+
131
+ Returns:
132
+ float: Rating between 0 (overload) and 10 (light performance).
133
+ """
134
+ try:
135
+ cpu_usage = psutil.cpu_percent(interval=1)
136
+ memory_usage = psutil.virtual_memory().percent
137
+
138
+ cpu_score = max(0, min(10, 10 - cpu_usage / 10))
139
+ memory_score = max(0, min(10, 10 - memory_usage / 10))
140
+
141
+ pc_score = (cpu_score + memory_score) / 2
142
+ return pc_score
143
+
144
+ except Exception as e:
145
+ print(f"[PC Score Error] {e}")
146
+ return 0
147
+
148
+ def wait_wifi(self, speed: float, ssid: str) -> float:
149
+ """
150
+ Calculates the wait time based on PC performance and Wi-Fi quality.
151
+
152
+ Args:
153
+ speed (float): Speed factor. Higher values result in shorter wait times.
154
+ ssid (str): Name of the Wi-Fi network to be analyzed.
155
+
156
+ Returns:
157
+ float: Recommended wait time.
158
+ """
159
+ try:
160
+ pc_score = self.get_pc_score()
161
+ wifi_score = self.get_wifi_signal(ssid)
162
+
163
+ risk_score = (pc_score + wifi_score) / 2
164
+ wait_time = max(1, (10 - risk_score) / speed)
165
+ return wait_time
166
+
167
+ except Exception as e:
168
+ print(f"[Wait_wifi Error] {e}")
169
+ return 1
170
+
171
+ def wait_n_wifi(self, speed: float) -> float:
172
+ """
173
+ Calculates the wait time based only on the PC's performance (no Wi-Fi).
174
+
175
+ Args:
176
+ speed (float): Speed factor.
177
+
178
+ Returns:
179
+ float: Recommended wait time.
180
+ """
181
+ try:
182
+ pc_score = self.get_pc_score()
183
+ wait_time = max(1, (10 - pc_score) / speed)
184
+ return wait_time
185
+
186
+ except Exception as e:
187
+ print(f"[Error wait_n_wifi] {e}")
188
+ return 1
189
+
190
+ def nano_wait(self, t: float, use_wifi: bool = False, ssid: str = "", speed: float = 1.5) -> None:
191
+ """
192
+ Main library function. Adaptively waits for precisely t seconds.
193
+
194
+ The wait is divided between passive time (with time.sleep) and active time (status check).
195
+
196
+ Args:
197
+ t (float): Desired total wait time, in seconds.
198
+ use_wifi (bool): If True, considers the Wi-Fi network status in the analysis.
199
+ ssid (str): Wi-Fi network name (required if use_wifi=True).
200
+ speed (float): Adaptive speed. Higher values result in shorter waits.
201
+ """
202
+ try:
203
+ if use_wifi:
204
+ if not ssid:
205
+ raise ValueError("SSID required when use_wifi=True")
206
+ wait_time = self.wait_wifi(speed, ssid)
207
+ else:
208
+ wait_time = self.wait_n_wifi(speed)
209
+
210
+ t_passive = max(0, t - wait_time)
211
+ t_active = min(t, wait_time)
212
+
213
+ time.sleep(t_passive)
214
+
215
+ start = time.time()
216
+ while (time.time() - start) < t_active:
217
+ continue # Active wait — ensures accuracy at the end of the wait
218
+
219
+ except Exception as e:
220
+ print(f"[Error nano_wait] {e}")
221
+ time.sleep(t) # fallback: simple wait
222
+
223
+ # Usage examples (to put in a separate file or test interactively):
224
+
225
+ # Usage example without Wi-Fi
226
+ # import time
227
+ # from nano_wait.nano_wait import NanoWait
228
+
229
+ # automation = NanoWait()
230
+ # speeds = 10
231
+ # wait_time = automation.wait_n_wifi(speed=speeds)
232
+ # time.sleep(wait_time)
233
+
234
+ # Usage example with Wi-Fi
235
+ # ssid = "WiFiNetworkName"
236
+ # wait_time = automation.wait_wifi(speed=speeds, ssid=ssid)
237
+ # time.sleep(wait_time)
238
+
239
+ # How much more efficient would it be?
240
+ # Efficiency Comparison: NanoWait vs. Fixed Wait (Guess)
241
+
242
+ This snippet mathematically explains how much the NanoWait library can improve wait time efficiency compared to a fixed wait performed by "guessing."
243
+
244
+ ---
245
+
246
+ ## Formula for calculating adaptive wait time (NanoWait)
247
+
248
+ For Wi-Fi, the wait time is calculated by:
249
+
250
+ \[
251
+ wait\_time = \max\left(min\_wait, \frac{10 - risk\_score}{speed}\right)
252
+ \]
253
+
254
+ Where:
255
+
256
+ - \( risk\_score = \frac{pc\_score + wifi\_score}{2} \) — combined score of the computer's performance and Wi-Fi network quality (varies between 0 and 10).
257
+ - \( speed \) — configurable factor that indicates the desired speed (higher values generate shorter wait times).
258
+ - \( min\_wait \) — minimum wait time allowed (example: 0.05 seconds).
259
+
260
+ ---
261
+
262
+ ## Percentage Gain Calculation
263
+
264
+ The percentage gain in efficiency, comparing the fixed wait \( t_{fixed} \) with the adaptive wait time \( wait\_time \), is:
265
+
266
+ \[
267
+ G = \frac{t_{fixed} - wait\_time}{t_{fixed}} \times 100\%
268
+ \]
269
+
270
+ ---
271
+
272
+ ## Example Scenarios
273
+
274
+ ### Scenario A — Very Good PC and Wi-Fi
275
+
276
+ - \( pc\_score = 9 \)
277
+ - \( wifi\_score = 9 \)
278
+ - \( risk\_score = 9 \)
279
+ - \( speed = 10 \)
280
+ - \( min\_wait = 0.05 \) seconds
281
+
282
+ Calculating the wait time:
283
+
284
+ \[
285
+ wait\_time = \max(0.05, \frac{10 - 9}{10}) = \max(0.05, 0.1) = 0.1 \text{ seconds}
286
+ \]
287
+
288
+ If the fixed time is 0.2 seconds, the gain is:
289
+
290
+ \[
291
+ G = \frac{0.2 - 0.1}{0.2} \times 100\% = 50\%
292
+ \]
293
+
294
+ **Conclusion:** NanoWait halves the wait time.
295
+
296
+ ---
297
+
298
+ ### Scenario B — Reasonable PC and Poor Wi-Fi
299
+
300
+ - \( pc\_score = 5 \)
301
+ - \( wifi\_score = 3 \)
302
+ - \( risk\_score = 4 \)
303
+ - \( speed = 5 \)
304
+ - \( min\_wait = 0.05 \) seconds
305
+
306
+ Calculating the wait time:
307
+
308
+ \[
309
+ wait\_time = \max(0.05, \frac{10 - 4}{5}) = \max(0.05, 1.2) = 1.2 \text{ seconds}
310
+ \]
311
+
312
+ If the fixed time is 1 second, the gain is:
313
+
314
+ \[
315
+ G = \frac{1 - 1.2}{1} \times 100\% = -20\%
316
+ \]
317
+
318
+ **Conclusion:** Longer wait to ensure stability, which is important to avoid errors.
319
+
320
+ ---
321
+
322
+ ### Scenario C — Good PC, Average Wi-Fi
323
+
324
+ - \( pc\_score = 8 \)
325
+ - \( wifi\_score = 5 \)
326
+ - \( risk\_score = 6.5 \)
327
+ - \( speed = 10 \)
328
+ - \( min\_wait = 0.05 \) seconds
329
+
330
+ Calculating the wait time:
331
+
332
+ \[
333
+ wait\_time = \max(0.05, \frac{10 - 6.5}{10}) = \max(0.05, 0.35) = 0.35 \text{ seconds}
334
+ \]
335
+
336
+ If the fixed time is 0.5 seconds, the gain is:
337
+
338
+ \[
339
+ G = \frac{0.5 - 0.35}{0.5} \times 100\% = 30%
340
+ \]
341
+
342
+ **Conclusion:** 30% savings in total wait time.
343
+
344
+ ---
345
+ ## Summary
346
+
347
+ | Condition | Estimated Gain (%) |
348
+ |-------------------|-----------------------------------|
349
+ | Very good PC and Wi-Fi | Up to 50% reduction in wait time |
350
+ | Reasonable PC, poor Wi-Fi | Can increase the time for robustness |
351
+ | Good PC, average Wi-Fi | Approximately 20% to 35% savings |
352
+
353
+ ---
354
+
355
+ ## Practical Benefits of NanoWait
356
+
357
+ - **Adaptive time savings**: wait time decreases when the system is under stress.
358
+ - **Robustness**: time increases when the system is under stress, avoiding errors.
359
+ - **Customization**: the `speed` parameter allows you to adjust the behavior to your needs.
360
+
361
+ ---
362
+
363
+ In other words, on average, it's a 20% to 50% increase in efficiency.
364
+
365
+ ---
366
+
367
+ ### ⚠️ Error Handling
368
+
369
+ The **Nano-Wait** library is designed with robust fallback mechanisms to ensure stability, even under unexpected conditions.
370
+
371
+ #### ✅ How the library behaves in case of failures:
372
+
373
+ | Scenario | Behavior |
374
+ |---------------------------------|--------------------------------------------------------------------------|
375
+ | **Wi-Fi network not found** | Returns a Wi-Fi score of `0` and logs: `[WiFi Error]` |
376
+ | **CPU or RAM usage unavailable**| Returns a PC score of `0` and logs: `[PC Score Error]` |
377
+ | **Unexpected internal error** | Falls back to `time.sleep(t)` and logs: `[Error nano_wait]` |
378
+
379
+ #### 🔐 Why this matters:
380
+
381
+ - Ensures **safe execution** even when the system is under high load or lacks necessary permissions.
382
+ - Avoids crashes by using default behaviors in case of unexpected conditions.
383
+ - Ideal for **automation scripts** and **real-time systems** that require reliability and resilience.
384
+
385
+ ### Authors
386
+
387
+ Author: Luiz Filipe Seabra de Marco and Vitor Seabra
388
+ (and optionally the Wi-Fi network), ideal for applications that disable more intelligent waiting time control.Official Nano-Wait Library: Accurate and Adaptive Waiting in Python ⚡
@@ -1,3 +1,2 @@
1
1
  psutil
2
2
  pywifi
3
- time
@@ -1,10 +1,11 @@
1
1
  from setuptools import setup
2
2
 
3
- with open("README.md", "r") as arq:
3
+ with open("README.md", "r", encoding="utf-8") as arq:
4
4
  readme = arq.read()
5
5
 
6
+
6
7
  setup(name='nano_wait',
7
- version='0.0.1',
8
+ version='1.3',
8
9
  license='MIT License',
9
10
  author='Luiz Filipe Seabra de Marco',
10
11
  long_description=readme,
@@ -13,4 +14,4 @@ setup(name='nano_wait',
13
14
  keywords='automation automação wifi wait',
14
15
  description=u'Waiting Time Calculation for Automations Based on WiFi and PC Processing',
15
16
  packages=['nano_wait'],
16
- install_requires=['psutil','pywifi','time'],)
17
+ install_requires=['psutil','pywifi'],)
nano_wait-0.0.1/PKG-INFO DELETED
@@ -1,28 +0,0 @@
1
- Metadata-Version: 2.1
2
- Name: nano_wait
3
- Version: 0.0.1
4
- Summary: Waiting Time Calculation for Automations Based on WiFi and PC Processing
5
- Author: Luiz Filipe Seabra de Marco
6
- Author-email: luizfilipeseabra@icloud.com
7
- License: MIT License
8
- Keywords: automation automação wifi wait
9
- Description-Content-Type: text/markdown
10
- License-File: LICENSE
11
- Requires-Dist: psutil
12
- Requires-Dist: pywifi
13
- Requires-Dist: time
14
-
15
- # NanoWait
16
-
17
- **NanoWait** é uma biblioteca Python para automação de tarefas com ajuste dinâmico do tempo de espera com base na qualidade da conexão WiFi e no desempenho do computador. É ideal para situações onde o tempo de espera deve ser ajustado de acordo com a condição da rede e do sistema para garantir que as operações de automação sejam executadas suavemente.
18
-
19
- **Requisitos**
20
- Antes de usar o NanoWait, você deve instalar as seguintes bibliotecas:
21
-
22
- pywifi: Para verificar a qualidade do sinal WiFi.
23
- psutil: Para monitorar o desempenho do sistema.
24
- pyautogui: Para realizar ações de automação no computador.
25
-
26
- **Principais Funções**
27
- wait_wifi: Ela deve ser passada junto com speed e ssid. Ela calcula o tempo de espera considerando o Wifi e o processamento do PC.
28
- wait_n_wifi: Ela deve ser passada junto com speed. Ela calcula o tempo de espera considerando o processamento do PC no momento.
nano_wait-0.0.1/README.md DELETED
@@ -1,14 +0,0 @@
1
- # NanoWait
2
-
3
- **NanoWait** é uma biblioteca Python para automação de tarefas com ajuste dinâmico do tempo de espera com base na qualidade da conexão WiFi e no desempenho do computador. É ideal para situações onde o tempo de espera deve ser ajustado de acordo com a condição da rede e do sistema para garantir que as operações de automação sejam executadas suavemente.
4
-
5
- **Requisitos**
6
- Antes de usar o NanoWait, você deve instalar as seguintes bibliotecas:
7
-
8
- pywifi: Para verificar a qualidade do sinal WiFi.
9
- psutil: Para monitorar o desempenho do sistema.
10
- pyautogui: Para realizar ações de automação no computador.
11
-
12
- **Principais Funções**
13
- wait_wifi: Ela deve ser passada junto com speed e ssid. Ela calcula o tempo de espera considerando o Wifi e o processamento do PC.
14
- wait_n_wifi: Ela deve ser passada junto com speed. Ela calcula o tempo de espera considerando o processamento do PC no momento.
@@ -1,28 +0,0 @@
1
- Metadata-Version: 2.1
2
- Name: nano_wait
3
- Version: 0.0.1
4
- Summary: Waiting Time Calculation for Automations Based on WiFi and PC Processing
5
- Author: Luiz Filipe Seabra de Marco
6
- Author-email: luizfilipeseabra@icloud.com
7
- License: MIT License
8
- Keywords: automation automação wifi wait
9
- Description-Content-Type: text/markdown
10
- License-File: LICENSE
11
- Requires-Dist: psutil
12
- Requires-Dist: pywifi
13
- Requires-Dist: time
14
-
15
- # NanoWait
16
-
17
- **NanoWait** é uma biblioteca Python para automação de tarefas com ajuste dinâmico do tempo de espera com base na qualidade da conexão WiFi e no desempenho do computador. É ideal para situações onde o tempo de espera deve ser ajustado de acordo com a condição da rede e do sistema para garantir que as operações de automação sejam executadas suavemente.
18
-
19
- **Requisitos**
20
- Antes de usar o NanoWait, você deve instalar as seguintes bibliotecas:
21
-
22
- pywifi: Para verificar a qualidade do sinal WiFi.
23
- psutil: Para monitorar o desempenho do sistema.
24
- pyautogui: Para realizar ações de automação no computador.
25
-
26
- **Principais Funções**
27
- wait_wifi: Ela deve ser passada junto com speed e ssid. Ela calcula o tempo de espera considerando o Wifi e o processamento do PC.
28
- wait_n_wifi: Ela deve ser passada junto com speed. Ela calcula o tempo de espera considerando o processamento do PC no momento.
File without changes
File without changes
File without changes