Extract from Skynet to Plot.ly
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pymongo import Connection | |
import time | |
from datetime import datetime | |
import plotly | |
conn = Connection('localhost', 27017) | |
db = conn.skynet | |
collection = db.events | |
# 24 hour time range | |
time = int(round((time.time() - 86400) * 1000)) | |
results = collection.find({ | |
"timestamp": {"$gte" : time }, | |
"uuid": "UUID" | |
}) | |
x = [] | |
y = [] | |
for i in results: | |
if 'temperature' in i.keys(): | |
ts= str(int(i['timestamp']))[:-3] | |
x.append(datetime.fromtimestamp(int(ts))) | |
y.append(str(i['temperature'])) | |
# start time | |
#print x[0] | |
# end time | |
#print x[-1] | |
py = plotly.plotly("USERNAME", "PASSWORD") | |
py.plot(x,y) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment