Ejemplo n.º 1
0
def get_emissions_timeseries(code_structure=None):
    """
        Render and update a barplot figure to show emissions evolution with time
    """
    # Load chorus dt data based on chosen code_structure
    # TODO: improve and standardize data import logic
    chorus_dt_df = ch.get_structure_data(code_structure)
    chorus_dt_df["year_month"] = chorus_dt_df[
        "date_debut_mission"].dt.to_period("M")
    timeseries_df = chorus_dt_df.groupby(["year_month"
                                          ])["distance"].sum().reset_index()
    fig = go.Figure()
    fig.add_trace(
        go.Scatter(
            x=timeseries_df["year_month"].astype(str),
            y=timeseries_df["distance"].values,
            mode="lines+markers",
            line=dict(width=3),
        ))
    fig.update_layout(plot_bgcolor="white",
                      template="plotly_white",
                      margin={
                          "t": 30,
                          "r": 30,
                          "l": 30
                      },
                      xaxis=xaxis_format)
    return fig
Ejemplo n.º 2
0
def get_donut_by_prestation_type(code_structure=None):
    """
        Render and update a donut figure to show emissions distribution by prestation type
    """
    # Load chorus dt data based on chosen code_structure
    # TODO: improve and standardize data import logic
    chorus_dt_df = ch.get_structure_data(code_structure)
    prestation_df = chorus_dt_df.groupby(["prestation_type"])["distance"].sum().reset_index()
    fig = go.Figure(data=[go.Pie(labels=prestation_df.prestation_type, values=prestation_df["distance"], hole=0.3)])
    fig.update_layout(plot_bgcolor="white", template="plotly_white", margin={"t": 30, "r": 30, "l": 30})
    return fig
Ejemplo n.º 3
0
def update_graphs(selected_entity, n_clicks, prestation_types: list, years, unreliable):
    oc = OrganizationChart()
    oc.load_current()
    service = oc.get_entity_by_id(selected_entity)
    chorus_dt_df = ch.get_structure_data(service.code_chorus).copy()
    if "fiable" not in chorus_dt_df.columns:
        chorus_dt_df["fiable"] = True
    filters = (
        chorus_dt_df.prestation.isin(prestation_types)
        & chorus_dt_df.date_debut_mission.dt.year.isin(years)
        & (chorus_dt_df.fiable.isin(unreliable) | chorus_dt_df.fiable)
    )
    chorus_dt_df = chorus_dt_df.loc[filters, :]
    return [
        get_kpi_emissions(chorus_dt_df),
        get_kpi_trips_count(chorus_dt_df),
        get_kpi_distance(chorus_dt_df),
        get_donut_by_prestation_type(chorus_dt_df),
        get_scatter_by_emission(chorus_dt_df),
        get_emissions_timeseries(chorus_dt_df),
        get_hist_top_emission(chorus_dt_df),
        get_dashtable_by_emission(chorus_dt_df),
    ]
Ejemplo n.º 4
0
 def load_data(self):
     self.chorus_dt_df = ch.get_structure_data(self.service.code_chorus)
     self.odrive_df = ov.get_structure_data(self.service.code_odrive)
     self.osfi_df = oh.get_structure_data(self.service.code_osfi)