def test_iqa_from_tvoc_for_good_air(self):
        # given
        tvoc = '250'
        expected_result = {
            'score': 'Good',
            'value': int(tvoc),
            'action': 'Ventilation recommended.',
            'information': 'Good Air Quality'
        }

        # when
        result = get_description_for.iqa_from_tvoc(tvoc)

        # then
        self.assertEqual(expected_result, result)
    def test_iqa_from_tvoc_for_clean_air(self):
        # given
        tvoc = '50'
        expected_result = {
            'score': 'Very Good',
            'value': int(tvoc),
            'action': 'No action required',
            'information': 'Clean air'
        }

        # when
        result = get_description_for.iqa_from_tvoc(tvoc)

        # then
        self.assertEqual(expected_result, result)
    def test_iqa_from_tvoc_for_poor_air(self):
        # given
        tvoc = '3500'
        expected_result = {
            'score':
            'POOR',
            'value':
            int(tvoc),
            'action':
            'Ventilate now!',
            'information':
            'Air Quality is POOR. (Not recommended for exposure for than month)'
        }

        # when
        result = get_description_for.iqa_from_tvoc(tvoc)

        # then
        self.assertEqual(expected_result, result)
    def test_iqa_from_tvoc_for_radioactive_air(self):
        # given
        tvoc = '128256'
        expected_result = {
            'score':
            'BAD',
            'value':
            int(tvoc),
            'action':
            'Use only if unavoidable!',
            'information':
            'Unacceptable Air Quality! Use only if unavoidable and only for short periods.'
        }

        # when
        result = get_description_for.iqa_from_tvoc(tvoc)

        # then
        self.assertEqual(expected_result, result)
    def test_iqa_from_tvoc_for_medium_air(self):
        # given
        tvoc = '750'
        expected_result = {
            'score':
            'Medium',
            'value':
            int(tvoc),
            'action':
            'Ventilation required.',
            'information':
            'Air Quality is not good. (Not recommended for exposure for than year)'
        }

        # when
        result = get_description_for.iqa_from_tvoc(tvoc)

        # then
        self.assertEqual(expected_result, result)
def get_warnings_as_list(data) -> list:
    warnings = []
    if data['temp'] < 16:
        warnings.append('Temp. is TOO LOW')
        warnings_logger.error(
            '[tle] Temperature is too low. Current temperature is: {}'.format(
                str(data['temp'])))
    elif data['temp'] < 18:
        warnings.append('Temp. is low')
        warnings_logger.warning(
            '[tlw] Temperature is low. Current temperature is: {}'.format(
                str(data['temp'])))
    elif data['temp'] > 25:
        warnings.append('Temp. is high')
        warnings_logger.warning(
            '[thw] Temperature is high. Current temperature is: {}'.format(
                str(data['temp'])))
    elif data['temp'] > 30:
        warnings.append('Temp. is TOO HIGH')
        warnings_logger.error(
            '[the] Temperature is too high. Current temperature is: {}'.format(
                str(data['temp'])))

    if data['humidity'] < 30:
        warnings.append('Humidity is TOO LOW')
        warnings_logger.error(
            '[hle] Humidity is too low. Current humidity is: {}'.format(
                str(data['humidity'])))
    elif data['humidity'] < 40:
        warnings.append('Humidity is low')
        warnings_logger.warning(
            '[hlw] Humidity is low. Current humidity is: {}'.format(
                str(data['humidity'])))
    elif data['humidity'] > 60:
        warnings.append('Humidity is high')
        warnings_logger.warning(
            '[hhw] Humidity is high. Current humidity is: {}'.format(
                str(data['humidity'])))
    elif data['humidity'] > 70:
        warnings.append('Humidity is TOO HIGH')
        warnings_logger.error(
            '[hhe] Humidity is too high. Current humidity is: {}'.format(
                str(data['humidity'])))

    if data['uva_index'] > 6:
        warnings.append('UV A is TOO HIGH')
        warnings_logger.error(
            '[uvae] UV A is too high. Current UV A is: {}'.format(
                str(data['uva_index'])))

    if data['uvb_index'] > 6:
        warnings.append('UV B is TOO HIGH')
        warnings_logger.error(
            '[uvbe] UV B is too high. Current UV B is: {}'.format(
                str(data['uvb_index'])))

    if data['motion'] > shaking_level:
        warnings_logger.info(
            '[dsl] Dom is shaking his legs. Value: {} [mhe]'.format(
                str(data['motion'])))

    if type(data['cpu_temp']) != float:
        data['cpu_temp'] = float(re.sub('[^0-9.]', '', data['cpu_temp']))

    if data['cpu_temp'] > config['sensor']['cpu_temp_fatal']:
        warnings.append('CPU temp. TOO HIGH!')
        warnings_logger.error(
            '[cthf] CPU temperature is too high. Current temperature is: {}'.
            format(str(data['cpu_temp'])))
    elif data['cpu_temp'] > config['sensor']['cpu_temp_error']:
        warnings.append('CPU temp. VERY HIGH')
        warnings_logger.error(
            '[cthe] CPU temperature is very high. Current temperature is: {}'.
            format(str(data['cpu_temp'])))
    elif data['cpu_temp'] > config['sensor']['cpu_temp_warn']:
        warnings.append('CPU temp. is high')
        warnings_logger.warning(
            '[cthw] CPU temperature is high. Current temperature is: {}'.
            format(str(data['cpu_temp'])))

    free_space = int(commands.get_space_available())
    if free_space < 500:
        warnings.append('Low Free Space: {}'.format(str(free_space) + 'MB'))
        warnings_logger.warning(
            '[fsl] Low Free Space: {}'.format(str(free_space) + 'MB'))

    data_free_space = int(commands.get_data_space_available())
    if data_free_space < 500:
        warnings.append('Low Free Space on Data Partition: {}'.format(
            str(data_free_space) + 'MB'))
        warnings_logger.warning(
            '[dfsl] Low Free Space on Data Partition: {}'.format(
                str(data_free_space) + 'MB'))

    eco2 = int(data['eco2'])
    if eco2 > 1000:
        warnings.append('High CO2 level (Time to open window?): {}'.format(
            str(eco2)))
        warnings_logger.warning(
            '[cow] High CO2 level (Time to open window?): {}'.format(
                str(eco2)))

    tvoc = get_description_for.iqa_from_tvoc(data['tvoc'])
    if tvoc['value'] > 5000:
        warnings.append('{} with value {}'.format(tvoc['information'],
                                                  tvoc['value']))
        warnings_logger.error('[iqe] {} with value {}'.format(
            tvoc['information'], tvoc['value']))
    elif tvoc['value'] > 1500:
        warnings.append('{} with value {}'.format(tvoc['information'],
                                                  tvoc['value']))
        warnings_logger.warning('[iqw] {} with value {}'.format(
            tvoc['information'], tvoc['value']))
    loggy.log_error_count(warnings)
    return warnings
