diff --git a/POCloud/w_sqlite/poc.py b/POCloud/w_sqlite/poc.py index fb94af0..3af506b 100644 --- a/POCloud/w_sqlite/poc.py +++ b/POCloud/w_sqlite/poc.py @@ -134,6 +134,36 @@ class start(threading.Thread, deviceBase): print "couldn't load enent ID's from pickle" self.eventIds = [] + # load stored Well Test ID's + try: + with open('welltestIDs.p', 'rb') as handle: + self.welltestIDs = pickle.load(handle) + + print "found pickled welltestIDs dictionary: {0}".format(self.welltestIDs) + except: + print "couldn't load well test ID's from pickle" + self.welltestIDs = [] + + # load stored Fluid Shot ID's + try: + with open('fluidshotIDs.p', 'rb') as handle: + self.fluidshotIDs = pickle.load(handle) + + print "found pickled fluidshotIDs dictionary: {0}".format(self.fluidshotIDs) + except: + print "couldn't load fluid shot ID's from pickle" + self.fluidshotIDs = [] + + # load stored note ID's + try: + with open('noteIDs.p', 'rb') as handle: + self.noteIDs = pickle.load(handle) + + print "found pickled noteID dictionary: {0}".format(self.noteIDs) + except: + print "couldn't load note ID's from pickle" + self.noteIDs = [] + # load stored wellconfig's try: with open('wellSetup.p', 'rb') as handle: @@ -161,6 +191,15 @@ class start(threading.Thread, deviceBase): runLoopStatus = "checkEvents" self.checkEvents() + runLoopStatus = "checkNotes" + self.checkNotes() + + runLoopStatus = "checkWellTests" + self.checkWellTests() + + runLoopStatus = "checkFluidShots" + self.checkFluidShots() + runLoopStatus = "checkStatus" self.checkStatus() @@ -219,6 +258,20 @@ class start(threading.Thread, deviceBase): with open('eventIds.p', 'wb') as handle: pickle.dump(self.eventIds, handle) + def checkNotes(self): + data = json.loads(requests.get(self.device_address + "/json/notes/get").text) + notes = data["notes"] + for note in notes: + if int(note["id"]) not in self.noteIDs: + timestamp = calendar.timegm(time.strptime(note["date_time"], '%Y-%m-%d %H:%M:%S')) + # we have a new note + self.sendtodbJSON("notes", json.dumps(note), timestamp) + self.noteIDs.append(int(note["id"])) + if len(self.noteIDs) > 50: + del self.noteIDs[0] + with open('noteIDs.p', 'wb') as handle: + pickle.dump(self.noteIDs, handle) + def checkStatus(self): statusMap = { 0: 'Stopped',