update: send a csv file every 30 seconds
fix: manage_csv_files
This commit is contained in:
parent
93f5da18f8
commit
9434092b6f
|
@ -881,7 +881,10 @@ import random
|
|||
logging.debug('finished update cycle\n')
|
||||
return True'''
|
||||
|
||||
start_time = time.time()
|
||||
|
||||
def update(modbus, batteries, dbus, signals, csv_signals):
|
||||
global start_time
|
||||
# type: (Modbus, Iterable[Battery], DBus, Iterable[Signal]) -> bool
|
||||
"""
|
||||
Main update function
|
||||
|
@ -910,7 +913,11 @@ def update(modbus, batteries, dbus, signals, csv_signals):
|
|||
#print(update_state_from_dictionaries(current_warnings, current_alarms))
|
||||
status_message, alarms_number_list, warnings_number_list = update_state_from_dictionaries(current_warnings, current_alarms, node_numbers)
|
||||
publish_values(dbus, signals, statuses)
|
||||
create_csv_files(csv_signals, statuses, node_numbers, alarms_number_list, warnings_number_list)
|
||||
elapsed_time = time.time() - start_time
|
||||
if elapsed_time >= 30:
|
||||
create_csv_files(csv_signals, statuses, node_numbers, alarms_number_list, warnings_number_list)
|
||||
start_time = time.time()
|
||||
print(f"Elapsed time: {elapsed_time:.2f} seconds")
|
||||
logging.debug('finished update cycle\n')
|
||||
return True
|
||||
|
||||
|
@ -975,7 +982,7 @@ def get_installation_name(file_path):
|
|||
return file.read().strip()
|
||||
|
||||
def manage_csv_files(directory_path, max_files=20):
|
||||
csv_files = [f for f in os.listdir(directory_path)]
|
||||
csv_files = [f for f in os.listdir(directory_path) if os.path.isfile(os.path.join(directory_path, f))]
|
||||
csv_files.sort(key=lambda x: os.path.getctime(os.path.join(directory_path, x)))
|
||||
# Remove oldest files if exceeds maximum
|
||||
while len(csv_files) > max_files:
|
||||
|
|
Loading…
Reference in New Issue