powerguru-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Powerguru-commit] [SCM] powerguru branch, master, updated. a7bed69c0ac6


From: Rob Savoye
Subject: [Powerguru-commit] [SCM] powerguru branch, master, updated. a7bed69c0ac6756f5af5629bf33be6f0aec27962
Date: Fri, 11 Jan 2019 14:04:19 -0500 (EST)

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "powerguru".

The branch, master has been updated
       via  a7bed69c0ac6756f5af5629bf33be6f0aec27962 (commit)
      from  b3c189ae63cd04ee67f8486eb2ef552a7a823f1c (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
http://git.savannah.gnu.org/cgit/powerguru.git/commit/?id=a7bed69c0ac6756f5af5629bf33be6f0aec27962


commit a7bed69c0ac6756f5af5629bf33be6f0aec27962
Author: Rob Savoye <address@hidden>
Date:   Fri Jan 11 12:04:06 2019 -0700

    Use animation to refresh the plot data

diff --git a/python/chart.py b/python/chart.py
index 552447b..4ec6b31 100755
--- a/python/chart.py
+++ b/python/chart.py
@@ -28,6 +28,7 @@ import matplotlib.dates as mdates
 from matplotlib.figure import Figure
 from matplotlib.lines import Line2D
 from matplotlib.dates import DateFormatter
+import matplotlib.animation as animation
 from datetime import datetime
 import numpy as np
 import getopt
@@ -107,10 +108,6 @@ ch.setLevel(verbosity)
 
 dbname = ""
 connect = ""
-x = list()
-y = list()
-xx = list()
-yy = list()
 if options['dbserver'] != "localhost":
     connect = "host='" + options['dbserver'] + "'"
 connect += " dbname='" + options['dbname'] + "'"
@@ -131,43 +128,56 @@ if dbcursor.closed != 0:
 
 logging.info("Opened cursor in %r" % options['dbserver'])
 
-query = "SELECT id,temperature,timestamp FROM temperature ORDER BY timestamp"
-logging.debug(connect)
-dbcursor.execute(query)
-print(dbcursor.rowcount)
-for id,temperature,timestamp in dbcursor:
-    #print("%r, %r" % (temperature,timestamp))
-    x.append(timestamp)
-    y.append(temperature)
-
-query = "SELECT id,current,volts,timestamp FROM battery ORDER BY timestamp"
-logging.debug(query)
-dbcursor.execute(query)
-for id,current,volts,timestamp in dbcursor:
-    #print("BATTERY: %r, %r, %r, %r" % id, current, volts, timestamp)
-    xx.append(timestamp)
-    yy.append(volts)
-
-
 fig, (temp, power) = plt.subplots(2, 1, sharex=True)
-fig.suptitle('PowerGuru')
-temp.set_ylabel("Temperature in F")
-temp.set_title("Temperature")
-temp.grid(which='major', color='red')
-temp.grid(which='minor', color='blue', linestyle='dashed')
-temp.minorticks_on()
-temp.plot(x, y, color="green")
-
-power.set_title("Battery")
-power.plot(xx, yy, color="purple")
-plt.setp(power.xaxis.get_majorticklabels(), rotation=90)
-power.xaxis.set_major_formatter(mdates.DateFormatter('%m-%d %H'))
-power.xaxis.set_major_locator(mdates.HourLocator(byhour=range(0,24,12)))
-power.xaxis.set_minor_locator(mdates.HourLocator())
-power.set_ylabel("DC Volts")
-power.set_xlabel("Time (hourly)")
-power.grid(which='major', color='red')
-power.grid(which='minor', color='blue', linestyle='dashed')
-power.minorticks_on()
 
+def animate(i):
+    logging.debug("Refreshing data...")
+    x = list()
+    y = list()
+    xx = list()
+    yy = list()
+    query = "SELECT id,temperature,timestamp FROM temperature ORDER BY 
timestamp"
+    logging.debug(query)
+    dbcursor.execute(query)
+    logging.debug("Query returned %r records" % dbcursor.rowcount)
+    for id,temperature,timestamp in dbcursor:
+        #print("%r, %r" % (temperature,timestamp))
+        x.append(timestamp)
+        y.append(temperature)
+
+    query = "SELECT id,current,volts,timestamp FROM battery ORDER BY timestamp"
+    logging.debug(query)
+    dbcursor.execute(query)
+    logging.debug("Query returned %r records" % dbcursor.rowcount)
+    for id,current,volts,timestamp in dbcursor:
+        #print("BATTERY: %r, %r, %r, %r" % id, current, volts, timestamp)
+        xx.append(timestamp)
+        yy.append(volts)
+
+    #
+    # There will be more plots in the future
+    #
+    fig.suptitle('PowerGuru')
+    temp.set_ylabel("Temperature in F")
+    temp.set_title("Temperature")
+    temp.grid(which='major', color='red')
+    temp.grid(which='minor', color='blue', linestyle='dashed')
+    temp.minorticks_on()
+    temp.plot(x, y, color="green")
+    
+    power.set_title("Battery")
+    power.plot(xx, yy, color="purple")
+    power.set_ylabel("DC Volts")
+    power.set_xlabel("Time (hourly)")
+    power.grid(which='major', color='red')
+    power.grid(which='minor', color='blue', linestyle='dashed')
+    power.minorticks_on()
+    plt.setp(power.xaxis.get_majorticklabels(), rotation=90)
+    power.xaxis.set_major_formatter(mdates.DateFormatter('%m-%d %H'))
+    power.xaxis.set_major_locator(mdates.HourLocator(byhour=range(0,24,6)))
+    power.xaxis.set_minor_locator(mdates.HourLocator())
+
+# The timeout is in miliseconds
+seconds = 1000 * 100
+ani = animation.FuncAnimation(fig, animate, interval=seconds)
 plt.show()

-----------------------------------------------------------------------

Summary of changes:
 python/chart.py | 92 ++++++++++++++++++++++++++++++++-------------------------
 1 file changed, 51 insertions(+), 41 deletions(-)


hooks/post-receive
-- 
powerguru



reply via email to

[Prev in Thread] Current Thread [Next in Thread]