Example #1
0
 def check_voice_server(self):
     """Check for messages from the voice server."""
     if self.voice_pipe.poll():
         msg = self.voice_pipe.recv()
         if msg["type"] == "CRITICAL":
             try:
                 raise VoiceServerError(msg["data"]["traceback"])
             except:
                 self.logger.critical("VoiceServer failed", exc_info=True)
                 raise
         elif msg["type"] == "TIMESTAMP":
             create_logger("voicetimes").debug(
                 json.dumps({
                     "voice_time": msg["data"]["timestamp"],
                     "main_time": time.time() * 1000,
                     "pyepl_time": timing.now()
                 }))
         elif msg["type"] == "VOCALIZATION":
             start = msg["data"]["speaking"]
             log_msg = {
                 "event":
                 "VOCALIZATION_START" if start else "VOCALIZATION_END",
                 "timestamp": msg["data"]["timestamp"]
             }
             self.event_log.info(json.dumps(log_msg))
             self.socket.enqueue_message(
                 self.build_message("STATE", "VOCALIZATION", start))
         else:
             self.logger.error("Received malformed message: %s", msg)
Example #2
0
    def state_context(self, state, **kwargs):
        """Context manager to log and send state messages. Usage example::

            with self.state_context("COUNTDOWN"):
                self.do_thing()

        :param str state: Name of state.
        :param dict kwargs: Additional keyword arguments to append to the STATE
            message sent to the host PC.

        """
        self.log_event(state + "_START", **kwargs)
        self.controller.send(
            StateMessage(state, True, timestamp=timing.now(), **kwargs))
        yield
        self.controller.send(
            StateMessage(state, False, timestamp=timing.now(), **kwargs))
        self.log_event(state + "_END", **kwargs)
Example #3
0
    def _send_event(self, type, *args, **kwargs):
        """
        Sends an arbitrary event
        :param args: Inputs to RAMControl.sendEvent()
        """
        if 'timestamp' not in kwargs:
            kwargs['timestamp'] = timing.now()

        if self.config.control_pc:
            ram_control.send(ram_control.build_message(type, *args, **kwargs))
Example #4
0
    def log_event(self, event, **kwargs):
        """Log an event. Logs are currently stored both by PyEPL and in a more
        pandas-friendly JSONized format. The JSON format has one entry per line
        and can be read into a pandas DataFrame like::

            with open("sessionlog.log") as log:
                entries = [json.loads(entry) for entry in log.readlines()]
                df = pd.DataFrame.from_records(entries, index="index")

        :param str event: Event description.
        :param dict kwargs: Additional details to log with event.

        """
        self.log.logMessage(event + " " + json.dumps(kwargs), self.clock)
        kwargs.update({"event": event, "timestamp": timing.now()})
        msg = json.dumps(kwargs)
        self.event_logger.info(msg)