This commit is contained in:
Wolfgang Hottgenroth 2015-07-10 21:51:33 +02:00
commit 827ee3ec77
4 changed files with 58 additions and 0 deletions

3
.hgignore Normal file
View File

@ -0,0 +1,3 @@
syntax: glob
*.pyc

17
.project Normal file
View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>FridgeAlarm2</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.python.pydev.PyDevBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.python.pydev.pythonNature</nature>
</natures>
</projectDescription>

8
.pydevproject Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?eclipse-pydev version="1.0"?><pydev_project>
<pydev_pathproperty name="org.python.pydev.PROJECT_SOURCE_PATH">
<path>/${PROJECT_DIR_NAME}</path>
</pydev_pathproperty>
<pydev_property name="org.python.pydev.PYTHON_PROJECT_VERSION">python 2.7</pydev_property>
<pydev_property name="org.python.pydev.PYTHON_PROJECT_INTERPRETER">Default</pydev_property>
</pydev_project>

30
FridgeAlarm.py Normal file
View File

@ -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'}}}