Commit a4cfee21 authored by patrick.lambert's avatar patrick.lambert
Browse files

fix jet pilot + code cleaning

Showing with 46 additions and 42 deletions
+46 -42
...@@ -5,8 +5,6 @@ import java.io.File; ...@@ -5,8 +5,6 @@ import java.io.File;
import java.io.FileWriter; import java.io.FileWriter;
import java.io.IOException; import java.io.IOException;
import java.util.HashMap; import java.util.HashMap;
import java.util.Hashtable;
import java.util.List;
import java.util.Map; import java.util.Map;
import com.thoughtworks.xstream.XStream; import com.thoughtworks.xstream.XStream;
...@@ -17,55 +15,57 @@ import environment.Time; ...@@ -17,55 +15,57 @@ import environment.Time;
import environment.Time.Season; import environment.Time.Season;
import fr.cemagref.simaqualife.kernel.processes.AquaNismsGroupProcess; import fr.cemagref.simaqualife.kernel.processes.AquaNismsGroupProcess;
import fr.cemagref.simaqualife.pilot.Pilot; import fr.cemagref.simaqualife.pilot.Pilot;
import miscellaneous.Miscellaneous;
import species.DiadromousFish.Stage; import species.DiadromousFish.Stage;
import species.ReproduceAndSurviveAfterReproductionWithDiagnose;
/** /**
* *
*/ */
public class WriteBiomassFluxes extends AquaNismsGroupProcess<DiadromousFish, DiadromousFishGroup> { public class WriteBiomassFluxes extends AquaNismsGroupProcess<DiadromousFish, DiadromousFishGroup> {
private Season exportSeason = Season.SPRING; private Season exportSeason = Season.SPRING;
private String fileNameOutput = "biomassFluxes"; private String fileNameOutput = "biomassFluxes";
private transient BufferedWriter bW; private transient BufferedWriter bW;
private transient String sep=";"; private transient String sep = ";";
public static void main(String[] args) { public static void main(String[] args) {
System.out.println((new XStream(new DomDriver())) System.out.println((new XStream(new DomDriver())).toXML(new WriteBiomassFluxes()));
.toXML(new WriteBiomassFluxes()));
} }
/* (non-Javadoc)
* @see fr.cemagref.simaqualife.kernel.processes.AquaNismsGroupProcess#initTransientParameters(fr.cemagref.simaqualife.pilot.Pilot) /*
* (non-Javadoc)
*
* @see
* fr.cemagref.simaqualife.kernel.processes.AquaNismsGroupProcess#initTransientParameters(fr.cemagref.simaqualife.
* pilot.Pilot)
*/ */
@Override @Override
public void initTransientParameters(Pilot pilot) { public void initTransientParameters(Pilot pilot) {
super.initTransientParameters(pilot); super.initTransientParameters(pilot);
sep=";";
} }
@Override @Override
public void doProcess(DiadromousFishGroup group) { public void doProcess(DiadromousFishGroup group) {
if (bW==null){ if (bW == null) {
if (fileNameOutput != null){ sep = ";";
new File(group.getOutputPath()+fileNameOutput).getParentFile().mkdirs(); if (fileNameOutput != null) {
new File(group.getOutputPath() + fileNameOutput).getParentFile().mkdirs();
try { try {
bW = new BufferedWriter(new FileWriter(new File(group.getOutputPath()+ bW = new BufferedWriter(
fileNameOutput +group.getSimulationId()+ ".csv"))); new FileWriter(new File(group.getOutputPath() + fileNameOutput + group.getSimulationId() + ".csv")));
bW.write("year"+sep+"migrationBasin" ); //create the field of the column bW.write("year" + sep + "migrationBasin"); // create the field of the column
for (String birthBasinName : group.getEnvironment().getRiverBasinNames()) { 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"); bW.write("\n");
bW.flush();
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
...@@ -75,17 +75,19 @@ public class WriteBiomassFluxes extends AquaNismsGroupProcess<DiadromousFish, Di ...@@ -75,17 +75,19 @@ public class WriteBiomassFluxes extends AquaNismsGroupProcess<DiadromousFish, Di
try { try {
Time time = group.getEnvironment().getTime(); Time time = group.getEnvironment().getTime();
if (time.getSeason(pilot) == exportSeason & time.getYear(pilot) >= group.getMinYearToWrite()) { System.out.println(time.getSeason(group.getPilot()));
System.out.println(time.getYear(group.getPilot()));
if (time.getSeason(group.getPilot()) == exportSeason & time.getYear(group.getPilot()) >= group.getMinYearToWrite()) {
for (RiverBasin migrationBasin : group.getEnvironment().getRiverBasins()) { for (RiverBasin migrationBasin : group.getEnvironment().getRiverBasins()) {
//Create the map to get the biomass in each birth basin // Create the map to get the biomass in each birth basin
Map<String, Double> spawnerAbundancesPerOrigin = new HashMap<String, Double>(group.getEnvironment().getRiverBasinNames().length); Map<String, Double> spawnerAbundancesPerOrigin = new HashMap<String, Double>(
for (String basinName : group.getEnvironment().getRiverBasinNames()){ group.getEnvironment().getRiverBasinNames().length);
spawnerAbundancesPerOrigin.put(basinName, 0.); for (String basinName : group.getEnvironment().getRiverBasinNames()) {
spawnerAbundancesPerOrigin.put(basinName, 0.);
} }
double biomass=0.; double biomass = 0.;
//compute the cumulative effective per birth basin // compute the cumulative effective per birth basin
if (migrationBasin.getFishs(group) != null) { if (migrationBasin.getFishs(group) != null) {
for (DiadromousFish fish : migrationBasin.getFishs(group)) { for (DiadromousFish fish : migrationBasin.getFishs(group)) {
...@@ -93,24 +95,28 @@ public class WriteBiomassFluxes extends AquaNismsGroupProcess<DiadromousFish, Di ...@@ -93,24 +95,28 @@ public class WriteBiomassFluxes extends AquaNismsGroupProcess<DiadromousFish, Di
if (fish.getStage() == Stage.MATURE) { if (fish.getStage() == Stage.MATURE) {
biomass = group.getNutrientRoutine().getWeight(fish) * fish.getAmount(); biomass = group.getNutrientRoutine().getWeight(fish) * fish.getAmount();
String birthBasinName = fish.getBirthBasin().getName(); String birthBasinName = fish.getBirthBasin().getName();
spawnerAbundancesPerOrigin.put(birthBasinName, spawnerAbundancesPerOrigin.get(birthBasinName) + biomass); spawnerAbundancesPerOrigin.put(birthBasinName,
spawnerAbundancesPerOrigin.get(birthBasinName) + biomass);
} }
} }
} }
//write the first two fields of the line // write the first two fields of the line
bW.write(time.getYear(pilot)+sep+migrationBasin.getName()); bW.write(time.getYear(group.getPilot()) + sep + migrationBasin.getName());
//write the cumulative effective from birth basin // write the cumulative effective from birth basin
for (String birthBasinName : group.getEnvironment().getRiverBasinNames()) { for (String birthBasinName : group.getEnvironment().getRiverBasinNames()) {
bW.write(sep+spawnerAbundancesPerOrigin.get(birthBasinName)); bW.write(sep + spawnerAbundancesPerOrigin.get(birthBasinName));
} }
//write an end-of(line // write an end-of(line
bW.write("\n"); bW.write("\n");
} }
} }
if (group.getPilot().getCurrentTime()== group.getPilot().getSimBegin()+group.getPilot().getSimDuration()-1) if (group.getPilot().getCurrentTime() == group.getPilot().getSimBegin() + group.getPilot().getSimDuration() - 1) {
bW.flush();
bW.close(); bW.close();
}
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
......
...@@ -76,8 +76,8 @@ public class WriteEffectiveAndBiomassImportFluxes extends AquaNismsGroupProcess< ...@@ -76,8 +76,8 @@ public class WriteEffectiveAndBiomassImportFluxes extends AquaNismsGroupProcess<
if (fileNameOutput != null) { if (fileNameOutput != null) {
new File(group.getOutputPath() + fileNameOutput).getParentFile().mkdirs(); new File(group.getOutputPath() + fileNameOutput).getParentFile().mkdirs();
try { try {
bW = new BufferedWriter(new FileWriter( bW = new BufferedWriter(
new File(group.getOutputPath() + fileNameOutput + group.getSimulationId() + ".csv"))); new FileWriter(new File(group.getOutputPath() + fileNameOutput + group.getSimulationId() + ".csv")));
bW.write("year" + sep + "type" + sep + "originBasin"); // create the field of the column bW.write("year" + sep + "type" + sep + "originBasin"); // create the field of the column
for (String birthBasinName : group.getEnvironment().getRiverBasinNames()) { for (String birthBasinName : group.getEnvironment().getRiverBasinNames()) {
...@@ -93,7 +93,7 @@ public class WriteEffectiveAndBiomassImportFluxes extends AquaNismsGroupProcess< ...@@ -93,7 +93,7 @@ public class WriteEffectiveAndBiomassImportFluxes extends AquaNismsGroupProcess<
Time time = group.getEnvironment().getTime(); Time time = group.getEnvironment().getTime();
if (time.getSeason(pilot) == exportSeason & time.getYear(pilot) >= group.getMinYearToWrite()) { if (time.getSeason(group.getPilot()) == exportSeason & time.getYear(group.getPilot()) >= group.getMinYearToWrite()) {
// Create the map to get the biomass in each migration basin and birth basin // Create the map to get the biomass in each migration basin and birth basin
Map<String, Map<String, Long>> spawnerEffectivePerDestination = new HashMap<String, Map<String, Long>>( Map<String, Map<String, Long>> spawnerEffectivePerDestination = new HashMap<String, Map<String, Long>>(
...@@ -130,8 +130,7 @@ public class WriteEffectiveAndBiomassImportFluxes extends AquaNismsGroupProcess< ...@@ -130,8 +130,7 @@ public class WriteEffectiveAndBiomassImportFluxes extends AquaNismsGroupProcess<
double biomass = group.getNutrientRoutine().getWeight(fish) * fish.getAmount(); double biomass = group.getNutrientRoutine().getWeight(fish) * fish.getAmount();
spawnerBiomassPerDestination.get(destinationBasin.getName()).put(originBasinName, spawnerBiomassPerDestination.get(destinationBasin.getName()).put(originBasinName,
spawnerBiomassPerDestination.get(destinationBasin.getName()).get(originBasinName) spawnerBiomassPerDestination.get(destinationBasin.getName()).get(originBasinName) + biomass);
+ biomass);
} }
} }
} }
...@@ -160,8 +159,7 @@ public class WriteEffectiveAndBiomassImportFluxes extends AquaNismsGroupProcess< ...@@ -160,8 +159,7 @@ public class WriteEffectiveAndBiomassImportFluxes extends AquaNismsGroupProcess<
bW.write("\n"); bW.write("\n");
} }
if (group.getPilot().getCurrentTime() == group.getPilot().getSimBegin() if (group.getPilot().getCurrentTime() == group.getPilot().getSimBegin() + group.getPilot().getSimDuration() - 1) {
+ group.getPilot().getSimDuration() - 1) {
bW.flush(); bW.flush();
bW.close(); bW.close();
} }
......
Supports Markdown
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