Esempio n. 1
0
def setup():
    start_time = timer()
    config_service.set_mode_to('server')
    data_files.setup_logging('app')
    information.refresh_all()
    metrics_service.setup()
    loggy.log_time('Mothership App Setup', start_time, timer())
Esempio n. 2
0
    def test_get_irregular_verbs_path(self):
        # given
        config_service.set_mode_to('dev')

        # when
        result = config_service.get_irregular_verbs_path()

        # then
        self.assertTrue(result.endswith('data/irregular_verbs.txt'))
Esempio n. 3
0
    def test_get_report_path_at_server_for_server(self):
        # given
        config_service.settings['mode'] = 'server'
        expected_result = "D:\\denva\\data\\reports\\"

        # when
        result = config_service.get_report_path_at_server()

        # then
        self.assertEqual(expected_result, result)

        # after
        config_service.set_mode_to('dev')
Esempio n. 4
0
        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')


if __name__ == '__main__':
    config_service.set_mode_to('cctv')
    data_files.setup_logging('cctv')
    logging.info('Starting application ...')
    email_sender_service.send_ip_email('CCTV APP')
    try:
        if config_service.is_sky_camera_on():
            main()
        else:
            logger.warning('Camera disabled.')
    except KeyboardInterrupt as keyboard_exception:
        print('Received request application to shut down.. goodbye. {}'.format(keyboard_exception))
        logging.info('Received request application to shut down.. goodbye!', exc_info=True)
    except Exception as exception:
        print(f'Whoops. {exception}')
        logger.error('Something went badly wrong. {}'.format(exception), exc_info=True)
        email_sender_service.send_error_log_email("CCTV APP", "Application crashed due to {}.".format(exception))
Esempio n. 5
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


def cleanup_before_exit():
    two_led_service.on()
    led_matrix_service.set_red()
    sys.exit(0)


if __name__ == '__main__':
    global points
    config_service.set_mode_to('denva')
    data_files.setup_logging('app')
    logging.info('Starting application ... \n Press Ctrl+C to shutdown')
    email_sender_service.send_ip_email('denva')
    try:
        logging.info('Mounting network drives')
        commands.mount_all_drives()

        logging.info("Sensor warming up, please wait...")
        air_quality_service.start_measurement()
        motion_service.sample()
        logging.info('Sensor needed {} seconds to warm up'.format(counter))
        two_led_service.off()
        main()
    except KeyboardInterrupt as keyboard_exception:
        print('Received request application to shut down.. goodbye. {}'.format(
Esempio n. 6
0
    if measurement_is_older_than_5_minutes():
        is_ok = False
        reasons.append("Getting measurement is not working")

    if not is_ok:
        logger.warning("FAILED ( {} )".format(response))

    return is_ok


def send_email_on_fail(problem: str):
    email_sender_service.send_error_log_email("healthcheck", problem)


if __name__ == '__main__':
    try:
        config_service.set_mode_to('hc')
        data_files.setup_logging('hc')
        healthcheck_test_runner()
    except KeyboardInterrupt as keyboard_exception:
        print('Received request application to shut down.. goodbye. {}'.format(
            keyboard_exception))
        logging.info('Received request application to shut down.. goodbye!',
                     exc_info=True)
    except BaseException as disaster:
        msg = 'Shit hit the fan and application died badly because {}'.format(
            disaster)
        print(msg)
        traceback.print_exc()
        logger.fatal(msg, exc_info=True)
Esempio n. 7
0
    def test_set_mode_to(self):
        # when
        config_service.set_mode_to('server')

        # then
        self.assertEqual(config_service.get_mode(), 'dev')
Esempio n. 8
0
    stop = datetime.datetime.now()

    delta = stop - start
    time = int(delta.total_seconds() * 1000)
    logger.info(f'It took {time} ms.')
    return render_template('hq.html', message=all_data)


@app.route("/")
def welcome():
    return hq()  # redirect


if __name__ == '__main__':
    config_service.set_mode_to('server')
    data_files.setup_logging('ui')
    logger.info('Starting web server')

    try:
        app.config['JSONIFY_PRETTYPRINT_REGULAR'] = True
        app.config['JSON_AS_ASCII'] = False
        app.run(host='0.0.0.0',
                debug=True)  # host added so it can be visible on local network
        healthcheck()
    except KeyboardInterrupt as keyboard_exception:
        print('Received request application to shut down.. goodbye. {}'.format(
            keyboard_exception))
        logging.info('Received request application to shut down.. goodbye!',
                     exc_info=True)
    except Exception as exception:
Esempio n. 9
0
            device_status()
            delight_display.reset_screen()
            local_data_gateway.post_healthcheck_beat('delight', 'app')
            sub_light.sub_light_travel(unicornhathd, clock, cycle)
            delight_display.reset_screen()
            local_data_gateway.post_healthcheck_beat('delight', 'app')
            device_status()
            delight_display.reset_screen()
            forest.in_the_forest(unicornhathd)
            delight_display.reset_screen()
            local_data_gateway.post_healthcheck_beat('delight', 'app')
            warp.in_the_warp(unicornhathd, clock, cycle)


if __name__ == '__main__':
    config_service.set_mode_to('delight')
    data_files.setup_logging('app')
    try:
        logger.info('Starting application ...')
        main()
    except KeyboardInterrupt as keyboard_exception:
        print('Received request application to shut down.. goodbye. {}'.format(
            keyboard_exception))
        logging.info('Received request application to shut down.. goodbye!',
                     exc_info=True)
        unicornhathd.off()
    except Exception as exception:
        logger.error('Something went wrong\n{}'.format(exception),
                     exc_info=True)
        unicornhathd.brightness(0.2)
        ui_utils.set_all_pixel_to(255, 0, 0, unicornhathd)
Esempio n. 10
0
        mode = override_mode()
        if is_in_override(mode):
            set_manual_mode(mode)
        else:
            if is_night_mode():
                mote_lighting.night_mode()
            elif is_stand_up():
                mote_lighting.party_random_color_mode()
            elif is_busy_at_work():
                mote_lighting.red_alert()
            else:
                mote_lighting.daydream()


if __name__ == '__main__':
    config_service.set_mode_to(APP_NAME)
    data_files.setup_logging(APP_NAME)
    logger.info('Starting application ... \n Press Ctrl+C to shutdown')
    try:
        app_loop()
    except KeyboardInterrupt as keyboard_exception:
        print('Received request application to shut down.. goodbye. {}'.format(
            keyboard_exception))
        logging.info('Received request application to shut down.. goodbye!',
                     exc_info=True)
        sys.exit(0)
    except Exception as exception:
        logger.error('Something went badly wrong\n{}'.format(exception),
                     exc_info=True)
        email_sender_service.send_error_log_email(
            APP_NAME, '{} crashes due to {}'.format(APP_NAME, exception))
Esempio n. 11
0
        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)


if __name__ == '__main__':
    config_service.set_mode_to('ddd')
    data_files.setup_logging('ddd')
    try:
        digest()
    except KeyboardInterrupt as keyboard_exception:
        logger.warning('Requesting shutdown: {}'.format(keyboard_exception),
                       exc_info=True)
    except Exception as exception:
        logger.error('Something went badly wrong: {}'.format(exception),
                     exc_info=True)
    except BaseException as disaster:
        disaster_error_message = 'Shit hit the fan and application died badly because {}'.format(
            disaster)
        print(disaster_error_message)
        traceback.print_exc()
        logger.fatal(disaster_error_message, exc_info=True)