Small fixes
This commit is contained in:
parent
48eed72acb
commit
12602f4579
1 changed files with 4 additions and 11 deletions
|
@ -159,26 +159,19 @@ class PeopleCounter ():
|
||||||
th = threading.Thread(target=cb, args=(countChange, self.directionState))
|
th = threading.Thread(target=cb, args=(countChange, self.directionState))
|
||||||
th.start()
|
th.start()
|
||||||
|
|
||||||
def getDirectionTime(self, direction: Directions, time: str) -> datetime:
|
|
||||||
if len(self.directionState[direction]) <= 0:
|
|
||||||
return None
|
|
||||||
|
|
||||||
return self.directionState[direction][-1][time]
|
|
||||||
|
|
||||||
def updateState(self, direction: Directions, triggered: bool) -> bool:
|
def updateState(self, direction: Directions, triggered: bool) -> bool:
|
||||||
currentlyTriggered = False
|
previouslyTriggered = False
|
||||||
if len(self.directionState[direction]) > 0:
|
if len(self.directionState[direction]) > 0:
|
||||||
currentlyTriggered = self.getDirectionTime(
|
previouslyTriggered = self.directionState[direction][-1][END_TIME] is None
|
||||||
direction, END_TIME) is None
|
|
||||||
|
|
||||||
if triggered and not currentlyTriggered:
|
if triggered and not previouslyTriggered:
|
||||||
# Set as new beginning for this direction
|
# Set as new beginning for this direction
|
||||||
self.directionState[direction].append({
|
self.directionState[direction].append({
|
||||||
START_TIME: datetime.now(),
|
START_TIME: datetime.now(),
|
||||||
END_TIME: None
|
END_TIME: None
|
||||||
})
|
})
|
||||||
return True
|
return True
|
||||||
elif not triggered and currentlyTriggered:
|
elif not triggered and previouslyTriggered:
|
||||||
# Set as end for this direction
|
# Set as end for this direction
|
||||||
self.directionState[direction][-1][END_TIME] = datetime.now()
|
self.directionState[direction][-1][END_TIME] = datetime.now()
|
||||||
return True
|
return True
|
||||||
|
|
Loading…
Reference in a new issue