[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Powerguru-commit] [SCM] powerguru branch, master, updated. b3c189ae63cd
From: |
Rob Savoye |
Subject: |
[Powerguru-commit] [SCM] powerguru branch, master, updated. b3c189ae63cd04ee67f8486eb2ef552a7a823f1c |
Date: |
Thu, 10 Jan 2019 23:02:16 -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 b3c189ae63cd04ee67f8486eb2ef552a7a823f1c (commit)
via 071e6b25e63d7a710098fb1ef8d0406012c3b3a8 (commit)
via 4b688a08088bcf6990852088195d10fdcf2b10a3 (commit)
from 420643130b72417ae7dc5373780d3b57133075b1 (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=b3c189ae63cd04ee67f8486eb2ef552a7a823f1c
commit b3c189ae63cd04ee67f8486eb2ef552a7a823f1c
Author: Rob Savoye <address@hidden>
Date: Thu Jan 10 21:01:58 2019 -0700
Use a shared X axis
diff --git a/python/chart.py b/python/chart.py
index 5f9f4ad..552447b 100755
--- a/python/chart.py
+++ b/python/chart.py
@@ -149,37 +149,25 @@ for id,current,volts,timestamp in dbcursor:
yy.append(volts)
-# plt.subplots(2, 2, sharex=True
-# 2 rows, 2 columns, index 1 (upper left corner
-plt.subplot(211)
-
-#plt.xlabel("Timestamps")
-plt.xticks(rotation='45')
-#plt.xaxis.set_major_formatter(mdates.DateFormatter('%d-%H'))
-#plt.set_major_locator(mdates.HourLocator(byhour=range(0,24,12)))
-#plt.set_minor_locator(mdates.HourLocator())
-
-plt.ylabel("Temperature in F")
-
-plt.grid(which='major', color='red')
-plt.grid(which='minor', color='blue', linestyle='dashed')
-plt.minorticks_on()
-
-plt.title("Temperature")
-plt.plot(x, y, color="green")
-plt.tight_layout()
-
-ax = plt.subplot(212)
-ax.set_title("Battery")
-ax.plot(xx, yy, color="purple")
-plt.setp(ax.xaxis.get_majorticklabels(), rotation=90)
-ax.xaxis.set_major_formatter(mdates.DateFormatter('%d-%H'))
-ax.xaxis.set_major_locator(mdates.HourLocator(byhour=range(0,24,12)))
-ax.xaxis.set_minor_locator(mdates.HourLocator())
-ax.set_ylabel("DC Volts")
-ax.set_xlabel("When by the Hour")
-ax.grid(which='major', color='red')
-ax.grid(which='minor', color='blue', linestyle='dashed')
-ax.minorticks_on()
+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()
plt.show()
http://git.savannah.gnu.org/cgit/powerguru.git/commit/?id=071e6b25e63d7a710098fb1ef8d0406012c3b3a8
commit 071e6b25e63d7a710098fb1ef8d0406012c3b3a8
Author: Rob Savoye <address@hidden>
Date: Thu Jan 10 20:29:14 2019 -0700
Add doxygen file block
diff --git a/python/mergedb.py b/python/mergedb.py
index 181a8fa..b418961 100755
--- a/python/mergedb.py
+++ b/python/mergedb.py
@@ -19,6 +19,10 @@
# API documentation at: https://pyownet.readthedocs.io/en/latest/
+## \file mergedb.py
+# Simple script to merge logged data from a remote database to
+# local one.
+
import epdb
import logging
import time
http://git.savannah.gnu.org/cgit/powerguru.git/commit/?id=4b688a08088bcf6990852088195d10fdcf2b10a3
commit 4b688a08088bcf6990852088195d10fdcf2b10a3
Author: Rob Savoye <address@hidden>
Date: Thu Jan 10 20:28:51 2019 -0700
Plot battery data too
diff --git a/python/chart.py b/python/chart.py
index 0337945..5f9f4ad 100755
--- a/python/chart.py
+++ b/python/chart.py
@@ -24,42 +24,162 @@ import logging
import time
import psycopg2
import matplotlib.pyplot as plt
+import matplotlib.dates as mdates
+from matplotlib.figure import Figure
+from matplotlib.lines import Line2D
+from matplotlib.dates import DateFormatter
+from datetime import datetime
import numpy as np
+import getopt
+import sys
+from sys import argv
-dbname = "";
-connect = " dbname=" + dbname
+# http://initd.org/psycopg/docs/
+options = dict()
+options['dbserver'] = "pi" # hostname of the database
+options['dbname'] = "powerguru" # hostname of the database
+
+#import matplotlib
+#matplotlib.use('agg')
+
+# menu for --help
+def usage(argv):
+ print(argv[0] + ": options: ")
+ print("""\t--help(-h) Help
+ \t--dbserver(-s) Database server [host]:port]], default '%s'
+ \t--database(-d) Database on server, default '%s'
+ \t--verbose(-v) Enable verbosity
+ """ % (options['dbserver'], options['dbname'])
+ )
+ quit()
+
+# Check command line arguments
try:
- dbname = "powerguru"
- connect = "dbname=" + dbname
- dbshell = psycopg2.connect(connect)
- if dbshell.closed == 0:
- dbshell.autocommit = True
- logging.info("Opened connection to %r" % dbname)
-
- dbcursor = dbshell.cursor()
- if dbcursor.closed == 0:
- logging.info("Opened cursor in %r" % dbname)
-except Exception as e:
- print("Couldn't connect to database: %r" % e)
-
-fig = plt.figure()
+ (opts, val) = getopt.getopt(argv[1:], "h,d:,s;v,",
+ ["help", "database", "dbserver", "verbose"])
+except getopt.GetoptError as e:
+ logging.error('%r' % e)
+ usage(argv)
+ quit()
+
+# Setup a disk space log filemode. By default, everything
+# gets logged to the disk file
+logging.basicConfig(
+ filename='chart.log',
+ filemode='w',
+ level=logging.DEBUG,
+ format= '[%(asctime)s] {%(filename)s:%(lineno)d} %(levelname)s -
%(message)s',
+ datefmt='%Y-%m-%d %H:%M:%S'
+)
+
+# Setup console logging, useful for debugging
+# By default, print nothing to the console. There
+# re two versosity levels, the first just informational
+# messages, the second all debugging messages as well.
+root = logging.getLogger()
+ch = logging.StreamHandler(sys.stdout)
+ch.setLevel(logging.CRITICAL)
+formatter = logging.Formatter('%(message)s')
+#formatter = logging.Formatter('{%(filename)s:%(lineno)d} - %(message)s')
+ch.setFormatter(formatter)
+root.addHandler(ch)
+terminator = ch.terminator
+verbosity = logging.CRITICAL
+
+# process command line arguments, will override the defaults
+for (opt, val) in opts:
+ if opt == '--help' or opt == '-h':
+ usage(argv)
+ elif opt == "--dbserver" or opt == '-s':
+ options['dbserver'] = val
+ elif opt == "--database" or opt == '-d':
+ options['dbname'] = val
+ elif opt == "--verbose" or opt == '-v':
+ if verbosity == logging.INFO:
+ verbosity = logging.DEBUG
+ formatter = logging.Formatter('{%(filename)s:%(lineno)d}
%(levelname)s - %(message)s')
+ ch.setFormatter(formatter)
+ if verbosity == logging.CRITICAL:
+ verbosity = logging.INFO
+ch.setLevel(verbosity)
+
+dbname = ""
+connect = ""
x = list()
y = list()
-query = "SELECT temperature,timestamp FROM temperature ORDER BY timestamp"
+xx = list()
+yy = list()
+if options['dbserver'] != "localhost":
+ connect = "host='" + options['dbserver'] + "'"
+connect += " dbname='" + options['dbname'] + "'"
+
+logging.debug(connect)
+dbshell = psycopg2.connect(connect)
+if dbshell.closed != 0:
+ logging.error("Couldn't connect with %r" % connect)
+ quit();
+
+dbshell.autocommit = True
+logging.info("Opened connection to %r" % options['dbserver'])
+
+dbcursor = dbshell.cursor()
+if dbcursor.closed != 0:
+ logging.error("Couldn't get a cursor from %r" % options['dbname'])
+ quit();
+
+logging.info("Opened cursor in %r" % options['dbserver'])
+
+query = "SELECT id,temperature,timestamp FROM temperature ORDER BY timestamp"
+logging.debug(connect)
dbcursor.execute(query)
-for temperature,timestamp in dbcursor:
- # print("%r, %r" % (temperature,timestamp))
+print(dbcursor.rowcount)
+for id,temperature,timestamp in dbcursor:
+ #print("%r, %r" % (temperature,timestamp))
x.append(timestamp)
y.append(temperature)
-plt.plot(x, y, label="foo")
-plt.xlabel("Timestamps")
-plt.xticks(rotation='vertical')
-plt.grid(which='both')
+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)
+
+
+# plt.subplots(2, 2, sharex=True
+# 2 rows, 2 columns, index 1 (upper left corner
+plt.subplot(211)
+
+#plt.xlabel("Timestamps")
+plt.xticks(rotation='45')
+#plt.xaxis.set_major_formatter(mdates.DateFormatter('%d-%H'))
+#plt.set_major_locator(mdates.HourLocator(byhour=range(0,24,12)))
+#plt.set_minor_locator(mdates.HourLocator())
+
plt.ylabel("Temperature in F")
-#plt.xticks(np.arange(min(y), max(y)+1, 1.0))
+
+plt.grid(which='major', color='red')
+plt.grid(which='minor', color='blue', linestyle='dashed')
plt.minorticks_on()
-plt.title("Test")
+
+plt.title("Temperature")
+plt.plot(x, y, color="green")
+plt.tight_layout()
+
+ax = plt.subplot(212)
+ax.set_title("Battery")
+ax.plot(xx, yy, color="purple")
+plt.setp(ax.xaxis.get_majorticklabels(), rotation=90)
+ax.xaxis.set_major_formatter(mdates.DateFormatter('%d-%H'))
+ax.xaxis.set_major_locator(mdates.HourLocator(byhour=range(0,24,12)))
+ax.xaxis.set_minor_locator(mdates.HourLocator())
+ax.set_ylabel("DC Volts")
+ax.set_xlabel("When by the Hour")
+ax.grid(which='major', color='red')
+ax.grid(which='minor', color='blue', linestyle='dashed')
+ax.minorticks_on()
+
plt.show()
-----------------------------------------------------------------------
Summary of changes:
python/chart.py | 162 +++++++++++++++++++++++++++++++++++++++++++++---------
python/mergedb.py | 4 ++
2 files changed, 139 insertions(+), 27 deletions(-)
hooks/post-receive
--
powerguru
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Powerguru-commit] [SCM] powerguru branch, master, updated. b3c189ae63cd04ee67f8486eb2ef552a7a823f1c,
Rob Savoye <=