From: NeilBrown Date: Fri, 13 Dec 2013 07:36:29 +0000 (+1100) Subject: Battery: improve time-to-empty and average-period display. X-Git-Url: http://git.neil.brown.name/?a=commitdiff_plain;h=47840a3aad24ee9a4bc357d04521fa95a33a19fa;p=plato.git Battery: improve time-to-empty and average-period display. "average period" is now minutes+seconds (not just seconds) "tiem to empty" is based on long-term average current and is minutes+seconds. --- diff --git a/utils/battery.py b/utils/battery.py index d2d2d9b..8343557 100755 --- a/utils/battery.py +++ b/utils/battery.py @@ -152,8 +152,24 @@ class BatteryMonitor: return "%+d" %((self.chg_start - chg) * 3600 / (now - self.period_start)) def avg_period(self): - return "%d minutes" % ((time.time() - self.period_start) / 60) - + min = ((time.time() - self.period_start) / 60) + if min < 90: + return "%d minutes" % min + hr = int(min/60) + min -= hr * 60 + return "%d hr %d min" % (hr, min) + + def time_empty(self): + now = time.time() + chg = file_num(cnowfile) + if now < self.period_start + 5: + return "-" + cur = (self.chg_start - chg) * 3600 / (now - self.period_start) + sec = chg * 3600 / cur + min = sec/60 + hr = int(min / 60) + min -= hr*60 + return "%d hr %d min" % (hr, min) class BatteryConfig(gtk.Window): def __init__(self, oneshot, monitor): @@ -286,7 +302,8 @@ class BatteryConfig(gtk.Window): self.labels['Capacity Status'].set_text(to_percent(file_num(cffile), file_num(cfdfile))) self.labels['TimeToFull'].set_text(to_time(file_num(fullfile))) - self.labels['TimeToEmpty'].set_text(to_time(file_num(emptyfile))) + #self.labels['TimeToEmpty'].set_text(to_time(file_num(emptyfile))) + self.labels['TimeToEmpty'].set_text(self.m.time_empty()) self.labels['FlightMode'].set_text(self.get_flight()) global icon setfile(icon) @@ -320,7 +337,7 @@ def main(args): global configwindow monitor = BatteryMonitor() configwindow = BatteryConfig(True, monitor) - + gtk.main() if __name__ == '__main__':