コード例 #1
0
    def open(self):
        self.websocket_ping_interval = 0
        self.websocket_ping_timeout = float("inf")
        self.app_state_control = ApplicationStateController(1)
        self.adaptation_loop = AdaptationLoop(self.app_state_control, [self])

        self.tobii_controller = TobiiController()
        self.tobii_controller.liveWebSocket.add(self)
        self.tobii_controller.waitForFindEyeTracker()
        print self.tobii_controller.eyetrackers
        self.fixation_component = FixationDetector(
            self.tobii_controller,
            self.adaptation_loop,
            liveWebSocket=self.tobii_controller.liveWebSocket)
        self.emdat_component = EMDATComponent(
            self.tobii_controller,
            self.adaptation_loop,
            callback_time=params.EMDAT_CALL_PERIOD)

        self.tobii_controller.activate(
            self.tobii_controller.eyetrackers.keys()[0])
        self.tobii_controller.startTracking()
        self.fixation_component.start()
        self.emdat_component.start()
        print "tracking started"
    def open(self):
        self.websocket_ping_interval = 0
        self.websocket_ping_timeout = float("inf")

        self.app_state_control = ApplicationStateController(4)
        self.adaptation_loop = AdaptationLoop(self.app_state_control)
        self.adaptation_loop.liveWebSocket.append(self)

        self.tobii_controller = TobiiController()
        self.tobii_controller.liveWebSocket.add(self)
        self.tobii_controller.waitForFindEyeTracker()
        print self.tobii_controller.eyetrackers
        self.fixation_component = FixationDetector(self.tobii_controller, self.adaptation_loop)
        self.emdat_component = EMDATComponent(self.tobii_controller, self.adaptation_loop, callback_time = params.EMDAT_CALL_PERIOD)
class EchoWebSocketHandler(tornado.websocket.WebSocketHandler):

    def open(self):
        self.websocket_ping_interval = 0
        self.websocket_ping_timeout = float("inf")

        self.app_state_control = ApplicationStateController(4)
        self.adaptation_loop = AdaptationLoop(self.app_state_control)
        self.adaptation_loop.liveWebSocket.append(self)

        self.tobii_controller = TobiiController()
        self.tobii_controller.liveWebSocket.add(self)
        self.tobii_controller.waitForFindEyeTracker()
        print self.tobii_controller.eyetrackers
        self.fixation_component = FixationDetector(self.tobii_controller, self.adaptation_loop)
        self.emdat_component = EMDATComponent(self.tobii_controller, self.adaptation_loop, callback_time = params.EMDAT_CALL_PERIOD)

    def on_message(self, message):
        if (message == "close"):
            print("destroying")
            #DummyController.receiveFixations = False
            self.emdat_component.execfile.close()
            self.fixation_component.stop()
            #self.emdat_component.stop()

            self.tobii_controller.stopTracking()
            self.tobii_controller.destroy()
            self.app_state_control.resetApplication()
            return
        elif (message == "next_task"):
            del self.fixation_component
            self.tobii_controller.stop()
            self.tobii_controller.flush()
            self.app_state_control.changeTask(2)
            self.fixation_component = FixationDetector(self.tobii_controller, self.app_state_control)
            #self.emdat_component = EMDATComponent(self.tobii_controller, self.app_state_control, liveWebSocket = self.tobii_controller.liveWebSocket, callback_time = 6000)
            self.tobii_controller.start()
            self.fixation_component.start()
            #self.emdat_component.start()
        else:

            self.tobii_controller.activate(self.tobii_controller.eyetrackers.keys()[0])
            self.tobii_controller.startTracking()
            self.fixation_component.start()
            self.emdat_component.start()
            print "tracking started"

    def on_close(self):
        print("WebSocket closed")
コード例 #4
0
    def open(self):

        #TODO: delete this handler
        #For testing connection between middle and front end

        #self.set_status(200)
        #self.set_header('Content-Type', 'text/event-stream')
        #self.set_header('Cache-Control', 'no-cache')
        #self.set_header('Connection', 'keep-alive')

        #self.write('\n')
        #self.flush()
        #self.flush()
        #self.flush()
        #self.write('data:' + 'hello hello \n\n')
        #self.flush()
        #self.app_state_control = ApplicationStateController(1)
        #self.adapt_loop = AdaptationLoop(self.app_state_control)
        #self.adapt_loop.liveWebSocket.append(self)
        #self.adapt_loop.test()

        self.app_state_control = ApplicationStateController(1)
        self.adapt_loop = AdaptationLoop(self.app_state_control)
        self.adapt_loop.liveWebSocket.append(self)
        self.adapt_loop.test()
        self.write_message('{"message":"hey"}')
