def make_region_plots(all_observations_list,
                      region_ids,
                      months,
                      plot_folder=env.plot_folder,
                      html_folder=env.output_folder + 'views/'):
    """Method prepares data for plotting and making the corresponding table for the observations for one
    region.

    :param all_observations_list:
    :param region_ids:
    :param months:
    :param plot_folder:         Folder for saving the plots.
    :param html_folder:         Output folder for the html files generated.
    :return:
    """

    for frid in region_ids:

        region_observations_list = [
            all_obs for all_obs in all_observations_list
            if all_obs.ForecastRegionTID == frid
        ]
        region_name = gkdv.get_name('ForecastRegionKDV', frid)
        ml.log_and_print(
            "[info] plotcalendardata.py -> make_region_plots: {} {}".format(
                frid, region_name))

        # plot one month at the time
        for m in months:
            dates = _make_day_data_list(region_observations_list, m, frid=frid)

            _make_plot(dates, region_name=region_name, plot_folder=plot_folder)
            _make_html(dates, region_name=region_name, html_folder=html_folder)
Ejemplo n.º 2
0
 def __init__(self, d):
     self.TripID = int(d["TripID"])
     self.ObserverID = int(d["ObserverID"])
     self.ObsLocationID = int(d["ObsLocationID"])
     self.GeoHazardTID = int(d["GeoHazardTID"])
     self.TripTypeTID = int(d["TripTypeTID"])
     self.ObservationExpectedTime = fe.unix_time_2_normal( int(d["ObservationExpectedTime"][6:-2]) )
     self.Comment = d["Comment"]
     self.IsFinished = bool(d["IsFinished"])
     self.TripRegistrationTime = fe.unix_time_2_normal( int(d["TripRegistrationTime"][6:-2]) )
     if d["TripFinishedTime"] is not None:
         self.TripFinishedTime = fe.unix_time_2_normal( int(d["TripFinishedTime"][6:-2]) )
     else:
         self.TripFinishedTime = None
     self.DeviceID = d["DeviceID"]
     self.TripTypeName = kdv.get_name("TripTypeKDV", self.TripTypeTID)
def make_svv_plots(all_observations_list,
                   observer_dict,
                   region_ids,
                   months,
                   plot_folder=env.plot_folder,
                   html_folder=env.output_folder + 'views/'):
    """

    :param all_observations_list:
    :param observer_dict:
    :param region_ids:
    :param months:
    :param plot_folder:         Folder for saving the plots.
    :param html_folder:         Output folder for the html files generated.
    :return:
    """

    # Make a list of all svv observers.
    # Look for members of groups with names containing 'svv' or 'vegvesen' or
    # look for user nick containing 'svv' or 'vegvesen'
    groups = gm.get_observer_group_member()

    svv_group_ids_dict = {}
    for g in groups:
        if 'svv' in g.ObserverGroupName.lower(
        ) or 'vegvesen' in g.ObserverGroupName.lower():
            if g.ObserverGroupName in svv_group_ids_dict.keys():
                svv_group_ids_dict[g.ObserverGroupName].append(g.ObserverID)
            else:
                svv_group_ids_dict[g.ObserverGroupName] = [g.ObserverID]

    observer_ids_list = []
    for k, v in svv_group_ids_dict.items():
        for id in v:
            observer_ids_list.append(id)
    observer_ids_list = list(set(observer_ids_list))  # remove duplicates

    svv_observer_dict = {}
    for k, v in observer_dict.items():
        if k not in [237, 4075, 6696,
                     6]:  # not elrapp, wyssen-svv, cautus-svv, ragnar
            if 'svv' in v.observer_nick.lower(
            ) or 'vegvesen' in v.observer_nick.lower():
                svv_observer_dict[k] = v
            if k in observer_ids_list:
                if k not in svv_observer_dict.keys():
                    svv_observer_dict[k] = v

    svv_observer_ids = list(svv_observer_dict.keys())

    svv_observations_list = [
        all_obs for all_obs in all_observations_list
        if all_obs.ObserverId in svv_observer_ids
    ]

    for frid in region_ids:
        region_observations_list = [
            all_obs for all_obs in svv_observations_list
            if all_obs.ForecastRegionTID == frid
        ]
        region_name = gkdv.get_name('ForecastRegionKDV', frid)
        data_description = 'svv_i_{0}'.format(region_name)
        ml.log_and_print(
            "[info] plotcalendardata.py -> make_svv_plots: {} {}".format(
                frid, region_name))

        # plot one month at the time
        for m in months:
            dates = _make_day_data_list(region_observations_list, m, frid=frid)
            _make_plot(dates,
                       region_name=region_name,
                       data_description=data_description,
                       plot_folder=plot_folder)
            _make_html(dates,
                       region_name=region_name,
                       data_description=data_description,
                       html_folder=html_folder)