Exemple #1
0
def main():
    try:
        sleep_mins = 10
        sleep_secs = sleep_mins * 60

        query = {}
        query['app_name'] = 'hello_light_use_rest_api'
        query['uuid'] = uuid.uuid4().__str__()

        status_code, response_dict = call_rest_api.call_rest_api(endpoint_base + '/status', query)
        light_service_version = response_dict['version']
        print('light_service_version=' + light_service_version)

        fp_out = open('../data/lux.tsv', 'a')   # file will get infinite length

        while True:
            query['uuid'] = uuid.uuid4().__str__()
            status_code, response_dict = call_rest_api.call_rest_api(endpoint_base + '/get_lux', query)
            lux = response_dict['lux']
            watts = response_dict['watts']
            sky_condition = response_dict['sky_condition']
            lux_rec = time.ctime() + '\t' + lux.__str__() + '\t' +\
                      query['uuid'].__str__() + '\t' + \
                      watts.__str__() + '\t' +\
                      sky_condition.__str__() + '\t' +\
                      light_service_version.__str__()

            fp_out.write(lux_rec + '\n')
            fp_out.flush()
            print(lux_rec)
            time.sleep(sleep_secs)

    except Exception as e:
        print(e.__str__())
def test_take_picture():
    """
    Test /status
    :return:
    """
    query = {}
    this_uuid = uuid.uuid4()  # generate a uuid to simulate the client doing so

    query['app_name'] = 'integration_tests'
    query['uuid'] = this_uuid.__str__()

    query[
        'output_filename'] = integration_definitions.MEDIA_ROOT + 'test_images/integration_test_image.png'

    status_code, response_dict = call_rest_api.call_rest_api(
        integration_definitions.webcam_service_endpoint_base + '/get_image',
        query)

    if response_dict is None:
        assert False

    assert status_code == 200
    assert response_dict['status'] == 'OK'
    assert response_dict['uuid'] == this_uuid.__str__()
    assert int(response_dict['filesize']) > 0
Exemple #3
0
def test_take_video():
    """
    Test /status
    :return:
    """
    query = {}
    this_uuid = uuid.uuid4()  # generate a uuid to simulate the client doing so

    query['app_name'] = 'integration_tests'
    query['uuid'] = this_uuid.__str__()
    query['video_length_secs'] = 5  # excludes preamble_secs
    query[
        'preamble_secs'] = 2  # ignore first few secs as video is often overexposed in bright conditions

    status_code, response_dict = call_rest_api.call_rest_api(
        integration_definitions.webcam_service_endpoint_base + '/get_video',
        query)

    if response_dict is None:
        assert False

    assert status_code == 200
    assert response_dict['status'] == 'OK'
    assert response_dict['uuid'] == this_uuid.__str__()

    assert int(response_dict['video_filesize']) > 10
    assert int(response_dict['jpeg_filesize']) > 10

    assert '/metminiwx/media' in response_dict['video_filename']
    assert '/metminiwx/media' in response_dict['jpeg_filename']
def get_key_weather_variables():
    """
    Get some critical weather variables by querying the CumumlusMX REST API
    """

    endpoint = 'http://192.168.1.180:8998/api/data/currentdata'

    status_code, response_dict = call_rest_api.call_rest_api(endpoint, None)
    # print('status_code=' + status_code.__str__())
    pprint(response_dict)

    if status_code == 200:
        return response_dict
    else:
        return None
Exemple #5
0
def test_get_solar_times():
    """
    Test /status
    :return:
    """
    query = {}
    query['app_name'] = 'integration_tests'
    query['lat'] = 51.414
    query['lon'] = -1.375

    status_code, response_dict = call_rest_api.call_rest_api(
        integration_definitions.metminimisc_service_endpoint_base +
        '/get_solar_times', query)

    assert status_code == 200
    assert 'AM' not in response_dict['sunrise']
    assert 'PM' not in response_dict['sunset']
Exemple #6
0
def send_tweet(tweet_text, filename, uuid):
    """
    Send a Tweet with a video file
    """
    query = {}  # API call to twitter-service
    query['app_name'] = 'take_sky_webcamd'
    query['uuid'] = uuid
    query['tweet_text'] = tweet_text
    query['hashtag_arg'] = 'metminiwx'  # do not supply the #
    query['lat'] = 51.4151  # Stockcross
    query['lon'] = -1.3776  # Stockcross
    query['video_pathname'] = filename

    twitter_service_endpoint_base = 'http://192.168.1.5:9506'
    status_code, response_dict = call_rest_api.call_rest_api(
        twitter_service_endpoint_base + '/send_video', query)
    print('status_code=' + status_code.__str__())
    pprint(response_dict)
Exemple #7
0
def get_lux():
    """
    Read lux/watts levels from light sensor
    """
    query = {}  # API call to light-service
    query['app_name'] = 'take_sky_webcamd'
    light_service_listen_port = 9503
    light_service_endpoint_base = 'http://192.168.1.180:' + light_service_listen_port.__str__(
    )

    status_code, response_dict = call_rest_api.call_rest_api(
        light_service_endpoint_base + '/get_lux', query)

    lux = response_dict['lux']
    sky_condition = response_dict['sky_condition']
    watts = response_dict['watts']

    return int(lux), int(watts), sky_condition
Exemple #8
0
def test_status():
    """
    Test /status
    :return:
    """
    query = {}
    query['app_name'] = 'integration_tests'

    status_code, response_dict = call_rest_api.call_rest_api(
        integration_definitions.metminimisc_service_endpoint_base + '/status',
        query)

    if response_dict is None:
        return None

    assert status_code == 200
    assert response_dict['status'] == 'OK'
    assert 'version' in response_dict
Exemple #9
0
def test_get_lux():
    """
    Test /status
    :return:
    """
    query = {}
    this_uuid = uuid.uuid4().__str__()

    query['app_name'] = 'integration_tests'
    query['uuid'] = this_uuid.__str__()

    status_code, response_dict = call_rest_api.call_rest_api(
        integration_definitions.endpoint_base + '/get_lux', query)

    assert status_code == 200
    assert response_dict['status'] == 'OK'

    assert response_dict['lux'] >= 0.0
    assert response_dict['watts'] >= 0.0

    assert response_dict['uuid'] == this_uuid
Exemple #10
0
def wind_deg_to_wind_dir_api():
    answer = {}

    wind_deg = int(request.args.get('wind_deg', None))

    wind_dir = 'GOT TO HERE'
    # Rest call to met_funcs microservice
    query = {'wind_deg': wind_deg}
    response_dict = call_rest_api.call_rest_api(
        'http://127.0.0.1:9500/wind_deg_to_wind_rose', query)
    if response_dict is None:
        return None
    wind = response_dict['wind_rose_id']

    # Put in the calling parameters to aid debugging
    answer['wind_deg'] = wind_deg
    answer['wind_dir'] = wind_dir

    response = jsonify(answer)

    return response
Exemple #11
0
def test_status():
    """
    Test /status
    :return:
    """

    query = {}
    this_uuid = uuid.uuid4()  # generate a uuid to simulate the client doing so
    query['app_name'] = 'integration_tests'
    query['uuid'] = this_uuid.__str__()

    status_code, response_dict = call_rest_api.call_rest_api(
        integration_definitions.webcam_service_endpoint_base + '/status',
        query)

    if response_dict is None:
        return None

    assert status_code == 200
    assert response_dict['status'] == 'OK'
    assert 'version' in response_dict
    assert response_dict['uuid'] == this_uuid.__str__()
Exemple #12
0
def test_status():
    """
    Test /status
    :return:
    """
    query = {}
    this_uuid = uuid.uuid4().__str__()

    query['app_name'] = 'integration_tests'
    query['uuid'] = this_uuid.__str__()

    status_code, response_dict = call_rest_api.call_rest_api(
        integration_definitions.endpoint_base + '/status', query)

    if response_dict is None:
        return None

    assert status_code == 200
    assert response_dict['status'] == 'OK'

    assert response_dict['uuid'] == this_uuid
    assert 'version' in response_dict
