Exemplo n.º 1
0
    def test_situation_manipulations(self):

        s1 = Situation()
        s2 = Situation()

        self.assertEqual(len(self.timeline), 0)

        self.timeline.append(s1)
        time.sleep(PROPAGATION_TIME)  # wait for propagation

        self.assertEqual(len(self.timeline), 1)
        self.assertIn(s1, self.timeline)
        self.assertEqual(self.timeline[0].endtime, 0)

        s1.endtime = 1
        self.timeline.update(s1)
        time.sleep(PROPAGATION_TIME)  # wait for propagation

        self.assertEqual(len(self.timeline), 1)
        self.assertEqual(self.timeline[0].endtime, 1)

        self.timeline.update(s2)  # alias for append
        time.sleep(PROPAGATION_TIME)  # wait for propagation

        self.assertEqual(len(self.timeline), 2)
        self.assertIn(s2, self.timeline)

        self.timeline.update(
            s2)  # shouldn't do anything, as s2 is already present
        time.sleep(PROPAGATION_TIME)  # wait for propagation

        self.assertEqual(len(self.timeline), 2)

        s1.endtime = 2
        s2.endtime = 3
        self.timeline.update(s1)
        self.timeline.update(s2)
        time.sleep(PROPAGATION_TIME)  # wait for propagation

        self.assertEqual(len(self.timeline), 2)
        self.assertEqual(self.timeline[s1.id].endtime, 2)
        self.assertEqual(self.timeline[s2.id].endtime, 3)

        self.timeline.remove(s1)
        time.sleep(PROPAGATION_TIME)  # wait for propagation

        self.assertEqual(len(self.timeline), 1)
        self.assertEqual(self.timeline[0].id, s2.id)

        self.timeline.remove(s2)
        time.sleep(PROPAGATION_TIME)  # wait for propagation

        self.assertEqual(len(self.timeline), 0)
Exemplo n.º 2
0
    def test_situation_manipulations(self):

        s1 = Situation()
        s2 = Situation()

        self.assertEqual(len(self.timeline),0)

        self.timeline.append(s1)
        time.sleep(PROPAGATION_TIME) # wait for propagation

        self.assertEqual(len(self.timeline),1)
        self.assertIn(s1, self.timeline)
        self.assertEqual(self.timeline[0].endtime, 0)
 
        s1.endtime = 1
        self.timeline.update(s1)
        time.sleep(PROPAGATION_TIME) # wait for propagation

        self.assertEqual(len(self.timeline),1)
        self.assertEqual(self.timeline[0].endtime, 1)

        self.timeline.update(s2) # alias for append
        time.sleep(PROPAGATION_TIME) # wait for propagation

        self.assertEqual(len(self.timeline),2)
        self.assertIn(s2, self.timeline)
 
        self.timeline.update(s2) # shouldn't do anything, as s2 is already present
        time.sleep(PROPAGATION_TIME) # wait for propagation

        self.assertEqual(len(self.timeline),2)
 
        s1.endtime = 2
        s2.endtime = 3
        self.timeline.update(s1)
        self.timeline.update(s2)
        time.sleep(PROPAGATION_TIME) # wait for propagation

        self.assertEqual(len(self.timeline),2)
        self.assertEqual(self.timeline[s1.id].endtime, 2)
        self.assertEqual(self.timeline[s2.id].endtime, 3)

 
        self.timeline.remove(s1)
        time.sleep(PROPAGATION_TIME) # wait for propagation

        self.assertEqual(len(self.timeline),1)
        self.assertEqual(self.timeline[0].id, s2.id)
 
        self.timeline.remove(s2)
        time.sleep(PROPAGATION_TIME) # wait for propagation

        self.assertEqual(len(self.timeline),0)
 def start_predicate(self, timeline, predicate, subject_name, object_name=None, isevent=False):
     if object_name is None:
         description = predicate + "(" + subject_name + ")"
     else:
         description = predicate + "(" + subject_name + "," + object_name + ")"
     sit = Situation(desc=description)
     sit.starttime = time.time()
     if isevent:
         sit.endtime = sit.starttime
     self.current_situations_map[description] = sit
     self.log_pub[predicate].publish("START " + description)
     timeline.update(sit)
     return sit.id
Exemplo n.º 4
0
    def event(self):
        """ Creates (and return) a new event (situation with 0 duration)

        This method sends the new event to the
        remote. IT DOES NOT DIRECTLY modify the local
        copy of situations: the roundtrip is slower, but data
        consistency is easier to ensure.

        Note that the event time is set by the client, at the time
        at which this method is called.
        """
        situation = Situation()
        situation.starttime = time.time()
        situation.endtime = situation.starttime
        self.update(situation)
        return situation
Exemplo n.º 5
0
    def event(self):
        """ Creates (and return) a new event (situation with 0 duration)

        This method sends the new event to the
        remote. IT DOES NOT DIRECTLY modify the local
        copy of situations: the roundtrip is slower, but data
        consistency is easier to ensure.

        Note that the event time is set by the client, at the time
        at which this method is called.
        """
        situation = Situation()
        situation.starttime = time.time()
        situation.endtime = situation.starttime
        self.update(situation)
        return situation