Skip to content

the issue in outputs of csv #226

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
AviwellLiu opened this issue Mar 26, 2025 · 0 comments
Open

the issue in outputs of csv #226

AviwellLiu opened this issue Mar 26, 2025 · 0 comments

Comments

@AviwellLiu
Copy link

def save_csv(self, out_csv_name, episode):
"""Save metrics of the simulation to a .csv file.

    Args:
        out_csv_name (str): Path to the output .csv file. E.g.: "results/my_results
        episode (int): Episode number to be appended to the output file name.
    """
    if out_csv_name is not None:
        df = pd.DataFrame(self.metrics)
        Path(Path(out_csv_name).parent).mkdir(parents=True, exist_ok=True)
        df.to_csv(out_csv_name + f"_conn{self.label}_ep{episode}" + ".csv", index=False)

def _compute_info(self):
info = {"step": self.sim_step}
if self.add_system_info:
info.update(self._get_system_info())
if self.add_per_agent_info:
info.update(self._get_per_agent_info())
self.metrics.append(info.copy())
return info
def _get_system_info(self):
vehicles = self.sumo.vehicle.getIDList()
speeds = [self.sumo.vehicle.getSpeed(vehicle) for vehicle in vehicles]
waiting_times = [self.sumo.vehicle.getWaitingTime(vehicle) for vehicle in vehicles]
num_backlogged_vehicles = len(self.sumo.simulation.getPendingVehicles())
return {
"system_total_running": len(vehicles),
"system_total_backlogged": num_backlogged_vehicles,
"system_total_stopped": sum(
int(speed < 0.1) for speed in speeds
), # In SUMO, a vehicle is considered halting if its speed is below 0.1 m/s
"system_total_arrived": self.num_arrived_vehicles,
"system_total_departed": self.num_departed_vehicles,
"system_total_teleported": self.num_teleported_vehicles,
"system_total_waiting_time": sum(waiting_times),
"system_mean_waiting_time": 0.0 if len(vehicles) == 0 else np.mean(waiting_times),
"system_median_waiting_time": 0.0 if len(waiting_times) == 0 else np.median(waiting_times), #------traget data
"system_mean_speed": 0.0 if len(vehicles) == 0 else np.mean(speeds),
}
the above code means if I want to get new index in csv,I need to update info,but when i try to add it into _get_system_info,There hasn't been any change in output csv.otherwise,the output csv only has partial information of _get_system_info.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant