Пример #1
0
def environment_ts_data(kind, episode, equipments):
    """
        Get the selected kind of timeserie trace for an equipment used in episode.

        There's four kind of trace possible:
            - Load
            - Production
            - Hazards
            - Maintenances

        :param kind: Type of trace
        :param episode: Episode studied
        :param equipments: A equipment to analyze like substation etc.
        :param prod_types: Different types of production
        :return: A list of plotly object corresponding to a trace
    """
    if kind == "Load":
        return EpisodeTrace.get_load_trace_per_equipment(episode, equipments)
    if kind == "Production":
        prod_types = episode.get_prod_types()
        return EpisodeTrace.get_all_prod_trace(episode, prod_types, equipments)
    if kind == "Hazards":
        return EpisodeTrace.get_hazard_trace(episode, equipments)
    if kind == "Maintenances":
        return EpisodeTrace.get_maintenance_trace(episode, equipments)
Пример #2
0
    def update_agent_log_graph(study_agent, relayout_data_store,
                               figure_overflow, figure_usage, scenario,
                               agent_study_ts, relayoutStoreMacro_ts):

        if agent_study_ts is not None and relayoutStoreMacro_ts is not None:
            condition = (relayout_data_store is not None
                         and relayout_data_store["relayout_data"]
                         and relayoutStoreMacro_ts > agent_study_ts)
        else:
            condition = (relayout_data_store is not None
                         and relayout_data_store["relayout_data"])
        if condition:
            relayout_data = relayout_data_store["relayout_data"]
            layout_usage = figure_usage["layout"]
            new_axis_layout = get_axis_relayout(figure_usage, relayout_data)
            if new_axis_layout is not None:
                layout_usage.update(new_axis_layout)
                figure_overflow["layout"].update(new_axis_layout)
                return figure_overflow, figure_usage
        new_episode = make_episode(study_agent, scenario)
        figure_overflow["data"] = new_episode.total_overflow_trace.copy()
        maintenance_traces = EpisodeTrace.get_maintenance_trace(
            new_episode, ["total"])
        if len(maintenance_traces) != 0:
            maintenance_traces[0].update({"name": "Nb of maintenances"})
            figure_overflow["data"].append(maintenance_traces[0])

        hazard_traces = EpisodeTrace.get_hazard_trace(new_episode,
                                                      ["total"]).copy()
        if len(hazard_traces) != 0:
            hazard_traces[0].update({"name": "Nb of hazards"})
            figure_overflow["data"].append(hazard_traces[0])

        attacks_trace = EpisodeTrace.get_attacks_trace(new_episode).copy()
        if len(attacks_trace) != 0:
            attacks_trace[0].update({"name": "Attacks"})
            figure_overflow["data"].append(attacks_trace[0])

        figure_usage["data"] = new_episode.usage_rate_trace

        return figure_overflow, figure_usage
Пример #3
0
def update_agent_log_graph(study_agent, relayout_data_store, figure_overflow,
                           figure_usage, scenario):
    if relayout_data_store is not None and relayout_data_store["relayout_data"]:
        relayout_data = relayout_data_store["relayout_data"]
        layout_usage = figure_usage["layout"]
        new_axis_layout = get_axis_relayout(figure_usage, relayout_data)
        if new_axis_layout is not None:
            layout_usage.update(new_axis_layout)
            figure_overflow["layout"].update(new_axis_layout)
            return figure_overflow, figure_usage
    new_episode = make_episode(study_agent, scenario)
    figure_overflow["data"] = new_episode.total_overflow_trace
    maintenance_traces = EpisodeTrace.get_maintenance_trace(
        new_episode, ["total"])
    if len(maintenance_traces) != 0:
        maintenance_traces[0].update({"name": "Nb of maintenances"})
        figure_overflow["data"].append(maintenance_traces[0])

    figure_usage["data"] = new_episode.usage_rate_trace
    return figure_overflow, figure_usage
Пример #4
0
def update_production_share_graph(scenario, figure):
    """Display best agent's production share when page load"""
    best_agent_ep = make_episode(best_agents[scenario]['agent'], scenario)
    share_prod = EpisodeTrace.get_prod_share_trace(best_agent_ep)
    figure["data"] = share_prod
    return figure
