trying to lineplot simple temperature data from a sqlite3 database. New to python, not sure what I'm doing wrong. my data from sql looks like:
[(70.8,), (70.8,), (70.9,), (71.0,), (71.0,), (71.2,), (71.2,), (71.2,), (71.4,), (71.7,), (71.7,), (72.0,), (72.0,), (72.0,), (72.2,), (72.2,), (71.9,), (72.0,), (72.0,), (72.2,), (72.2,), (72.2,), (72.2,), (71.7,), (71.9,), (71.9,), (72.0,), (72.0,), (72.3,), (72.0,), (72.0,), (72.2,), (72.2,), (72.2,), (72.3,), (72.2,), (72.2,), (72.3,), (72.3,), (72.3,), (72.3,), (72.4,), (72.5,), (72.4,), (72.5,), (72.5,), (72.6,), (72.7,), (72.7,), (73.0,), (73.0,), (73.0,), (73.1,), (73.1,), (73.3,), (73.5,), (73.5,), (73.6,), (73.7,), (73.8,), (73.7,), (73.7,), (73.7,), (73.8,), (73.7,), (73.7,), (73.6,), (73.7,), (73.8,), (73.8,), (73.8,), (73.8,), (73.7,), (73.6,), (73.6,), (73.5,), (73.6,), (73.5,), (73.5,), (73.5,), (73.5,), (73.2,), (73.1,), (73.0,), (73.0,), (72.7,), (72.8,), (72.8,), (72.8,), (72.7,), (72.7,), (72.6,), (72.6,), (72.7,), (72.7,), (72.7,), (72.7,), (72.7,), (72.8,), (72.7,), (72.8,), (72.8,), (72.8,), (72.8,), (72.8,), (72.8,), (72.7,), (72.7,), (72.7,), (73.0,), (73.0,), (73.0,), (73.0,), (73.4,), (73.5,), (73.5,), (73.6,), (73.5,), (73.6,), (73.5,), (73.5,), (73.6,), (73.6,), (73.5,), (73.5,), (73.6,), (73.5,), (73.6,), (73.6,), (73.6,), (73.6,), (73.5,)]
The error message I get is:
Traceback (most recent call last):
File "db-test5.py", line 93, in <module>
renderPM.drawToFile(d, 'rework6.png')
File "/usr/lib/python2.7/dist-packages/reportlab/graphics/renderPM.py", line 655, in drawToFile
c = drawToPMCanvas(d, dpi=dpi, bg=bg, configPIL=configPIL,showBoundary=showBoundary)
File "/usr/lib/python2.7/dist-packages/reportlab/graphics/renderPM.py", line 641, in drawToPMCanvas
draw(d, c, 0, 0, showBoundary=showBoundary)
File "/usr/lib/python2.7/dist-packages/reportlab/graphics/renderPM.py", line 50, in draw
R.draw(renderScaledDrawing(drawing), canvas, x, y, showBoundary=showBoundary)
File "/usr/lib/python2.7/dist-packages/reportlab/graphics/renderbase.py", line 199, in draw
self.drawNode(drawing)
File "/usr/lib/python2.7/dist-packages/reportlab/graphics/renderPM.py", line 109, in drawNode
self.drawNodeDispatcher(node)
File "/usr/lib/python2.7/dist-packages/reportlab/graphics/renderbase.py", line 280, in drawNodeDispatcher
self.drawGroup(node)
File "/usr/lib/python2.7/dist-packages/reportlab/graphics/renderbase.py", line 297, in drawGroup
node = _expandUserNode(node,canvas)
File "/usr/lib/python2.7/dist-packages/reportlab/graphics/renderbase.py", line 161, in _expandUserNode
node = node.provideNode()
File "/usr/lib/python2.7/dist-packages/reportlab/graphics/widgetbase.py", line 150, in provideNode
return self.draw()
File "/usr/lib/python2.7/dist-packages/reportlab/graphics/charts/lineplots.py", line 351, in draw
self.calcPositions()
File "/usr/lib/python2.7/dist-packages/reportlab/graphics/charts/lineplots.py", line 194, in calcPositions
if isinstance(datum[0],str):
TypeError: 'float' object has no attribute '__getitem__'
my code is:
#!/usr/bin/python
from reportlab.graphics.charts.lineplots import LinePlot, AreaLinePlot
from reportlab.graphics.shapes import Drawing
from reportlab.lib import colors
from random import randint
from datetime import date, timedelta
from reportlab.graphics import renderPM
import sqlite3, os, datetime, time
##############################################
######## time functions ##################
##############################################
def RecYear():
return datetime.date.today().strftime("%Y")
def RecMonth():
return datetime.date.today().strftime("%m")
def RecFullDateTime():
return time.time()
def RecTime():
return datetime.datetime.now().strftime("%H:%M:%S")
def RecDate():
return datetime.datetime.now().strftime("%m-%d-%Y")
def RecDay():
return datetime.date.today().strftime("%d")
currentdate_ds18b20=int(datetime.date.today().strftime("%Y"))*1000+ int(time.localtime().tm_yday)
os.system('clear')
sqlite_file="2-database_archived/archived_2017-02-27-HMS-ds18b20-v2.2-DATABASE.db"
table_name = "DS18B20temps"
print "filename = ", sqlite_file
print "table = ", table_name
conn = sqlite3.connect(sqlite_file)
c = conn.cursor()
print "db open"
### Calculate total length of table
c.execute('SELECT * FROM {tn}'.\
format(tn=table_name))
print "the length of the database is:", len(c.fetchall()), " rows\n"
###Calculate total number of kitchen temp readings
c.execute('SELECT ({coi}) FROM {tn} WHERE {cn}="Kitchen"'.\
format(coi="temp", tn=table_name, cn="sensor_name"))
kitchen_temp_list = c.fetchall()
print "the number of kitchen temp readings = ", len(kitchen_temp_list)
new_kitchen_list = list(sum(kitchen_temp_list, ()))
print "averge temp = ", (sum(new_kitchen_list))/len(new_kitchen_list)
print ""
# 4) Retrieve all IDs of entries between 6am and noon
c.execute("SELECT {idf} FROM {tn} WHERE {cnn}='Kitchen' AND {cn} BETWEEN '18:00:00' AND '23:59:59'".\
format(idf="temp", tn=table_name, cnn="sensor_name", cn="recorded_time"))
all_date_times = c.fetchall()
print "readings from 6 pm to midnight = ", len(all_date_times)
print all_date_times
width=800
height=500
d = Drawing(width, height)
lp = LinePlot()
lp.data=all_date_times
lp.width= 700
lp.height = 400
lp.xValueAxis.valueMin = 0
lp.xValueAxis.valueMax =400
#lp.xValueAxis.valueSteps = [6,8,10,12,14,16,18,20]
lp.yValueAxis.valueMin = 0
lp.yValueAxis.valueMax =200
lp.strokeColor=colors.black
lp.fillColor=colors.grey
#lp.reversePlotOrder = False
lp.joinedLines=1
d.add(lp)
renderPM.drawToFile(d, 'rework6.png')
It seams like whenever I pass bad data it craps out at renderPM, but I'm having a hard time understanding the error. My hunch is the data I'm passing is not appropriate for a line plot?
any help greatly appreciated......