From 1e69b5c56f52a5958d781a81e0ff4ac18fc5695d Mon Sep 17 00:00:00 2001 From: Chris Sewell Date: Sat, 7 Dec 2024 00:31:31 -0500 Subject: [PATCH] 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. --- PiTemp.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/PiTemp.py b/PiTemp.py index 02da4c8..5f94658 100755 --- a/PiTemp.py +++ b/PiTemp.py @@ -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.")