/
meantime.py.save
95 lines (80 loc) · 2 KB
/
meantime.py.save
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
import time
import pickle
import sys
start_time = time.time()
current_id = 0
instance = None
people = []
def main(argv):
if argv == "run":
loadData()
saveData()
genData()
if argv == "save":
genData()
people_count = len(people)
#people.append(user(1,2,3,3,4))
print "saving data"
saveData()
if argv == "load":
print "loading data"
loadData()
#Use pickle to save "people" List
def saveData():
pickle.dump(people,open("Data.pkl","rb"))
print "Data Saved"
printPeople()
#use pickle to load "people" List
def loadData():
global people
f = open("Data.pkl","a")
people = pickle.load(open(f))
# instance = pickle.load(f)
f.close()
print "Data loaded"
printPeople()
#seach through "people" list to find mac entry
def macSearch(id):
print "MACSEARCH"
position = None
for x in range(0,len(people)):
print "Number:",x
if people[x].mac == id:
print "Not Empty"
print "The id is ", id
current_id = x
return id
#return index of entry
return None
def updateExisting(id):
print "updating"
people[current_id].lastSeen = time.time()
def createEntry(mac):
people.append(user(mac,1,start_time,start_time,0,0))
print "creating"
#Print Structure
def printPeople():
print "mac |State|Start |lastSeen |duration|misscount"
print "=============================================================="
for x in range(0,len(people)):
print people[x].mac + "|" , people[x].state , " |" ,people[x].start,"|" ,people[x].lastSeen , "|", people[x].duration ," |", people[x].misscount
#Data Structure
class user(object):
def __init__(self,mac,state,start,lastSeen,duration,misscount):
self.mac = mac
self.state = state
self.start = start
self.lastSeen = lastSeen
self.duration = duration
self.misscount = misscount
def genData():
with open('hashFile') as infile:
for line in infile:
print "BASE ID " , line[:-1]
id = macSearch(line[:-1])
if id != None:
updateExisting(id)
else:
createEntry(line[:-1])
if __name__ == "__main__":
main(sys.argv[1])