Commit 957c9e54 authored by Lambert Patrick's avatar Lambert Patrick
Browse files

with right output path

parent 562f7472
......@@ -8,7 +8,6 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.xml.DomDriver;
......@@ -17,42 +16,43 @@ import fr.cemagref.simaqualife.kernel.processes.AquaNismsGroupProcess;
public class WriteNutrientExportFluxes extends AquaNismsGroupProcess<DiadromousFish, DiadromousFishGroup> {
private String fileName= "nutrientExportFluxes";
private String fileName = "nutrientExportFluxes";
public static void main(String[] args) {
System.out.println((new XStream(new DomDriver()))
.toXML(new WriteNutrientExportFluxes()));
System.out.println((new XStream(new DomDriver())).toXML(new WriteNutrientExportFluxes()));
}
@Override
public void doProcess(DiadromousFishGroup group) {
BufferedWriter bW;
String outputPath = "data/output/" ;
String sep = ";";
String outputPath = group.getOutputPath();
String sep = ";";
new File(outputPath + fileName).getParentFile().mkdirs();
try {
bW = new BufferedWriter(new FileWriter(new File(outputPath+
fileName + group.getSimulationId() + ".csv")));
bW = new BufferedWriter(new FileWriter(new File(outputPath + fileName + group.getSimulationId() + ".csv")));
bW.write("year"+sep+"nutrient" + sep + "originBasin" + sep + "value" + "\n");
bW.write("year" + sep + "nutrient" + sep + "originBasin" + sep + "value" + "\n");
Map<Long, Map <String, Map<String, Double>>> fluxesCollection = group.getNutrientRoutine().getNutrientExportFluxesCollection().getExportFluxesCollection();
Map<Long, Map<String, Map<String, Double>>> fluxesCollection = group.getNutrientRoutine()
.getNutrientExportFluxesCollection().getExportFluxesCollection();
// to iterate on sorted years
List<Long> years = new ArrayList<Long>(fluxesCollection.keySet());
List<Long> years = new ArrayList<Long>(fluxesCollection.keySet());
Collections.sort(years);
for (long year :years) {
for (long year : years) {
if (year >= group.getMinYearToWrite()) {
for (String nutrient : group.getNutrientRoutine().getNutrientsOfInterest()) {
for (String originBasinName : group.getEnvironment().getRiverBasinNames()) {
bW.write(year+ sep+ nutrient + sep + originBasinName );
bW.write( sep + fluxesCollection.get(year).get(nutrient).get(originBasinName) + '\n');
bW.write(year + sep + nutrient + sep + originBasinName);
bW.write(sep + fluxesCollection.get(year).get(nutrient).get(originBasinName) + '\n');
}
}
......
......@@ -8,7 +8,6 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.xml.DomDriver;
......@@ -17,57 +16,55 @@ import fr.cemagref.simaqualife.kernel.processes.AquaNismsGroupProcess;
public class WriteNutrientImportFluxes extends AquaNismsGroupProcess<DiadromousFish, DiadromousFishGroup> {
private String fileName= "fluxes";
private String fileName = "fluxes";
public static void main(String[] args) {
System.out.println((new XStream(new DomDriver()))
.toXML(new WriteNutrientImportFluxes()));
System.out.println((new XStream(new DomDriver())).toXML(new WriteNutrientImportFluxes()));
}
@Override
public void doProcess(DiadromousFishGroup group) {
BufferedWriter bW;
String outputPath = "data/output/" ;
String sep = ";";
String outputPath = group.getOutputPath();
String sep = ";";
new File(outputPath + fileName).getParentFile().mkdirs();
try {
bW = new BufferedWriter(new FileWriter(new File(outputPath+
fileName + group.getSimulationId() + ".csv")));
bW = new BufferedWriter(new FileWriter(new File(outputPath + fileName + group.getSimulationId() + ".csv")));
bW.write("year"+sep+"nutrient" + sep + "originBasin");
bW.write("year" + sep + "nutrient" + sep + "originBasin");
for (String birthBasinName : group.getEnvironment().getRiverBasinNames()) {
bW.write(sep + birthBasinName); // write each basin name in the file
bW.write(sep + birthBasinName); // write each basin name in the file
}
bW.write("\n");
Map<Long, Map <String, Map<String, Map<String, Double>>>> fluxesCollection = group.getNutrientRoutine().getNutrientImportFluxesCollection().getImportFluxesCollection();
Map<Long, Map<String, Map<String, Map<String, Double>>>> fluxesCollection = group.getNutrientRoutine()
.getNutrientImportFluxesCollection().getImportFluxesCollection();
// to iterate on sorted years
List<Long> years = new ArrayList<Long>(fluxesCollection.keySet());
List<Long> years = new ArrayList<Long>(fluxesCollection.keySet());
Collections.sort(years);
for (long year :years) {
for (long year : years) {
if (year >= group.getMinYearToWrite()) {
Map <String, Map<String, Map<String, Double>>> yearsMap = fluxesCollection.get(year);
Map<String, Map<String, Map<String, Double>>> yearsMap = fluxesCollection.get(year);
for (String nutrient : group.getNutrientRoutine().getNutrientsOfInterest()) {
Map<String, Map<String, Double>> originsMap = yearsMap.get(nutrient);
Map<String, Map<String, Double>> originsMap = yearsMap.get(nutrient);
for (String originBasinName : group.getEnvironment().getRiverBasinNames()) {
bW.write(year+ sep+ nutrient + sep + originBasinName );
Map<String, Double> destinationsMap = originsMap.get(originBasinName);
bW.write(year + sep + nutrient + sep + originBasinName);
Map<String, Double> destinationsMap = originsMap.get(originBasinName);
for (String destinationBasinName : group.getEnvironment().getRiverBasinNames()) {
Double aFlux = destinationsMap.get(destinationBasinName);
bW.write( sep + aFlux);
Double aFlux = destinationsMap.get(destinationBasinName);
bW.write(sep + aFlux);
}
bW.write("\n");
......@@ -83,5 +80,4 @@ public class WriteNutrientImportFluxes extends AquaNismsGroupProcess<DiadromousF
}
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment