1+ /*
2+ * Copyright (c) 2023 Smart Operating Block
3+ *
4+ * Use of this source code is governed by an MIT-style
5+ * license that can be found in the LICENSE file or at
6+ * https://opensource.org/licenses/MIT.
7+ */
8+
9+ #include " PeopleTracking.h"
10+ #include " ../../../../utils/ArrayStream.h"
11+
12+ PeopleTracking::PeopleTracking (const int period, PeopleTrackingContext* const context): AbstractFsm(period) {
13+ this ->changeState (new T (context));
14+ }
15+
16+ /*
17+ ##############################################################################
18+ ------------------State of LuminosityMonitoring FSM ---------------
19+ ##############################################################################
20+ */
21+
22+ PeopleTracking::T::T (PeopleTrackingContext* const context): context(context) {}
23+
24+ void PeopleTracking::T::run (Fsm* const parentFsm) {
25+ ArrayStream<PersonTracker*>(this ->context ->personTrackers , this ->context ->readerCount )
26+ .foreach ([this ](PersonTracker* tracker) {
27+ if (tracker->checkNewPerson ()) {
28+ Person newPerson = tracker->getLastPersonDetected ();
29+ Room* nextRoom = tracker->getNextRoom ();
30+ Room* previousRoom = tracker->getPreviousRoom ();
31+ if (ArrayStream<Pair<String, String>>(this ->trackInfo .toArray (), this ->trackInfo .size ())
32+ .exist (Pair<String, String>(nextRoom->getId (), newPerson.getId ()))) {
33+ this ->trackInfo .deleteElement (Pair<String, String>(nextRoom->getId (), newPerson.getId ()), true );
34+ if (previousRoom == nullptr ) {
35+ this ->context ->eventList ->add (new PersonTrackExit (newPerson));
36+ } else {
37+ this ->trackInfo .add (Pair<String, String>(previousRoom->getId (), newPerson.getId ()));
38+ this ->context ->eventList ->add (new PersonTrack (newPerson, *previousRoom));
39+ }
40+ } else {
41+ if (previousRoom != nullptr ) {
42+ this ->trackInfo .deleteElement (Pair<String, String>(previousRoom->getId (), newPerson.getId ()), true );
43+ }
44+ this ->trackInfo .add (Pair<String, String>(nextRoom->getId (), newPerson.getId ()));
45+ this ->context ->eventList ->add (new PersonTrack (newPerson, *nextRoom));
46+ }
47+ }
48+ });
49+ }
0 commit comments