Example #7
0
def draw_image_on_screen(data, app_uptime):
    global cycle
    warnings_list = sensor_warnings_service.get_warnings_as_list(data)
    img = Image.open(
        "/home/pi/denva-master/src/images/background.png").convert(oled.mode)
    draw = ImageDraw.Draw(img)
    draw.rectangle([(0, 0), (128, 128)], fill="black")
    if len(warnings_list) > 0 and cycle % 3 == 2:
        draw.text((0, 0), "WARNINGS", fill="white", font=rr_14)
        y = 2
        for warning in warnings_list:
            y += 14
            draw.text((0, y), warning, fill="white", font=rr_12)
    elif cycle % 6 == 1:
        statuses = web_data_gateway.get_status()
        draw.text((0, 0), "Train & Tubes", fill="white", font=rr_14)
        y = 2
        for status in statuses:
            y += 14
            draw.text((0, y), status, fill="white", font=rr_12)
    else:
        draw.text((0, 0),
                  "Temp: {}".format(data["temp"]),
                  fill="white",
                  font=rr_12)
        draw.text((0, 14),
                  "Pressure: {}".format(data["pressure"]),
                  fill="white",
                  font=rr_12)
        if cycle % 2 == 0:
            draw.text((0, 28),
                      "Humidity: {}".format(data["humidity"]),
                      fill="white",
                      font=rr_12)
            draw.text((0, 42),
                      "Motion: {:05.02f}".format(data["motion"]),
                      fill="white",
                      font=rr_12)
            draw.text(
                (0, 56),
                "Colour: {}".format(dom_utils.get_color_name(data["colour"])),
                fill="white",
                font=rr_12)
            draw.text(
                (0, 70),
                "UVA: {}".format(get_description_for.uv(data["uva_index"])),
                fill="white",
                font=rr_12)
        else:
            draw.text((0, 28),
                      "eco2: {}".format(data["eco2"]),
                      fill="white",
                      font=rr_12)
            draw.text(
                (0, 42),
                "Tvoc: {}".format(
                    get_description_for.iqa_from_tvoc(data["tvoc"])['score']),
                fill="white",
                font=rr_12)
            draw.text(
                (0, 56),
                "Brightness: {}".format(
                    get_description_for.brightness(data["r"], data["g"],
                                                   data["b"])),
                fill="white",
                font=rr_12)
            draw.text(
                (0, 70),
                "UVB: {}".format(get_description_for.uv(data["uvb_index"])),
                fill="white",
                font=rr_12)

    if cycle % 7 == 0:
        draw.text((0, 84),
                  'CPU: {}'.format(commands.get_cpu_temp()),
                  fill="white",
                  font=rr_12)
    elif cycle % 7 == 1:
        draw.text((0, 84), commands.get_uptime(), fill="white", font=rr_12)
    elif cycle % 7 == 2:
        draw.text((0, 84),
                  'CPU: {}'.format(commands.get_cpu_speed()),
                  fill="white",
                  font=rr_12)
    elif cycle % 7 == 3:
        draw.text((0, 84),
                  'IP: {}'.format(commands.get_ip()),
                  fill="white",
                  font=rr_12)
    elif cycle % 7 == 4:
        draw.text((0, 84),
                  'Space: {} MB'.format(commands.get_space_available()),
                  fill="white",
                  font=rr_12)
    elif cycle % 7 == 5:
        draw.text((0, 84),
                  'Data: {} MB'.format(commands.get_data_space_available()),
                  fill="white",
                  font=rr_12)
    elif cycle % 7 == 6:
        draw.text((0, 84),
                  'RAM avail.: {}'.format(
                      system_data_service.get_memory_available_in_mb()),
                  fill="white",
                  font=rr_12)
    else:
        draw.text((0, 84), app_uptime, fill="white", font=rr_12)

    oled.display(img)
    cycle += 1
    if cycle > 12:
        cycle = 0