from __future__ import print_function, absolute_import, division
import sys, re, json, pymongo, unittest
from pymongo import MongoClient
+from configparser import ConfigParser
+from timeit import timeit
__all__ = ['SensorData','SensorDataIterator']
__version__ = '1.0.0'
print(item)
return 0
+def test_recent(*args, **kwargs):
+ from timeit import timeit
+ print(timeit('recent()', setup='from __main__ import recent', number=100))
+ print(recent())
+
+def recent(*args, **kwargs):
+ client = opendb()
+ db = client.sensorhub.sensorlog
+ db.create_index([("timestamp", pymongo.ASCENDING)]) # creates if not already present
+ cursor = db.find().sort([("timestamp", pymongo.DESCENDING)]).limit(1)
+ item = next(cursor)
+ return item
+
+def opendb():
+ config = ConfigParser()
+ config.read('sensor-hub.config')
+ uri = config['database']['uri'].strip("\'")
+ client = MongoClient(uri)
+ return client
+
def testing(*args, **kwargs):
'''
{"timestamp": "1460971800",
tojson(*sys.argv[2:])
elif sys.argv[1] == 'test':
testing(*sys.argv[2:])
+ elif sys.argv[1] == 'recent':
+ test_recent(*sys.argv[2:])
else:
print("usage: SensorData test")
1