NickA
NickA

Reputation: 443

How to export statistics_log data cumulatively to the desired Excel sheet in AnyLogic?

I have selected to export tables at the end of model execution to an Excel file, and I would like that data to accumulate on the same Excel sheet after every stop and start of the model. As of now, every stop and start just exports that 1 run's data and overwrites what was there previously. I may be approaching the method of exporting multiple runs wrong/inefficiently but I'm not sure.

Upvotes: 0

Views: 83

Answers (1)

Benjamin
Benjamin

Reputation: 12640

Best method is to export the raw data, as you do (if it is not too large).

However, 2 improvements:

  1. manage your output data yourself, i.e. do not rely on the standard export tables but only write data that you really need. Check this help article to learn how to write your own data
  2. in your custom output data tables, add additional identification columns such as date_of_run. I often use iteration and replication columns to also identify from which of those the data stems.

custom csv approach

Alternative approach is to write create your own csv file programmatically, this is possible with Java code. Then, you can create a new one (with a custom filename) after any run:

First, define a “Text file” element as below: enter image description here

Then, use this code below to create your own csv with a custom name and write to it:

File outputDirectory = new File("outputs");
outputDirectory.mkdir();
String outputFileNameWithExtension = outputDirectory.getPath()+File.separator+"output_file.csv";

file.setFile(outputFileNameWithExtension, Mode.WRITE_APPEND);

// create header
file.println(        "col_1"+","+"col_2");

// Write data from dbase table                                
List<Tuple> rows = selectFrom(my_dbase_table).list();

for (Tuple row : rows) {
        file.println(        row.get( my_dbase_table.col_1) + "," + 
                                        row.get( my_dbase_table.col_2));
}
file.close();

Upvotes: 2

Related Questions