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

add a new observer

parent 5f5f855b
......@@ -19,18 +19,24 @@
*/
package analysis;
import java.util.ArrayList;
import java.util.HashMap;
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;
import environment.RIOBasinNetwork;
import environment.RiverBasin;
import environment.Time.Season;
import fr.cemagref.observation.kernel.Observable;
import fr.cemagref.observation.kernel.ObservablesHandler;
import fr.cemagref.simaqualife.kernel.processes.AquaNismsGroupProcess;
import fr.cemagref.simaqualife.pilot.Pilot;
import miscellaneous.QueueMemory;
import observer.ObservableRecord;
import species.DiadromousFish;
import species.DiadromousFish.Gender;
import species.DiadromousFishGroup;
......@@ -47,10 +53,25 @@ public class AnalyseSpawnerFeatures extends AquaNismsGroupProcess<DiadromousFish
private transient Map<RiverBasin, QueueMemory<Double>> maleAgeMemories;
private transient Map<RiverBasin, QueueMemory<Double>> primiparousMemories;
protected static transient ObservablesHandler cobservable;
@Override
public void initTransientParameters(Pilot pilot) {
super.initTransientParameters(pilot);
femaleAgeMemories = new HashMap<RiverBasin, QueueMemory<Double>>();
maleAgeMemories = new HashMap<RiverBasin, QueueMemory<Double>>();
primiparousMemories = new HashMap<RiverBasin, QueueMemory<Double>>();
for (RiverBasin riverBasin : ((RIOBasinNetwork) pilot.getAquaticWorld().getEnvironment()).getRiverBasins()) {
femaleAgeMemories.put(riverBasin, new QueueMemory<>(memorySize));
maleAgeMemories.put(riverBasin, new QueueMemory<>(memorySize));
primiparousMemories.put(riverBasin, new QueueMemory<>(memorySize));
}
if (cobservable == null) {
cobservable = pilot.addObservable(this.getClass());
}
}
......@@ -59,15 +80,7 @@ public class AnalyseSpawnerFeatures extends AquaNismsGroupProcess<DiadromousFish
// first passage
if (femaleAgeMemories == null) {
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, new QueueMemory<>(memorySize));
maleAgeMemories.put(riverBasin, new QueueMemory<>(memorySize));
primiparousMemories.put(riverBasin, new QueueMemory<>(memorySize));
}
this.initTransientParameters(group.getPilot());
}
if (group.getEnvironment().getTime().getSeason(group.getPilot()) == analysisSeason) {
......@@ -117,7 +130,27 @@ public class AnalyseSpawnerFeatures extends AquaNismsGroupProcess<DiadromousFish
primiparousMemories.get(riverBasin).push(Double.NaN);
}
}
// --------------------------------------------------------------------------------------------------
// update the observers
// ------------------------------------------------------------------------------------------------------
cobservable.fireChanges(this, pilot.getCurrentTime());
}
}
@Observable(description = "PrimarousRate versus latitude")
public List<Record> getPrimarousRateVsLatitude() {
List<Record> records = new ArrayList<Record>();
for (Entry<RiverBasin, QueueMemory<Double>> entry : primiparousMemories.entrySet()) {
double latitude = entry.getKey().getLatitude();
double meanPrimarousRate = entry.getValue().getMeanWithoutNaN();
records.add(new Record(latitude, meanPrimarousRate));
}
return records;
}
......@@ -147,6 +180,18 @@ public class AnalyseSpawnerFeatures extends AquaNismsGroupProcess<DiadromousFish
}
private class Record implements ObservableRecord {
@Information(unit = "°")
private double latitude;
@Information(unit = "#/#")
private double meanPrimarousRate;
public Record(double latitude, double meanPrimarousRate) {
this.latitude = latitude;
this.meanPrimarousRate = meanPrimarousRate;
}
}
public static void main(String[] args) {
System.out.println((new XStream(new DomDriver())).toXML(new AnalyseSpawnerFeatures()));
......
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