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()" runLoopStatus = "getDataLoggerStatus()"
self.getDataLoggerStatus() self.getDataLoggerStatus()
# if self.statusChanged: if self.statusChanged:
# runLoopStatus = "getLatestXCards" runLoopStatus = "getLatestXCards"
# self.getLatestXCards(5) self.forceSend = True
# else: self.checkLatestCard(5)
# runLoopStatus = "checkLatestCard" else:
# self.checkLatestCard() runLoopStatus = "checkLatestCard"
runLoopStatus = "checkLatestCard" self.checkLatestCard()
self.checkLatestCard()
if self.forceSend or (checkBackupSkipped > checkBackupEvery): # if self.forceSend or (checkBackupSkipped > checkBackupEvery):
runLoopStatus = "checkBackup" # runLoopStatus = "checkBackup"
self.checkBackup() # self.checkBackup()
checkBackupSkipped = 0 # checkBackupSkipped = 0
checkBackupSkipped = checkBackupSkipped + 1 # checkBackupSkipped = checkBackupSkipped + 1
runLoopStatus = "Complete" runLoopStatus = "Complete"
time.sleep(3) time.sleep(3)
@@ -350,8 +349,8 @@ class start(threading.Thread, deviceBase):
st_response = requests.get(self.device_address + "/json/status") st_response = requests.get(self.device_address + "/json/status")
if st_response.status_code == 200: if st_response.status_code == 200:
data = json.loads(st_response.text) data = json.loads(st_response.text)
date = data["ISOdate"] # date = data["ISOdate"]
status_read = statusMap[int(data["status"])] status_read = data["run_status"]
if status.last_value != status_read: if status.last_value != status_read:
self.statusChanged = True self.statusChanged = True
@@ -361,12 +360,12 @@ class start(threading.Thread, deviceBase):
if self.statusChanged or self.forceSend: if self.statusChanged or self.forceSend:
self.status = status_read self.status = status_read
reg = "(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}).(\d{3})Z" # reg = "(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}).(\d{3})Z"
fd = re.search(reg, date) # 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))) # 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 = int(time.mktime(time.strptime(date, '%Y-%m-%dT%H:%M:%S.%fZ')))
timestamp = calendar.timegm(dt.timetuple()) # timestamp = calendar.timegm(dt.timetuple())
self.sendtodb("status", status_read, timestamp) self.sendtodb("status", status_read, 0)
status.last_value = status_read status.last_value = status_read
def checkDailyTotals(self): def checkDailyTotals(self):
@@ -396,35 +395,39 @@ class start(threading.Thread, deviceBase):
if go_channels[entry].checkSend(day[entry], False): if go_channels[entry].checkSend(day[entry], False):
self.sendtodb(go_channels[entry].mesh_name, day[entry], timestamp) self.sendtodb(go_channels[entry].mesh_name, day[entry], timestamp)
def checkLatestCard(self): def checkLatestCard(self, numCards = 1):
latest = json.loads(requests.get(self.device_address + "/json/latestcard").text) 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 # check the card to see if its new
# 1. if its new send the folder/file_name to the card_history channel # 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 # 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): reg = "(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})"
dateTime = str(latest["card_data"]["Stroke_Time"]) 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})" print "New card detected @ {0}".format(datetime.strftime(datetime.fromtimestamp(timestamp), "%Y-%m-%d %H:%M:%S.%f"))
fd = re.search(reg, dateTime) # set the last value = to current value and upload your data
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))) self.sendtodb("card_history", card_channels['card_id'].value, timestamp)
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")) # check the last time the card was updated
# set the last value = to current value and upload your data if (time.time() - card_channels['card'].last_send_time) > self.cardLoopTimer or self.statusChanged or self.forceSend:
self.sendtodb("card_history", card_channels['card_id'].value, timestamp) # its been 10 minutes, send the full upload
print "Either status has changed or last stored card is too old."
# check the last time the card was updated card_channels["card"].last_send_time = time.time()
if (time.time() - card_channels['card'].last_send_time) > self.cardLoopTimer or self.statusChanged or self.forceSend: self.process_card(card, timestamp, card_timestamp, sendCards=True)
# its been 10 minutes, send the full upload return
print "Either status has changed or last stored card is too old." else:
card_channels["card"].last_send_time = time.time() self.process_card(card, timestamp, card_timestamp, sendCards=False)
self.process_card(latest, timestamp, card_timestamp, sendCards=True)
return
else:
self.process_card(latest, timestamp, card_timestamp, sendCards=False)
def process_card(self, data, data_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 # 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: 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_p = data["Surface_Position"]
s_l = data['card_data']["Surface_Load"] s_l = data["Surface_Load"]
d_p = data['card_data']["Downhole_Position"] d_p = data["Downhole_Position"]
d_l = data['card_data']["Downhole_Load"] d_l = data["Downhole_Load"]
newSc = "[" newSc = "["
newDc = "[" newDc = "["