def financial_template(client): datum = api.get("/Graphs?id=update_date_baan_realisation") datum_baan = datum[0]["date"][0:-10].replace( "T", " ") if datum else "[Niet beschikbaar]" explain_barchart_1 = f""" Deze barchart geeft de financiele status weer op {datum_baan}. We zien hier wat er is begroot, hoeveel hiervan is gerealiseerd, en wat er operationeel is gedaan.""" explain_barchart_2 = """ De operationele voortgang is berekend door het aantal aangesloten huizen te vermenigvuldigen met de gemiddelde kosten voor het aansluiten van een huis in een bepaalde categorie / sub-categorie. """ return [ html.Div( className="container-display ml-3", id=f"finance-warnings-{client}", children=[], ), html.Div( className="container-display", children=[ figure( figure=no_graph(), container_id=f"budget-bar-category-{client}-container", graph_id=f"budget-bar-category-{client}", title="Begroting/Realisatie/Operationeel", ), dbc.Tooltip( children=[ html.P(explain_barchart_1), html.Br(), html.P(explain_barchart_2), ], id=f"{client}-hover-finance-main-barchart", target=f"budget-bar-category-{client}-container-title", placement="below", style={"font-size": 12}, ), ], ), html.Div( className="container-display", children=[ figure( figure=no_graph(text="Geen selectie"), container_id=f"budget-bar-sub-category-{client}-container", graph_id=f"budget-bar-sub-category-{client}", title="Begroting/Realisatie/Operationeel", ), figure( figure=no_graph(text="Geen selectie"), container_id=f"progress-over-time-{client}-container", graph_id=f"progress-over-time-{client}", title="Verloop", ), ], ), ]
def get_html(client): return [ dcc.Store(id="aggregate_data", data=None), dcc.Store(id="aggregate_data2", data=None), dcc.Store(id=f"status-count-filter-{client}", data={}), html.Div(children=html.Div(id=f"activatie-indicators-{client}", className="container-display")), html.Div( [ figure( figure=no_graph(title="Gerealiseerde aansluitingen", text="Loading..."), container_id= f"realised-connections-activatie-dif-{client}-container", graph_id=f"realised-connections-activatie-dif-{client}", ), figure( figure=no_graph( title="Gerealiseerde aansluitingen cumulatief", text="Loading...", ), container_id= f"realised-connections-activatie-{client}-container", graph_id=f"realised-connections-activatie-{client}", ), html.Div( [ figure( figure=no_graph(title="ActualConnection types", text="Loading..."), graph_id= f"graph-actual-connection-type-activatie-{client}", className=None), dcc.DatePickerRange( id= f'date-picker-actual-connection-type-activatie-{client}', initial_visible_month=date(date.today().year, date.today().month, date.today().day), clearable=True, ) ], className='pretty_container column', ) ], id="main_graphs", className="container-display", ), ]
def budget_bar_category(dropdown_selection, project, client=client): data = collection.get_document(collection="Finance", project=dropdown_selection, client=client) if data: fig = calculate_figure(client, project, data, "categorie") return [fig] return [no_graph("Barchart")]
def get_html(client): return [ html.Div(children=html.Div(id=f"info-container-year-{client}", className="container-display")), html.Div(children=html.Div(id=f"info-container2-year-{client}", className="container-display")), html.Div( className="container-display", children=[ figure( graph_id=f"month-overview-year-{client}", figure=no_graph(title="Jaaroverzicht", text="Loading..."), ), figure( graph_id=f"week-overview-year-{client}", figure=no_graph(title="Maandoverzicht", text="Loading..."), ), figure( container_id=f"pie_chart_overview_{client}_container", graph_id=f"pie_chart_overview-year_{client}", figure=no_graph(title="Opgegeven reden na", text="Loading..."), ), ], ), html.Div( className="container-display", children=[ figure( graph_id=f"project-performance-year-{client}", figure=no_graph(title="Jaaroverzicht", text="Loading..."), ) ], ), html.Div( className="container-display", children=[ table( table_id=f"FTU_table_c_{client}", table=dummy_table(), ) ], ), ]
def get_html(client): return [ dcc.Store(id="aggregate_data", data=None), dcc.Store(id="aggregate_data2", data=None), dcc.Store(id=f"status-count-filter-{client}", data={}), html.Div( id=f"indicators-{client}", className="container-display", ), html.Div( [ figure( figure=no_graph( title="Progress of HPend over time", text="Loading..." ), graph_id=f"graph_prog-{client}", ), figure( figure=no_graph( title="Status oplevering per fase (LB)", text="Loading..." ), container_id=f"status-counts-laagbouw-{client}-container", graph_id=f"status-counts-laagbouw-{client}", ), figure( figure=no_graph( title="Status oplevering per fase (HB)", text="Loading..." ), container_id=f"status-counts-hoogbouw-{client}-container", graph_id=f"status-counts-hoogbouw-{client}", ), figure( figure=no_graph(title="Opgegeven reden na", text="Loading..."), container_id=f"redenna_project_{client}_container", graph_id=f"redenna_project_{client}", ), ], id="main_graphs", className="container-display", ), ]
def actual_connection_type(project, start_date, end_date, client=client): if project: ordered_dict = fetch_data_for_barchart_ActualConnectionTypes( project, client, start_date, end_date ) if ordered_dict: fig = get_fig_ActualConnectionTypes(ordered_dict) else: fig = no_graph(title="ActualConnection types", text="No Data") return fig raise PreventUpdate
def phase_buttons(*args, client=client): """ This callback switches the view based on which tab is clicked. The input variables are not used as callback_context.triggered is used to access which trigger caused the callback. When the view changes the data is retrieved and rendered in the dashboard. Args: schouwen: lassen: graven: hassen: Returns: A rendered view with the relevant data for the selected phase. """ if not callback_context.triggered: raise PreventUpdate phase = callback_context.triggered[0]["prop_id"].split("-")[2] if config.capacity_phases.get(phase) is None: phase = callback_context.states[f"memory_phase_{client}.data"] phase_name = config.capacity_phases[phase].get("name") else: phase_name = config.capacity_phases[phase].get("name") project = callback_context.inputs[f"project-dropdown-{client}.value"] freq = callback_context.inputs[f"frequency-selector-{client}.value"] unit_type = callback_context.inputs[f"unit-selector-{client}.value"] indicator_values, timeseries, line_graph_bool = fetch_data_productionstatus( project, client, freq, phase_name, unit_type=unit_type) if line_graph_bool: line_graph = productionstatus.get_fig(timeseries, unit_type) else: line_graph = no_graph("No data") return [ capacity_summary( phase_name=phase_name, target=indicator_values["Target"], work_stock=indicator_values["Hoeveelheid Werkvoorraad"], capacity=indicator_values["Gerealiseerd & verwacht verloop"], poc=indicator_values["Gerealiseerd & ideaal verloop"], unit=config.capacity_phases[phase].get("unit"), ), line_graph, phase, ]
def get_graph(**filters): """ This function retrieves the graph from the firestore. The graph is in the record field of a document in the Graphs collection. This function automatically retrieves the necessary data from the document. Args: **filters: See :func:`get_document` Returns: dict: The graph in the document """ return get_document(collection="Graphs", **filters).get("figure", no_graph())
def update_graphs_using_status_clicks(click_filter, project_name, client=client): if not project_name: raise PreventUpdate data_laagbouw, data_hoogbouw = fetch_data_for_status_barchart( project_name, click_filter=click_filter, client=client ) if not data_laagbouw.empty: laagbouw = completed_status_counts_bar.get_fig( data_laagbouw, title="Status oplevering per fase (LB)" ) else: laagbouw = no_graph() if not data_hoogbouw.empty: hoogbouw = completed_status_counts_bar.get_fig( data_hoogbouw, title="Status oplevering per fase (HB & Duplex)" ) else: hoogbouw = no_graph() return laagbouw, hoogbouw
def update_redenna_status_clicks(click_filter, project_name, client=client): if not project_name: raise PreventUpdate total, laagbouw, hoogbouw = fetch_data_for_status_redenna_piechart( project_name, click_filter=click_filter, client=client ) if not total.empty: fig = redenna_status_pie.get_fig( total, laagbouw, hoogbouw, title="Opgegeven reden na" ) else: fig = no_graph() return [fig]
def budget_bar_sub_category(click, project, client=client): ctx = dash.callback_context if "budget-bar-category" in [ x["prop_id"].rpartition("-")[0] for x in ctx.triggered ]: for point in click.get("points", []): data = collection.get_document(collection="Finance", project=project, client=client) if data: parent = dict(level="categorie", value=point.get("label")) fig = calculate_figure(client, project, data, "sub_categorie", parent) return [fig, point.get("label")] break return [no_graph(text="Geen selectie"), ""]
def progress_over_time(click, project, client=client): ctx = dash.callback_context if "budget-bar-category" in [ x["prop_id"].rpartition("-")[0] for x in ctx.triggered ]: for point in click.get("points", []): finance_data = collection.get_document(collection="Finance", project=project, client=client) if finance_data: parent = dict(level="categorie", value=point.get("label")) actuals_df = pd.DataFrame( finance_data.get("actuals", { parent.get("level"): [], "bedrag": [] })) actuals_df = actuals_df[actuals_df[parent.get("level")] == parent.get("value")] time_series = (actuals_df.groupby("vastlegdatum") ["bedrag"].sum().sort_index().cumsum()) if "expected_actuals" in finance_data: expected_cost = pd.DataFrame( finance_data.get( "expected_actuals", { parent.get("level"): [], "bedrag": [] }, )) else: expected_cost = pd.DataFrame( finance_data.get("budget", { parent.get("level"): [], "bedrag": [] })) expected_cost = expected_cost[expected_cost[parent.get( "level")] == parent.get("value")].bedrag.sum() traces = [ go.Scatter( x=time_series.index, y=time_series, mode="lines+markers", name="Financieel", line=dict(color=config.colors_vwt["vwt_blue"]), ) ] if parent.get("value") in [ "has", "civiel", "montage", "schouwen" ]: progress_data = collection.get_document( collection="Data", project=project, client=client, data_set="progress_over_time", ) traces.append( get_progress_scatter( expected_cost, progress_data, parent.get("value"), color=config.colors_vwt["darkgray"], )) fig = go.Figure(data=traces) fig.update_layout( height=500, paper_bgcolor=config.colors_vwt["paper_bgcolor"], plot_bgcolor=config.colors_vwt["plot_bgcolor"], ) return [fig, parent.get("value")] break return [no_graph(text="Geen selectie"), ""]
def capacity_template(client): """ The template for the capacity view. The phase selector is shown at the top, followed by the summarized data that answers the most important questions. Lastly there is a button that lets you open the more information panel. Args: client: Returns: html.Div: The capacity view. """ return html.Div( id=f"cookie-factory-{client}", children=[ dcc.Store(id=f"memory_phase_{client}", data="geulen"), dbc.Row( id=f"selection-menu-{client}", children=[ html.Div( className=f"container-display-{client}", id=f"capacity-phase-{client}", children=dbc.ButtonGroup([ dbc.Button( phase_data.get("name"), id=f"capacity-phase-{phase}-{client}", ) for phase, phase_data in config.capacity_phases.items() ]), ), html.Div( className="container-display", children=dcc.Dropdown( id=f"frequency-selector-{client}", options=[ { "label": "Week", "value": "week" }, { "label": "Maand", "value": "month" }, ], value="week", clearable=False, style={ "color": config.colors_vwt.get("darkgray"), "margin-left": "10px", "width": "150%", }, ), ), ], ), html.Div(id=f"capacity-indicators-{client}", ), dbc.Row( id=f"capacity-info-{client}", children=dbc.Col( [ dbc.Button( "Meer informatie", id=f"collapse-button-{client}", className="mb-3", style={ "background-color": config.colors_vwt["vwt_blue"] }, ), dbc.Collapse( [ dcc.Dropdown( id=f"unit-selector-{client}", options=[ { "label": "Percentage", "value": "" }, { "label": "Units", "value": "_units" }, ], value="_units", clearable=False, style={ "color": config.colors_vwt.get("darkgray"), "margin-left": "4px", "width": "100px", }, ), figure( graph_id=f"more-info-graph-{client}", figure=no_graph( title="Verdieping Capaciteit", text="Geen data...", ), ), ], id=f"more-info-collapse-{client}", ), ], width=12, ), ), ], )