Blame view

src/mior/view/MiorResultWriter.java 1.71 KB
89f70c1ec   glaville   import current mc...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
  package mior.view;
  
  import java.io.BufferedWriter;
  import java.io.FileWriter;
  import java.io.PrintWriter;
  
  import mior.model.IMiorModel;
  import mior.model.IMiorUpdateListener;
  import mior.model.MiorMM;
  import mior.model.MiorOM;
  
  public class MiorResultWriter implements IMiorUpdateListener {
  	
  	private int step;
  	private PrintWriter output;
  	private int lastCO2;
  	private int CO2;
  	
  	private static final String SSEP = "\t";
  	private static final String SEP = "\t\t";
  	
  	public MiorResultWriter(String outputPath) {
  		try {
  			output = new PrintWriter(new BufferedWriter(new FileWriter(outputPath)));
  			output.println("#" + SSEP + "nbMM" + SSEP + "nbMMa" + SSEP + "CMM" + SEP + "COM" + SEP + "CO2" + SEP + "Total" + SEP + "dCO2");
  		} catch (Exception e) {
  			throw new RuntimeException("Invalid output file", e);
  		}
  	}
  	
  	@Override
  	public void onMiorModelUpdated(IMiorModel model) {
  		step++;
  		
  		int mmTotalActive = 0;
  		int mmTotalCarbon = 0;
  		int omTotalCarbon = 0;
  		
  		lastCO2 = Math.min(CO2, model.getWorld().CO2);
  		CO2 = model.getWorld().CO2;
  			
  		for (MiorMM mm : model.getMMList()) {
  			mmTotalCarbon += mm.getCarbone();
  			if (mm.dormance == 0) {
  				mmTotalActive ++;
  			}
  		}
  		
  		for (MiorOM om : model.getOMList()) {
  			omTotalCarbon += om.getCarbone();
  		}
  		
  		output.print(step);
  		output.append(SSEP);
  		
  		output.print(model.getMMList().length);
  		output.append(SSEP);
  		
  		output.print(mmTotalActive);
  		output.append(SSEP);
  		
  		output.print(mmTotalCarbon);
  		output.append(SEP);
  		
  		output.print(omTotalCarbon);
  		output.append(SEP);
  		
  		output.print(CO2);
  		output.append(SEP);
  		
  		output.print(mmTotalCarbon + omTotalCarbon + CO2);
  		output.append(SEP);
  		
  		output.println(CO2 - lastCO2);
  		output.flush();
  	}	
  	
  
  }