Exemple #13
0
def main():

    min_lux = 30  # was 100
    crf = 19  # H264 encoding quality parameter
    my_app_name = 'take_sky_webcamd'

    video_length_secs = 20  # use 5 for testing
    preamble_secs = 5

    webcam_query = {}  # API call to webcam-service
    webcam_query['app_name'] = my_app_name
    webcam_query['video_length_secs'] = video_length_secs
    webcam_query['preamble_secs'] = preamble_secs

    print('take_sky_webcamd : started...')

    while True:
        this_uuid = uuid.uuid4().__str__()  # unique uuid per cycle

        cumulus_weather_info = get_cumulus_weather_info.get_key_weather_variables(
        )  # REST API call

        lux, watts, sky_condition = get_lux()
        if lux <= min_lux:  # do not bother taking video if it is too dark
            print(time.ctime() + ' : light level is below ' +
                  min_lux.__str__() + ' lux, so sleeping... lux=' +
                  lux.__str__())
            time.sleep(600)  # 10 minutes
            continue

        webcam_query['uuid'] = this_uuid
        print('Grabbing webcam mp4 video and a jpg..., uuid=' + this_uuid)
        status_code, response_dict = call_rest_api.call_rest_api(
            integration_definitions.webcam_service_endpoint_base +
            '/get_video', webcam_query)
        mp4_filename = response_dict['video_filename']
        jpeg_filename = response_dict['jpeg_filename']

        print('wrote webcam video to : ' + mp4_filename + ', uuid=' +
              this_uuid)
        print('wrote webcam jpeg to  : ' + jpeg_filename + ', uuid=' +
              this_uuid)

        filename = mp4_filename.split('/')[-1]  # ignore the filepath

        # Tweet the video
        tweet_text = cumulus_weather_info['Beaufort'] + ' (max=' + cumulus_weather_info['HighBeaufortToday'] + ')' + \
            ', cbase=' + cumulus_weather_info['Cloudbase'].__str__() + ' ' + cumulus_weather_info['CloudbaseUnit'] + \
            ', ' + cumulus_weather_info['Pressure'].__str__() + ' ' + cumulus_weather_info['PressUnit'] + \
            ', trend=' + cumulus_weather_info['PressTrend'].__str__() + \
            ', temp=' + cumulus_weather_info['OutdoorTemp'].__str__() + cumulus_weather_info['TempUnit'] + \
            ', wind_chill=' + cumulus_weather_info['WindChill'].__str__() + cumulus_weather_info['TempUnit'] + \
            ', dew_point=' + cumulus_weather_info['OutdoorDewpoint'].__str__() + cumulus_weather_info['TempUnit'] + \
            ', ' + cumulus_weather_info['DominantWindDirection'] + \
            ', last_rain=' + cumulus_weather_info['LastRainTipISO'] + \
            ', fcast=' + cumulus_weather_info['Forecast'] + \
            ', watts=' + watts.__str__() + \
            ', lux=' + lux.__str__() + \
            ', sunrise=' + cumulus_weather_info['Sunrise'] + \
            ', sunset=' + cumulus_weather_info['Sunset'] + \
            ' ' + filename

        send_tweet(tweet_text, mp4_filename, this_uuid)
        print(tweet_text)

        mins_between_videos = 15
        sleep_secs = mins_between_videos * 60
        print('----------------------------------------------')
        print(time.ctime() + ' sleeping for ' + sleep_secs.__str__() + ' ...')
        time.sleep(sleep_secs)
