def __init__(self): db_path = os.path.join(get_data_path(), 'faces_detect.sqlite') # Introduce a bug on purpose in newer version, removing the database content # On older ubuntu core version, SNAP_VERSION is the sideloaded one, so we don't rely on that for now #if os.getenv("SNAP_VERSION", "0.1") != "0.1": # num_faces = -10 file_path = os.path.join(os.getenv("SNAP_APP_PATH"), "meta", "package.yaml") with suppress(OSError): with open(file_path, 'rt') as f: if yaml.load(f.read())["version"] != 0.1: os.remove(db_path) self._conn = sqlite3.connect(db_path) c = self._conn.cursor() with suppress(sqlite3.OperationalError): c.execute( "CREATE TABLE FacesDetect(Timestamp DATETIME, Number INTEGER);" ) self._conn.commit() c.execute("SELECT * FROM FacesDetect ORDER BY Timestamp") self.face_detect_data = c.fetchall() logger.debug("Found {}".format(self.face_detect_data)) WebClientsCommands.sendFacesDetectAll(self.face_detect_data)
def enabled(self, value): self._enabled = value if self._enabled: logger.info("Enabling speech recognition feature") else: logger.info("Disabling speech recognition feature") WebClientsCommands.sendSpeechRecognitionStateAll()
def end_calibration(self): """End calibration phase and turn on stabilizer again""" logger.info("Calibration done") self.reset_default_color() self.sphero.set_back_led(0) self.sphero.set_heading(0) self.in_calibration = False WebClientsCommands.sendCalibrationStateAll()
def _start_calibration_sync(self): """Sync version of start calibration""" logger.info("Calibration starting") self.in_calibration = True self.sphero.set_back_led(255) self.sphero.set_rgb(0, 0, 0) self.sphero.roll(0, 0) self.sphero.set_heading(0) WebClientsCommands.sendCalibrationStateAll()
def add_one_facedetect_entry(self, timestamp, count): """Add one face detect datapoint at timestamp""" logger.info("Add new data point: {} at {}".format(count, datetime.datetime.utcfromtimestamp(timestamp).isoformat())) c = self._conn.cursor() c.execute("INSERT INTO FacesDetect VALUES({}, {})".format(timestamp, count)) self._conn.commit() new_data = (timestamp, count) self.face_detect_data.append(new_data) WebClientsCommands.sendNewFacesEntryAll(self.face_detect_data, new_data)
def enabled(self, value): self._enabled = value if self._enabled: logger.info("Enabling face detection feature") self._source_id = GLib.timeout_add_seconds(self.FACE_DETECTION_INTERNAL, self.detect_face) else: logger.info("Disabling face detection feature") if self._source_id: GLib.source_remove(self._source_id) self._source_id = None self._last_detected_face = time() WebClientsCommands.sendFaceDetectionStateAll()
def add_one_facedetect_entry(self, timestamp, count): """Add one face detect datapoint at timestamp""" logger.info("Add new data point: {} at {}".format( count, datetime.datetime.utcfromtimestamp(timestamp).isoformat())) c = self._conn.cursor() c.execute("INSERT INTO FacesDetect VALUES({}, {})".format( timestamp, count)) self._conn.commit() new_data = (timestamp, count) self.face_detect_data.append(new_data) WebClientsCommands.sendNewFacesEntryAll(self.face_detect_data, new_data)
def __init__(self): db_path = os.path.join(get_data_path(), 'faces_detect.sqlite') # Introduce a bug on purpose in newer version, removing the database content # On older ubuntu core version, SNAP_VERSION is the sideloaded one, so we don't rely on that for now #if os.getenv("SNAP_VERSION", "0.1") != "0.1": # num_faces = -10 file_path = os.path.join(os.getenv("SNAP"), "meta", "snap.yaml") with suppress(OSError): with open(file_path, 'rt') as f: if yaml.load(f.read())["version"] != 0.1: os.remove(db_path) self._conn = sqlite3.connect(db_path) c = self._conn.cursor() with suppress(sqlite3.OperationalError): c.execute("CREATE TABLE FacesDetect(Timestamp DATETIME, Number INTEGER);") self._conn.commit() c.execute("SELECT * FROM FacesDetect ORDER BY Timestamp") self.face_detect_data = c.fetchall() logger.debug("Found {}".format(self.face_detect_data)) WebClientsCommands.sendFacesDetectAll(self.face_detect_data)
def current_room(self, value): self._current_room = value WebClientsCommands.sendCurrentRoomAll()