nano-wait 0.0.2__py3-none-any.whl → 1.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 nano-wait might be problematic. Click here for more details.

@@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
18
  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
19
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
20
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
21
+ SOFTWARE.
@@ -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,7 @@
1
+ nano_wait/__init__.py,sha256=I5jtVftNdesvR689O2eOz3CeTAtFs8ZP5GJhn7RrQvA,24
2
+ nano_wait/nano_wait.py,sha256=k1ENwE77qY687iAdMGIVZYlrDpV_ErNpXeOIX7JdWH0,2431
3
+ nano_wait-1.3.dist-info/LICENSE,sha256=h77N3ma56KwtT-tI-UQ8LntVneq5t506SCJXmdTx5-Y,1105
4
+ nano_wait-1.3.dist-info/METADATA,sha256=be9LJw0AjtT9aoE8S5TeliTItQorq2kJJawpDm6pvsg,10719
5
+ nano_wait-1.3.dist-info/WHEEL,sha256=cpQTJ5IWu9CdaPViMhC9YzF8gZuS5-vlfoFihTBC86A,91
6
+ nano_wait-1.3.dist-info/top_level.txt,sha256=dSiF3Wc3ZEB1pzcp_ubHZeb0OE7n1nPMntkL48uz6aI,10
7
+ nano_wait-1.3.dist-info/RECORD,,
@@ -1,114 +0,0 @@
1
- Metadata-Version: 2.1
2
- Name: nano_wait
3
- Version: 0.0.2
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
- <<<<<<< HEAD
15
- # Nano-Wait Library Documentation
16
-
17
- ## Overview
18
-
19
- The Nano-Wait library is designed to automate PC tasks by dynamically calculating the wait time between actions based on system performance and WiFi signal strength. This library is particularly useful for scripting and automation tasks where timing is critical, and variations in system resources and network conditions can impact the execution of actions.
20
-
21
- ## Installation
22
-
23
- To use the Nano-Wait library, ensure that the necessary dependencies are installed:
24
- ```bash
25
- pip install pywifi psutil
26
- ```
27
-
28
- ## Initialization
29
-
30
- Before using the Nano-Wait library, you need to create an instance of the PCAutomation class. This instance will provide methods to calculate wait times based on your PC's performance and WiFi signal strength.
31
-
32
- ```
33
- from biblioteca import PCAutomation
34
-
35
- # Initialize the automation
36
- automation = PCAutomation()
37
- ```
38
- ## Parameters
39
-
40
- speed
41
- Type: int
42
- Range: 1 to 10
43
- Description: This parameter controls the desired speed of automation. A value of 1 represents the slowest speed with the longest wait times, while a value of 10 represents the fastest speed with the shortest wait times. Adjust this parameter based on your specific requirements and system performance.
44
-
45
- ## Main Functions
46
-
47
- wait_wifi(speed)
48
- Description: Calculates the necessary wait time between actions when considering both PC performance and WiFi signal strength.
49
- Parameters:
50
- speed (int): A value between 1 and 10 that controls the speed of automation.
51
- Returns: The calculated wait time in seconds as a float.
52
-
53
- Below is an example of how to use the Nano-Wait library in a Python automation script:
54
-
55
- ```
56
- import pyautogui
57
- import time
58
- from biblioteca import PCAutomation
59
-
60
- # Initialize the automation
61
- automation = PCAutomation()
62
-
63
- # Set the desired speed of automation
64
- speed = 1
65
-
66
- # Press the Windows key and wait for the appropriate time
67
- wait_time = automation.wait_n_wifi(speed=speed)
68
- pyautogui.press('win')
69
- time.sleep(wait_time)
70
-
71
- # Type 'chrome' and wait for the appropriate time
72
- wait_time = automation.wait_n_wifi(speed=speed)
73
- pyautogui.write('chrome', interval=0.1)
74
- time.sleep(wait_time)
75
-
76
- # Press 'Enter' to open Chrome and wait for the appropriate time
77
- wait_time = automation.wait_wifi(speed=speed)
78
- pyautogui.press('enter')
79
- time.sleep(wait_time) # Wait for Chrome to open
80
-
81
- # Type the URL of YouTube and wait for the appropriate time
82
- wait_time = automation.wait_wifi(speed=speed)
83
- pyautogui.write('youtube.com', interval=0.1)
84
- time.sleep(wait_time)
85
-
86
- # Press 'Enter' to go to YouTube and wait for the appropriate time
87
- wait_time = automation.wait_n_wifi(speed=speed)
88
- pyautogui.press('enter')
89
- Detailed Functionality
90
- get_wifi_signal()
91
- Description: Scans the available WiFi networks and returns a score (0-10) based on the signal strength of a specified WiFi network.
92
- Internal Usage: Used within the wait_wifi function to determine the WiFi score.
93
- get_pc_score()
94
- Description: Computes a score (0-10) based on CPU and memory usage, indicating the PC's performance.
95
- Internal Usage: Used within both wait_wifi and wait_n_wifi functions to determine the PC performance score.
96
- Conclusion
97
- The Nano-Wait library provides a simple yet powerful way to manage wait times in PC automation scripts by dynamically adjusting based on system and network conditions. By configuring the speed parameter, users can control the pace of automation to match their specific needs.
98
- ```
99
- =======
100
- # NanoWait
101
-
102
- **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.
103
-
104
- **Requisitos**
105
- Antes de usar o NanoWait, você deve instalar as seguintes bibliotecas:
106
-
107
- pywifi: Para verificar a qualidade do sinal WiFi.
108
- psutil: Para monitorar o desempenho do sistema.
109
- pyautogui: Para realizar ações de automação no computador.
110
-
111
- **Principais Funções**
112
- 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.
113
- wait_n_wifi: Ela deve ser passada junto com speed. Ela calcula o tempo de espera considerando o processamento do PC no momento.
114
- >>>>>>> 01ab9c961b388fc5b69865a3b28d04b4be6679c2
@@ -1,7 +0,0 @@
1
- nano_wait/__init__.py,sha256=I5jtVftNdesvR689O2eOz3CeTAtFs8ZP5GJhn7RrQvA,24
2
- nano_wait/nano_wait.py,sha256=k1ENwE77qY687iAdMGIVZYlrDpV_ErNpXeOIX7JdWH0,2431
3
- nano_wait-0.0.2.dist-info/LICENSE,sha256=xPiTfTb6bSRJa60ZARdG1oGnfnkIVJc0b-N-vdv1iSM,1104
4
- nano_wait-0.0.2.dist-info/METADATA,sha256=L6iSjnjXYxfev98D2RrTpemA75tgf4f4F4uwkSVQAcc,4920
5
- nano_wait-0.0.2.dist-info/WHEEL,sha256=cpQTJ5IWu9CdaPViMhC9YzF8gZuS5-vlfoFihTBC86A,91
6
- nano_wait-0.0.2.dist-info/top_level.txt,sha256=dSiF3Wc3ZEB1pzcp_ubHZeb0OE7n1nPMntkL48uz6aI,10
7
- nano_wait-0.0.2.dist-info/RECORD,,