new subpage for daily diagram

master
ademant 2019-08-20 05:23:30 +02:00
parent 2ee6944fb4
commit 8eb16c1454
1 changed files with 22 additions and 13 deletions

View File

@ -312,19 +312,28 @@ def show_graph(mid,kind):
mydb=pymysql.connect(read_default_file="~/.my.cnf",database="rasolar")
mycursor=mydb.cursor()
print(str(time.time()-starttime)+' sql open')
mycursor.execute('select ((select max(time) from '+sqltable+')-'+sqltable+'.time)/6400000 as time,'+sqltable+'.value/1000 as value from '+sqltable+' where id=%s order by time',str(mid))
row=numpy.array(mycursor.fetchall())
print(str(time.time()-starttime)+' sql fetched')
mycursor.close()
mydb.close()
print(str(time.time()-starttime)+' sql closed')
plt.figure(figsize=[6,8])
plt.plot(row[:,0],row[:,1])
print(str(time.time()-starttime)+' picture')
plt.savefig("svg/"+mid+".svg")
print(str(time.time()-starttime)+' saved')
if len(row)>0:
return template('verlauf.tpl',measdata=row,mid=mid)
nrow=mycursor.execute('select ((select max(time) from '+sqltable+')-'+sqltable+'.time)/6400000 as time,'+sqltable+'.value/1000 as value from '+sqltable+' where id=%s order by time',str(mid))
if (nrow>0):
row=numpy.array(mycursor.fetchall())
print(str(time.time()-starttime)+' sql fetched')
mycursor.close()
mydb.close()
print(str(time.time()-starttime)+' sql closed')
plt.figure(figsize=[6,8])
plt.plot(row[:,0],row[:,1])
print(str(time.time()-starttime)+' picture')
plt.savefig("svg/"+mid+".svg")
print(str(time.time()-starttime)+' saved')
if len(row)>0:
return template('verlauf.tpl',measdata=row,mid=mid)
else:
return '''
<!DOCTYPE html><html><head>
<title>Keine Daten</title>
</head><body>
<p>Die Daten verstecken sich.</p>
</body></html>
'''
@app.post('/data/<hash_id>')