Applying stashed changes

This commit is contained in:
Patrick McDonagh
2016-03-26 17:09:54 -05:00
parent 509fac659f
commit 084c2d8cdf

View File

@@ -243,20 +243,19 @@ class start(threading.Thread, deviceBase):
runLoopStatus = "getDataLoggerStatus()"
self.getDataLoggerStatus()
# if self.statusChanged:
# runLoopStatus = "getLatestXCards"
# self.getLatestXCards(5)
# else:
# runLoopStatus = "checkLatestCard"
# self.checkLatestCard()
runLoopStatus = "checkLatestCard"
self.checkLatestCard()
if self.statusChanged:
runLoopStatus = "getLatestXCards"
self.forceSend = True
self.checkLatestCard(5)
else:
runLoopStatus = "checkLatestCard"
self.checkLatestCard()
if self.forceSend or (checkBackupSkipped > checkBackupEvery):
runLoopStatus = "checkBackup"
self.checkBackup()
checkBackupSkipped = 0
checkBackupSkipped = checkBackupSkipped + 1
# if self.forceSend or (checkBackupSkipped > checkBackupEvery):
# runLoopStatus = "checkBackup"
# self.checkBackup()
# checkBackupSkipped = 0
# checkBackupSkipped = checkBackupSkipped + 1
runLoopStatus = "Complete"
time.sleep(3)
@@ -350,8 +349,8 @@ class start(threading.Thread, deviceBase):
st_response = requests.get(self.device_address + "/json/status")
if st_response.status_code == 200:
data = json.loads(st_response.text)
date = data["ISOdate"]
status_read = statusMap[int(data["status"])]
# date = data["ISOdate"]
status_read = data["run_status"]
if status.last_value != status_read:
self.statusChanged = True
@@ -361,12 +360,12 @@ class start(threading.Thread, deviceBase):
if self.statusChanged or self.forceSend:
self.status = status_read
reg = "(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}).(\d{3})Z"
fd = re.search(reg, date)
dt = datetime(int(fd.group(1)), int(fd.group(2)), int(fd.group(3)), int(fd.group(4)), int(fd.group(5)), int(fd.group(6)), int(fd.group(7)))
# timestamp = int(time.mktime(time.strptime(date, '%Y-%m-%dT%H:%M:%S.%fZ')))
timestamp = calendar.timegm(dt.timetuple())
self.sendtodb("status", status_read, timestamp)
# reg = "(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}).(\d{3})Z"
# fd = re.search(reg, date)
# dt = datetime(int(fd.group(1)), int(fd.group(2)), int(fd.group(3)), int(fd.group(4)), int(fd.group(5)), int(fd.group(6)), int(fd.group(7)))
# # timestamp = int(time.mktime(time.strptime(date, '%Y-%m-%dT%H:%M:%S.%fZ')))
# timestamp = calendar.timegm(dt.timetuple())
self.sendtodb("status", status_read, 0)
status.last_value = status_read
def checkDailyTotals(self):
@@ -396,35 +395,39 @@ class start(threading.Thread, deviceBase):
if go_channels[entry].checkSend(day[entry], False):
self.sendtodb(go_channels[entry].mesh_name, day[entry], timestamp)
def checkLatestCard(self):
latest = json.loads(requests.get(self.device_address + "/json/latestcard").text)
def checkLatestCard(self, numCards = 1):
latest = ""
if numCards == 1:
latest = json.loads(requests.get(self.device_address + "/json/latestcard").text)
else:
latest = json.loads(requests.get(self.device_address + "/json/latestcard/{}".format(numCards)).text)
# check the card to see if its new
# 1. if its new send the folder/file_name to the card_history channel
# 2. if its new and its been 10 minutes since you last sent an entire card, then send up all of the data
for i in range(0, len(latest['card_data'])):
card = latest['card_data'][i]
if card_channels['card_id'].checkSend(card['Card_ID'], self.forceSend):
dateTime = str(card["Stroke_Time"])
if card_channels['card_id'].checkSend(latest['card_data']['Card_ID'], self.forceSend):
dateTime = str(latest["card_data"]["Stroke_Time"])
reg = "(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})"
fd = re.search(reg, dateTime)
dt = datetime(int(fd.group(1)), int(fd.group(2)), int(fd.group(3)), int(fd.group(4)), int(fd.group(5)), int(fd.group(6)))
timestamp = calendar.timegm(dt.timetuple())
card_timestamp = int(time.mktime(dt.timetuple()))
reg = "(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})"
fd = re.search(reg, dateTime)
dt = datetime(int(fd.group(1)), int(fd.group(2)), int(fd.group(3)), int(fd.group(4)), int(fd.group(5)), int(fd.group(6)))
timestamp = calendar.timegm(dt.timetuple())
card_timestamp = int(time.mktime(dt.timetuple()))
print "New card detected @ {0}".format(datetime.strftime(datetime.fromtimestamp(timestamp), "%Y-%m-%d %H:%M:%S.%f"))
# set the last value = to current value and upload your data
self.sendtodb("card_history", card_channels['card_id'].value, timestamp)
print "New card detected @ {0}".format(datetime.strftime(datetime.fromtimestamp(timestamp), "%Y-%m-%d %H:%M:%S.%f"))
# set the last value = to current value and upload your data
self.sendtodb("card_history", card_channels['card_id'].value, timestamp)
# check the last time the card was updated
if (time.time() - card_channels['card'].last_send_time) > self.cardLoopTimer or self.statusChanged or self.forceSend:
# its been 10 minutes, send the full upload
print "Either status has changed or last stored card is too old."
card_channels["card"].last_send_time = time.time()
self.process_card(latest, timestamp, card_timestamp, sendCards=True)
return
else:
self.process_card(latest, timestamp, card_timestamp, sendCards=False)
# check the last time the card was updated
if (time.time() - card_channels['card'].last_send_time) > self.cardLoopTimer or self.statusChanged or self.forceSend:
# its been 10 minutes, send the full upload
print "Either status has changed or last stored card is too old."
card_channels["card"].last_send_time = time.time()
self.process_card(card, timestamp, card_timestamp, sendCards=True)
return
else:
self.process_card(card, timestamp, card_timestamp, sendCards=False)
def process_card(self, data, data_timestamp, card_timestamp, sendCards=False):
@@ -436,12 +439,12 @@ class start(threading.Thread, deviceBase):
# so to avoid comparing a string to a float, and to make sure on startup we send all of the values, the first time through we send everything that has a "" as its last value
if sendCards:
self.sendtodb("cardtype", str(data['card_data']['Card_Type']), int(data_timestamp))
self.sendtodb("cardtype", str(data['Card_Type']), int(data_timestamp))
s_p = data['card_data']["Surface_Position"]
s_l = data['card_data']["Surface_Load"]
d_p = data['card_data']["Downhole_Position"]
d_l = data['card_data']["Downhole_Load"]
s_p = data["Surface_Position"]
s_l = data["Surface_Load"]
d_p = data["Downhole_Position"]
d_l = data["Downhole_Load"]
newSc = "["
newDc = "["