コード例 #5
0
    def open(self):
        self.websocket_ping_interval = 0
        self.websocket_ping_timeout = float("inf")
        self.app_state_control = ApplicationStateController(1)
        self.adaptation_loop = AdaptationLoop(self.app_state_control)
        self.adaptation_loop.liveWebSocket.append(self)

        self.tobii_controller = TobiiController()
        self.tobii_controller.liveWebSocket.add(self)
        self.tobii_controller.waitForFindEyeTracker()
        self.initialize_detection_components()
        print self.tobii_controller.eyetrackers

        self.tobii_controller.activate(
            self.tobii_controller.eyetrackers.keys()[0])
        self.tobii_controller.startTracking()
        self.start_detection_components()
        print "tracking started"
    def __init__(self):
        #connects url with code

        self.tobii_controller = TobiiControllerNewSdk()
        self.tobii_controller.activate()
        self.app_state_control = ApplicationStateController(0)
        self.adaptation_loop = AdaptationLoop(self.app_state_control)

        self.fixation_component = FixationDetector(self.tobii_controller, self.adaptation_loop)
        self.emdat_component = EMDATComponent(self.tobii_controller, self.adaptation_loop, callback_time = params.EMDAT_CALL_PERIOD)
        self.ml_component = MLComponent(self.tobii_controller, self.adaptation_loop, callback_time = params.EMDAT_CALL_PERIOD, emdat_component = self.emdat_component)
        self.mouse_key_component = MouseKeyboardEventDetector(self.tobii_controller, self.adaptation_loop, self.emdat_component, params.USE_MOUSE, params.USE_KEYBOARD)
        websocket_dict = {TOBII_CONTROLLER: self.tobii_controller,
                         APPLICATION_STATE_CONTROLLER: self.app_state_control,
                         ADAPTATION_LOOP: self.adaptation_loop,
                         FIXATION_ALGORITHM: self.fixation_component,
                         EMDAT_COMPONENT: self.emdat_component,
                         ML_COMPONENT: self.ml_component,
                         MOUSE_KEY_COMPONENT: self.mouse_key_component}
        handlers = [
            (r"/", MainHandler),
            (r"/mmd", MMDHandler),
            (r"/questionnaire", QuestionnaireHandler),
            (r"/resume", ResumeHandler),
            (r"/userID", UserIDHandler),
            (r"/prestudy", PreStudyHandler), (r"/(Sample_bars.png)", tornado.web.StaticFileHandler, {'path': params.FRONT_END_STATIC_PATH + 'sample/'}),
                                             (r"/(Sample_bars_2.png)", tornado.web.StaticFileHandler, {'path': params.FRONT_END_STATIC_PATH + 'sample/'}),
            (r"/sample_MMD", SampleHandler), (r"/(ExampleMMD.png)", tornado.web.StaticFileHandler, {'path': params.FRONT_END_STATIC_PATH + 'sample/'}),
            (r"/sample_Q", SampleHandler2), (r"/(ExampleQ.png)", tornado.web.StaticFileHandler, {'path': params.FRONT_END_STATIC_PATH + 'sample/'}),
            (r"/calibration", CalibrationHandler), (r"/(blank_cross.jpg)", tornado.web.StaticFileHandler, {'path': params.FRONT_END_STATIC_PATH + 'sample/'}),
            (r"/tobii", TobiiHandler),
            (r"/ready", ReadyHandler),
            (r"/done", DoneHandler),
            (r"/final_question", FinalHandler), (r"/(post_question.png)", tornado.web.StaticFileHandler, {'path': params.FRONT_END_STATIC_PATH + 'sample/'}),
            (r"/done2", DoneHandler2),
            (r"/websocket", MMDWebSocket, dict(websocket_dict = websocket_dict))
        ]
        #connects to database
        self.conn = sqlite3.connect('database.db')
        #"global variable" to save current UserID of session
        UserID = -1;
        #global variable to track start and end times
        start_time = '';
        end_time = '';
        #where to look for the html files
        settings = dict(
            template_path=os.path.join(os.path.dirname(__file__), params.FRONT_END_TEMPLATE_PATH),
            static_path=os.path.join(os.path.dirname(__file__), params.FRONT_END_STATIC_PATH),
            debug=True,
        )
        #initializes web app
        tornado.web.Application.__init__(self, handlers, **settings)
    def __init__(self):
        # connects url with code
        self.tobii_controller = TobiiControllerNewSdk()
        self.tobii_controller.activate()
        self.app_state_control = ApplicationStateController(0)
        self.adaptation_loop = AdaptationLoop(self.app_state_control)

        self.fixation_component = FixationDetector(self.tobii_controller, self.adaptation_loop)
        self.emdat_component = EMDATComponent(self.tobii_controller, self.adaptation_loop, callback_time = params.EMDAT_CALL_PERIOD)
        self.ml_component = MLComponent(self.tobii_controller, self.adaptation_loop, callback_time = params.EMDAT_CALL_PERIOD, emdat_component = self.emdat_component)
        self.mouse_key_component = MouseKeyboardEventDetector(self.tobii_controller, self.adaptation_loop, self.emdat_component, params.USE_MOUSE, params.USE_KEYBOARD)
        websocket_dict = {TOBII_CONTROLLER: self.tobii_controller,
                          APPLICATION_STATE_CONTROLLER: self.app_state_control,
                          ADAPTATION_LOOP: self.adaptation_loop,
                          FIXATION_ALGORITHM: self.fixation_component,
                          EMDAT_COMPONENT: self.emdat_component,
                          ML_COMPONENT: self.ml_component,
                          MOUSE_KEY_COMPONENT: self.mouse_key_component}
        handlers = [
            (r"/", MainHandler),
            (r"/writePolygon", PolygonAjaxHandler),
            (r"/websocket", MMDWebSocket, dict(websocket_dict=websocket_dict))
        ]
        # connects to database
        self.conn = sqlite3.connect(params.USER_MODEL_STATE_PATH)
        # "global variable" to save current UserID of session
        UserID = -1;
        # global variable to track start and end times
        start_time = '';
        end_time = '';
        # where to look for the html files
        settings = dict(
            template_path=os.path.join(os.path.dirname(__file__), params.FRONT_END_TEMPLATE_PATH),
            static_path=os.path.join(os.path.dirname(__file__), params.FRONT_END_STATIC_PATH),
            debug=True,
        )
        # initializes web app
        tornado.web.Application.__init__(self, handlers, **settings)
