def launch(self): self.service = MainService() self.service.run() self.is_running = True t = Thread(target=self.poll) t.setDaemon(True) t.start() self.run_button.pack_forget() self.stop_button.pack()
def gen(): service = MainService(fixed_action_connector, repetitive_action_connector) service.run() while True: lst = service.get_action_from_queue() for i in lst: yield str( dt.timedelta(seconds=int(i.time))) + ' : ' + i.name + '\n' time.sleep(1)
def run(queue: Queue, queue_from_client: Queue): service = MainService() service.run() while True: if not queue_from_client.empty() and queue_from_client.get() == 'STOP': break lst = service.get_action_from_queue() for i in lst: queue.put(i) time.sleep(1) return jsonify({'response': 'ok'})
def __init__(self, parent): Frame.__init__(self, parent) self.service = MainService() lst = self.service.fixed_action_service.get_action_list() self.fixed_action_service_view = ActionListView( self, lst, ActionType.FIXED_ACTION) lst = self.service.repetitive_action_service.get_action_list() self.repetitive_action_service_view = ActionListView( self, lst, ActionType.REPETITIVE_ACTION) self.fixed_action_service_view.grid(column=0, row=0) self.repetitive_action_service_view.grid(column=2, row=0)
class RunView(Frame): def __init__(self, parent): Frame.__init__(self, parent) self.is_running = True self.title = Label(self, text='RUN') self.middle_frame = Frame(self) self.run_button = Button(self, text='Launch', command=self.launch) self.stop_button = Button(self, text='Stop', command=self.stop) self.title.pack() self.middle_frame.pack() self.run_button.pack() self.stop_button.pack() self.stop_button.pack_forget() def launch(self): self.service = MainService() self.service.run() self.is_running = True t = Thread(target=self.poll) t.setDaemon(True) t.start() self.run_button.pack_forget() self.stop_button.pack() def poll(self): StatusBar().set_label('Polling has begun') self.temp_frame = Frame(self.middle_frame) self.temp_frame.pack() while True: lst = self.service.get_action_from_queue() for action in lst: StatusBar().set_label(f'Add {action} to queue') view = ActionView(self.temp_frame, action) view.forget_delete_button() view.pack() Speaker().add_to_queue(action.name) Speaker().run_and_wait() time.sleep(1) if not self.is_running: break def stop(self): StatusBar().set_label('Stop') self.is_running = False self.run_button.pack() self.stop_button.pack_forget() self.temp_frame.destroy()
class ManageView(Frame): def __init__(self, parent): Frame.__init__(self, parent) self.service = MainService() lst = self.service.fixed_action_service.get_action_list() self.fixed_action_service_view = ActionListView( self, lst, ActionType.FIXED_ACTION) lst = self.service.repetitive_action_service.get_action_list() self.repetitive_action_service_view = ActionListView( self, lst, ActionType.REPETITIVE_ACTION) self.fixed_action_service_view.grid(column=0, row=0) self.repetitive_action_service_view.grid(column=2, row=0) def delete_entry(self, action: Action, action_type: ActionType): self.service.delete_action(action, action_type) def add_entry(self, action: Action, action_type: ActionType): self.service.add_action(action, action_type)
def test_main_service_db_connection(self): with transaction_context() as session: entry = Action(time=1, name="test1", action_type=ActionType.FIXED_ACTION.value) session.add(entry) entry = Action(time=2, name="test2", action_type=ActionType.FIXED_ACTION.value) session.add(entry) entry = Action(time=0, name="test3", action_type=ActionType.REPETITIVE_ACTION.value) session.add(entry) service = MainService() service.run() lst = service.get_action_from_queue() self.assertEqual(len(lst), 0) time.sleep(3) lst = service.get_action_from_queue() self.assertEqual(len(lst), 3) with transaction_context() as session: lst = session.query(Action).all() for i in lst: print(i) session.delete(i)
def test_main_service(self): fixed_connector = TestActionConnector() repetitive_connector = TestRepetitiveActionConnector() service = MainService(fixed_connector, repetitive_connector) service.run() lst = service.get_action_from_queue() self.assertEqual(len(lst), 0) time.sleep(3) lst = service.get_action_from_queue() print(lst) self.assertEqual(len(lst), 5)
import pandas as pd from app.domain.model.action import Action from app.domain.service.main_service import MainService from app.domain.service.action_type import ActionType if __name__ == '__main__': lst_fixed = [ Action(time=0, name="Let's go bro !"), Action(time=2, name="Make drone"), Action(time=4, name="Scout for expand") ] lst_rep = [Action(time=0, name="creep"), Action(time=0, name="inject")] service = MainService() for action in lst_fixed: service.add_action(action, ActionType.FIXED_ACTION) for action in lst_rep: service.add_action(action, ActionType.REPETITIVE_ACTION)