Commit 435d2e8f authored by patrick.lambert's avatar patrick.lambert
Browse files

rename to ExportExchangeSBetweenCatchments

parent 9c525f3a
......@@ -24,8 +24,6 @@ import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.xml.DomDriver;
......@@ -34,27 +32,34 @@ import environment.RiverBasin;
import environment.Time;
import environment.Time.Season;
import fr.cemagref.simaqualife.kernel.processes.AquaNismsGroupProcess;
import observer.ObservableRecord;
import species.DiadromousFish;
import species.DiadromousFishGroup;
/**
*
*/
public class IdentifyPopulation extends AquaNismsGroupProcess<DiadromousFish, DiadromousFishGroup> {
public class ExportExchangeSBetweenCatchments extends AquaNismsGroupProcess<DiadromousFish, DiadromousFishGroup> {
/**
*
*/
public class Record implements Serializable {
public class Record implements Serializable, ObservableRecord {
/**
*
* @unit
*/
private static final long serialVersionUID = 3605733432812631453L;
long year;
String migrationBasin;
String originBasin;
String destinationBasin;
@Information(unit = "#")
long effective;
public Record(long year, String migrationBasin, String originBasin, long effective) {
public Record(long year, String originBasin, String destinationBasin, long effective) {
super();
this.year = year;
this.migrationBasin = migrationBasin;
this.destinationBasin = destinationBasin;
this.originBasin = originBasin;
this.effective = effective;
}
......@@ -62,7 +67,7 @@ public class IdentifyPopulation extends AquaNismsGroupProcess<DiadromousFish, Di
@Override
public String toString() {
return "[" + this.year + "; " + this.migrationBasin + "; " + this.originBasin + "; " + this.effective + "]";
return "[" + this.year + "; " + this.originBasin + "; " + this.destinationBasin + "; " + this.effective + "]";
}
......@@ -75,10 +80,10 @@ public class IdentifyPopulation extends AquaNismsGroupProcess<DiadromousFish, Di
/**
* @return the migrationBasin
* @return the destinationBasin
*/
public String getMigrationBasin() {
return this.migrationBasin;
public String getDestinationBasin() {
return this.destinationBasin;
}
......@@ -100,22 +105,45 @@ public class IdentifyPopulation extends AquaNismsGroupProcess<DiadromousFish, Di
}
private boolean consoleDisplay = false;
private List<Long> years;
private long yearStart = 1920;
private long yearEnd = 1950;
private Season fluxesSeason = Season.SPRING;
private String fileNameOutput = "effectiveFluxes";
private transient List<Record> records;
private String fileNameOutput = "effectiveFluxes";
private transient BufferedWriter bW;
private transient String sep;
// @Observable(description = "fluxes")
// private transient long[] fluxes;
public static void main(String[] args) {
System.out.println((new XStream(new DomDriver())).toXML(new IdentifyPopulation()));
System.out.println((new XStream(new DomDriver())).toXML(new ExportExchangeSBetweenCatchments()));
}
//
// @Override
// public void initTransientParameters(Pilot pilot) {
// super.initTransientParameters(pilot);
// // create output file if necessary
// if (fileNameOutput != null) {
// sep = ",";
//
// String outputPath = ((DiadromousFishGroup)
// pilot.getAquaticWorld().getAquaNismsGroupsList().get(0)).getOutputPath();
// String simulationId = ((DiadromousFishGroup) pilot.getAquaticWorld().getAquaNismsGroupsList().get(0))
// .getSimulationId();
// try {
// new File(outputPath + fileNameOutput).getParentFile().mkdirs();
// bW = new BufferedWriter(new FileWriter(new File(outputPath + fileNameOutput + simulationId + ".csv")));
//
// bW.write("year" + sep + "destinationBasin" + sep + "originBasin" + sep + "effective");
// bW.write("\n");
// } catch (IOException e) {
// e.printStackTrace();
// }
// }
//
// }
/*
* (non-Javadoc)
......@@ -124,6 +152,8 @@ public class IdentifyPopulation extends AquaNismsGroupProcess<DiadromousFish, Di
*/
@Override
public void doProcess(DiadromousFishGroup group) {
// write header in the file
if (bW == null) {
if (fileNameOutput != null) {
sep = ",";
......@@ -132,79 +162,66 @@ public class IdentifyPopulation extends AquaNismsGroupProcess<DiadromousFish, Di
bW = new BufferedWriter(
new FileWriter(new File(group.getOutputPath() + fileNameOutput + group.getSimulationId() + ".csv")));
bW.write("year" + sep + "migrationBasin" + sep + "originBasin" + sep + "effective");
bW.write("year" + sep + "migrationBasin" + sep + "natalBasin" + sep + "effective");
bW.write("\n");
} catch (IOException e) {
e.printStackTrace();
}
}
}
Time time = group.getEnvironment().getTime();
if (years.contains(time.getYear(group.getPilot())) && time.getSeason(group.getPilot()) == fluxesSeason) {
if (time.getYear(group.getPilot()) >= yearStart && time.getYear(group.getPilot()) <= yearEnd
&& time.getSeason(group.getPilot()) == fluxesSeason) {
String[] basinNames = group.getEnvironment().getRiverBasinNames();
// put in hasmap
if (records == null)
records = new ArrayList<Record>();
for (RiverBasin basin : group.getEnvironment().getRiverBasins()) {
for (RiverBasin originBasin : group.getEnvironment().getRiverBasins()) {
long effective = Math.round(basin.getSpawnerOrigins().getMeans().get(originBasin.getName()));
records.add(new Record(time.getYear(group.getPilot()), basin.getName(), originBasin.getName(), effective));
// display headers on console
if (consoleDisplay) {
System.out.print("migration\\natal" + "\t");
for (String basinName : basinNames) {
System.out.print(basinName + "\t");
}
System.out.println();
}
// write in file
if (fileNameOutput != null) {
try {
for (RiverBasin migrationBasin : group.getEnvironment().getRiverBasins()) {
for (String originBasinName : basinNames) {
bW.write(time.getYear(group.getPilot()) + sep + migrationBasin.getName() + sep + originBasinName);
bW.write(sep + Math.round(migrationBasin.getSpawnerOrigins().getMeans().get(originBasinName)));
bW.write("\n");
}
}
bW.flush();
} catch (IOException e) {
e.printStackTrace();
for (RiverBasin migrationBasin : group.getEnvironment().getRiverBasins()) {
// /display data on console
if (consoleDisplay) {
System.out.print(migrationBasin.getName() + '\t');
}
// display in console
if (consoleDisplay) {
System.out.print("MIGRATION" + "\t");
for (String basinName : basinNames) {
System.out.print(basinName + "\t");
}
System.out.println();
for (RiverBasin basin : group.getEnvironment().getRiverBasins()) {
System.out.print(basin.getName() + '\t');
for (String natalBasinName : basinNames) {
double effective = Math.round(migrationBasin.getSpawnerOrigins().getMeans().get(natalBasinName));
for (String basinName : basinNames) {
System.out.print(+Math.round(basin.getSpawnerOrigins().getMeans().get(basinName)) + "\t");
if (consoleDisplay)
System.out.print(effective + "\t");
// write in the file
if (fileNameOutput != null) {
try {
bW.write(time.getYear(group.getPilot()) + sep + migrationBasin.getName() + sep + natalBasinName);
bW.write(sep + effective + "\n");
} catch (IOException e) {
e.printStackTrace();
}
System.out.println();
}
}
if (consoleDisplay) {
System.out.println();
}
}
}
// cloce the bW at end
if (group.getPilot().getCurrentTime() == group.getPilot().getSimBegin() + group.getPilot().getSimDuration() - 1) {
try {
bW.flush();
bW.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
/**
* @return the records
*/
public List<Record> getRecords() {
return this.records;
}
}
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