commit 827ee3ec777b35c030952e3da4c363606229da55 Author: Wolfgang Hottgenroth Date: Fri Jul 10 21:51:33 2015 +0200 initial diff --git a/.hgignore b/.hgignore new file mode 100644 index 0000000..da61a25 --- /dev/null +++ b/.hgignore @@ -0,0 +1,3 @@ +syntax: glob +*.pyc + diff --git a/.project b/.project new file mode 100644 index 0000000..b5eea39 --- /dev/null +++ b/.project @@ -0,0 +1,17 @@ + + + FridgeAlarm2 + + + + + + org.python.pydev.PyDevBuilder + + + + + + org.python.pydev.pythonNature + + diff --git a/.pydevproject b/.pydevproject new file mode 100644 index 0000000..037bd25 --- /dev/null +++ b/.pydevproject @@ -0,0 +1,8 @@ + + + +/${PROJECT_DIR_NAME} + +python 2.7 +Default + diff --git a/FridgeAlarm.py b/FridgeAlarm.py new file mode 100644 index 0000000..d087021 --- /dev/null +++ b/FridgeAlarm.py @@ -0,0 +1,30 @@ +import pymongo +import datetime + +client = pymongo.MongoClient('172.16.2.15') +db = client.iot +iot = db.iot + +now1 = datetime.datetime.now() +now = now1.replace(now1.year, now1.month, now1.day, now1.hour, now1.minute, now1.second, 0) +midnight = now.replace(now.year, now.month, now.day, 0,0,0,0) +seconds = (now - midnight).seconds +intervalBegin = seconds - 15 * 60 + +if intervalBegin > 0: + pipeline = [ + {'$match': {'metadata.device': 'ModbusHub', + 'metadata.day': midnight, + 'metadata.seconds': {'$gt': intervalBegin, '$lt': seconds} + }}, + {'$sort': {'seconds': 1}}, + {'$project': {'_id': 0, 'ts': '$metadata.timestamp', 't': '$data.t2'}} + ] + cursor = iot.aggregate(pipeline, useCursor=True) + for item in cursor: + print(item) + + + +# {'$group': {'_id': 0, +# 'avgTemp': {'$avg': '$data.t2'}}}