mirror of
https://github.com/ChrisSewell/PiTemp.git
synced 2025-04-19 06:28:01 -04:00
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:
parent
c8a9d99328
commit
1e69b5c56f
14
PiTemp.py
14
PiTemp.py
@ -45,6 +45,19 @@ def log_temperature(temp):
|
|||||||
with open(LOG_FILE, "a") as log_file:
|
with open(LOG_FILE, "a") as log_file:
|
||||||
log_file.write(f"{time.strftime('%Y-%m-%d %H:%M:%S')} - {temp} °C\n")
|
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
|
# Function to draw the graph using asciichartpy
|
||||||
def draw_graph(stdscr, temps, cpu_load, paused):
|
def draw_graph(stdscr, temps, cpu_load, paused):
|
||||||
stdscr.clear()
|
stdscr.clear()
|
||||||
@ -151,5 +164,6 @@ def main(stdscr):
|
|||||||
try:
|
try:
|
||||||
curses.wrapper(main)
|
curses.wrapper(main)
|
||||||
finally:
|
finally:
|
||||||
|
display_summary()
|
||||||
print("\nMonitoring stopped.")
|
print("\nMonitoring stopped.")
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user