From e3d0902c458ad309b166f3538879ab5ce7956cdb Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Mon, 11 Nov 2019 23:22:47 -0700 Subject: [PATCH] Updated wk.hw.sensors * Added monitor_to_file() * Added save_average_temps() --- scripts/wk/hw/sensors.py | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/scripts/wk/hw/sensors.py b/scripts/wk/hw/sensors.py index 2380fbf1..7307818b 100644 --- a/scripts/wk/hw/sensors.py +++ b/scripts/wk/hw/sensors.py @@ -10,7 +10,7 @@ from subprocess import CalledProcessError from wk.cfg.hw import CPU_THERMAL_LIMIT, SMC_IDS, TEMP_COLORS from wk.exe import run_program -from wk.std import color_string +from wk.std import color_string, sleep # STATIC VARIABLES @@ -77,6 +77,32 @@ class Sensors(): # Done return report + def monitor_to_file(self, path): + """Write report to path every second until stopped.""" + while True: + self.update_sensor_data() + report = self.generate_report('Current', 'Max') + with open(path, 'w') as _f: + _f.write('\n'.join(report)) + sleep(1) + + def save_average_temps(self, temp_label, seconds=10): + # pylint: disable=unused-variable + """Save average temps under temp_label over provided seconds..""" + self.clear_temps() + + # Get temps + for i in range(seconds): + self.update_sensor_data() + sleep(1) + + # Calculate averages + for adapters in self.data.values(): + for sources in adapters.values(): + for source_data in sources.values(): + temps = source_data['Temps'] + source_data[temp_label] = sum(temps) / len(temps) + def update_sensor_data(self, exit_on_thermal_limit=True): """Update sensor data via OS-specific means.""" if platform.system() == 'Darwin':