pyswmm / Stormwater-Management-Model

PySWMM Stormwater Management Model repository
Other
99 stars 77 forks source link

Why dataframe exports only last value of iteration to csv? #351

Closed Husnain2244 closed 2 years ago

Husnain2244 commented 2 years ago

Hi, I am trying to export results from dataframe to csv, but the below-mentioned code only exports the last values of the iteration. Please check my code and let me know, where I am doing wrong. Thank you for your support.

from pyswmm import Simulation, Nodes import os import pandas as pd

output_path = "E:\VARS_Research\pyswmm_master\Test_Model\Test_Model_Manual" output_csv_file = "node_flow.csv"

with Simulation('Test_model_LID.inp') as sim: nodes = Nodes(sim)

for step in sim:
    j1 = Nodes(sim)["J1"]
    j2 = Nodes(sim)["J2"]
    j3 = Nodes(sim)["J3"]
    j4 = Nodes(sim)["J4"]
    results = {j1.total_inflow, j2.total_inflow, j3.total_inflow, j4.total_inflow} 
    sim.step_advance(300)

    for step in results:
        current_time = sim.current_time
        my_df = pd.DataFrame.from_dict({'j1': [j1.total_inflow], 'j2': [j2.total_inflow], 'j3': [j3.total_inflow], 'j4': [j4.total_inflow]})
        my_df.to_csv(os.path.join(output_path, "node_flow.csv"))
    print(my_df)
michaeltryby commented 2 years ago

@Husnain2244 Are you using pyswmm? If so please post your issue in that repository as opposed to this one.

https://github.com/OpenWaterAnalytics/pyswmm