Add display_summary function and ensure summary is printed on exit

- Reintroduce `display_summary` function to calculate and display the highest, lowest, and average temperatures.
- Ensure the summary is printed when the script exits by calling `display_summary()` in the `finally` block.
- Update comments to reflect the restored functionality.
This commit is contained in:
Chris Sewell 2024-12-07 00:31:31 -05:00
parent c8a9d99328
commit 1e69b5c56f

View File

@ -45,6 +45,19 @@ def log_temperature(temp):
with open(LOG_FILE, "a") as log_file:
log_file.write(f"{time.strftime('%Y-%m-%d %H:%M:%S')} - {temp} °C\n")
# Function to display summary on exit
def display_summary():
if temps:
max_temp = max(temps)
min_temp = min(temps)
avg_temp = statistics.mean(temps)
print("\n--- Temperature Summary ---")
print(f"Highest Temp: {max_temp:.1f} °C")
print(f"Lowest Temp: {min_temp:.1f} °C")
print(f"Average Temp: {avg_temp:.1f} °C")
else:
print("\nNo temperature data collected.")
# Function to draw the graph using asciichartpy
def draw_graph(stdscr, temps, cpu_load, paused):
stdscr.clear()
@ -151,5 +164,6 @@ def main(stdscr):
try:
curses.wrapper(main)
finally:
display_summary()
print("\nMonitoring stopped.")