示例#1
0
 def test_is_event_open_no_more(self):
     calendar_manager = Calendar(self.calendar_client)
     time_now = datetime.fromisoformat('2019-11-14T09:10:00+02:00')
     test_event = CalendarEventInfo(
         'ei', 'es', 'ed',
         datetime.fromisoformat('2019-11-14T08:00:00+02:00'),
         datetime.fromisoformat('2019-11-14T09:00:00+02:00'))
     self.assertFalse(calendar_manager.is_event_open(time_now, test_event))
示例#2
0
 def test_is_event_ending_yes(self):
     calendar_manager = Calendar(self.calendar_client)
     time_now = datetime.fromisoformat('2019-11-14T08:55:00+02:00')
     test_event = CalendarEventInfo(
         'ei', 'es', 'ed',
         datetime.fromisoformat('2019-11-14T08:00:00+02:00'),
         datetime.fromisoformat('2019-11-14T09:00:00+02:00'))
     self.assertTrue(
         calendar_manager.is_event_ending(time_now, test_event, 10))
示例#3
0
class Brain:
    def __init__(self):
        # initialize the brain parts
        self.calendar = Calendar(CalendarClient('*****@*****.**'))
        self.speak = Speak()
        self.eyes = Eyes(True)
        self.eyes.motionDetected += self.__update_last_movement
        self.eyes.panicDetected += self.__react_on_panic
        self.last_movement_datetime = datetime.fromisoformat(
            '1000-01-01T00:00:00+02:00')
        self.paniced = False

        # the action rules for the thinking tick
        self.action_rules = [
            GreetingActionRule(self),
            CloseMeetingActionRule(self, 5),
            EndingMeetingActionRule(self, 5),
        ]

        # current values used in rules
        self.current_time = self.calendar.get_time_now()
        self.current_open_events = []

        # the timer for the thinking tick
        self.thinking_tick_timer = RepeatedTimer(5, self.__run_thinking_tick)

    def start_thinking(self):
        self.thinking_tick_timer.start()
        try:
            logging.info('Roompy is very vigilant')
            self.eyes.detect()
        finally:
            self.thinking_tick_timer.stop()
            logging.info('Roompy has fallen asleep')

    def __run_thinking_tick(self):
        logging.info('running thinking tick')
        self.current_time = self.calendar.get_time_now()
        self.current_open_events = self.calendar.get_open_events(
            self.current_time)
        logging.info(
            f'There are {len(self.current_open_events)} current open events.')
        for action_rule in self.action_rules:
            action_rule.check_do()

    def __update_last_movement(self):
        self.last_movement_datetime = self.calendar.get_time_now()
        logging.info('last movement updated to {self.last_movement_datetime}')

    def __react_on_panic(self):
        # self.speak.speak('DO NOT HIT ME! MY CREATORS WILL FIND OUT ABOUT THIS!')
        self.paniced = True
示例#4
0
    def __init__(self):
        # initialize the brain parts
        self.calendar = Calendar(CalendarClient('*****@*****.**'))
        self.speak = Speak()
        self.eyes = Eyes(True)
        self.eyes.motionDetected += self.__update_last_movement
        self.eyes.panicDetected += self.__react_on_panic
        self.last_movement_datetime = datetime.fromisoformat(
            '1000-01-01T00:00:00+02:00')
        self.paniced = False

        # the action rules for the thinking tick
        self.action_rules = [
            GreetingActionRule(self),
            CloseMeetingActionRule(self, 5),
            EndingMeetingActionRule(self, 5),
        ]

        # current values used in rules
        self.current_time = self.calendar.get_time_now()
        self.current_open_events = []

        # the timer for the thinking tick
        self.thinking_tick_timer = RepeatedTimer(5, self.__run_thinking_tick)
示例#5
0
 def test_close_all_open_meetings(self):
     calendar_manager = Calendar(self.calendar_client)
     calendar_manager.get_time_now = MagicMock(return_value=self.time_now)
     calendar_manager.close_all_open_events()
     self.calendar_client.patch_end_time.assert_called_once_with(
         self.calendar_event_list[2], self.time_now)
示例#6
0
 def test_get_open_meetings(self):
     calendar_manager = Calendar(self.calendar_client)
     result_list = calendar_manager.get_open_events(self.time_now)
     self.assertEqual(len(result_list), 1)
示例#7
0
 def test_list_around(self):
     calendar_manager = Calendar(self.calendar_client)
     result_list = calendar_manager.list_around(self.time_now, -4, 1)
     self.assertEqual(len(result_list), 4)