]> git.neil.brown.name Git - plato.git/commitdiff
Battery: improve time-to-empty and average-period display.
authorNeilBrown <neilb@suse.de>
Fri, 13 Dec 2013 07:36:29 +0000 (18:36 +1100)
committerNeilBrown <neilb@suse.de>
Fri, 13 Dec 2013 07:36:29 +0000 (18:36 +1100)
"average period" is now minutes+seconds (not just seconds)
"tiem to empty" is based on long-term average current and is minutes+seconds.

utils/battery.py

index d2d2d9b67a1013596efd7bf87e11f302d14542ce..83435575d304f7c7f8d3150661c81fc365dfabfb 100755 (executable)
@@ -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__':