Exemple #14
0
def update_forecasts(julian_day, forecast_hour_utc, met_source):
    query = {}
    container_version = predictord_funcs.get_version()

    try:
        for place in locations.locations:
            #print("===========================================================")
            print("Location : " + place['location'])

            lat, lon, pressure, ptrend, wind_deg, wind_quadrant, wind_strength, temp_avg, rain_avg, snow_avg, humidity_avg, dew_point_avg, slope , last_weather_description, last_record_id , last_record_timestamp = \
                get_forecast_prereqs(place['location'], julian_day, forecast_hour_utc, met_source)

            if lat is None:
                print('Unable to retrieve data for ' + place['location'])
                continue

            query['pressure'] = pressure
            query['trend_str'] = ptrend
            query['wind_deg'] = wind_deg

            status_code, response_dict = call_rest_api.call_rest_api(
                definitions.endpoint_base + '/get_forecast_hughes38', query)

            if status_code != 200:
                raise

            hughes38_forecast_text = response_dict['forecast_text']
            hughes38_forecast_id = response_dict['forecast_id']

            zambretti_forecast_text = 'NOT_IMPLEMENTED'
            zambretti_forecast_id = '0'  # 0 is not a valid Zambretti id

            metmini_forecast_text = 'NOT_IMPLEMENTED'
            metmini_forecast_id = -1

            api_forecast_text = 'NOT_IMPLEMENTED'  # e.g. forecast from a Weather API

            full_forecast_txt = "MetMini Forecast\n"
            full_forecast_txt += "----------------\n"
            full_forecast_txt += time.ctime() + "\n"
            full_forecast_txt += "Location  : " + place['location'] + "\n"
            full_forecast_txt += "Latitude  : " + lat.__str__() + "\n"
            full_forecast_txt += "Longitude : " + lon.__str__() + "\n"
            full_forecast_txt += "Meteorological data source : " + met_source + "\n"
            full_forecast_txt += "Hughes38  forecast for next 12 hours : " + hughes38_forecast_text + "\n"
            full_forecast_txt += "Hughes38  forecast id : " + hughes38_forecast_id.__str__(
            ) + "\n"
            full_forecast_txt += "Zambretti forecast for next 12 hours : " + zambretti_forecast_text + "\n"
            full_forecast_txt += "Zambretti forecast id : " + zambretti_forecast_id.__str__(
            ) + "\n"
            full_forecast_txt += "MetMini forecast for next 12 hours : " + metmini_forecast_text + "\n"
            full_forecast_txt += "MetMini forecast id : " + metmini_forecast_id.__str__(
            ) + "\n"
            full_forecast_txt += "API forecast for next 12 hours : " + api_forecast_text + "\n"
            full_forecast_txt += "{"
            full_forecast_txt += "pressure=" + pressure.__str__(
            ) + " mbar (ptrend=" + ptrend + ")"
            full_forecast_txt += ", wind_deg=" + wind_deg.__str__()
            full_forecast_txt += ", wind_quadrant=" + wind_quadrant.__str__()
            full_forecast_txt += ", wind_strength=F" + wind_strength.__str__()
            full_forecast_txt += ", pressure_slope=" + slope.__str__()
            full_forecast_txt += ", last_record_id=" + last_record_id.__str__()
            full_forecast_txt += "}"
            full_forecast_txt += "\n"
            full_forecast_txt += "["
            full_forecast_txt += "temp_avg=" + temp_avg.__str__()
            full_forecast_txt += ", dew_point_avg=" + dew_point_avg.__str__()
            full_forecast_txt += ", humidity_avg=" + humidity_avg.__str__()
            full_forecast_txt += ", rain_avg=" + rain_avg.__str__()
            full_forecast_txt += ", snow_avg=" + snow_avg.__str__()
            full_forecast_txt += ", last_weather_description=" + last_weather_description.__str__(
            )
            full_forecast_txt += "]"

            #print("------------------------------------------------")
            #print(full_forecast_txt)
            #print("------------------------------------------------")

            add_forecast_to_db(julian_day, place['location'], lat, lon,
                               pressure, ptrend, wind_deg, wind_quadrant,
                               wind_strength, temp_avg, rain_avg, snow_avg,
                               humidity_avg, dew_point_avg, slope, met_source,
                               last_weather_description, last_record_id,
                               hughes38_forecast_text, hughes38_forecast_id,
                               zambretti_forecast_text, zambretti_forecast_id,
                               metmini_forecast_text, metmini_forecast_id,
                               api_forecast_text, last_record_timestamp,
                               container_version)

            # only Tweet out my local forecast
            if place['location'] == "Stockcross, UK":
                tweet = '12-14 hour forecast for ' + place[
                    'location'] + ' is ' + hughes38_forecast_text.lower()
                print('Tweet = ' + tweet)
                twitter.send_tweet(tweet, lat, lon)

    except Exception as e:
        print("update_forecasts() : error : " + e.__str__())