Commit 7fd22080 authored by patrick.lambert's avatar patrick.lambert
Browse files

first step to an export into string matrix

parent 0496e161
......@@ -32,8 +32,8 @@ import fr.cemagref.simaqualife.kernel.processes.AquaNismsGroupProcess;
import fr.cemagref.simaqualife.pilot.Pilot;
import miscellaneous.QueueMemory;
import species.DiadromousFish;
import species.DiadromousFishGroup;
import species.DiadromousFish.Gender;
import species.DiadromousFishGroup;
/**
*
......@@ -43,9 +43,9 @@ public class AnalyseSpawnerFeatures extends AquaNismsGroupProcess<DiadromousFish
private int memorySize = 30;
private Season analysisSeason = Season.SPRING;
private transient Map<Integer, QueueMemory<Double>> femaleAgeMemories;
private transient Map<Integer, QueueMemory<Double>> maleAgeMemories;
private transient Map<Integer, QueueMemory<Double>> primiparousMemories;
private transient Map<RiverBasin, QueueMemory<Double>> femaleAgeMemories;
private transient Map<RiverBasin, QueueMemory<Double>> maleAgeMemories;
private transient Map<RiverBasin, QueueMemory<Double>> primiparousMemories;
@Override
public void initTransientParameters(Pilot pilot) {
......@@ -59,14 +59,14 @@ public class AnalyseSpawnerFeatures extends AquaNismsGroupProcess<DiadromousFish
// first passage
if (femaleAgeMemories == null) {
femaleAgeMemories = new HashMap<Integer, QueueMemory<Double>>();
maleAgeMemories = new HashMap<Integer, QueueMemory<Double>>();
primiparousMemories = new HashMap<Integer, QueueMemory<Double>>();
femaleAgeMemories = new HashMap<RiverBasin, QueueMemory<Double>>();
maleAgeMemories = new HashMap<RiverBasin, QueueMemory<Double>>();
primiparousMemories = new HashMap<RiverBasin, QueueMemory<Double>>();
for (RiverBasin riverBasin : group.getEnvironment().getRiverBasins()) {
femaleAgeMemories.put(riverBasin.getBasin_id(), new QueueMemory<>(memorySize));
maleAgeMemories.put(riverBasin.getBasin_id(), new QueueMemory<>(memorySize));
primiparousMemories.put(riverBasin.getBasin_id(), new QueueMemory<>(memorySize));
femaleAgeMemories.put(riverBasin, new QueueMemory<>(memorySize));
maleAgeMemories.put(riverBasin, new QueueMemory<>(memorySize));
primiparousMemories.put(riverBasin, new QueueMemory<>(memorySize));
}
}
......@@ -104,11 +104,11 @@ public class AnalyseSpawnerFeatures extends AquaNismsGroupProcess<DiadromousFish
}
// add value in the queues
if (nbAgeForFemale > 0.)
femaleAgeMemories.get(riverBasin.getBasin_id()).push(meanAgeForFemale / nbAgeForFemale);
femaleAgeMemories.get(riverBasin).push(meanAgeForFemale / nbAgeForFemale);
else
femaleAgeMemories.get(riverBasin.getBasin_id()).push(Double.NaN);
femaleAgeMemories.get(riverBasin).push(Double.NaN);
if (nbAgeForMale > 0.)
maleAgeMemories.get(riverBasin.getBasin_id()).push(meanAgeForMale / nbAgeForMale);
maleAgeMemories.get(riverBasin).push(meanAgeForMale / nbAgeForMale);
else
maleAgeMemories.get(riverBasin.getBasin_id()).push(Double.NaN);
if (nbOfSpawners > 0.)
......@@ -121,17 +121,24 @@ public class AnalyseSpawnerFeatures extends AquaNismsGroupProcess<DiadromousFish
}
public double[][] exportToR() {
public String[][] exportToR() {
int nbBasin = femaleAgeMemories.size();
double[][] result = new double[nbBasin][4];
int i = 0;
for (Entry<Integer, QueueMemory<Double>> entry : femaleAgeMemories.entrySet()) {
result[i][0] = entry.getKey();
result[i][1] = entry.getValue().getMean();
result[i][2] = maleAgeMemories.get(entry.getKey()).getMean();
result[i][3] = primiparousMemories.get(entry.getKey()).getMean();
String[][] result = new String[nbBasin + 1][4];
// headers
result[0][0] = "basin_id";
result[0][1] = "basin_name";
result[0][2] = "mean_age_female";
result[0][3] = "mean_age _male";
result[0][4] = "pct_primiparous";
int i = 1;
for (Entry<RiverBasin, QueueMemory<Double>> entry : femaleAgeMemories.entrySet()) {
result[i][0] = String.valueOf(entry.getKey().getBasin_id());
result[i][1] = entry.getKey().getName();
result[i][2] = String.valueOf(entry.getValue().getMean());
result[i][3] = String.valueOf(maleAgeMemories.get(entry.getKey()).getMean());
result[i][4] = String.valueOf(primiparousMemories.get(entry.getKey()).getMean());
i++;
}
......
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