Exemplo n.º 1
0
def get_incident(from_date,
                 to_date,
                 region_ids=None,
                 location_id=None,
                 group_id=None,
                 observer_ids=None,
                 observer_nick=None,
                 observer_competence=None,
                 output='List',
                 geohazard_tids=None,
                 lang_key=1):
    inc_list = go.get_incident(from_date,
                               to_date,
                               region_ids=None,
                               location_id=None,
                               group_id=None,
                               observer_ids=None,
                               observer_nick=None,
                               observer_competence=None,
                               output='List',
                               geohazard_tids=10,
                               lang_key=1)
    inc_list = [i.to_dict() for i in inc_list]
    df = pd.DataFrame(inc_list)

    return df
def get_data(from_date, to_date, region_ids, pickle_file_name_1, get_new):
    """Time consuming and inefficient. Not proud..

    :param from_date:
    :param to_date:
    :param region_ids:
    :param pickle_file_name_1:
    :param get_new:
    :return:
    """

    if get_new:
        # get all data and save to pickle
        all_incidents = go.get_incident(from_date,
                                        to_date,
                                        region_ids=region_ids,
                                        geohazard_tids=10)
        all_forecasts = gd.get_forecasted_dangers(region_ids, from_date,
                                                  to_date)
        mp.pickle_anything([all_forecasts, all_incidents], pickle_file_name_1)
    else:
        # load data from pickle
        all_forecasts, all_incidents = mp.unpickle_anything(pickle_file_name_1)

    return all_forecasts, all_incidents
Exemplo n.º 3
0
# If multiple id's wil be used, give them as list. Result may be returned as a list of forms (default) or
# nested, i.e. all forms are listed under their respective observations.
two_obs = go.get_data(reg_ids=[130548, 130328])

# A request may specify a time period and specific geohazards.
# Snow is 10 and ice is 70. Water is 60. Dirt is [20, 30, 40]
all_data_snow = go.get_data('2016-12-30', '2017-01-01', geohazard_tids=10)
ice_data = go.get_data(from_date='2016-10-01', to_date='2016-11-01', geohazard_tids=70)

# The data may be returned as a list of classes, as opposed to the default return in get_data which are dictionaries
# raw as given on regObs webapi.
data_as_classes = go.get_all_observations('2018-05-01', '2018-08-01')

# We may get observation forms directly. Note, from and to date are first and may also be given as
# positional arguments, even though Is recommend keyword arguments.
land_slides = go.get_land_slide_obs('2018-01-01', '2018-02-01')
incident = go.get_incident('2012-03-01', '2012-03-10')
ice_thicks = go.get_ice_thickness('2018-01-20', '2018-02-10')
snow_surface = go.get_snow_surface_observation('2018-01-28', '2018-02-01')
problems = go.get_avalanche_problem_2('2017-03-01', '2017-03-10')

# We may request an observation count.
seasonal_count_regs = go.get_count('2016-08-01', '2017-08-01')

# And give date as a date time, and not a string.
# Note the argument specifying a part of an Observer Nick.
count_registrations_snow_10 = go.get_data(dt.date(2018, 10, 1), dt.date.today(), geohazard_tids=10, observer_nick='obskorps')

pass
def make_dl_incident_markus():
    """
    From the beginning of time:

    get all forecasts.
    and then get how many on dl 3.

    get all incidents,
    excpt elrapp, and all in back country

    all these, get all on days in regions of dl 3.
    get all with serious caracter on days and in regions on dl 3

    :return:
    """

    pickle_file_name = '{0}incident_on_dl3_for_markus.pickle'.format(
        env.local_storage)
    years = ['2012-13', '2013-14', '2014-15', '2015-16', '2016-17']
    get_new = False

    all_dangers = []
    all_incidents = []

    if get_new:
        for y in years:

            # get forecast regions used this year
            from_date, to_date = gm.get_forecast_dates(y)

            # get incidents for this year and map to this years forecast regions
            this_year_incidents = go.get_incident(from_date,
                                                  to_date,
                                                  geohazard_tids=10)
            for i in this_year_incidents:
                utm33x = i.UTMEast
                utm33y = i.UTMNorth
                region_id, region_name = gm.get_forecast_region_for_coordinate(
                    utm33x, utm33y, y)
                i.region_regobs_id = region_id
                i.region_name = region_name
            all_incidents += this_year_incidents

            # get regions and the forecasts used this year
            region_ids = gm.get_forecast_regions(y)
            all_dangers += gd.get_forecasted_dangers(region_ids, from_date,
                                                     to_date)

        # in the end, pickle it all
        mp.pickle_anything([all_dangers, all_incidents], pickle_file_name)

    else:
        [all_dangers, all_incidents] = mp.unpickle_anything(pickle_file_name)

    all_dl3 = []
    for d in all_dangers:
        if d.danger_level == 3:
            all_dl3.append(d)

    all_back_country_incidents = []
    for i in all_incidents:
        if 'drift@svv' not in i.NickName:
            # if activity influenced is backcounty og scooter
            # should probably include 100 which is non specified incidents
            # giving this dataset the observations not specified
            if i.ActivityInfluencedTID in [
                    100, 110, 111, 112, 113, 114, 115, 116, 117, 130
            ]:
                all_back_country_incidents.append(i)

    all_back_country_incidents_with_consequence = []
    for i in all_back_country_incidents:
        # If damageextent is nestenulykke, personer skadet eller personer omkommet
        if i.DamageExtentTID > 28:
            all_back_country_incidents_with_consequence.append(i)

    # find incidents in regions on days with danger level 3
    # find incidetns in region on day with dl3
    all_back_country_incidents_on_region_dl3 = []
    all_back_country_incidents_with_consequence_on_region_dl3 = []

    for d in all_dl3:
        danger_date = d.date
        danger_region_id = d.region_regobs_id

        for i in all_back_country_incidents:
            incident_date = i.DtObsTime.date()
            incident_region_id = i.ForecastRegionTID
            if incident_date == danger_date and incident_region_id == danger_region_id:
                all_back_country_incidents_on_region_dl3.append(i)

        for i in all_back_country_incidents_with_consequence:
            incident_date = i.DtObsTime.date()
            incident_region_id = i.ForecastRegionTID
            if incident_date == danger_date and incident_region_id == danger_region_id:
                all_back_country_incidents_with_consequence_on_region_dl3.append(
                    i)

    print('Totalt varsler laget siden tidenes morgen: {}'.format(
        len(all_dangers)))
    print('Totalt varsler på fg 3: {}'.format(len(all_dl3)))
    print('Totalt antall hendelser i baklandet: {}'.format(
        len(all_back_country_incidents)))
    print('Totalt antall hendelser i baklandet med konsekvens: {}'.format(
        len(all_back_country_incidents_with_consequence)))
    print(
        'Totalt antall hendelser i baklandet i regioner på dager med fg3: {}'.
        format(len(all_back_country_incidents_on_region_dl3)))
    print(
        'Totalt antall hendelser i baklandet i regioner på dager med fg3 med konsekvens: {}'
        .format(
            len(all_back_country_incidents_with_consequence_on_region_dl3)))

    return
Exemplo n.º 5
0
 def test_get_incident(self):
     incident = go.get_incident('2012-03-01', '2012-03-10')
     incident_df = go.get_incident('2012-03-01', '2012-03-10', output='DataFrame')
     incident_count = go.get_incident('2012-03-01', '2012-03-10', output='Count')
     self.assertEqual(len(incident), incident_count)
     self.assertIsInstance(incident_df, pd.DataFrame)