def update_actions_graph(study_agent, relayout_data_store, figure, agent_ref, scenario): if relayout_data_store is not None and relayout_data_store["relayout_data"]: relayout_data = relayout_data_store["relayout_data"] layout = figure["layout"] new_axis_layout = get_axis_relayout(figure, relayout_data) if new_axis_layout is not None: layout.update(new_axis_layout) return figure return make_action_ts(study_agent, agent_ref, scenario, figure['layout'])
def load_ts( relayout_data_store, window, study_agent, rew_figure, cumrew_figure, actions_figure, agent_ref, scenario, ): figures = [rew_figure, cumrew_figure, actions_figure] condition = (relayout_data_store is not None and relayout_data_store["relayout_data"]) if condition: relayout_data = relayout_data_store["relayout_data"] relayouted = False for figure in figures: axis_layout = get_axis_relayout(figure, relayout_data) if axis_layout is not None: figure["layout"].update(axis_layout) relayouted = True if relayouted: return figures rew_figure, cumrew_figure = common_graph.make_rewards_ts( study_agent, agent_ref, scenario, rew_figure, cumrew_figure) actions_figure = common_graph.make_action_ts(study_agent, agent_ref, scenario, actions_figure["layout"]) figures = [rew_figure, cumrew_figure, actions_figure] if window is not None: start_datetime = dt.datetime.strptime(window[0], "%Y-%m-%dT%H:%M:%S") end_datetime = dt.datetime.strptime(window[-1], "%Y-%m-%dT%H:%M:%S") for figure in figures: figure["layout"].update(xaxis=dict( range=[start_datetime, end_datetime], autorange=False)) return figures
def load_actions_ts(relayout_data_store, window, figure, selected_timestamp, study_agent, agent_ref, scenario): layout = figure["layout"] if relayout_data_store is not None and relayout_data_store["relayout_data"]: relayout_data = relayout_data_store["relayout_data"] new_axis_layout = get_axis_relayout(figure, relayout_data) if new_axis_layout is not None: layout.update(new_axis_layout) return figure figure = common_graph.make_action_ts(study_agent, agent_ref, scenario, layout) if window is not None: figure["layout"].update(xaxis=dict(range=window, autorange=False)) return figure
def update_actions_graph(study_agent, relayout_data_store, figure, agent_ref, 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 = figure["layout"] new_axis_layout = get_axis_relayout(figure, relayout_data) if new_axis_layout is not None: layout.update(new_axis_layout) return figure return make_action_ts(study_agent, agent_ref, scenario, figure['layout'])
def update_synchronized_figures( agent_study_ts, ref_agent, relayout_data_store, rew_figure, cumrew_figure, overflow_figure, usage_rate_figure, actions_figure, scenario, study_agent, relayoutStoreMacro_ts, ): figures = [ rew_figure, cumrew_figure, overflow_figure, usage_rate_figure, actions_figure, ] episode = make_episode(study_agent, scenario) 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"] relayouted = False for figure in figures: axis_layout = get_axis_relayout(figure, relayout_data) if axis_layout is not None: figure["layout"].update(axis_layout) relayouted = True if relayouted: return figures new_reward_fig, new_cumreward_fig = make_rewards_ts( study_agent, ref_agent, scenario, rew_figure, cumrew_figure) overflow_figure["data"] = episode.total_overflow_trace.copy() for event in ["maintenance", "hazard", "attacks"]: func = getattr(EpisodeTrace, f"get_{event}_trace") traces = func(episode, ["total"]) if len(traces) > 0: traces[0].update({"name": event.capitalize()}) overflow_figure["data"].append(traces[0]) usage_rate_figure["data"] = episode.usage_rate_trace new_action_fig = make_action_ts(study_agent, ref_agent, scenario, actions_figure["layout"]) return ( new_reward_fig, new_cumreward_fig, overflow_figure, usage_rate_figure, new_action_fig, )