Example #1
0
def get_forecasted_dangers(region_ids,
                           from_date,
                           to_date,
                           include_ikke_vurdert=False,
                           lang_key=1):
    """Gets forecasted dangers for multiple regions.

    :param region_id:               [int] only one region. ID as given in regObs
    :param from_date:               [date or string as yyyy-mm-dd] gets dates [from, to>
    :param to_date:                 [date or string as yyyy-mm-dd] gets dates [from, to>
    :param include_ikke_vurdert:    [bool] if true, it includes forecasts where danger_level = 0

    :return:
    """

    # get all warning and problems for this region and then loop though them joining them where dates match.
    region_warnings = gfa.get_avalanche_warnings_deprecated(region_ids,
                                                            from_date,
                                                            to_date,
                                                            lang_key=lang_key)

    if not include_ikke_vurdert:
        all_non_zero_warnings = []

        for w in region_warnings:
            if w.danger_level != 0:
                all_non_zero_warnings.append(w)

        region_warnings = all_non_zero_warnings

    return region_warnings
def test_AvalancheDanger_to_dict():
    region_ids = [3022]  # Trollheimen

    from_date = dt.date(2018, 12, 1)
    to_date = dt.date(2018, 12, 5)

    warnings_ = gf.get_avalanche_warnings_deprecated(region_ids,
                                                     from_date,
                                                     to_date,
                                                     lang_key=1)

    _d = warnings_[0].to_dict()

    k = 'm'
Example #3
0
def pickle_warnings(regions, date_from, date_to, pickle_file_name):
    """All warnings and problems are selected from regObs or the avalanche api and neatly pickel'd for later use.
    This method also gets all warnings in english for the english main message.

    :param regions:             [int or list of ints] RegionID as given in the forecast api
    :param date_from:           [date or string as yyyy-mm-dd]
    :param date_to:             [date or string as yyyy-mm-dd]
    :param pickle_file_name:    filename including directory as string

    :return:
    """

    warnings = []

    # get all warning and problems for this region and then loop though them joining them on date
    for r in regions:
        warnings_no = gfa.get_avalanche_warnings_deprecated(
            r, date_from, date_to)
        warnings_en = gfa.get_avalanche_warnings_deprecated(r,
                                                            date_from,
                                                            date_to,
                                                            lang_key=2)

        # loop trough all the norwegian forecasts
        for i in range(0, len(warnings_no), 1):

            # add english main message with same dates
            for k in range(0, len(warnings_en), 1):

                if warnings_no[i].date == warnings_en[k].date:
                    warnings_no[i].set_main_message_en(
                        warnings_en[k].main_message_en)
                    continue

        warnings = warnings + warnings_no

    mp.pickle_anything(warnings, pickle_file_name)
def test_AvalancheDanger_as_df():
    """
    Put class data into a pandas.DataFrame
    :return:
    """
    region_ids = [3022]  # Trollheimen

    from_date = dt.date(2018, 12, 1)
    to_date = dt.date(2018, 12, 6)

    warnings_ = gf.get_avalanche_warnings_deprecated(region_ids,
                                                     from_date,
                                                     to_date,
                                                     lang_key=1,
                                                     as_dict=True)

    df = pandas.DataFrame.from_dict(warnings_)
    df.to_csv(r'../localstorage/aval_danger.csv', header=True)

    k = 'm'
def test_MountainWeather_class():
    """
    Requires "forecast_api_version" : "v4.0.1" in /config/api.json
    """
    region_ids = [3022]  # Trollheimen

    from_date = dt.date(2018, 12, 1)
    to_date = dt.date(2018, 12, 4)

    warnings_as_json = gf.get_avalanche_warnings_as_json(region_ids,
                                                         from_date,
                                                         to_date,
                                                         lang_key=1)
    warnings_ = gf.get_avalanche_warnings_deprecated(region_ids,
                                                     from_date,
                                                     to_date,
                                                     lang_key=1)

    w = warnings_as_json[0]
    mw = gf.MountainWeather()
    mw.from_dict(w['MountainWeather'])

    k = 'm'
Example #6
0
def pickle_warnings(regions, date_from, date_to, pickle_file_name):
    '''All forecasted warnings and problems are selected from regObs or the avalanche api.
    Dangers and problems are connected and neatly pickel'd for later use.

    :param regions:            list [int] RegionID as given in regObs [101-199]
    :param date_from:          string as 'yyyy-mm-dd'
    :param date_to:            string as 'yyyy-mm-dd'
    :param pickle_file_name:   filename including directory as string
    :return:
    '''

    warnings = []

    for r in regions:

        # get all warning and problems for this region and then loop though them joining them where dates match.
        region_warnings = gfa.get_avalanche_warnings_deprecated(
            r, date_from, date_to)
        #name = gro.get_forecast_region_name(r)
        '''
        problems = gro.get_problems_from_AvalancheWarnProblemV(r, date_from, date_to)

        print('matrix.py -> pickle_warnings: {0} problems found for {1}'.format(len(problems), name))

        for i in range(0, len(region_warnings), 1):
            for j in range(0, len(problems), 1):
                if region_warnings[i].date == problems[j].date:
                    region_warnings[i].add_problem(problems[j])
        '''
        warnings += region_warnings
    '''
    # make sure all problems are ordered from lowest id (main problem) to largest.
    for w in warnings:
        w.avalanche_problems = sorted(w.avalanche_problems, key=lambda AvalancheProblem: AvalancheProblem.order)
    '''
    mp.pickle_anything(warnings, pickle_file_name)
Example #7
0
# -*- coding: utf-8 -*-
__author__ = 'raek'

from varsomdata import getforecastapi as gfa
from varsomdata import getkdvelements as gkdv
from datetime import date as date

if __name__ == '__main__':
    """Lists how many times different forecasters hva made a forecast for a given reigon."""

    # Get all regions
    # regions = gkdv.get_kdv('ForecastRegionKDV')

    # Get forecasts
    nordenskiold_warnings_201516 = gfa.get_avalanche_warnings_deprecated(
        130, '2016-01-27', '2016-07-01')
    nordenskiold_warnings_201617 = gfa.get_avalanche_warnings_deprecated(
        3003, '2016-12-02', date.today())
    nordenskiold_warnings = nordenskiold_warnings_201516 + nordenskiold_warnings_201617

    # Count occurences
    dict_of_forecasters = {}
    for w in nordenskiold_warnings:
        forecaster = w.nick
        if w.danger_level > 0:
            if forecaster in dict_of_forecasters.keys():
                dict_of_forecasters[forecaster] += 1
            else:
                dict_of_forecasters[forecaster] = 1

    a = 1