Пример #5
0
def load_scenario_cards(url):
    """
        Create and display html cards with scenario's kpi for
        the 15 first scenarios using cache file.
    """
    cards_list = []
    cards_count = 0
    episode_graph_layout = {
        'autosize': True,
        'showlegend': False,
        'xaxis': {'showticklabels': False},
        'yaxis': {'showticklabels': False},
        'margin': {'l': 0, 'r': 0, 't': 0, 'b': 0},
    }
    is_episode_page = (url == "/" or url == "" or url == "/episodes")
    if cards_count < 15 and is_episode_page:
        for scenario in sorted(scenarios):
            best_agent_episode = make_episode(best_agents[scenario]['agent'], scenario)
            prod_share = EpisodeTrace.get_prod_share_trace(best_agent_episode)
            consumption = best_agent_episode.profile_traces

            cards_list.append(
                dbc.Col(lg=4, width=12, children=[
                    dbc.Card(className='mb-3', children=[
                        dbc.CardBody([
                            html.H5(className="card-title",
                                    children="Scenario {0}".format(scenario)),
                            dbc.Row(children=[
                                dbc.Col(className="mb-4", children=[
                                    html.P(className="border-bottom h3 mb-0 text-right",
                                           children=best_agents[scenario]['out_of']),
                                    html.P(className="text-muted", children="Agents on Scenario")
                                ]),
                                dbc.Col(className="mb-4", children=[
                                    html.P(className="border-bottom h3 mb-0 text-right",
                                           children='{}/{}'.format(best_agents[scenario]['value'],
                                                                   meta_json[scenario]['chronics_max_timestep'])),
                                    html.P(className="text-muted", children="Agent's Survival")
                                ]),
                                dbc.Col(className="mb-4", children=[
                                    html.P(className="border-bottom h3 mb-0 text-right",
                                           children=round(best_agents[scenario]['cum_reward'])),
                                    html.P(className="text-muted", children="Cumulative Reward")
                                ]),
                                dbc.Col(className="mb-4", children=[
                                    html.P(className="border-bottom h3 mb-0 text-right",
                                           children='{} min'.format(round(
                                               best_agent_episode.total_maintenance_duration
                                           ))),
                                    html.P(className="text-muted", children="Total Maintenance Duration")
                                ]),
                            ]),
                            dbc.Row(className="align-items-center", children=[
                                dbc.Col(lg=4, width=12, children=[
                                    html.H5('Production Share',  className='text-center'),
                                    dcc.Graph(
                                        style={'height': '150px'},
                                        figure=go.Figure(
                                            layout=episode_graph_layout,
                                            data=prod_share,
                                        )
                                    )
                                ]),
                                dbc.Col(lg=8, width=12, children=[
                                    html.H5('Consumption Profile', className='text-center'),
                                    dcc.Graph(
                                        style={'height': '150px'},
                                        figure=go.Figure(
                                            layout=episode_graph_layout,
                                            data=consumption
                                        ))
                                    ]
                                )
                            ])
                        ]),
                        dbc.CardFooter(dbc.Button(
                            "Open", id=scenario, key=scenario,
                            className="btn-block",
                            style={"background-color": "#2196F3"}))
                    ])
                ])
            )
            cards_count += 1
    return cards_list
