def _process_next_uuid(self): next_uuid = self._work_queue_db.get_next_uuid() if next_uuid is None: LOGGER.info('No UUID yet..') return LOGGER.info('Processing UUID: {}'.format(next_uuid)) raw_accelerometer_data = self._get_raw_accelerometer_data_by_uuid( next_uuid) raw_gyroscope_data = self._get_raw_gyroscope_data_by_uuid(next_uuid) raw_barometer_data = self._get_raw_barometer_data_by_uuid(next_uuid) full_raw_data = { **raw_accelerometer_data, **raw_gyroscope_data, **raw_barometer_data } current_datetime = str( datetime.fromtimestamp( self._get_first_sp_timestamp(raw_accelerometer_data) / 1e3)) predicted_activity = self._get_activity_prediction(full_raw_data) self._store_activity_history(current_datetime, next_uuid, predicted_activity) self._notify_web_client(current_datetime, next_uuid, predicted_activity)
def kill_activity_recognizer_worker(signum, handler): activity_recognizer_worker.stop() worker_thread.join() io_loop = ioloop.IOLoop.instance() io_loop.stop() LOGGER.info('Shutting down server!')
def post(self): f = json_decode(self.request.body) LOGGER.info('SMARTWATCH MONITORING DATA RECEIVED!') real_time_monitoring_service = self.settings[ 'real_time_monitoring_service'] real_time_monitoring_service.insert_sw_raw_data_to_db(f) self.write(json_encode({'result': True}))
def post(self): d = json_decode(self.request.body) if d['start']: LOGGER.info('Smartwatch recording start!') SmartwatchWebsocketHandler.broadcast('start_recording {}'.format(d['activityType'])) else: LOGGER.info('Smartwatch recording stop!') SmartwatchWebsocketHandler.broadcast('stop_recording') self.write(json_encode({'result': True}))
def post(self): d = json_decode(self.request.body) if d['start']: LOGGER.info('Smartwatch monitoring start!') SmartwatchWebsocketHandler.broadcast('start_monitoring') else: LOGGER.info('Smartwatch monitoring stop!') SmartwatchWebsocketHandler.broadcast('stop_monitoring') self.write(json_encode({'result': True}))
def __init__(self): LOGGER.info('Connecting to MongoDB...') try: self._client = MongoClient(CONFIG.MONGODB_URI) self._db = self._client[CONFIG.DB_NAME] LOGGER.info('Connected to MongoDB!') except Exception as e: LOGGER.error('Connection to MongoDB failed!') LOGGER.error(e) LOGGER.error('\n\n')
def post(self): f = json_decode(self.request.body) uuid = f['uuid'] LOGGER.info('Smartphone: {}'.format(uuid)) real_time_monitoring_service = self.settings[ 'real_time_monitoring_service'] real_time_monitoring_service.insert_sp_raw_data_to_db(f) SmartwatchWebsocketHandler.broadcast( 'send_data_monitoring {}'.format(uuid)) self.write(json_encode({'result': True}))
def start(self): LOGGER.info('Starting activity recognizer worker..') while self._working: try: self._process_next_uuid() time.sleep(1) except FileExistsError as e: print(e) print('Exception during processing the next UUID!') except ValueError: print('ValueError in Worker!')
def post(self): f = json_decode(self.request.body) activity_type = f['activityType'] sensory_data = f['sensoryData'] file_id = str(f['fileId']) LOGGER.info('Smartphone: {}'.format(file_id)) sensory_data_service = self.settings['sensory_data_service'] sensory_data_service.handle_smartphone_sensory_data( activity_type, sensory_data, file_id) SmartwatchWebsocketHandler.broadcast( 'send_data_recording {}'.format(file_id)) self.write(json_encode({'result': True}))
def broadcast(cls, message): LOGGER.info("Writing message to clients: {}".format(message)) for c in cls.clients: c.write_message(message)
def on_close(self): LOGGER.info("WebSocket for Clients closed!") ClientWebsocketHandler.clients.remove(self)
def on_message(self, message): LOGGER.info(message)
def open(self): LOGGER.info("WebSocket for Clients opened!") ClientWebsocketHandler.clients.append(self)
import tornado.ioloop as ioloop import tornado.web as web import config as CONFIG from util.logger import web_logger as LOGGER from handler.test_handler import TestHandler if __name__ == '__main__': app = web.Application([(r"/test", TestHandler)], debug=True) # Start server LOGGER.info("Starting server at port {}...".format( CONFIG.SERVER_PORT_NUMBER)) app.listen(CONFIG.SERVER_PORT_NUMBER) ioloop.IOLoop.current().start()
import tornado.ioloop as ioloop import tornado.web as web import config as CONFIG from webapp.handler.test_handler import TestHandler from webapp.handler.ac_handler import AcHandler from webapp.handler.status_handler import StatusHandler from util.logger import web_logger as LOGGER from servo.ac_servo import AcServo if __name__ == '__main__': objects = { 'ac_servo': AcServo(CONFIG.SERVO_PIN, CONFIG.SERVO_DELAY) } # Initial state objects['ac_servo'].off() # Tornado app setup app = web.Application([ (r"/test", TestHandler), (r"/ac", AcHandler), (r"/status", StatusHandler) ], debug=True, **objects) LOGGER.info('Starting server at port {}...'.format(CONFIG.SERVER_PORT)) app.listen(CONFIG.SERVER_PORT, address='0.0.0.0') ioloop.IOLoop.current().start()
def open(self): LOGGER.info("WebSocket for Smartwatch opened!") SmartwatchWebsocketHandler.clients.append(self)
def stop(self): LOGGER.info('Stopping activity recognizer worker..') self._working = False LOGGER.info('Activity recognizer worker stopped!')
def on_close(self): LOGGER.info("WebSocket for Smartwatch closed!") SmartwatchWebsocketHandler.clients.remove(self)