import pandas as pd import numpy as np def run_rl_inference(model, env): obs, _ = env.reset() done = False history = [] while not done: # action is [market_choice, charge_fraction] action, _ = model.predict(obs, deterministic=True) # Capture state BEFORE the step for the dashboard current_step_idx = env.current_step prices = env.input_data.iloc[current_step_idx] # Step the environment obs, reward, terminated, truncated, _ = env.step(action) done = terminated or truncated # Logic for the dashboard market = "Ancillary (FCR)" if action[0] >= 0.5 else "Arbitrage" decision = "Idle" if market == "Arbitrage": if action[1] > 0.1: decision = "Sell (Discharge)" elif action[1] < -0.1: decision = "Buy (Charge)" history.append({ "Timestamp": prices.name, "Market_Choice": market, "Decision": decision, "Action_Value": action[1], "Energy_Price": prices.get("energy", 0), "FCR_Price": prices.get("fcr", 0), "SoC": env.battery.soc, "Hourly_Revenue": reward }) return pd.DataFrame(history)