def add_dropdown(values, dropdowns): ctx = dash.callback_context ctx_msg = json.dumps({"states": ctx.states, "triggered": ctx.triggered, "inputs": ctx.inputs}, indent=2) selected_entity = None # If the dropdowns are empty, we are adding the dropdowns for the first level if not dropdowns: dropdowns = [get_dropdown()] return dropdowns, None if not ctx.triggered: raise PreventUpdate else: depth = json.loads(ctx.triggered[0]["prop_id"].split(".")[0])["id"] # We delete the decedents dropdowns of the current changed value dropdowns = dropdowns[:depth] entity_id = ctx.triggered[0]["value"] # The value can be None if the dropdown is cleared if entity_id: entity = oc.get_entity_by_id(entity_id) # If there are some children, we add a dropdown with the children choices if entity.children: dropdowns.append(get_dropdown(parent_id=entity_id, depth=entity.depth + 1)) # Else, we set the selected_entity with the selected value else: selected_entity = entity.id return dropdowns, selected_entity
def update_graphs(selected_entity): service = oc.get_entity_by_id(selected_entity) data = oh.get_structure_data(service.code_osfi) columns = [{"name": i, "id": i} for i in data.columns] data_to_return = data.to_dict("records") electricity_pie_graph = get_pie(data, "emission_electricity") gas_pie_graph = get_pie(data, "emission_gaz") return columns, data_to_return, electricity_pie_graph, gas_pie_graph
def on_selected_entity_show_selected_entity(selected_entity): if selected_entity is not None: service = oc.get_entity_by_id(selected_entity) return html.Div([ html.H3(service.parent.label, style={"text-align": "center"}), html.Br(), html.H4(service.label, style={"text-align": "center"}), ])
def fill_dash_table_with_buildings(selected_entity): service = oc.get_entity_by_id(selected_entity) data = oh.get_structure_data(service.code_osfi) columns_to_keep = [ "Nom du bien", "Building type", "Adresse", "Code postal", "Ville", "Departement" ] columns = [{"name": i, "id": i} for i in columns_to_keep] row_selectable = "multi" buildings = data[columns_to_keep].drop_duplicates() data_to_return = buildings.to_dict("records") return columns, row_selectable, data_to_return
def update_graphs_selected(selected_entity, selected_rows, buildings): entity = oc.get_entity_by_id(selected_entity) data = oh.get_structure_data(entity.code_osfi) # If no rows are selected, we are displaying all of them # Might seem a bit conter intuitive. if selected_rows is None or len(selected_rows) == 0: data_to_display = pd.DataFrame(data) else: biens = [buildings[int(i)] for i in selected_rows] biens = pd.DataFrame(biens) codes = biens["Nom du bien"] data_to_display = data[data["Nom du bien"].isin(codes)] data_to_display = pd.DataFrame(data_to_display) electricity_pie_graph = get_pie(data_to_display, "emission_electricity") gas_pie_graph = get_pie(data_to_display, "emission_gaz") electricity_time_series = get_emissions_timeseries(data_to_display, "emission_electricity") gaz_time_series = get_emissions_timeseries(data_to_display, "emission_gaz") return electricity_pie_graph, gas_pie_graph, electricity_time_series, gaz_time_series
def update_donut_by_prestation(selected_entity): service = oc.get_entity_by_id(selected_entity) return get_donut_by_prestation_type(service.code_chorus)
def update_emissions_timeseries(selected_entity): service = oc.get_entity_by_id(selected_entity) return get_emissions_timeseries(service.code_chorus)
def update_montly_kilometer_odrive(selected_entity, filter_vehicle_type): service = oc.get_entity_by_id(selected_entity) return get_montly_kilometer_odrive(service.code_odrive, filter_vehicle_type)
def on_click_go_to_dashboard(n_clicks, selected_entity): if n_clicks: entity = oc.get_entity_by_id(selected_entity) return dcc.Location(id="url-redirect-to-dashboard", pathname="/tableau_de_bord/%s" % entity.id)
def update_total_emissions_vehicles(selected_entity, filter_vehicle_type): service = oc.get_entity_by_id(selected_entity) return get_total_emisions_vehicles(service.code_odrive, filter_vehicle_type)
def update_fleet_vehicle(selected_entity, filter_vehicle_type): service = oc.get_entity_by_id(selected_entity) return get_fleet_vehicle(service.code_odrive, filter_vehicle_type)
def update_plot_by_vehicle_type(selected_entity, filter_vehicle_type): service = oc.get_entity_by_id(selected_entity) print(service) return get_plot_by_vehicle_type(service.code_odrive, filter_vehicle_type)
def update_histogram_plot_by_vehicle(selected_entity, filter_vehicle_type): service = oc.get_entity_by_id(selected_entity) return get_histogram_plot_by_vehicle(service.code_odrive, filter_vehicle_type)
def update_donut_by_prestation(selected_entity, filter_vehicle_type): service = oc.get_entity_by_id(selected_entity) return get_donut_by_entity_type(service.code_odrive, filter_vehicle_type)