initial
This commit is contained in:
33
test.py
Normal file
33
test.py
Normal file
@ -0,0 +1,33 @@
|
||||
import pymongo
|
||||
from bson.son import SON
|
||||
import datetime
|
||||
|
||||
DBHOST = '172.16.2.15'
|
||||
DBNAME = 'iot'
|
||||
DBCOLL = 'iot'
|
||||
FILENAME = 'measurementData.xls'
|
||||
|
||||
|
||||
client = pymongo.MongoClient(DBHOST)
|
||||
db = client[DBNAME]
|
||||
coll = db[DBCOLL]
|
||||
|
||||
startDate = datetime.datetime(2015, 8, 13)
|
||||
|
||||
cursor = coll.aggregate(
|
||||
[
|
||||
{"$match":{"metadata.device":"MeterbusHub", "metadata.name": {"$in": ["light", "laundry", "dishwasher"]}, "metadata.day": {"$gte": startDate}}},
|
||||
{"$sort":SON([("metadata.name",1),("metadata.day",1), ("metadata.seconds",1)])},
|
||||
{"$group":{"_id":{"device":"$metadata.name","day":"$metadata.day"}, "first":{"$first":"$data.energy"},"last":{"$last":"$data.energy"}}},
|
||||
{"$sort":{"_id":1}},
|
||||
{"$project": {"energy":{"$subtract":["$last","$first"]}}}
|
||||
],
|
||||
useCursor=True
|
||||
)
|
||||
|
||||
for c in cursor:
|
||||
print(c)
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user