Пример #1
0
def build_narrator(**kwargs):
    memories = kwargs.pop("memories", [])
    rv = Narrator(
        memories=collections.deque(memories, maxlen=max(6, len(memories))),
        **kwargs
    )
    if not kwargs:
        return rv.set_state(
            Spot.w12_ducane_prison_wing
        ).set_state(
            int(blue_monday.strftime("%Y%m%d0800"))
        )
    else:
        return rv
Пример #2
0
 def test_parse_timespan_day(self):
     rv = Narrator.parse_timespan(blue_monday.strftime("%Y%m%d"))
     self.assertEqual(2, len(rv))
     self.assertEqual(
         datetime.datetime(blue_monday.year, blue_monday.month,
                           blue_monday.day), rv[0])
     self.assertEqual(datetime.timedelta(days=1), rv[1])
Пример #3
0
 def test_hours(self):
     start, span = Narrator.parse_timespan("2019110817")
     self.assertEqual(2019, start.year)
     self.assertEqual(11, start.month)
     self.assertEqual(8, start.day)
     self.assertEqual(17, start.hour)
     self.assertEqual(3600, span.seconds)
Пример #4
0
 def test_parse_timespan_period(self):
     rv = Narrator.parse_timespan(blue_monday.strftime("%Y%m%d") + "1")
     self.assertEqual(2, len(rv))
     self.assertEqual(
         datetime.datetime(blue_monday.year,
                           blue_monday.month,
                           blue_monday.day,
                           hour=10), rv[0])
     self.assertEqual(datetime.timedelta(hours=10), rv[1])
Пример #5
0
 def test_seconds(self):
     start, span = Narrator.parse_timespan("20191108173004")
     self.assertEqual(2019, start.year)
     self.assertEqual(11, start.month)
     self.assertEqual(8, start.day)
     self.assertEqual(17, start.hour)
     self.assertEqual(30, start.minute)
     self.assertEqual(4, start.second)
     self.assertEqual(1, span.seconds)
Пример #6
0
 def decorate_folder(folder, min_t, max_t):
     integer_states = [
         i for i in MultiMatcher.entity_states(folder) if i.isdigit()
     ]
     object_states = [
         Pathfinder.string_import(i)
         for i in MultiMatcher.entity_states(folder)
         if i not in integer_states
     ]
     folder.metadata["spots"] = {
         i
         for i in object_states if isinstance(i, Spot)
     }
     for entity_state in integer_states:
         t, span = Narrator.parse_timespan(entity_state)
         if span is not None:
             min_t = min(min_t,
                         t if span else min_t) if min_t is not None else t
             max_t = max(max_t, (t + span) if span else
                         max_t) if max_t is not None else t + span
             folder.metadata["min_t"] = min_t
             folder.metadata["max_t"] = max_t
     return folder
Пример #7
0
 def test_parse_timespan_integer(self):
     rv = Narrator.parse_timespan("4")
     self.assertEqual(2, len(rv))
     self.assertEqual(("4", None), rv)
Пример #8
0
 def test_creation(self):
     narrator = Narrator()
     self.assertTrue(hasattr(narrator, "id"))
Пример #9
0
 def test_days(self):
     start, span = Narrator.parse_timespan("20191108")
     self.assertEqual(2019, start.year)
     self.assertEqual(11, start.month)
     self.assertEqual(8, start.day)
     self.assertEqual(1, span.days)