-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathparseLog.py
More file actions
executable file
·116 lines (89 loc) · 2.89 KB
/
parseLog.py
File metadata and controls
executable file
·116 lines (89 loc) · 2.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# parses LuaUPnP.log for sensor output data
# Call shell script to pull LuaUpNP.log file from Vera
import time
import subprocess
import datetime
from collections import deque
import os
import json
# global variable
stopTime = datetime.datetime.now().strftime("%H:%M:%S:%f")[:-3]
stopLine = ""
def initSensorMap():
sensorMap = dict()
# Sherri
sensorMap['1'] = 'Distance'
# Jeff
sensorMap['2'] = 'Distance'
# Andy
sensorMap['3'] = 'Distance'
# Dave
sensorMap['4'] = 'Distance'
# Goldfeather
sensorMap['5'] = 'Distance'
# Layla
sensorMap['21'] = 'Color'
sensorMap['111'] = 'Color' #alternate
# DLN
sensorMap['31'] = 'Sound'
# Other ones
return sensorMap
def initValueTypes():
valueTypes = []
valueTypes.append('CurrentDistance,')
valueTypes.append('Variable2,')
return valueTypes
def writeEntry(inFile, outFile, sensorMap, valueTypes, entryDeque):
global stopTime
global stopLine
for curLine in reversed(inFile.readlines()):
# if any of value type keywords (e.g. "CurrentDistance, "") are in the line
# then read the line as an entry
# if any(valType in curLine for valType in valueTypes):
fields = [field.lstrip() for field in curLine.split(",")]
sensorID = fields[3].split(" ")[0].strip()
sensorValue = fields[2].strip()
print sensorID
sensorType = sensorMap[sensorID]
timeStamp = fields[0].split("\t")[1].split(" ")[1].replace(".", ":")
entry = timeStamp+"\t"+sensorType+"\t"+sensorID+"\t"+sensorValue+"\n"
# to avoid reading in duplicates
if entry == stopLine:
print "SAAAAAMESIES BREAAAAK"
break
if int(timeStamp.replace(":", "")) < int(stopTime.replace(":","")):
# *** to fix??: theoretically we could end up with a sensor trip that is never acknowledged
if int(timeStamp.replace(":", "")) == int(stopTime.replace(":","")):
raise StandardError("Skipped a sensor reading")
print "BREAK"
print "timestamp", timeStamp
print "stoptime", stopTime
break
entryDeque.append(entry)
# # peek first item in queue (newest time)
if entryDeque:
stopTime = entryDeque[0].split("\t")[0]
stopLine = entryDeque[0]
# while deque is not empty:
while entryDeque:
curEntry = entryDeque.pop()
print "****WRITTEN: ", curEntry
outFile.write(curEntry)
return
sensorMap = initSensorMap()
valueTypes = initValueTypes()
while True:
print "--------------------------------------"
print datetime.datetime.now().strftime("%m-%d_%H.%M.%S.%f")[:-3]
print
subprocess.call(['./rsync.sh'])
entryDeque = deque()
with open("filtered.log", "r") as fullLog:
# with open("LuaUPnP.log", "r") as fullLog:
# Set the title of the output file to the current time
now = datetime.datetime.now()
output_title = now.strftime("%m-%d_%H.%M.%S.%f")[:-3]
# Creates output file
# with open("log_"+output_title+".log", "w") as outLog:
with open("webpage.js/logFileUpdating.txt", "w") as outLog:
writeEntry(fullLog, outLog, sensorMap, valueTypes, entryDeque)