mod alterna valori ping pong
This commit is contained in:
@@ -1,17 +1,37 @@
|
||||
import glob
|
||||
import os
|
||||
from itertools import cycle, chain
|
||||
|
||||
import logging
|
||||
|
||||
logger = logging.getLogger()
|
||||
|
||||
def alterna_valori(val1: str, val2: str) -> any:
|
||||
def alterna_valori(*valori: any, ping_pong: bool = False) -> any:
|
||||
"""
|
||||
Restituisce alternativamente il primo ed il secondo valore
|
||||
Genera una sequenza ciclica di valori, con opzione per una sequenza "ping-pong".
|
||||
|
||||
Args:
|
||||
*valori (any): Uno o più valori da ciclare.
|
||||
ping_pong (bool, optional): Se True, la sequenza sarà valori -> valori al contrario.
|
||||
Ad esempio, per (1, 2, 3) diventa 1, 2, 3, 2, 1, 2, 3, ...
|
||||
Se False, la sequenza è semplicemente ciclica.
|
||||
Defaults to False.
|
||||
|
||||
Yields:
|
||||
any: Il prossimo valore nella sequenza ciclica.
|
||||
|
||||
"""
|
||||
while True:
|
||||
yield val1
|
||||
yield val2
|
||||
if not valori:
|
||||
return
|
||||
|
||||
if ping_pong:
|
||||
# Crea la sequenza ping-pong: valori + valori al contrario (senza ripetere primo e ultimo)
|
||||
forward = valori
|
||||
backward = valori[-2:0:-1] # Esclude ultimo e primo elemento
|
||||
ping_pong_sequence = chain(forward, backward)
|
||||
yield from cycle(ping_pong_sequence)
|
||||
else:
|
||||
yield from cycle(valori)
|
||||
|
||||
|
||||
async def read_error_lines_from_logs(base_path: str, pattern: str) -> tuple[list[str], list[str]]:
|
||||
@@ -46,13 +66,11 @@ async def read_error_lines_from_logs(base_path: str, pattern: str) -> tuple[list
|
||||
try:
|
||||
with open(file_path, 'r', encoding='utf-8') as file:
|
||||
lines = file.readlines()
|
||||
for line in lines:
|
||||
stripped_line = line.strip()
|
||||
if stripped_line: # Ignora righe vuote
|
||||
if stripped_line.startswith('Error'):
|
||||
errors.append(stripped_line)
|
||||
else:
|
||||
warnings.append(stripped_line)
|
||||
# Usando dict.fromkeys() per mantenere l'ordine e togliere le righe duplicate per i warnings
|
||||
non_empty_lines = [line.strip() for line in lines if line.strip()]
|
||||
|
||||
errors = [line for line in non_empty_lines if line.startswith('Error')]
|
||||
warnings = list(dict.fromkeys(line for line in non_empty_lines if not line.startswith('Error')))
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Errore durante la lettura del file {file_path}: {e}")
|
||||
|
||||
Reference in New Issue
Block a user