<commit_before>#!/usr/bin/env python3

from Sensor import SenseController
from KeyDispatcher import KeyDispatcher
from Display import Display
from DataLogger import SQLiteLogger
import time


DEVICE = "PiSense"
DELAY = 0.25


class Handler:
    def __init__(self, display, logger, sensor):
        self.display = display
        self.logger = logger
        self.sensor = sensor
        self.recording = False
        self.logger.log(DEVICE, "running", 1)

    def read(self):
        values = {}

        if self.recording:
            for reading in self.sensor.get_data():
                values[reading[1]] = reading[2]
                self.logger.log(DEVICE, reading[1], reading[2], reading[0])
            display.show_properties(values, self.sensor.get_properties())
        else:
            values["recording"] = False
            display.show_properties(values)

        return True

    def record(self):
        self.recording = not self.recording

        if self.recording:
            self.logger.log(DEVICE, "recording", 1)
        else:
            self.logger.log(DEVICE, "recording", 0)

        return True

    def quit(self):
        self.logger.log(DEVICE, "running", 0)

        return False


with SenseController() as sensor, KeyDispatcher() as dispatcher, SQLiteLogger() as logger:
    # setup display
    display = Display("PiSense", "[r]ecord [q]uit")

    # setup key handlers
    handler = Handler(display, logger, sensor)

    dispatcher.add("r", handler, "record")
    dispatcher.add("q", handler, "quit")

    # start processing key presses
    while True:
        if dispatcher.can_process_key():
            if not dispatcher.process_key():
                break
        else:
            handler.read()
            time.sleep(DELAY)<commit_msg>Use DEVICE for screen title<commit_after>#!/usr/bin/env python3

from Sensor import SenseController
from KeyDispatcher import KeyDispatcher
from Display import Display
from DataLogger import SQLiteLogger
import time


DEVICE = "PiSense"
DELAY = 0.25


class Handler:
    def __init__(self, display, logger, sensor):
        self.display = display
        self.logger = logger
        self.sensor = sensor
        self.recording = False
        self.logger.log(DEVICE, "running", 1)

    def read(self):
        values = {}

        if self.recording:
            for reading in self.sensor.get_data():
                values[reading[1]] = reading[2]
                self.logger.log(DEVICE, reading[1], reading[2], reading[0])
            display.show_properties(values, self.sensor.get_properties())
        else:
            values["recording"] = False
            display.show_properties(values)

        return True

    def record(self):
        self.recording = not self.recording

        if self.recording:
            self.logger.log(DEVICE, "recording", 1)
        else:
            self.logger.log(DEVICE, "recording", 0)

        return True

    def quit(self):
        self.logger.log(DEVICE, "running", 0)

        return False


with SenseController() as sensor, KeyDispatcher() as dispatcher, SQLiteLogger() as logger:
    # setup display
    display = Display(DEVICE, "[r]ecord [q]uit")

    # setup key handlers
    handler = Handler(display, logger, sensor)

    dispatcher.add("r", handler, "record")
    dispatcher.add("q", handler, "quit")

    # start processing key presses
    while True:
        if dispatcher.can_process_key():
            if not dispatcher.process_key():
                break
        else:
            handler.read()
            time.sleep(DELAY)
{'fraction_non_alphanumeric': 0.10299468233977051, 'fraction_numerical': 0.007276798208788134, 'mean_word_length': 2.3000923361034165, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5121299', 'n_tokens_mistral': 1042, 'n_tokens_neox': 970, 'n_words': 267}