示例#1
0
def main():
    measurement_counter = 0
    setup()
    while True:
        measurement_counter += 1
        logger.debug('Measurement No.{}'.format(measurement_counter))

        start_time = timer()
        measurement = get_measurement()
        # FIXME temporary disabled  denviro_display.display_on_screen(measurement)
        measurement['cpu_temp'] = commands.get_cpu_temp()
        end_time = timer()
        measurement_time = str(int((end_time - start_time) * 1000))  # in ms
        measurement['measurement_time'] = measurement_time
        logger.info('it took ' + str(measurement_time) + ' milliseconds to measure it.')
        cl_display.print_measurement(measurement)

        # FIXME do not work due to “sounddevice.PortAudioError: Error querying device -1" error
        # logger.warning(noise_service.get_noise_measurement())

        data_files.store_enviro_measurement(measurement)

        sensor_warnings_service.get_current_warnings_for_enviro()

        if measurement_counter % 2 == 0:
            local_data_gateway.post_healthcheck_beat('denviro', 'app')

        remaining_time_in_millis = 5 - (float(measurement_time) / 1000)

        if int(measurement_time) > config_service.max_latency(fast=False):
            logger.warning("Measurement {} was slow.It took {} ms".format(measurement_counter, measurement_time))

        if remaining_time_in_millis > 0:
            time.sleep(remaining_time_in_millis)
示例#2
0
    def test_max_latency_fast(self):
        # given
        expected_result = 200

        # when
        result = config_service.max_latency()

        # then
        self.assertEqual(result, expected_result)
示例#3
0
    def test_max_latency_slow(self):
        # given
        expected_result = 1000

        # when
        result = config_service.max_latency(False)

        # then
        self.assertEqual(result, expected_result)

        # debug
        print(result)
示例#4
0
def digest():
    # load and save them to file for stats
    counter = 0
    errors = 0  # add when error was happen last time
    warnings = 0
    while True:
        counter += 1
        start_time = timer()

        result = local_data_gateway.get_data_for(
            config_service.get_url_for_dump1090(), 5)

        if 'error' in result:
            logger.error(result['error'])
            local_data_gateway.post_metrics_update('flight', 'errors')
            errors += 1
            logger.error('Errors: {}'.format(errors))
        else:
            aircraft_storage.save_raw_reading(result)
            aircraft_storage.save_processed_data(result)
            if counter % 2 == 0:
                local_data_gateway.post_healthcheck_beat('other', 'radar')
            local_data_gateway.post_metrics_update('flight', 'ok')

        end_time = timer()

        measurement = int((end_time - start_time) * 1000)
        measurement_time = str(measurement)  # in ms

        if measurement > config_service.max_latency():
            warnings += 1
            logger.warning("Measurement {} was slow.It took {} ms".format(
                counter, measurement))

        if counter % 2 == 0:
            local_data_gateway.post_healthcheck_beat('other', 'digest')
        display_stats()
        measurement_message = 'Measurement no. {} It took {} milliseconds to process. Errors: {}. Warnings: {}'.format(
            counter, measurement_time, errors, warnings)
        logger.info(measurement_message)
        remaining_time = refresh_rate_in_seconds - (float(measurement_time) /
                                                    1000)

        if remaining_time > 0:
            time.sleep(remaining_time)
示例#5
0
def main():
    global email_cooldown
    logger.info('Starting up camera')
    sleep(WARM_UP_TIME)

    camera.start_preview()
    camera.resolution = (640, 480)  # 3280x2464, 3280x2464,1920x1080,1640x1232, 1640x922,1280x720, 640x480
    logger.info('Camera is on.')

    measurement_counter = 0
    while config_service.is_sky_camera_on():
        measurement_counter += 1
        logger.info('Capturing photo no.{}'.format(measurement_counter))

        start_time = timer()
        last_picture = EMPTY
        captured_picture_path = capture_picture()
        if captured_picture_path != EMPTY:
            last_picture = captured_picture_path

        end_time = timer()
        measurement_time = int((end_time - start_time) * 1000)  # in ms

        remaining_time = 5 - (float(measurement_time) / 1000)
        if measurement_time > config_service.max_latency(fast=False):
            logger.warning("Measurement {} was slow. It took {} ms.".format(measurement_counter, measurement_time))
        else:
            logger.debug("It took {} ms.".format(measurement_time))

        if remaining_time > 0:
            time.sleep(remaining_time)

        if measurement_counter == 1 and last_picture != EMPTY:
            email_sender_service.send_picture(last_picture, measurement_counter)

        if app_timer.is_time_to_run_every_15_minutes(email_cooldown) and last_picture != EMPTY:
            email_sender_service.send_picture(last_picture, measurement_counter)
            email_cooldown = datetime.now()
        if measurement_counter % 2 == 0:
            local_data_gateway.post_healthcheck_beat('other', 'cctv')
示例#6
0
def main():
    measurement_counter = 0
    two_led_service.led_startup_show()
    while True:
        measurement_counter += 1
        logger.debug('Getting measurement no.{}'.format(measurement_counter))
        start_time = timer()
        data = get_data_from_measurement()
        data['cpu_temp'] = commands.get_cpu_temp()
        end_time = timer()
        measurement_time = int((end_time - start_time) * 1000)  # in ms

        logger.info(
            'Measurement no. {} took {} milliseconds to measure it.'.format(
                measurement_counter, measurement_time))

        data['measurement_counter'] = measurement_counter
        data['measurement_time'] = str(measurement_time)
        data_files.store_measurement(
            data, motion_service.get_current_motion_difference())

        cl_display.print_measurement(data)

        if measurement_counter % 2 == 0:
            local_data_gateway.post_healthcheck_beat('denva', 'app')

        remaining_of_five_s = 5 - (float(measurement_time) / 1000)

        if measurement_time > config_service.max_latency(fast=False):
            logger.warning("Measurement {} was slow.It took {} ms".format(
                measurement_counter, measurement_time))

        if measurement_counter % 10 == 0:
            led_matrix_service.display_fasting_mode()

        if remaining_of_five_s > 0:
            time.sleep(remaining_of_five_s
                       )  # it should be 5 seconds between measurements