コード例 #8
0
class WebSocketHandler(tornado.websocket.WebSocketHandler):
    def open(self):
        self.websocket_ping_interval = 0
        self.websocket_ping_timeout = float("inf")
        self.app_state_control = ApplicationStateController(1)
        self.adaptation_loop = AdaptationLoop(self.app_state_control)
        self.adaptation_loop.liveWebSocket.append(self)

        self.tobii_controller = TobiiController()
        self.tobii_controller.liveWebSocket.add(self)
        self.tobii_controller.waitForFindEyeTracker()
        self.initialize_detection_components()
        print self.tobii_controller.eyetrackers

        self.tobii_controller.activate(
            self.tobii_controller.eyetrackers.keys()[0])
        self.tobii_controller.startTracking()
        self.start_detection_components()
        print "tracking started"

    def on_message(self, message):
        print("RECEIVED MESSAGE: " + message)
        if (message == "close"):
            print("destroying")
            self.stop_detection_components()
            self.tobii_controller.stopTracking()
            self.tobii_controller.destroy()
            self.app_state_control.resetApplication()
            return
        elif (message.find("next_task") != -1):
            result = message.split(":")
            next_task = int(result[1])

            self.stop_detection_components()
            """ ??? """
            # TODO: Decide what to do with emdat when task finishes!
            self.tobii_controller.stopTracking()
            self.tobii_controller.flush()
            self.app_state_control.changeTask(next_task)
            self.initialize_detection_components()
            self.start_detection_components()
            self.tobii_controller.startTracking()
        else:
            self.stop_detection_components()
            self.tobii_controller.stopTracking()
            self.tobii_controller.destroy()
            self.app_state_control.resetApplication()
            """ wtf """
            return
            print("unexpected message")

    def on_close(self):
        self.stop_detection_components()
        self.tobii_controller.stopTracking()
        self.tobii_controller.destroy()
        self.app_state_control.resetApplication()
        print("WebSocket closed")

    def initialize_detection_components(self):
        if (params.USE_FIXATION_ALGORITHM):
            self.fixation_component = FixationDetector(self.tobii_controller,
                                                       self.adaptation_loop)
        if (params.USE_EMDAT):
            self.emdat_component = EMDATComponent(
                self.tobii_controller,
                self.adaptation_loop,
                callback_time=params.EMDAT_CALL_PERIOD)
            if (params.USE_ML):
                self.ml_component = MLComponent(
                    self.tobii_controller,
                    self.adaptation_loop,
                    callback_time=params.EMDAT_CALL_PERIOD,
                    emdat_component=self.emdat_component)

    def start_detection_components(self):
        if (params.USE_FIXATION_ALGORITHM):
            self.fixation_component.start()
        if (params.USE_EMDAT):
            self.emdat_component.start()
            if (params.USE_ML):
                self.ml_component.start()

    def stop_detection_components(self):
        if (params.USE_FIXATION_ALGORITHM):
            self.fixation_component.stop()
            del self.fixation_component
        if (params.USE_EMDAT):
            #self.emdat_component.stop()
            del self.emdat_component
            if (params.USE_ML):
                #self.ml_component.stop()
                del self.ml_component