def test_event(self): open = SignalEvent(SignalAction.OPEN, HLHBTrendStrategy.name, HLHBTrendStrategy.version, HLHBTrendStrategy.magic_number, instrument='EURUSD', side=OrderSide.BUY, order_type=OrderType.MARKET, stop_loss=30, take_profit=50, trailing_stop=None, percent=None) close = SignalEvent(SignalAction.CLOSE, HLHBTrendStrategy.name, HLHBTrendStrategy.version, HLHBTrendStrategy.magic_number, instrument='EURUSD', side=OrderSide.BUY, percent=0.5) data = json.dumps(open.to_dict()) data2 = json.loads(data) open2 = Event.from_dict(data2) self.assertEqual(open.type, open2.type) for k in open.__dict__.keys(): self.assertEqual(open.__dict__[k], open2.__dict__[k]) data = json.dumps(close.to_dict()) data2 = json.loads(data) close2 = Event.from_dict(data2) self.assertEqual(close.type, close2.type) for k in close.__dict__.keys(): self.assertEqual(close.__dict__[k], close2.__dict__[k])
def _on_text(self, e: Event, entity: str, who: str, text: str) -> None: words = text.split() if len(words): Event.trigger(Event(words[0], self, entity=entity, args=words[1:])) else: text = f'你要作什麼?' Channel.toRole(entity, Message.TEXT, text)
def _on_linefeed_id(self, e: Event) -> None: Event.trigger( Event(Event.CLICK, self, x=self.left + self._field_passwd.left, y=self.top + self._field_passwd.top)) return self._field_id.value
def _read(self, entity: str, socket: socket) -> None: for msg in InStream.instance(entity).read(socket): Event.trigger( Event( msg.type, self._servant, entity=entity, **msg.kwargs ) )
class EventQuery(object): def __init__(self, router): self._event = Event(router) def get(self, key): return self._event.get(key) def put(self, key, value): return self._event.put(key, value)
def _on_read(self, socket: socket, entity: str) -> None: msg_buffer = InStream.instance(entity).read(socket) for msg in msg_buffer: Event.trigger( Event(msg.type, Servant.instance(), entity=entity, **msg.kwargs))
def _on_click(self, e: Event, x: int, y: int) -> bool: for element in self.elements: if element.contains(x - self.x, y - self.y): Event.trigger(Event(Event.CLICK, element, x=x, y=y)) if element.focusable: self._focus = element break return False
def _loop(self) -> None: while True: self._net_io.check() while Event.ready(): e = Event.next() if e.target: e.target.on_event(e) else: self.on_event(e)
def _on_click(self, e: Event, x: int, y: int) -> bool: for widget in self.components: if widget.contains(x - self.x, y - self.y): Event.trigger(Event(Event.CLICK, widget, x=x, y=y)) if widget.focusable: self._focus = widget break return False
def _on_sign_in( self, e: Event, entity: str, user_id: str = '', passwd: str = '' ) -> None: role = Stats.text('entity', user_id) Stats.update_text('binding', entity, role) room = Stats.text('at_room', role) Stats.list_append('guest', room, Link(entity, role)) text = f'歡迎來到 MUTE: Multi-User Texting Environment' Channel.to_role(entity, Message.SYSTEM, text) Event.trigger(Event(Event.CMD_LOOK, self._servant, entity=entity))
def _scroll_v(self, e: Event, y: int) -> None: if y == self.top: Event.trigger(Event(Event.SCROLL_DOWN, e.target)) elif y == self.bottom: Event.trigger(Event(Event.SCROLL_UP, e.target)) else: r = (y - self.top - 1) / (self.height - 2) Event.trigger(Event(Event.SCROLL_V, e.target, r=r))
def _scroll_h(self, e: Event, x: int) -> None: if x == self.left: Event.trigger(Event(Event.SCROLL_LEFT, e.target)) elif y == self.right: Event.trigger(Event(Event.SCROLL_RIGHT, e.target)) else: Event.trigger( Event(Event.SCROLL_H, e.target, r=(x - self.left) / self.width))
def _loop(self) -> None: while True: self._on_net_io() if Event.events(): events = Event.events().copy() Event.empty() for e in events: if e.target: e.target.on_event(e) else: self.on_event(e)
def create_new_event(event_creation_info: json): """ This function creates new event and saves it in the events dictionary :param event_creation_info: a json with info about the new event to create :return: pin code of the new event, None if error occurred """ try: new_event = Event(event_creation_info) pin_code = new_event.get_pin_code() AppEngine.events_dict[pin_code] = new_event return pin_code except KeyError: raise
def _on_sign_in(self, e: Event, entity: str, user_id: str = '', passwd: str = '') -> None: role = Role.instance(user_id, name=user_id) Name.instance(entity, name=role.name) Room.instance(role.room).enter(entity) text = f'歡迎來到 MUTE: Multi-User Texting Environment' Channel.toRole(entity, Message.SYSTEM, text) Event.trigger(Event(Event.CMD_LOOK, self._servant, entity=entity))
def _on_new_connection(self, socket: socket) -> None: connection, address = socket.accept() # Should be ready to read print(f'Connected by: {address}') connection.setblocking(False) mask = selectors.EVENT_READ | selectors.EVENT_WRITE entity = Entity.eid() self._multiplexer.register(connection, mask, entity) Event.trigger(Event(Event.RECEPTION, Servant.instance(), entity=entity))
def __init__(self, x=0, y=0, width=80): super().__init__(x, y, width) self._text = '' self._place_holder = ' ' * width self._max_len = width self._color = Color.INPUT_FIELD self.on(Event.FOCUS_IN, lambda _: Event.trigger(Event(Event.CURSOR_ON))) self.on(Event.FOCUS_OUT, lambda _: Event.trigger(Event(Event.CURSOR_OFF))) self.on(Event.KEY_BACKSPACE, self._on_key_backspace) self.on(Event.KEY_PRESSED, self._on_key_pressed)
def get_zero_seven_events(sportName, season_year_start, season_year_end): conn = connect() season = Season(conn=conn, sportName=sportName, year_start=season_year_start, year_end=season_year_end) cursor = conn.cursor(buffered=True) query = ( "SELECT * FROM `Event` WHERE `seasonId` = '%s' AND `dateUTC` BETWEEN %s AND %s ORDER BY dateUTC ASC" ) cursor.execute(query, (season.seasonId, datetime.datetime.utcnow(), datetime.datetime.utcnow() + timedelta(days=7))) data = cursor.fetchall() events = [] if len(data) > 0: for i in data: events.append( Event(conn=conn, stubhubId=i[0], dateUTC=i[1], sportName=sportName, seasonName=season.name, teamId=i[2])) return events
def __getAllEvents(self): docListEvents = self.__database.getAllEvents() eventList = [] for document in docListEvents: eventList.append(Event.convertDocument(document)) return eventList
def paint(self): self._window.border() self._window.refresh() self._window_manager.on_event(Event(Event.PAINT)) self._dirty = False
def _on_click(self, e: Event, x: int, y: int) -> None: Event.trigger(Event(Event.FOCUS_OUT, self.focus)) if not self._modal: for uid in reversed(self._z_stack): if self._windows[uid].contains(x, y): self.raise_to_top(uid) break Event.trigger(Event(Event.CLICK, self.focus, x=x, y=y)) Event.trigger(Event(Event.FOCUS_IN, self.focus))
def _on_cmd_move( self, e: Event, entity: str = '', args: List[str] = [] ) -> None: role = Role.instance(entity) exit = Exit.instance(role.room) room = exit.to(e.type[0]) if None != room: Room.instance(role.room).leave(entity) Room.instance(room).enter(entity) role.enter(room) Event.trigger(Event(Event.CMD_LOOK, self._servant, entity=entity)) else: Channel.to_role(entity, Message.TEXT, f' 這裡沒有出口')
def _on_cmd_move( self, e: Event, entity: str = '', args: Sequence[str] = [] ) -> None: role = Stats.text('binding', entity) at = Stats.text('at_room', role) exit = Stats.text('exit', at) try: room = exit[e.type[0]] Stats.list_remove('guest', at, Link(entity, role)) Stats.update_text('at_room', role, room) Stats.list_append('guest', room, Link(entity, role)) Event.trigger(Event(Event.CMD_LOOK, self._servant, entity=entity)) except KeyError: Channel.to_role(entity, Message.TEXT, f' 這裡沒有出口')
def handle_event(self, event: Event): def handle_key(source_id, values): if values == ("SPACE", ): self._player.play_pause() def reset_player(source_id, values): self._player.stop() def restart_player(source_id, values): self._view.reset() self._player.stop() handle = { "KEY": handle_key, "MODEL_UPDATE": reset_player, "DATA_UPDATE": restart_player, }.get(event.type(), lambda *_: None) handle(event.id(), event.values())
def handle_event(self, event: Event): def recreate_view(*_): self._view.recreate() def select_data(source_id, values): if self._selected_panel: self._selected_panel.model().unselect() panel = self._view.panel_from_id(source_id) if not panel: return self._selected_panel = panel text = panel.model() if not text: return text.select(*values) self._view.refresh() def edit_data(source_id, values): if values == ("SPACE", ) or values == ("TAB", ): return panel = self._view.panel_from_id(source_id) if not panel or panel != self._selected_panel: return text = panel.model() text.input_ch(*values) data = text.as_data() Song().edit(data) self._view.refresh() handle = { "DATA_UPDATE": recreate_view, "CLICK": select_data, "KEY": edit_data, }.get(event.type(), lambda *_: None) handle(event.id(), event.values())
def _loop(self) -> None: while True: if self._dirty: self.paint() self._check_input() while Event.ready(): e = Event.next() if e.type == Event.EXIT: exit() elif e.target: e.target.on_event(e) else: self.on_event(e) self._dirty = True OutStream.instance('').write(self._socket)
def _loop(self) -> None: self.paint() while True: self._check_input() if Event.events(): events = Event.events().copy() Event.empty() for e in events: if e.type == Event.EXIT: exit() elif e.target: e.target.on_event(e) else: self.on_event(e) self.paint() OutStream.instance('').write(self._socket)
def createEvent( self, analyst, name=None, description=None, type: EventType = EventType.VERIFICATION_OF_FIXES, version=None, date=None, organizationName=None, securityClassificationTitleGuide=None, eventClassification: EventClassification = EventClassification. TOP_SECRET, classifiedBy=None, derivedFrom=None, declassificationDate=None, customerName=None, archiveStatus=None, eventTeam=None): event = Event( name=name, description=description, type=type, version=version, date=date, organizationName=organizationName, securityClassificationTitleGuide=securityClassificationTitleGuide, eventClassification=eventClassification, classifiedBy=classifiedBy, derivedFrom=derivedFrom, declassificationDate=declassificationDate, customerName=customerName, archiveStatus=archiveStatus, eventTeam=eventTeam) event.setId(self.updateEvent(analyst=analyst, event=event)) self.__event = event return
def insert_all_events(conn, sportName, seasonName, fileName): with open('game_schedules/%s/%s.csv' % (sportName, fileName), 'rU') as f: reader = csv.reader(f) reader.next() for row in reader: event = Event(conn=conn, stubhubId=row[3], sportName=sportName, seasonName=seasonName, teamId=row[0], teamCity=row[1], teamName=row[2], dateUTC=dparser.parse(row[4]), dateLocal=dparser.parse(row[5])) try: event.insert_event(conn) except: print("Error with inserting event %s - could be duplicate" % row[3])
def receive_ball(self, received_ball): logger.debug('I received a ball.', received_ball=received_ball) ball = [] for event in received_ball: logger.debug('Looping events.', current_event=event) ball.append(Event.from_dict(event)) for event in ball: if event.ttl < self.ttl: if event in self.next_ball: for e in self.next_ball: if e.event_id == event.event_id and e.ttl < event.ttl: e.ttl = event.ttl else: self.next_ball.add(event) self.stability_oracle.update_clock(event.ts)
def get_fifteen_up_to_collect(sportName, season_year_start, season_year_end, hour, minute): conn = connect() season = Season(conn=conn, sportName=sportName, year_start=season_year_start, year_end=season_year_end) cursor = conn.cursor(buffered=True) # First get team for this time slot query = ( "SELECT teamId FROM `Cron_Schedule` WHERE `seasonId`='%s' AND `time_hour` = '%s' AND `time_minute`= '%s'" ) cursor.execute(query, (season.seasonId, hour, minute)) data = cursor.fetchall() # If there is a team for this time, get their events that are 15 + days away events = [] if len(data) > 0: teamId = data[0][0] query = ( "SELECT * FROM `Event` WHERE teamId = '%s' AND `dateUTC` BETWEEN %s AND %s ORDER BY dateUTC ASC" ) cursor.execute( query, (teamId, datetime.datetime.utcnow() + timedelta(days=15), datetime.datetime.utcnow() + timedelta(days=250))) data = cursor.fetchall() for i in data: events.append( Event(conn=conn, stubhubId=i[0], dateUTC=i[1], sportName=sportName, seasonName=season.name, teamId=teamId)) return events
def __init__(self, router): self._event = Event(router)