Exemple #1
0
def get_label_column(app):
    with app.server.app_context():
        options = get_model_options(Labels)
    return html.Div(className="filter__labels",
                    children=[
                        html.Label("Labels"),
                        dcc.Textarea(id="labels",
                                     value=json.dumps(GRAPHS_DEFAULT_LABELS),
                                     style={
                                         "width": "100%",
                                         "height": "50px"
                                     }),
                        html.Label("Save labels as:"),
                        html.Div(className="save",
                                 children=[
                                     dcc.Input(id="save_labels_name",
                                               type="text"),
                                     html.Button("Save", id="save_labels"),
                                 ]),
                        html.Label("Load labels"),
                        dcc.Dropdown(id="load_labels",
                                     options=options,
                                     clearable=True),
                        html.P(id="labels_error", children="")
                    ])
Exemple #2
0
def get_scenario_column(app, scenarios):
    with app.server.app_context():
        options = get_model_options(Scenarios)
    return html.Div(
        className="scenarios",
        style={"padding-bottom": "50px"},
        children=[
            html.Label("Scenario"),
            dcc.Dropdown(
                id="dd_scenario",
                className="scenarios__dropdown",
                multi=True,
                options=[{
                    "label":
                    f"{scenario['id']}, {scenario['scenario']}, {scenario['source']}",
                    "value": scenario["id"],
                } for scenario in scenarios],
            ),
            dbc.Button("Reload",
                       id="scenario_reload",
                       className="scenarios__btn btn btn--refresh"),
            html.Label("Save scenarios as:"),
            html.Div(className="save-filters",
                     children=[
                         dcc.Input(id="save_scenarios_name", type="text"),
                         html.Button("Save",
                                     className="btn btn--small",
                                     id="save_scenarios")
                     ]),
            html.Label("Load Scenarios"),
            dcc.Dropdown(id="load_scenarios", options=options, clearable=True),
            html.P(id="scenarios_error", children="")
        ],
    )
Exemple #3
0
def save_filters(
    _,
    name,
    graph_scalars_options,
    graph_timeseries_options,
    order_by,
    agg_group_by,
    normalize,
    filter_div,
):
    if not name:
        raise PreventUpdate

    filters = preprocessing.extract_filters("scalars", filter_div)
    filters["order_by"] = order_by
    filters["agg_group_by"] = agg_group_by
    filters["normalize"] = normalize
    scalar_graph_options = preprocessing.extract_graph_options("scalars", graph_scalars_options)
    ts_graph_options = preprocessing.extract_graph_options("timeseries", graph_timeseries_options)

    db_filter = Filter(
        name=name,
        filters=filters,
        scalar_graph_options=scalar_graph_options,
        ts_graph_options=ts_graph_options,
    )
    db.session.add(db_filter)
    db.session.commit()

    return get_model_options(Filter), ""
Exemple #4
0
def save_labels(_, name, str_labels):
    if not name:
        raise PreventUpdate

    try:
        labels = json.loads(str_labels)
    except json.JSONDecodeError as je:
        flash(
            f"Could not read labels. Input must be valid JSON. (Error: {je})", "error"
        )
        return get_model_options(Labels), "", show_logs()[0]

    db_labels = Labels(name=name, labels=labels,)
    db.session.add(db_labels)
    db.session.commit()

    return get_model_options(Labels), "", show_logs()[0]
Exemple #5
0
def save_scenarios(_, name, scenario_ids):
    if not name or not scenario_ids:
        raise PreventUpdate

    db_scenarios = Scenarios(name=name, ids=scenario_ids,)
    db.session.add(db_scenarios)
    db.session.commit()

    return get_model_options(Scenarios), "", show_logs()[0]
Exemple #6
0
def save_colors(_, name, str_colors):
    if not name:
        raise PreventUpdate

    try:
        colors = json.loads(str_colors)
    except json.JSONDecodeError as je:
        flash(
            f"Could not read color mapping. Input must be valid JSON. (Error: {je})",
            "error",
        )
        return get_model_options(Colors), "", show_logs()[0]

    db_colors = Colors(name=name, colors=colors,)
    db.session.add(db_colors)
    db.session.commit()

    return get_model_options(Colors), "", show_logs()[0]
Exemple #7
0
def get_save_load_column(app):
    with app.server.app_context():
        options = get_model_options(Filter)
    return html.Div(children=[
        html.P(id="save_load_errors", children=""),
        html.Label("Save filters as:"),
        html.Div(className="save-filters",
                 children=[
                     dcc.Input(id="save_filters_name", type="text"),
                     html.Button(
                         "Save", className="btn btn--small", id="save_filters")
                 ]),
        html.Label("Load filters"),
        dcc.Dropdown(id="load_filters", options=options, clearable=True)
    ])