def get_infected_window(room_id, visit_window): '''Returns window between agent's entry and end of the first sanitized time after the agent's exit''' #Infected window starts when the agent visits the room. Time before that doesn't matter start = visit_window.start # First cleaning window begin, after user has left safe_cleaning_time_begin = (list( sanitizedEventCollection.find( { "room_id": room_id, "status": 1, "timestamp": { "$gte": visit_window.end } }, { "_id": 0, "timestamp": 1 }))[0])['timestamp'] #timestamp in sanitized collection for a time after the window end -- using safe time to begin cleaning end = (list( sanitizedEventCollection.find( { "room_id": room_id, "status": 0, "timestamp": { "$gte": safe_cleaning_time_begin } }, { "_id": 0, "timestamp": 1 }))[0])['timestamp'] return Window(start, end)
def basic_info_pt(lottus_context: LottusContext, command: str) -> GeneratedWindow: """ :param lottus_context: :param command: :return: """ return GeneratedWindow.fromWindow( Window(name="BASIC_INFO_PT", title="Portugues", message="Benjamim Chambule\nProject manager @ VM.CO.MZ"), session_identifier=lottus_context.current_session.identifier )
def merge_overlapping_windows(self): sorted_keys = sorted(self.infected_windows, key=lambda iw: iw.start) for iw1, iw2 in zip(sorted_keys[:-1], sorted_keys[1:]): if (iw2.start < iw1.end): new_iw_key = Window(min(iw1.start, iw2.start), max(iw1.end, iw2.end)) new_iw = self.InfectedWindow(new_iw_key) new_iw.agent_visit_windows = list( set(self.infected_windows[iw1].agent_visit_windows).union( set(self.infected_windows[iw2].agent_visit_windows))) new_iw.user_visit_windows = list( set(self.infected_windows[iw1].user_visit_windows).union( set(self.infected_windows[iw2].user_visit_windows))) del self.infected_windows[iw1], self.infected_windows[iw2] self.infected_windows[new_iw_key] = new_iw
def info_en(lottus_context: LottusContext, command: str) -> GeneratedWindow: """ :param lottus_context: :param command: :return: """ return GeneratedWindow.fromWindow( Window(name="INFO_EN", title="English", message="Please select one of the options", options=[ Option(identifier="1", display="Basic Information", window="BASIC_INFO_EN"), Option(identifier="2", display="Skills", window="SKILLS_INFO_EN"), Option(identifier="3", display="Contact", window="CONTACT_INFO_EN"), Option(identifier="4", display="Academic Formation", window="Academic_INFO_EN"), Option(identifier="5", display="Change Language", window="INITIAL") ]), session_identifier=lottus_context.current_session.identifier )
def initial(lottus_context: LottusContext, command: str) -> GeneratedWindow: """ :param lottus_context: :param command: :return: """ if not lottus_context.current_window: return GeneratedWindow.fromWindow( Window(name="INITIAL", title="Ben Chambule's USSD - CV", message="Select language/Escolha idioma", options=[ Option(identifier="1", display="Portugues", window="INFO_PT"), Option(identifier="2", display="English", window="INFO_EN") ]), session_identifier=lottus_context.current_session.identifier ) else: return default_processor(lottus_context=lottus_context, command=command)
def info_pt(lottus_context: LottusContext, command: str) -> GeneratedWindow: """ :param lottus_context: :param command: :return: """ if lottus_context.current_window.name == "INFO_PT": return default_processor(lottus_context=lottus_context, command=command) else: return GeneratedWindow.fromWindow( Window(name="INFO_PT", title="Portugues", message="Por favor seleccione uma das opcoes", options=[ Option(identifier="1", display="Informacao basica", window="BASIC_INFO_PT"), Option(identifier="2", display="Habilidades", window="SKILLS_INFO_PT"), Option(identifier="3", display="Contacto", window="CONTACT_INFO_PT"), Option(identifier="4", display="Formacao academica", window="Academic_INFO_PT"), Option(identifier="5", display="Mudar idioma", window="INITIAL") ]), session_identifier=lottus_context.current_session.identifier )
def add_agent_visit(self, entry_timestamp, exit_timestamp): visit_window = Window(entry_timestamp, exit_timestamp) infected_window = get_infected_window(self.room_id, visit_window) self.infected_windows.get(infected_window).add_agent_visit_window( visit_window)
"_id": 0, "timestamp": 1 }))[0])['timestamp'] #timestamp in sanitized collection for a time after the window end -- using safe time to begin cleaning end = (list( sanitizedEventCollection.find( { "room_id": room_id, "status": 0, "timestamp": { "$gte": safe_cleaning_time_begin } }, { "_id": 0, "timestamp": 1 }))[0])['timestamp'] return Window(start, end) def getEventObject(event): return Event(event['user_id'], event['room_id'], event['status'], event['timestamp']) if __name__ == "__main__": print( get_infected_window( "B21970", Window(dt(2020, 1, 24, 9, 0, 0, 0), dt(2020, 1, 24, 19, 0, 0, 0))))