Пример #6
0
    def load_scenario_cards(url):
        """
        Create and display html cards with scenario's kpi for
        the 15 first scenarios using cache file.
        """
        cards_list = []
        cards_count = 0
        episode_graph_layout = {
            "autosize": True,
            "showlegend": False,
            "xaxis": {
                "showticklabels": False
            },
            "yaxis": {
                "showticklabels": False
            },
            "margin": {
                "l": 0,
                "r": 0,
                "t": 0,
                "b": 0
            },
        }

        url_split = url.split("/")
        url_split = url_split[len(url_split) - 1]

        is_episode_page = url_split == "/" or url_split == "" or url_split == "episodes"
        start_time = time.time()
        if cards_count < 15 and is_episode_page:
            sorted_scenarios = list(sorted(scenarios))
            if not os.path.exists(cache_dir):
                print(
                    "Starting Multiprocessing for reading the best agent of each scenario"
                )
                pool = ProcessPool(n_cores)
                best_agents_data = list(
                    pool.imap(
                        make_episode_without_decorate,
                        [
                            best_agents[scenario]["agent"]
                            for scenario in sorted_scenarios
                        ],
                        sorted_scenarios,
                    ))
                pool.close()
                print("Multiprocessing done")
                for i, scenario in enumerate(sorted_scenarios):
                    best_agent_episode = best_agents_data[i]
                    episode_data = retrieve_episode_from_disk(
                        best_agent_episode.episode_name,
                        best_agent_episode.agent)
                    best_agent_episode.decorate(episode_data)
                    save_in_ram_cache(
                        best_agent_episode.episode_name,
                        best_agent_episode.agent,
                        best_agent_episode,
                    )

            for i, scenario in enumerate(sorted_scenarios):
                best_agent_episode = make_episode(
                    best_agents[scenario]["agent"], scenario)
                prod_share = EpisodeTrace.get_prod_share_trace(
                    best_agent_episode)
                consumption = best_agent_episode.profile_traces
                cards_list.append(
                    dbc.Col(
                        id=f"card_{scenario}",
                        lg=4,
                        width=12,
                        children=[
                            dbc.Card(
                                className="mb-3",
                                children=[
                                    dbc.CardBody([
                                        html.H5(
                                            className="card-title",
                                            children="Scenario {0}".format(
                                                scenario),
                                        ),
                                        dbc.Row(children=[
                                            dbc.Col(
                                                className="mb-4",
                                                children=[
                                                    html.P(
                                                        className=
                                                        "border-bottom h3 mb-0 text-right",
                                                        children=best_agents[
                                                            scenario]
                                                        ["out_of"],
                                                    ),
                                                    html.P(
                                                        className="text-muted",
                                                        children=
                                                        "Agents on Scenario",
                                                    ),
                                                ],
                                            ),
                                            dbc.Col(
                                                className="mb-4",
                                                children=[
                                                    html.P(
                                                        className=
                                                        "border-bottom h3 mb-0 text-right",
                                                        children="{}/{}".
                                                        format(
                                                            best_agents[
                                                                scenario]
                                                            ["value"],
                                                            meta_json[scenario]
                                                            ["chronics_max_timestep"],
                                                        ),
                                                    ),
                                                    html.P(
                                                        className="text-muted",
                                                        children=
                                                        "Agent's Survival",
                                                    ),
                                                ],
                                            ),
                                            dbc.Col(
                                                className="mb-4",
                                                children=[
                                                    html.P(
                                                        className=
                                                        "border-bottom h3 mb-0 text-right",
                                                        children=
                                                        f'{round(best_agents[scenario]["cum_reward"]):,}',
                                                    ),
                                                    html.P(
                                                        className="text-muted",
                                                        children=
                                                        "Cumulative Reward",
                                                    ),
                                                ],
                                            ),
                                            dbc.Col(
                                                className="mb-4",
                                                children=[
                                                    html.P(
                                                        className=
                                                        "border-bottom h3 mb-0 text-right",
                                                        children="{} min".
                                                        format(
                                                            round(
                                                                best_agent_episode
                                                                .
                                                                total_maintenance_duration
                                                            )),
                                                    ),
                                                    html.P(
                                                        className="text-muted",
                                                        children=
                                                        "Total Maintenance Duration",
                                                    ),
                                                ],
                                            ),
                                        ]),
                                        dbc.Row(
                                            className="align-items-center",
                                            children=[
                                                dbc.Col(
                                                    lg=4,
                                                    width=12,
                                                    children=[
                                                        html.H5(
                                                            "Production Share",
                                                            className=
                                                            "text-center",
                                                        ),
                                                        dcc.Graph(
                                                            style={
                                                                "height":
                                                                "150px"
                                                            },
                                                            figure=go.Figure(
                                                                layout=
                                                                episode_graph_layout,
                                                                data=prod_share,
                                                            ),
                                                        ),
                                                    ],
                                                ),
                                                dbc.Col(
                                                    lg=8,
                                                    width=12,
                                                    children=[
                                                        html.H5(
                                                            "Consumption Profile",
                                                            className=
                                                            "text-center",
                                                        ),
                                                        dcc.Graph(
                                                            style={
                                                                "height":
                                                                "150px"
                                                            },
                                                            figure=go.Figure(
                                                                layout=
                                                                episode_graph_layout,
                                                                data=
                                                                consumption,
                                                            ),
                                                        ),
                                                    ],
                                                ),
                                            ],
                                        ),
                                    ]),
                                    dbc.CardFooter(
                                        dbc.Button(
                                            "Open",
                                            id=scenario,
                                            key=scenario,
                                            className="btn-block",
                                            style={
                                                "background-color": "#2196F3"
                                            },
                                        )),
                                ],
                            )
                        ],
                    ))
                cards_count += 1
        print(
            "Initial loading time for the best agent of all scenarios = {:.1f} seconds"
            .format(time.time() - start_time))
        return cards_list