-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgroup.py
71 lines (53 loc) · 1.97 KB
/
group.py
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
GRANULARITY = 400
class Face:
def __init__(self, name):
self.name = name
self.start = -1.0
self.last = -1.0
class Group:
def __init__(self, membersMap):
self.members = {}
for faceId, name in membersMap.items():
self.members[faceId] = Face(name)
def getMemberFaceIds(self):
return [faceId for faceId in self.members]
def faceAppear(self, faceId, time):
if self.members[faceId].start == -1.0:
self.members[faceId].start = time
self.members[faceId].last = time
elif time - self.members[faceId].last > GRANULARITY:
self.printLastOccurance()
self.members[faceId].start = time
self.members[faceId].last = time
else:
self.members[faceId].last = time
# this should be reworked in python3 with members.items() and obj access
def printLastOccurance(self):
latestStart = max([self.members[faceId].start for faceId in self.members])
earliestEnd = min([self.members[faceId].last for faceId in self.members])
if latestStart > earliestEnd:
pass
# there is no crossection
else:
if len(self.members) == 1:
print "Person: ",
else:
print "Group: ",
for face in self.members:
print self.members[face].name,
print ' -> ',
timestampToNormal(latestStart)
print 'to',
timestampToNormal(earliestEnd)
print
print '==============================='
def timestampToNormal(time):
time, milis = divmod(time, 1000)
time, seconds = divmod(time, 60)
time, minutes = divmod(time, 60)
hours = time
print "%d:%02d:%02d:%03d" % (hours, minutes, seconds, milis),
if __name__ == '__main__':
face_map = {'a':'cecko', 'b':'mitko', 'c':'petkan'}
group = Group(face_map)
group.printLastOccurance()