Commit ad365ec9 authored by Dumoulin Nicolas's avatar Dumoulin Nicolas
Browse files

cleanup

parent 11afd67a
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>
.classpath
.project
.settings
target
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>SturioSaintSeurin</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
eclipse.preferences.version=1
encoding/<project>=ISO-8859-15
encoding/src=ISO-8859-15
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.6
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.source=1.6
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>SturioSaintSeurin</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
eclipse.preferences.version=1
encoding/<project>=ISO-8859-15
encoding/src=ISO-8859-15
/**
* Patrick.Lambert
* @author Patrick Lambert
* @copyright Copyright (c) 2014, Irstea
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package species;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.TreeMap;
import species.Sturgeon.Gender;
import species.Sturgeon.Status;
import environment.Station;
import fr.cemagref.observation.kernel.Observable;
import fr.cemagref.simaqualife.kernel.AquaNismsGroup;
import fr.cemagref.simaqualife.pilot.Pilot;
/**
*
*/
public class SturgeonGroup extends AquaNismsGroup<Sturgeon, Station> {
private transient Map<String, List<Sturgeon>> batches;
private transient List<Integer> femaleSpawnerNbHistory;
private transient List<Double> larvaeProductionHistory;
private transient double annualLarvaeProduction;
@Override
public void initTransientParameters(Pilot pilot) throws IllegalArgumentException,
IllegalAccessException, InvocationTargetException {
// TODO Auto-generated method stub
super.initTransientParameters(pilot);
batches = new TreeMap<String, List<Sturgeon>>();
femaleSpawnerNbHistory = new LinkedList<Integer>();
larvaeProductionHistory = new LinkedList<Double>();
}
@Override
public void addAquaNism(Sturgeon fish) {
super.addAquaNism(fish);
if(batches.containsKey(fish.getBatchName())){
batches.get(fish.getBatchName()).add(fish);
}
else {
List<Sturgeon> batch = new ArrayList<Sturgeon>();
batch.add(fish);
batches.put(fish.getBatchName(), batch);
}
}
@Override
public void removeAquaNism(Sturgeon fish) {
// TODO Auto-generated method stub
super.removeAquaNism(fish);
batches.get(fish.getBatchName()).remove(fish);
}
public void printNumberInBatches(){
int total=0;
for (Entry<String, List<Sturgeon>> entry : batches.entrySet()){
System.out.println(" "+ entry.getKey()+ ":\t"+entry.getValue().size());
total += entry.getValue().size();
}
System.out.println("-->"+total+"vs"+this.getAquaNismsList().size());
}
@Observable(description = "Fish number")
public int getFishNumber() {
if ( this.getAquaNismsList() != null)
return this.getAquaNismsList().size();
else
return 0;
}
public Integer[] getFemaleHistory() {
return (Integer[]) femaleSpawnerNbHistory.toArray();
}
@Observable(description = "nb of female ready to spawn")
public int getNumberOfFemaleInMaturation() {
int nb=0;
for (Sturgeon fish : this.getAquaNismsList()){
if (fish.getGender() == Gender.FEMALE & fish.isReadyToSpawn()){
nb++;
}
}
return nb;
}
@Observable(description = "nb of male ready to spawn")
public int getNumberOfMaleInMaturation() {
int nb=0;
for (Sturgeon fish : this.getAquaNismsList()){
if (fish.getGender() == Gender.MALE & fish.isReadyToSpawn()){
nb++;
}
}
return nb;
}
@Observable(description = "nb of normal fish")
public int getNormalFishNumber() {
int nb=0;
for (Sturgeon fish : this.getAquaNismsList()){
if (fish.getStatus() == Status.NORMAL){
nb++;
}
}
return nb;
}
@Observable(description = "nb of deformed fish")
public int getDeformedFishNumber() {
int nb=0;
for (Sturgeon fish : this.getAquaNismsList()){
if (fish.getStatus() == Status.DEFORMED){
nb++;
}
}
return nb;
}
@Observable(description = "annual larvae production")
public double getAnnualLarvaeProduction() {
return Math.round(annualLarvaeProduction * 1000.)/1000.;
}
public void setAnnualLarvaeProduction(double annualLarvaeProduction) {
this.annualLarvaeProduction = annualLarvaeProduction;
}
public void setLarvaeProductionHistory(List<Double> larvaeProductionHistory) {
this.larvaeProductionHistory = larvaeProductionHistory;
}
public Map<String, List<Sturgeon>> getBatches() {
return batches;
}
public List<Integer> getFemaleSpawnerNbHistory() {
return femaleSpawnerNbHistory;
}
public List<Double> getLarvaeProductionHistory() {
return larvaeProductionHistory;
}
@Observable(description = "female spawner history")
public Integer[] getFemaleSpawnersArray() {
Integer[] output= new Integer[femaleSpawnerNbHistory.size()];
for(int i=0; i < femaleSpawnerNbHistory.size(); i++){
output[i] =femaleSpawnerNbHistory.get(i);
}
return output;
}
@Observable(description = "female spawner history")
public String getFemaleSpawnersString() {
String output="";
String sep="";
for (int i=0; i< femaleSpawnerNbHistory.size(); i++){
output=output.concat(sep).concat(femaleSpawnerNbHistory.get(i).toString());
sep=", ";
}
return output;
}
@Observable(description = "larvae hsitory history")
public String getLarvaeProductionString() {
String output="";
String sep="";
for (int i=0; i< larvaeProductionHistory.size(); i++){
output=output.concat(sep).concat(larvaeProductionHistory.get(i).toString());
sep=", ";
}
return output;
}
}
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<!-- ************************************************************* -->
<!-- *** POM Relationships *************************************** -->
<!-- ************************************************************* -->
<groupId>SturioSaintSeurin</groupId>
<artifactId>SturioSaintSeurin</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>fr.cemagref</groupId>
<artifactId>simaqualife</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
<type>jar</type>
</dependency>
</dependencies>
<!-- ************************************************************* -->
<!-- *** Project Information ************************************* -->
<!-- ************************************************************* -->
<name>${project.artifactId} ${project.version}</name>
<description></description>
<url></url>
<licenses>
<license>
<name>GPL</name>
<url>http://www.gnu.org/copyleft/gpl.html</url>
<distribution>repo</distribution>
</license>
</licenses>
<!-- ************************************************************* -->
<!-- *** Build Settings ****************************************** -->
<!-- ************************************************************* -->
<packaging>jar</packaging>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>assembly</goal>
</goals>
<configuration>
<appendAssemblyId>false</appendAssemblyId>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<configuration>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>resources</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<manifestLocation>target/META-INF</manifestLocation>
<finalName>${symbolic.name}_${project.version}</finalName>
<instructions>
<Bundle-Name>${project.groupId}.${project.artifactId}</Bundle-Name>
<Bundle-SymbolicName>${project.groupId}.${project.artifactId}</Bundle-SymbolicName>
<Import-Package>*;resolution:=optional</Import-Package>
<Export-Package>fr.cemagref.simaqualife.extensions.pilot.BatchRunner;fr.cemagref.simaqualife.*;miscellaneous.*</Export-Package>
<Embed-Dependency>*;scope=!provided;inline=true</Embed-Dependency>
<Embed-Transitive>true</Embed-Transitive>
<eclipse.buddypolicy>global</eclipse.buddypolicy>
</instructions>
</configuration>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>trac.clermont.cemagref.fr.nexus.public</id>
<url>http://trac.clermont.cemagref.fr/nexus/content/groups/public</url>
</repository>
<repository>
<id>trac.clermont.cemagref.fr.nexus.snapshots</id>
<url>http://trac.clermont.cemagref.fr/nexus/content/repositories/snapshots</url>
</repository>
<repository>
<id>maven2-repository.dev.java.net</id>
<name>Java.net repository</name>
<url>http://download.java.net/maven/2</url>
</repository>
</repositories>
<properties>
<project.build.sourceEncoding>ISO-8859-15</project.build.sourceEncoding>
<build.timestamp>${maven.build.timestamp}</build.timestamp>
<netbeans.hint.license>gpl30</netbeans.hint.license>
</properties>
</project>
\ No newline at end of file
/**
* Patrick.Lambert
* @author Patrick Lambert
* @copyright Copyright (c) 2014, Irstea
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/**
*
*/
package environment;
\ No newline at end of file
package observer;
import java.lang.reflect.InvocationTargetException;
import fr.cemagref.observation.kernel.ObservablesHandler;
import fr.cemagref.observation.observers.ConsoleObserver;
import fr.cemagref.ohoui.annotations.Description;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
public class MyCSVObserver extends ConsoleObserver {
@Description(name = "Field separator", tooltip = "")
protected char separator = ';';
private List<String> observables;
protected transient List<ObservablesHandler.ObservableFetcher> fetchers;
/**
* <code>classObservable</code> is used to display name of attributes as
* header
*/
private transient ObservablesHandler classObservable;
public MyCSVObserver() {
}
public MyCSVObserver(boolean sysout, String outputFile) {
super(sysout, outputFile);
}
public MyCSVObserver(boolean sysout, String outputFile, String... obsvervables) {
super(sysout, outputFile);
this.observables = Arrays.asList(obsvervables);
}
public List<String> getObservables() {
return observables;
}
@Override
public void addObservable(ObservablesHandler classObservable) {
ObservablesHandler bak = this.classObservable;
this.classObservable = classObservable;
if (bak != null) // The observable has been changed
{
this.init();
}
}
@Override
public void valueChanged(ObservablesHandler clObservable, Object instance, long t) {
if (isInDates(t)) {
StringBuffer buf = new StringBuffer();
StringBuffer sbSeparator = new StringBuffer(" " + this.separator + " ");
// print current Time
buf.append(t);
// print value of each field
for (ObservablesHandler.ObservableFetcher fetcher : fetchers) {
buf.append(sbSeparator);
Object value = getValue(fetcher, instance);
buf.append(value == null ? "N/A" : value);
}
outputStream.println(buf);
}
}
/**
*
* @param fetcher
* @param instance
* @return the value returned by the fetcher or null if a problem has
* occured due to the introspection.
*/
protected Object getValue(ObservablesHandler.ObservableFetcher fetcher, Object instance) {
try {
return fetcher.fetchValue(instance);
} catch (IllegalArgumentException ex) {
Logger.getLogger(MyCSVObserver.class.getName()).log(Level.SEVERE, null, ex);
return null;
} catch (IllegalAccessException ex) {
Logger.getLogger(MyCSVObserver.class.getName()).log(Level.SEVERE, null, ex);
return null;
} catch (InvocationTargetException ex) {
Logger.getLogger(MyCSVObserver.class.getName()).log(Level.SEVERE, null, ex);
return null;
}
}
@Override
public void init() {
super.init();
if (classObservable != null) {
fetchers = new ArrayList<ObservablesHandler.ObservableFetcher>();
if (observables != null) {
for (String name : observables) {
fetchers.add(classObservable.getObservableFetcherByName(name));
}
} else {
fetchers.addAll(Arrays.asList(classObservable.getObservableFetchers()));
}
// Headers printing
StringBuffer buf = new StringBuffer();
StringBuffer sbSeparator = new StringBuffer(" " + this.separator + " ");
buf.append("Year");
buf.append(sbSeparator);