Isis-fish-commits
Threads by month
- ----- 2026 -----
- June
- May
- April
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
June 2014
- 6 participants
- 42 discussions
r4027 - in trunk: . src/main/java/fr/ifremer/isisfish src/main/java/fr/ifremer/isisfish/datastore src/main/java/fr/ifremer/isisfish/simulator src/main/java/fr/ifremer/isisfish/simulator/launcher src/main/java/fr/ifremer/isisfish/types src/main/java/fr/ifremer/isisfish/ui src/main/java/fr/ifremer/isisfish/ui/simulator src/main/resources/i18n
by bpoussin@users.forge.codelutin.com 30 Jun '14
by bpoussin@users.forge.codelutin.com 30 Jun '14
30 Jun '14
Author: bpoussin
Date: 2014-06-30 19:08:42 +0200 (Mon, 30 Jun 2014)
New Revision: 4027
Url: http://forge.codelutin.com/projects/isis-fish/repository/revisions/4027
Log:
- permit to configure number of step result to save
- add memory cache in ResultStorageCSV with configurable size
- ResultStorageInMemory is now deprecated
- add some information in param tag/value to transfert configuration to server
- add some method in TimeStep (add, minus, gap)
- add information about ResultStorage used in simulation
Modified:
trunk/pom.xml
trunk/src/main/java/fr/ifremer/isisfish/IsisConfig.java
trunk/src/main/java/fr/ifremer/isisfish/datastore/ResultMappedStorage.java
trunk/src/main/java/fr/ifremer/isisfish/datastore/ResultStorage.java
trunk/src/main/java/fr/ifremer/isisfish/datastore/ResultStorageAbstract.java
trunk/src/main/java/fr/ifremer/isisfish/datastore/ResultStorageCSV.java
trunk/src/main/java/fr/ifremer/isisfish/datastore/ResultStorageInMemory.java
trunk/src/main/java/fr/ifremer/isisfish/simulator/SimulationContext.java
trunk/src/main/java/fr/ifremer/isisfish/simulator/launcher/InProcessSimulatorLauncher.java
trunk/src/main/java/fr/ifremer/isisfish/types/TimeStep.java
trunk/src/main/java/fr/ifremer/isisfish/ui/WelcomeHandler.java
trunk/src/main/java/fr/ifremer/isisfish/ui/simulator/SimulAction.java
trunk/src/main/resources/i18n/isis-fish_en_GB.properties
trunk/src/main/resources/i18n/isis-fish_fr_FR.properties
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2014-06-29 18:44:00 UTC (rev 4026)
+++ trunk/pom.xml 2014-06-30 17:08:42 UTC (rev 4027)
@@ -27,7 +27,7 @@
<dependency>
<groupId>org.nuiton</groupId>
<artifactId>nuiton-config</artifactId>
- <version>3.0-alpha-2</version>
+ <version>3.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
Modified: trunk/src/main/java/fr/ifremer/isisfish/IsisConfig.java
===================================================================
--- trunk/src/main/java/fr/ifremer/isisfish/IsisConfig.java 2014-06-29 18:44:00 UTC (rev 4026)
+++ trunk/src/main/java/fr/ifremer/isisfish/IsisConfig.java 2014-06-30 17:08:42 UTC (rev 4027)
@@ -54,6 +54,7 @@
import fr.ifremer.isisfish.actions.OtherAction;
import fr.ifremer.isisfish.actions.SimulationAction;
import fr.ifremer.isisfish.actions.VCSAction;
+import fr.ifremer.isisfish.datastore.SimulationStorage;
import fr.ifremer.isisfish.simulator.SimulationContext;
import fr.ifremer.isisfish.simulator.SimulationControl;
import fr.ifremer.isisfish.simulator.launcher.InProcessSimulatorLauncher;
@@ -63,6 +64,7 @@
import fr.ifremer.isisfish.util.IsisCacheBackend;
import fr.ifremer.isisfish.util.IsisCacheBackendOnGuava;
import fr.ifremer.isisfish.vcs.VCS;
+import org.nuiton.config.OverwriteApplicationConfig;
import org.nuiton.math.matrix.DoubleVector;
/**
@@ -193,10 +195,8 @@
addActionAlias(alias, a.action);
}
}
-
}
-
//////////////////////////////////////////////////
// Methode d'acces aux options
//////////////////////////////////////////////////
@@ -831,7 +831,33 @@
saveForUser();
}
+ /**
+ * Retourne toutes les configurations specifiques aux simulations.
+ * Ces configurations sont cotes clients, mais lorsqu'on fait une simulation
+ * sur un serveur, il faut quelles soient utilisees a la place des valeurs
+ * du serveur
+ *
+ * @return
+ */
+ public Map<String, String> getDefaultSimulationConfig() {
+ Map<String, String> result = new HashMap<String, String>();
+ result.put(Option.SIMULATION_MATRIX_VECTOR_CLASS.key,
+ getOption(Option.SIMULATION_MATRIX_VECTOR_CLASS.key));
+ result.put(Option.SIMULATION_MATRIX_VECTOR_SPARSE_CLASS.key,
+ getOption(Option.SIMULATION_MATRIX_VECTOR_SPARSE_CLASS.key));
+ result.put(Option.SIMULATION_MATRIX_THRESHOLD_USE_SPARSE_CLASS.key,
+ getOption(Option.SIMULATION_MATRIX_THRESHOLD_USE_SPARSE_CLASS.key));
+ result.put(Option.SIMULATION_STORE_RESULT_ON_DISK.key,
+ getOption(Option.SIMULATION_STORE_RESULT_ON_DISK.key));
+ result.put(Option.SIMULATION_STORE_RESULT_CACHE_STEP.key,
+ getOption(Option.SIMULATION_STORE_RESULT_CACHE_STEP.key));
+
+ result.put(Option.CACHE_BACKEND_FACTORY_CLASS.key,
+ getOption(Option.CACHE_BACKEND_FACTORY_CLASS.key));
+
+ return result;
+ }
/**
* @return le dictionnaire des tags par defaut d'une simulation a partir
@@ -955,7 +981,8 @@
* @since 4.2.0.2
*/
public Class getSimulationMatrixVectorClass() {
- Class result = getOptionAsClass(Option.SIMULATION_MATRIX_VECTOR_CLASS.key);
+ ApplicationConfig config = SimulationContext.get().getConfig();
+ Class result = config.getOptionAsClass(Option.SIMULATION_MATRIX_VECTOR_CLASS.key);
return result;
}
@@ -967,7 +994,8 @@
* @since 4.2.0.2
*/
public Class getSimulationMatrixVectorSparseClass() {
- Class result = getOptionAsClass(Option.SIMULATION_MATRIX_VECTOR_SPARSE_CLASS.key);
+ ApplicationConfig config = SimulationContext.get().getConfig();
+ Class result = config.getOptionAsClass(Option.SIMULATION_MATRIX_VECTOR_SPARSE_CLASS.key);
return result;
}
@@ -978,18 +1006,45 @@
* @since 4.2.0.2
*/
public int getSimulationMatrixThresholdUseSparse() {
- int result = getOptionAsInt(Option.SIMULATION_MATRIX_THRESHOLD_USE_SPARSE_CLASS.key);
+ ApplicationConfig config = SimulationContext.get().getConfig();
+ int result = config.getOptionAsInt(Option.SIMULATION_MATRIX_THRESHOLD_USE_SPARSE_CLASS.key);
return result;
}
/**
+ * Indique le nombre de pas qui doivent etre sauve, en partant du dernier pas
+ * de temps.
+ *
+ * @return
+ * @since 4.2.0.2
+ */
+ public int getSimulationStoreResultOnDisk() {
+ ApplicationConfig config = SimulationContext.get().getConfig();
+ int result = config.getOptionAsInt(Option.SIMULATION_STORE_RESULT_ON_DISK.key);
+ return result;
+ }
+
+ /**
+ * Indique le nombre de pas qui doivent rester en memoire durant la simulation
+ *
+ * @return
+ * @since 4.2.0.2
+ */
+ public int getSimulationStoreResultCacheStep() {
+ ApplicationConfig config = SimulationContext.get().getConfig();
+ int result = config.getOptionAsInt(Option.SIMULATION_STORE_RESULT_CACHE_STEP.key);
+ return result;
+ }
+
+ /**
* Retourne la factory a utilise pour le cache
*
* @return factory a utilise pour le backend de cache
* @since 4.2.1.2
*/
public IsisCacheBackend.Factory getCacheBackendFactoryClass() {
- IsisCacheBackend.Factory result = getOptionAsObject(
+ ApplicationConfig config = SimulationContext.get().getConfig();
+ IsisCacheBackend.Factory result = config.getOptionAsObject(
IsisCacheBackend.Factory.class, Option.CACHE_BACKEND_FACTORY_CLASS.key);
return result;
}
@@ -1030,6 +1085,8 @@
SIMULATION_MATRIX_VECTOR_CLASS("simulation.matrix.vector.class", n("isisfish.config.simulation.matrix.vector.class.description"), DoubleBigVector.class.getName()),
SIMULATION_MATRIX_VECTOR_SPARSE_CLASS("simulation.matrix.vector.sparse.class", n("isisfish.config.simulation.matrix.vector.sparse.class.description"), DoubleVector.class.getName()),
SIMULATION_MATRIX_THRESHOLD_USE_SPARSE_CLASS("simulation.matrix.threshold.use.sparse.class", n("isisfish.config.simulation.matrix.threshold.use.sparse.class.description"), "1000"),
+ SIMULATION_STORE_RESULT_ON_DISK("simulation.store.result.ondisk", n("isisfish.config.simulation.store.result.ondisk.description"), "-1"),
+ SIMULATION_STORE_RESULT_CACHE_STEP("simulation.store.result.cachestep", n("isisfish.config.simulation.store.result.cachestep.description"), "13"),
/** Nombre maximum de thread de simulation in process. */
SIMULATOR_IN_MAXTHREADS("simulation.in.max.threads", n("isisfish.config.main.simulation.in.max.threads.description"), "1"),
Modified: trunk/src/main/java/fr/ifremer/isisfish/datastore/ResultMappedStorage.java
===================================================================
--- trunk/src/main/java/fr/ifremer/isisfish/datastore/ResultMappedStorage.java 2014-06-29 18:44:00 UTC (rev 4026)
+++ trunk/src/main/java/fr/ifremer/isisfish/datastore/ResultMappedStorage.java 2014-06-30 17:08:42 UTC (rev 4027)
@@ -30,7 +30,6 @@
import java.io.IOException;
import java.io.RandomAccessFile;
import java.util.ArrayList;
-import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
@@ -50,7 +49,6 @@
import fr.ifremer.isisfish.IsisFishRuntimeException;
import fr.ifremer.isisfish.types.TimeStep;
import fr.ifremer.isisfish.util.BitUtil;
-import java.util.HashMap;
/**
* Cette classe permet de conserver des résultats de simulation. Elle permet
@@ -73,8 +71,8 @@
protected RandomAccessFile raf;
protected long offset;
- protected Map<TimeStep, Map<String, ResultMapped>> stepNameResults =
- new TreeMap<TimeStep, Map<String, ResultMapped>>();
+// protected Map<TimeStep, Map<String, ResultMapped>> stepNameResults =
+// new TreeMap<TimeStep, Map<String, ResultMapped>>();
protected Map<String, Map<TimeStep, ResultMapped>> nameStepResults =
new TreeMap<String, Map<TimeStep, ResultMapped>>();
@@ -364,18 +362,18 @@
TimeStep step = r.getStep();
String name = r.getName();
- getResult(step).put(name, r);
+// getResult(step).put(name, r);
getResult(name).put(step, r);
}
- protected Map<String, ResultMapped> getResult(TimeStep step) {
- Map<String, ResultMapped> result = stepNameResults.get(step);
- if (result == null) {
- result = new TreeMap<String, ResultMapped>();
- stepNameResults.put(step, result);
- }
- return result;
- }
+// protected Map<String, ResultMapped> getResult(TimeStep step) {
+// Map<String, ResultMapped> result = stepNameResults.get(step);
+// if (result == null) {
+// result = new TreeMap<String, ResultMapped>();
+// stepNameResults.put(step, result);
+// }
+// return result;
+// }
protected Map<TimeStep, ResultMapped> getResult(String name) {
Map<TimeStep, ResultMapped> result = nameStepResults.get(name);
@@ -390,7 +388,7 @@
protected MatrixND readResult(TimeStep step, String name) {
MatrixND result = null;
- ResultMapped rm = getResult(step).get(name);
+ ResultMapped rm = getResult(name).get(step);
if (rm != null) {
result = rm.getMatrix();
}
@@ -398,18 +396,18 @@
return result;
}
- @Override
- protected Map<TimeStep, MatrixND> readResult(String name) {
- Map<TimeStep, MatrixND> result = Collections.EMPTY_MAP;
- Map<TimeStep, ResultMapped> rms = nameStepResults.get(name);
- if (rms != null) {
- result = new HashMap<TimeStep, MatrixND>();
- for (Map.Entry<TimeStep, ResultMapped> e : rms.entrySet()) {
- result.put(e.getKey(), e.getValue().getMatrix());
- }
- }
- return result;
- }
+// @Override
+// protected Map<TimeStep, MatrixND> readResult(String name) {
+// Map<TimeStep, MatrixND> result = Collections.EMPTY_MAP;
+// Map<TimeStep, ResultMapped> rms = nameStepResults.get(name);
+// if (rms != null) {
+// result = new HashMap<TimeStep, MatrixND>();
+// for (Map.Entry<TimeStep, ResultMapped> e : rms.entrySet()) {
+// result.put(e.getKey(), e.getValue().getMatrix());
+// }
+// }
+// return result;
+// }
@Override
protected void writeResult(TimeStep step, String name, MatrixND mat) {
Modified: trunk/src/main/java/fr/ifremer/isisfish/datastore/ResultStorage.java
===================================================================
--- trunk/src/main/java/fr/ifremer/isisfish/datastore/ResultStorage.java 2014-06-29 18:44:00 UTC (rev 4026)
+++ trunk/src/main/java/fr/ifremer/isisfish/datastore/ResultStorage.java 2014-06-30 17:08:42 UTC (rev 4027)
@@ -42,6 +42,13 @@
public interface ResultStorage extends SimulationResultListener {
/**
+ * Return some information on result storage. Information depend on
+ * result storage type
+ * @return
+ */
+ public String getInfo();
+
+ /**
* Permet de savoir si lorsque l'on ajoutera ce resultat, il sera
* sauvé ou non.
*
Modified: trunk/src/main/java/fr/ifremer/isisfish/datastore/ResultStorageAbstract.java
===================================================================
--- trunk/src/main/java/fr/ifremer/isisfish/datastore/ResultStorageAbstract.java 2014-06-29 18:44:00 UTC (rev 4026)
+++ trunk/src/main/java/fr/ifremer/isisfish/datastore/ResultStorageAbstract.java 2014-06-30 17:08:42 UTC (rev 4027)
@@ -28,7 +28,6 @@
import static org.nuiton.i18n.I18n.t;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
@@ -66,6 +65,7 @@
import fr.ifremer.isisfish.simulator.SimulationResultListener;
import fr.ifremer.isisfish.types.Month;
import fr.ifremer.isisfish.types.TimeStep;
+import java.util.LinkedHashMap;
import org.nuiton.math.matrix.MatrixFactory;
/**
@@ -88,6 +88,7 @@
static private Log log = LogFactory.getLog(ResultStorageAbstract.class);
protected SimulationStorage simulation = null;
+ protected EntitySemanticsDecorator decorator;
/** result enabled */
transient protected Set<String> enabledResult = null;
@@ -96,12 +97,12 @@
* Convertie une entite, month, timestep en string et inversement.
* Entity = "TopiaId:Entity.toString"
*/
- static protected class EntitySemanticsDecorator implements SemanticsDecorator {
+ static protected class EntitySemanticsDecorator implements SemanticsDecorator<Object, String> {
static final private String SEP = ":";
protected TopiaContext tx;
/** en cle les representation interne (get) en valeur les valeurs decoree (getKey) */
- protected BidiMap<Object, Object> cache = new DualHashBidiMap<>();
+ protected BidiMap<String, Object> cache = new DualHashBidiMap<>();
public EntitySemanticsDecorator() {
}
@@ -111,39 +112,36 @@
}
@Override
- public Object decorate(Object internalValue) {
+ public Object decorate(String internalValue) {
Object result = cache.get(internalValue);
if (result == null && internalValue != null) {
+ // on retrouve souvent les memes semantiques dans les matrices
+ // pour minimiser les chaines en memoire, on prend la representation
+ // interne avant de l'utiliser comme cle.
+ internalValue = internalValue.intern();
result = internalValue;
- if (internalValue instanceof String) {
- // on retrouve souvent les memes semantiques dans les matrices
- // pour minimiser les chaines en memoire, on prend la representation
- // interne avant de l'utiliser comme cle.
- internalValue = ((String)internalValue).intern();
- result = internalValue;
- if (StringUtils.startsWith((String)internalValue, Month.class.getName())) {
- String val = StringUtils.substringAfter((String)internalValue, SEP);
- int monthNumber = Integer.parseInt(val);
- result = new Month(monthNumber);
- } else if (StringUtils.startsWith((String)internalValue, TimeStep.class.getName())) {
- String val = StringUtils.substringAfter((String)internalValue, SEP);
- int stepNumber = Integer.parseInt(val);
- result = new TimeStep(stepNumber);
- } else if (StringUtils.startsWith((String)internalValue, "fr.ifremer.isisfish.entities.")) {
- if (tx == null) {
- result = StringUtils.substringAfter((String)internalValue, SEP);
- } else {
- try {
- String id = StringUtils.substringBefore((String)internalValue, SEP);
- result = tx.findByTopiaId(id);
- } catch (TopiaException eee) {
- log.info("Fallback use string representation because"
- + " i can't decorate (String->Entity): "
- + internalValue, eee);
- // si on arrive pas a convertir cette fois-ci, on
- // renvoi internalValue pour que le undecorate est toutes les infos
- // et donc que la prochaine fois on y arrive peut etre
- }
+ if (StringUtils.startsWith(internalValue, Month.class.getName())) {
+ String val = StringUtils.substringAfter(internalValue, SEP);
+ int monthNumber = Integer.parseInt(val);
+ result = new Month(monthNumber);
+ } else if (StringUtils.startsWith(internalValue, TimeStep.class.getName())) {
+ String val = StringUtils.substringAfter(internalValue, SEP);
+ int stepNumber = Integer.parseInt(val);
+ result = new TimeStep(stepNumber);
+ } else if (StringUtils.startsWith(internalValue, "fr.ifremer.isisfish.entities.")) {
+ if (tx == null) {
+ result = StringUtils.substringAfter(internalValue, SEP);
+ } else {
+ try {
+ String id = StringUtils.substringBefore(internalValue, SEP);
+ result = tx.findByTopiaId(id);
+ } catch (TopiaException eee) {
+ log.info("Fallback use string representation because"
+ + " i can't decorate (String->Entity): "
+ + internalValue, eee);
+ // si on arrive pas a convertir cette fois-ci, on
+ // renvoi internalValue pour que le undecorate est toutes les infos
+ // et donc que la prochaine fois on y arrive peut etre
}
}
}
@@ -153,8 +151,8 @@
}
@Override
- public Object undecorate(Object decoratedValue) {
- Object result = cache.getKey(decoratedValue);
+ public String undecorate(Object decoratedValue) {
+ String result = cache.getKey(decoratedValue);
if (result == null && decoratedValue != null) {
if (decoratedValue instanceof Month) {
result = Month.class.getName() + SEP + ((Month)decoratedValue).getMonthNumber();
@@ -168,7 +166,7 @@
// on retrouve souvent les memes semantiques dans les matrices
// pour minimiser les chaines en memoire, on prend la representation
// interne avant de l'utiliser comme cle.
- cache.put(((String)result).intern(), decoratedValue);
+ cache.put(result.intern(), decoratedValue);
}
return result;
}
@@ -176,20 +174,21 @@
}
/**
- * Return one result for step and name
+ * Return one result for step and name. Matrix returned must be undecorated
+ * (semantics must be string representation of object)
*
* @param step
* @param name
* @return
*/
abstract protected MatrixND readResult(TimeStep step, String name);
+// /**
+// * Return all available result for name in argument
+// * @param name
+// * @return
+// */
+// abstract protected Map<TimeStep, MatrixND> readResult(String name);
/**
- * Return all available result for name in argument
- * @param name
- * @return
- */
- abstract protected Map<TimeStep, MatrixND> readResult(String name);
- /**
* write result
* @param step
* @param name
@@ -217,6 +216,27 @@
return MatrixFactory.getInstance();
}
+ /**
+ * Les ResultStorage ne doivent pas etre instancier directement, mais
+ * recuperer a partir d'un
+ * {@link fr.ifremer.isisfish.datastore.SimulationStorage#getResultStorage()}
+ *
+ * @param simulation storage to get result
+ */
+ public ResultStorageAbstract(SimulationStorage simulation) {
+ this.simulation = simulation;
+ this.decorator = new EntitySemanticsDecorator();
+ }
+
+ /**
+ * Return some information on result storage. Information depend on
+ * result storage type
+ * @return
+ */
+ public String getInfo() {
+ return getClass().getSimpleName() + " No more information";
+ }
+
protected MatrixND decorate(MatrixND mat, TopiaContext tx) {
MatrixND result = null;
if (mat != null) {
@@ -229,16 +249,39 @@
}
/**
- * Les ResultStorage ne doivent pas etre instancier directement, mais
- * recuperer a partir d'un
- * {@link fr.ifremer.isisfish.datastore.SimulationStorage#getResultStorage()}
- *
- * @param simulation storage to get result
+ * Return undecorated version of matrix in argument
+ * @param mat
+ * @return new matrix undecorated
*/
- public ResultStorageAbstract(SimulationStorage simulation) {
- this.simulation = simulation;
+ protected MatrixND undecorate(MatrixND mat) {
+ MatrixND result = null;
+
+ if (mat != null) {
+ String name = mat.getName();
+ String[] dimNames = mat.getDimensionNames();
+ List[] sems = new List[mat.getDimCount()];
+ for (int i=0,maxi=sems.length; i<maxi; i++) {
+ sems[i] = undecorate(mat.getSemantic(i));
+ }
+ result = getMatrixFactory().create(name, sems, dimNames);
+ result.paste(mat);
+ }
+ return result;
}
+ /**
+ * return new list with undecorate item
+ * @param l
+ * @return new list
+ */
+ protected List<String> undecorate(List l) {
+ ArrayList<String> result = new ArrayList<String>(l.size());
+ for (Object o : l) {
+ result.add(decorator.undecorate(o));
+ }
+ return result;
+ }
+
@Override
public void delete() {
close();
@@ -488,76 +531,68 @@
public MatrixND getMatrix(String name, TopiaContext tx) {
log.debug("Get result: " + name);
- MatrixND resultMat = null;
- Map<TimeStep, MatrixND> results = readResult(name);
- // recuperation des resultats qui nous interesse
- if (!results.isEmpty()) {
- // creation de la liste de date
- TimeStep lastStep = getLastStep();
- List<TimeStep> steps = new ArrayList<TimeStep>();
- TimeStep step = new TimeStep(0);
+ // collect de tous les pas de temps possible
+ TimeStep lastStep = getLastStep();
+ List<TimeStep> steps = new ArrayList<TimeStep>();
+ TimeStep step = new TimeStep(0);
+ steps.add(step);
+ while (step.before(lastStep)) {
+ step = step.next();
steps.add(step);
- while (step.before(lastStep)) {
- step = step.next();
- steps.add(step);
- }
+ }
- if (log.isTraceEnabled()) {
- log.trace("Steps list : " + steps);
+
+ // collect de toutes les matrices existantes
+ Map<TimeStep, MatrixND> results = new LinkedHashMap<TimeStep, MatrixND>();
+ MatrixND sample = null;
+ for (TimeStep s : steps) {
+ MatrixND m = readResult(s, name);
+ if (m != null) {
+ results.put(s, m);
+ sample = m;
}
+ }
+ // creation des dimensions
+ String[] dimNames = new String[1 + sample.getDimCount()];
+ dimNames[0] = t("isisfish.common.date");
+ for (int i = 1; i < dimNames.length; i++) {
+ dimNames[i] = sample.getDimensionName(i - 1);
+ }
- MatrixND mat = results.values().iterator().next();
+ // collect des semantics. +1 pour les dates
+ List[] sem = new List[1 + sample.getDimCount()];
+ sem[0] = steps;
- // recuperation des noms des dimensions
- String[] dimNames = new String[1 + mat.getDimCount()];
- dimNames[0] = t("isisfish.common.date");
- for (int i = 1; i < dimNames.length; i++) {
- dimNames[i] = mat.getDimensionName(i - 1);
- }
+ for (int i = 1; i < sem.length; i++) {
+ sem[i] = new HashList();
+ }
- // creation de la semantique pour la matrice resultat. +1 pour les dates
- List[] sem = new List[1 + mat.getDimCount()];
- sem[0] = steps;
-
- for (int i = 1; i < sem.length; i++) {
- sem[i] = new HashList();
+ for (MatrixND m : results.values()) {
+ if (m != null) {
+ for (int s = 0; s < m.getDimCount(); s++) {
+ sem[s + 1].addAll(m.getSemantic(s));
+ }
}
+ }
- for (MatrixND mattmp : results.values()) {
- if (log.isTraceEnabled()) {
- log.trace("Ajout de la semantics: "
- + Arrays.asList(mattmp.getSemantics()));
- }
+ // creation de la matrice resultat
+ MatrixND resultMat = getMatrixFactory().create(name, sem, dimNames);
- for (int s = 0; s < mattmp.getDimCount(); s++) {
- sem[s + 1].addAll(mattmp.getSemantic(s));
- }
- }
- if (log.isTraceEnabled()) {
- log.trace("La semantique final est: " + Arrays.asList(sem));
- }
+ // recuperation du resultat pour chaque date de la simulation, de Date(0) à lastDate
+ for (Map.Entry<TimeStep, MatrixND> result : results.entrySet()) {
+ TimeStep d = result.getKey();
+ MatrixND m = result.getValue();
- // creation de la matrice resultat
- resultMat = getMatrixFactory().create(name, sem, dimNames);
-
- // recuperation du resultat pour chaque date de la simulation, de Date(0) à lastDate
- for (Map.Entry<TimeStep, MatrixND> result : results.entrySet()) {
- TimeStep d = result.getKey();
- mat = result.getValue();
- // on met ce resultat dans la matrice result si besoin
- if (mat != null) {
- // on recupere dans la matrice resultat l'endroit on il faut
- // mettre la matrice
- MatrixND submat = resultMat.getSubMatrix(0, d, 1);
- // on met les valeur de mat dans la sous matrice extraite
- for (MatrixIterator mi = mat.iterator(); mi.next();) {
- submat.setValue(
- ArrayUtil.concat(new Object[] { d },
+ // on recupere dans la matrice resultat l'endroit on il faut
+ // mettre la matrice
+ MatrixND submat = resultMat.getSubMatrix(0, d, 1);
+ // on met les valeur de mat dans la sous matrice extraite
+ for (MatrixIterator mi = m.iterator(); mi.next();) {
+ submat.setValue(
+ ArrayUtil.concat(new Object[] { d },
mi.getSemanticsCoordinates()), mi.getValue());
- }
- }
}
}
Modified: trunk/src/main/java/fr/ifremer/isisfish/datastore/ResultStorageCSV.java
===================================================================
--- trunk/src/main/java/fr/ifremer/isisfish/datastore/ResultStorageCSV.java 2014-06-29 18:44:00 UTC (rev 4026)
+++ trunk/src/main/java/fr/ifremer/isisfish/datastore/ResultStorageCSV.java 2014-06-30 17:08:42 UTC (rev 4027)
@@ -1,7 +1,9 @@
package fr.ifremer.isisfish.datastore;
+import fr.ifremer.isisfish.IsisFish;
import fr.ifremer.isisfish.IsisFishRuntimeException;
+import fr.ifremer.isisfish.simulator.SimulationContext;
import fr.ifremer.isisfish.types.TimeStep;
import fr.ifremer.isisfish.util.SimpleParser;
import java.io.BufferedWriter;
@@ -18,6 +20,7 @@
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
+import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.zip.GZIPInputStream;
@@ -31,9 +34,14 @@
import org.nuiton.math.matrix.MatrixND;
/**
- * Ecrit les resultats dans des fichiers au format pseudo csv compresser (gz)
- * Seule les valeurs differentes de 0 sont ecrite dans le fichier
+ * Ecrit les resultats dans des fichiers au format pseudo csv compresse (gz)
+ * Seules les valeurs differentes de 0 sont ecrites dans le fichier.
+ *
+ * Il est possible de modifier via la configuration:
+ * - le nombre de TimeStep en cache
+ * - de definir le nombre de TimeStep a conserver sur disque
*
+ *
* Format d'une matrice:
* <pre>
* # commentaire
@@ -75,13 +83,47 @@
static final private Charset charset = Charset.forName("UTF-8");
- protected EntitySemanticsDecorator decorator;
+ /** number of step result to store on disk. 0 for none, negative for all result */
+ protected int storeOnDiskStep = -1;
+ /** number of step in cache */
+ protected int cacheStep = 13; // default to 13 months
+ /** nombre total de resultat */
+ protected int numberOfResult = 0;
+ /** nombre de resultat reellement stocke sur disque */
+ protected int numberOfResultOnDisk = 0;
+ /** le nombre de resultat demande qui n'etait pas dans le pas de temps courant */
+ protected int numberOfPastResultAsked = 0;
+ /** le plus vieux pas de temps demande par rapport au pas de temps courant */
+ protected int maxGapWithCurrentStep = 0;
+
+ LinkedHashMap<TimeStep, Map<String, MatrixND>> cache =
+ new LinkedHashMap<TimeStep, Map<String, MatrixND>>() {
+ private static final long serialVersionUID = 1L;
+ @Override
+ protected boolean removeEldestEntry(Map.Entry eldest) {
+ return size() > cacheStep;
+ }
+ };
+
+
public ResultStorageCSV(SimulationStorage simulation) {
super(simulation);
- decorator = new EntitySemanticsDecorator();
+
+ storeOnDiskStep = IsisFish.config.getSimulationStoreResultOnDisk();
+ cacheStep = IsisFish.config.getSimulationStoreResultCacheStep();
}
+ @Override
+ public String getInfo() {
+ return String.format(
+ "ResultStorageCSV:\n"
+ + "\t%s results written to disk on a total of %s\n"
+ + "\t%s results read outside of current step\n"
+ + "\tthe oldest step was %s step before current step\n",
+ numberOfResultOnDisk, numberOfResult, numberOfPastResultAsked, maxGapWithCurrentStep);
+ }
+
/**
* donne le repertoire de stockage des resultats
* @return
@@ -106,10 +148,6 @@
return file;
}
- protected MatrixND readMatrix(File file) throws IOException {
- return readMatrix(file.getPath());
- }
-
protected MatrixND readMatrix(String file) throws IOException {
MatrixND result = null;
LineNumberReader in = null;
@@ -195,90 +233,145 @@
@Override
protected MatrixND readResult(TimeStep step, String name) {
- File file = getMatrixFile(step, name);
+ // un peu de statistique
+ TimeStep currentStep = SimulationContext.get().getSimulationControl().getStep();
+ if (!step.equals(currentStep)) {
+ numberOfPastResultAsked++;
+ maxGapWithCurrentStep = Math.max(maxGapWithCurrentStep, currentStep.gap(step));
+ }
+
MatrixND result = null;
- if (file.exists()) {
- try {
- result = readMatrix(file);
- } catch (IOException eee) {
- log.error("Can't read result file: " + file, eee);
+
+ // try to get in cache first
+ if(cache.containsKey(step)) {
+ result = getCacheForStep(step).get(name);
+ }
+
+ // if not found looking for result on disk
+ if (result == null) {
+ File file = getMatrixFile(step, name);
+ if (file.exists()) {
+ try {
+ result = readMatrix(file.getPath());
+ } catch (IOException eee) {
+ log.error("Can't read result file: " + file, eee);
+ }
}
}
return result;
}
- @Override
- protected Map<TimeStep, MatrixND> readResult(String name) {
- File dir = getMatrixDirectory(name);
- String[] files = dir.list();
+// @Override
+// protected Map<TimeStep, MatrixND> readResult(String name) {
+// File dir = getMatrixDirectory(name);
+// String[] files = dir.list();
+//
+// Map<TimeStep, MatrixND> result = new HashMap<TimeStep, MatrixND>();
+// for(String file : files) {
+// try {
+// TimeStep step = getTimeStep(file);
+// if (step != null) {
+// MatrixND mat = readResult(step, name);
+// if (mat != null) {
+// result.put(step, mat);
+// }
+// }
+// } catch (Exception eee) {
+// log.error("Can't read result file: " + file, eee);
+// }
+// }
+// return result;
+// }
- Map<TimeStep, MatrixND> result = new HashMap<TimeStep, MatrixND>();
- for(String file : files) {
- try {
- TimeStep step = getTimeStep(file);
- if (step != null) {
- MatrixND mat = readMatrix(dir + File.separator + file);
- if (mat != null) {
- result.put(step, mat);
- }
- }
- } catch (Exception eee) {
- log.error("Can't read result file: " + file, eee);
- }
+ /** Le pas de temps a partir duquel il faut sauver les resultats sur disque*/
+ protected TimeStep startDiskStep = null;
+
+ /**
+ * Indique s'il faut sauver sur disque les resultats
+ * @param step
+ * @return
+ */
+ protected boolean isDiskResult(TimeStep step) {
+ if (startDiskStep == null) {
+ startDiskStep = getLastStep().minus(storeOnDiskStep);
}
+ return storeOnDiskStep < 0 || startDiskStep.before(step);
+ }
+
+ protected Map<String, MatrixND> getCacheForStep(TimeStep step) {
+ Map<String, MatrixND> result = cache.get(step);
+ if (result == null) {
+ result = new HashMap<String, MatrixND>();
+ cache.put(step, result);
+ }
return result;
}
+
@Override
protected void writeResult(TimeStep step, String name, MatrixND mat) {
- File file = getMatrixFile(step, name);
- file.getParentFile().mkdirs();
- PrintWriter out = null;
- try {
- out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(
- new GZIPOutputStream(new FileOutputStream(file)),
- charset
- )));
+ // copy and undecorate matrix
+ mat = undecorate(mat);
+
+ // add mat in cache
+ getCacheForStep(step).put(name, mat);
- out.print(name);
- out.println();
+ // for statistics
+ numberOfResult++;
- List[] sems = mat.getSemantics();
- for (int i=0, maxi=sems.length; i<maxi; i++) {
- String dimName = mat.getDimensionName(i);
- out.print(dimName);
+ // write mat on disk
+ if (isDiskResult(step)) {
+ // for statistics
+ numberOfResultOnDisk++;
+
+ File file = getMatrixFile(step, name);
+ file.getParentFile().mkdirs();
+ PrintWriter out = null;
+ try {
+ out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(
+ new GZIPOutputStream(new FileOutputStream(file)),
+ charset
+ )));
- List l = sems[i];
- char sep = ':';
- for (Object o : l) {
- out.print(sep);
- out.print(decorator.undecorate(o));
- sep = ';';
- }
+ out.print(name);
out.println();
- }
- // blank line to separate header and data
- out.println();
+ List[] sems = mat.getSemantics();
+ for (int i=0, maxi=sems.length; i<maxi; i++) {
+ String dimName = mat.getDimensionName(i);
+ out.print(dimName);
- for (MatrixIterator i = mat.iteratorNotZero(); i.hasNext();) {
- i.next();
- int[] pos = i.getCoordinates();
- double value = i.getValue();
- for (int p : pos) {
- out.print(p);
- out.print(';');
+ List l = sems[i];
+ char sep = ':';
+ for (Object o : l) {
+ out.print(sep);
+ out.print(o);
+ sep = ';';
+ }
+ out.println();
}
- out.print(value);
+
+ // blank line to separate header and data
out.println();
+
+ for (MatrixIterator i = mat.iteratorNotZero(); i.hasNext();) {
+ i.next();
+ int[] pos = i.getCoordinates();
+ double value = i.getValue();
+ for (int p : pos) {
+ out.print(p);
+ out.print(';');
+ }
+ out.print(value);
+ out.println();
+ }
+
+ } catch (Exception eee) {
+ throw new IsisFishRuntimeException("Can't write result: " + file, eee);
+ } finally {
+ IOUtils.closeQuietly(out);
}
-
- } catch (Exception eee) {
- throw new IsisFishRuntimeException("Can't write result: " + file, eee);
- } finally {
- IOUtils.closeQuietly(out);
}
-
}
@Override
Modified: trunk/src/main/java/fr/ifremer/isisfish/datastore/ResultStorageInMemory.java
===================================================================
--- trunk/src/main/java/fr/ifremer/isisfish/datastore/ResultStorageInMemory.java 2014-06-29 18:44:00 UTC (rev 4026)
+++ trunk/src/main/java/fr/ifremer/isisfish/datastore/ResultStorageInMemory.java 2014-06-30 17:08:42 UTC (rev 4027)
@@ -52,6 +52,8 @@
*
* Mise a jour: $Date$
* par : $Author$
+ *
+ * @deprecated ResultStorageCSV now support no storage and in memory usage
*/
public class ResultStorageInMemory extends ResultStorageAbstract {
@@ -103,7 +105,7 @@
@Override
protected void writeResult(TimeStep step, String name, MatrixND mat) {
- MatrixND newMat = mat.copy();
+ MatrixND newMat = undecorate(mat);
Map<String, MatrixND> mats = data.get(step);
if (mats == null) {
mats = new HashMap<String, MatrixND>();
@@ -152,21 +154,21 @@
return result;
}
- /* (non-Javadoc)
- * @see fr.ifremer.isisfish.datastore.ResultStorage#getMatrix(java.lang.String)
- */
- @Override
- public Map<TimeStep, MatrixND> readResult(String name) {
- Map<TimeStep, MatrixND> result = new LinkedHashMap<TimeStep, MatrixND>();
- for (Map.Entry<TimeStep, Map<String, MatrixND>> e : data.entrySet()) {
- TimeStep ts = e.getKey();
- MatrixND mat = e.getValue().get(name);
- if (mat != null) {
- result.put(ts, mat);
- }
- }
+// /* (non-Javadoc)
+// * @see fr.ifremer.isisfish.datastore.ResultStorage#getMatrix(java.lang.String)
+// */
+// @Override
+// public Map<TimeStep, MatrixND> readResult(String name) {
+// Map<TimeStep, MatrixND> result = new LinkedHashMap<TimeStep, MatrixND>();
+// for (Map.Entry<TimeStep, Map<String, MatrixND>> e : data.entrySet()) {
+// TimeStep ts = e.getKey();
+// MatrixND mat = e.getValue().get(name);
+// if (mat != null) {
+// result.put(ts, mat);
+// }
+// }
+//
+// return result;
+// }
- return result;
- }
-
}
Modified: trunk/src/main/java/fr/ifremer/isisfish/simulator/SimulationContext.java
===================================================================
--- trunk/src/main/java/fr/ifremer/isisfish/simulator/SimulationContext.java 2014-06-29 18:44:00 UTC (rev 4026)
+++ trunk/src/main/java/fr/ifremer/isisfish/simulator/SimulationContext.java 2014-06-30 17:08:42 UTC (rev 4027)
@@ -43,6 +43,8 @@
import fr.ifremer.isisfish.types.TimeStep;
import fr.ifremer.isisfish.util.IsisCache;
import fr.ifremer.isisfish.util.Trace;
+import org.nuiton.config.ApplicationConfig;
+import org.nuiton.config.OverwriteApplicationConfig;
import org.nuiton.math.matrix.MatrixFactory;
/**
@@ -69,6 +71,8 @@
/** to use log facility, just put in your code: log.info(\"...\"); */
private static Log log = LogFactory.getLog(SimulationContext.class);
+ /** configuration for current simulation (some value of config is overwrited for simulation) */
+ protected ApplicationConfig config;
protected Map<String, Object> values = new HashMap<String, Object>();
protected SimulationStorage simulation = null;
protected SimulationControl simulationControl = null;
@@ -103,7 +107,17 @@
};
protected SimulationContext() {
- // force matrix backend for this simulation
+ }
+
+ /**
+ * init SimulationContext for simulation.
+ *
+ */
+ public void initForSimulation() {
+ // must be done after setSimulationStorage because config looking for
+ // value in simulation parameter via SimulationContext
+
+ // force matrix backend for this simulationcontext
MatrixFactory.initMatrixFactoryThreadLocal(
IsisFish.config.getSimulationMatrixVectorClass(),
IsisFish.config.getSimulationMatrixVectorSparseClass(),
@@ -111,6 +125,8 @@
}
/**
+ * Return SimulationContext if not created, create new context without
+ * initialisation needed for simulation
* @return simulation context for the current simulation (current thread)
*/
public static SimulationContext get() {
@@ -132,6 +148,27 @@
}
/**
+ * Get specifique ApplicationConfig for current thread.simulation.
+ * Needed for simulation some configurations values are overwrited by
+ * simulation parameter tag/value
+ *
+ * @return
+ */
+ public ApplicationConfig getConfig() {
+ if (config == null) {
+ if (getSimulationStorage()!= null) {
+ // in simulation, tag/value must be in config for simulation option
+ Map<String, String> tv = getSimulationStorage().getParameter().getTagValue();
+ config = new OverwriteApplicationConfig(IsisFish.config, tv);
+ } else {
+ config = IsisFish.config;
+ }
+ }
+ return config;
+ }
+
+
+ /**
* Add simulation listener, if listener is {@link SimulationResultListener}, it's
* automatically added as listener on {@link ResultManager}
* @param l
Modified: trunk/src/main/java/fr/ifremer/isisfish/simulator/launcher/InProcessSimulatorLauncher.java
===================================================================
--- trunk/src/main/java/fr/ifremer/isisfish/simulator/launcher/InProcessSimulatorLauncher.java 2014-06-29 18:44:00 UTC (rev 4026)
+++ trunk/src/main/java/fr/ifremer/isisfish/simulator/launcher/InProcessSimulatorLauncher.java 2014-06-30 17:08:42 UTC (rev 4027)
@@ -354,6 +354,7 @@
// Creation et initialisation du context de simulation
//
SimulationContext context = SimulationContext.get();
+
context.setSimulationControl(control != null ? control
: new SimulationControl(simulation.getName()));
@@ -372,7 +373,7 @@
// is simulation context
context.setScriptDirectory(rootDirectory);
context.setSimulationStorage(simulation);
-
+
// Warning : Rule have to be instanciated after aspect definition
classLoader.deploy(RuleAspect.class);
@@ -381,6 +382,10 @@
// forceReload, save all modification in parameter and reread it
parameters = simulation.getForceReloadParameter();
+ // must be done after setSimulationStorage because config looking for
+ // value in simulation parameter via SimulationContext
+ context.initForSimulation();
+
//
// Activation de l'OAP demandée
//
@@ -425,9 +430,8 @@
String matrixBackend = MatrixFactory.getInstance().getVectorClass().getName();
String matrixSparseBackend = MatrixFactory.getInstance().getSparseVectorClass().getName();
int threshold = MatrixFactory.getInstance().getThresholdSparse();
- simulation.getInformation().addInformation("Matrix backend: "
+ log.info("Matrix backend: "
+ matrixBackend + " and " + matrixSparseBackend + " threshold: " + threshold);
- log.info("Matrix backend: " + matrixBackend);
simulatorObject.simulate(context);
//
@@ -465,6 +469,7 @@
if (parameters.isSensitivityAnalysisOnlyKeepFirst() && !control.getId().endsWith("_0")) {
resultStorage.delete();
}
+ simulation.getInformation().addInformation(resultStorage.getInfo());
resultStorage.close();
} catch (OutOfMemoryError eee) {
Modified: trunk/src/main/java/fr/ifremer/isisfish/types/TimeStep.java
===================================================================
--- trunk/src/main/java/fr/ifremer/isisfish/types/TimeStep.java 2014-06-29 18:44:00 UTC (rev 4026)
+++ trunk/src/main/java/fr/ifremer/isisfish/types/TimeStep.java 2014-06-30 17:08:42 UTC (rev 4027)
@@ -85,6 +85,34 @@
}
/**
+ * Return new TimeStep equals to this.step + number
+ * @param number number of step to add
+ * @return new TimeStep
+ */
+ public TimeStep add(int number) {
+ return new TimeStep(step + number);
+ }
+
+ /**
+ * Return new TimeStep equals to this.step - number
+ * @param number number of step to remove
+ * @return new TimeStep
+ */
+ public TimeStep minus(int number) {
+ return new TimeStep(step - number);
+ }
+
+ /**
+ * Return number of step between current TimeStep and other TimeStep in argument
+ * (this - other)
+ * @param other
+ * @return
+ */
+ public int gap(TimeStep other) {
+ return step - other.step;
+ }
+
+ /**
* Method next retourne une nouvelle date qui est la date suivante de la
* date courante. la date courante n'est pas modifier.
*
Modified: trunk/src/main/java/fr/ifremer/isisfish/ui/WelcomeHandler.java
===================================================================
--- trunk/src/main/java/fr/ifremer/isisfish/ui/WelcomeHandler.java 2014-06-29 18:44:00 UTC (rev 4026)
+++ trunk/src/main/java/fr/ifremer/isisfish/ui/WelcomeHandler.java 2014-06-30 17:08:42 UTC (rev 4027)
@@ -229,6 +229,8 @@
modelBuilder.addOption(IsisConfig.Option.SIMULATION_MATRIX_VECTOR_SPARSE_CLASS);
modelBuilder.addOption(IsisConfig.Option.SIMULATION_MATRIX_THRESHOLD_USE_SPARSE_CLASS);
modelBuilder.addOption(IsisConfig.Option.MAPPED_RESULT_MATRIX_VECTOR_CLASS);
+ modelBuilder.addOption(IsisConfig.Option.SIMULATION_STORE_RESULT_ON_DISK);
+ modelBuilder.addOption(IsisConfig.Option.SIMULATION_STORE_RESULT_CACHE_STEP);
// category database vcs
modelBuilder.addCategory(t("isisfish.config.category.officialvcs"), t("isisfish.config.category.officialvcs.description"));
Modified: trunk/src/main/java/fr/ifremer/isisfish/ui/simulator/SimulAction.java
===================================================================
--- trunk/src/main/java/fr/ifremer/isisfish/ui/simulator/SimulAction.java 2014-06-29 18:44:00 UTC (rev 4026)
+++ trunk/src/main/java/fr/ifremer/isisfish/ui/simulator/SimulAction.java 2014-06-30 17:08:42 UTC (rev 4027)
@@ -99,6 +99,8 @@
import fr.ifremer.isisfish.ui.sensitivity.wizard.SensitivityWizardHandler;
import fr.ifremer.isisfish.ui.util.ErrorHelper;
import fr.ifremer.isisfish.ui.widget.editor.ScriptParameterDialog;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
/**
* SimulAction.
@@ -152,8 +154,12 @@
List<String> resultNames = getResultNames();
// put default value in param
param.setSimulatorName(IsisFish.config.getSimulatorClassfile());
- param.setTagValue(IsisFish.config.getDefaultTagValueAsMap());
+ Map<String, String> tv = new LinkedHashMap<String, String>();
+ tv.putAll(IsisFish.config.getDefaultTagValueAsMap());
+ tv.putAll(IsisFish.config.getDefaultSimulationConfig());
+ param.setTagValue(tv);
+
param.setExportNames(IsisFish.config.getDefaultExportNamesAsList());
List<String> defaultResultNames = IsisFish.config
.getDefaultResultNamesAsList();
@@ -987,6 +993,26 @@
return SimulationService.getService().getSimulationLaunchers();
}
+ protected boolean checkAndPrepare(String fullSimulationId) {
+ boolean result = !("".equals(fullSimulationId)
+ || SimulationStorage.localyExists(fullSimulationId)
+ || SimulationService.getService().exists(fullSimulationId));
+
+ if (result) {
+ // force all necessary config simulation in tag value
+ Map<String, String> m = new HashMap<String, String>(
+ IsisFish.config.getDefaultSimulationConfig());
+ Map<String, String> tv = param.getTagValue();
+ m.putAll(tv);
+ param.setTagValue(m);
+ } else {
+ ErrorHelper.showErrorDialog(t("isisfish.simulator.simulaction.badid",
+ fullSimulationId), null);
+ }
+
+ return result;
+ }
+
/**
* Launch automatically the simulation, when is possible (no other simulation)
* or wait for the last automatically simulation ended.
@@ -1008,12 +1034,7 @@
}
try {
- if ("".equals(fullSimulationId)
- || SimulationStorage.localyExists(fullSimulationId)
- || SimulationService.getService().exists(fullSimulationId)) {
- ErrorHelper.showErrorDialog(t("isisfish.simulator.simulaction.badid",
- fullSimulationId), null);
- } else {
+ if (checkAndPrepare(fullSimulationId)) {
SimulationService.getService().submit(fullSimulationId, param,
launcher, 0);
}
@@ -1051,12 +1072,7 @@
}
try {
- if ("".equals(fullSimulationId)
- || SimulationStorage.localyExists(fullSimulationId)
- || SimulationService.getService().exists(fullSimulationId)) {
- ErrorHelper.showErrorDialog(t("isisfish.simulator.simulaction.badid",
- fullSimulationId), null);
- } else {
+ if (checkAndPrepare(fullSimulationId)) {
DesignPlan designPlan = new DesignPlan();
designPlan.setFactorGroup(factorGroup);
SimulationService.getService().submit(fullSimulationId, param,
Modified: trunk/src/main/resources/i18n/isis-fish_en_GB.properties
===================================================================
--- trunk/src/main/resources/i18n/isis-fish_en_GB.properties 2014-06-29 18:44:00 UTC (rev 4026)
+++ trunk/src/main/resources/i18n/isis-fish_en_GB.properties 2014-06-30 17:08:42 UTC (rev 4027)
@@ -229,6 +229,11 @@
isisfish.config.main.userMail.description=User email address
isisfish.config.main.userName.description=User name
isisfish.config.mapped.result.matrix.vector.class.description=
+isisfish.config.simulation.matrix.threshold.use.sparse.class.description=
+isisfish.config.simulation.matrix.vector.class.description=
+isisfish.config.simulation.matrix.vector.sparse.class.description=
+isisfish.config.simulation.store.result.cachestep.description=
+isisfish.config.simulation.store.result.ondisk.description=
isisfish.config.ssh.key.file=SSH key
isisfish.config.ssh.key.file.description=Private SSH key path
isisfish.config.title=Preferences
Modified: trunk/src/main/resources/i18n/isis-fish_fr_FR.properties
===================================================================
--- trunk/src/main/resources/i18n/isis-fish_fr_FR.properties 2014-06-29 18:44:00 UTC (rev 4026)
+++ trunk/src/main/resources/i18n/isis-fish_fr_FR.properties 2014-06-30 17:08:42 UTC (rev 4027)
@@ -229,6 +229,11 @@
isisfish.config.main.userMail.description=le courriel de l'utilisateur
isisfish.config.main.userName.description=le nom - prénom de l'utilisateur
isisfish.config.mapped.result.matrix.vector.class.description=
+isisfish.config.simulation.matrix.threshold.use.sparse.class.description=
+isisfish.config.simulation.matrix.vector.class.description=
+isisfish.config.simulation.matrix.vector.sparse.class.description=
+isisfish.config.simulation.store.result.cachestep.description=
+isisfish.config.simulation.store.result.ondisk.description=
isisfish.config.ssh.key.file=Clé SSH
isisfish.config.ssh.key.file.description=Emplacement de la clé privée SSH
isisfish.config.title=Préférences
1
0
r4026 - in trunk/src/main/java/fr/ifremer/isisfish: . aspect datastore simulator simulator/launcher ui util
by bpoussin@users.forge.codelutin.com 29 Jun '14
by bpoussin@users.forge.codelutin.com 29 Jun '14
29 Jun '14
Author: bpoussin
Date: 2014-06-29 20:44:00 +0200 (Sun, 29 Jun 2014)
New Revision: 4026
Url: http://forge.codelutin.com/projects/isis-fish/repository/revisions/4026
Log:
- Add new default ResultStorage (store in pseudo csv compressed file)
- old simulation with mapped storage are automaticaly detected
- Add configuration for matrix type thresold (dense/sparse: default 1000 value)
- guava cache support sparse matrix
- factorisation of ResultStorage (ResultMappedStorage, ResultStorageInMemory, ResultStorageCSV) in ResultStorageAbstract
- add Trace for equation (but not very useful, because equation name is generated, perhaps need entity to string in name ?)
Added:
trunk/src/main/java/fr/ifremer/isisfish/datastore/ResultStorageAbstract.java
trunk/src/main/java/fr/ifremer/isisfish/datastore/ResultStorageCSV.java
trunk/src/main/java/fr/ifremer/isisfish/util/SimpleParser.java
Modified:
trunk/src/main/java/fr/ifremer/isisfish/IsisConfig.java
trunk/src/main/java/fr/ifremer/isisfish/aspect/TraceAspect.java
trunk/src/main/java/fr/ifremer/isisfish/datastore/ResultMappedStorage.java
trunk/src/main/java/fr/ifremer/isisfish/datastore/ResultStorageInMemory.java
trunk/src/main/java/fr/ifremer/isisfish/datastore/SimulationStorage.java
trunk/src/main/java/fr/ifremer/isisfish/simulator/SimulationContext.java
trunk/src/main/java/fr/ifremer/isisfish/simulator/launcher/InProcessSimulatorLauncher.java
trunk/src/main/java/fr/ifremer/isisfish/ui/WelcomeHandler.java
trunk/src/main/java/fr/ifremer/isisfish/util/IsisCacheBackendOnGuava.java
Modified: trunk/src/main/java/fr/ifremer/isisfish/IsisConfig.java
===================================================================
--- trunk/src/main/java/fr/ifremer/isisfish/IsisConfig.java 2014-06-17 16:17:51 UTC (rev 4025)
+++ trunk/src/main/java/fr/ifremer/isisfish/IsisConfig.java 2014-06-29 18:44:00 UTC (rev 4026)
@@ -63,6 +63,7 @@
import fr.ifremer.isisfish.util.IsisCacheBackend;
import fr.ifremer.isisfish.util.IsisCacheBackendOnGuava;
import fr.ifremer.isisfish.vcs.VCS;
+import org.nuiton.math.matrix.DoubleVector;
/**
* Isis fish configuration.
@@ -948,10 +949,10 @@
/**
* L'implementation de la class gérant les implémentations de vecteur de
- * matrice pour les simulations
+ * matrice pleine pour les simulations
*
* @return
- * @since 4.2.1.1
+ * @since 4.2.0.2
*/
public Class getSimulationMatrixVectorClass() {
Class result = getOptionAsClass(Option.SIMULATION_MATRIX_VECTOR_CLASS.key);
@@ -959,6 +960,29 @@
}
/**
+ * L'implementation de la class gérant les implémentations de vecteur de
+ * matrice creuse pour les simulations
+ *
+ * @return
+ * @since 4.2.0.2
+ */
+ public Class getSimulationMatrixVectorSparseClass() {
+ Class result = getOptionAsClass(Option.SIMULATION_MATRIX_VECTOR_SPARSE_CLASS.key);
+ return result;
+ }
+
+ /**
+ * Seuil d'uitilisation des matrices creuse
+ *
+ * @return
+ * @since 4.2.0.2
+ */
+ public int getSimulationMatrixThresholdUseSparse() {
+ int result = getOptionAsInt(Option.SIMULATION_MATRIX_THRESHOLD_USE_SPARSE_CLASS.key);
+ return result;
+ }
+
+ /**
* Retourne la factory a utilise pour le cache
*
* @return factory a utilise pour le backend de cache
@@ -1004,6 +1028,8 @@
// pour les simulations
SIMULATION_MATRIX_VECTOR_CLASS("simulation.matrix.vector.class", n("isisfish.config.simulation.matrix.vector.class.description"), DoubleBigVector.class.getName()),
+ SIMULATION_MATRIX_VECTOR_SPARSE_CLASS("simulation.matrix.vector.sparse.class", n("isisfish.config.simulation.matrix.vector.sparse.class.description"), DoubleVector.class.getName()),
+ SIMULATION_MATRIX_THRESHOLD_USE_SPARSE_CLASS("simulation.matrix.threshold.use.sparse.class", n("isisfish.config.simulation.matrix.threshold.use.sparse.class.description"), "1000"),
/** Nombre maximum de thread de simulation in process. */
SIMULATOR_IN_MAXTHREADS("simulation.in.max.threads", n("isisfish.config.main.simulation.in.max.threads.description"), "1"),
Modified: trunk/src/main/java/fr/ifremer/isisfish/aspect/TraceAspect.java
===================================================================
--- trunk/src/main/java/fr/ifremer/isisfish/aspect/TraceAspect.java 2014-06-17 16:17:51 UTC (rev 4025)
+++ trunk/src/main/java/fr/ifremer/isisfish/aspect/TraceAspect.java 2014-06-29 18:44:00 UTC (rev 4026)
@@ -76,6 +76,8 @@
}
@Before("execution(* scripts..*(..))"
+ + " || execution(* fr.ifremer.isisfish.entities..*(..))"
+ + " || execution(* org.nuiton.math.matrix..*(..))"
+ " || execution(* simulators..*(..))"
+ " || execution(* rules..*(..)) "
+ " || execution(* simulationplans..*(..)) "
@@ -86,6 +88,8 @@
@AfterThrowing(throwing = "ex",
pointcut = "execution(* scripts..*(..))"
+ + " || execution(* fr.ifremer.isisfish.entities..*(..))"
+ + " || execution(* org.nuiton.math.matrix..*(..))"
+ " || execution(* simulators..*(..))"
+ " || execution(* rules..*(..)) "
+ " || execution(* simulationplans..*(..)) "
@@ -96,6 +100,8 @@
}
@After("execution(* scripts..*(..))"
+ + " || execution(* fr.ifremer.isisfish.entities..*(..))"
+ + " || execution(* org.nuiton.math.matrix..*(..))"
+ " || execution(* simulators..*(..))"
+ " || execution(* rules..*(..)) "
+ " || execution(* simulationplans..*(..)) "
Modified: trunk/src/main/java/fr/ifremer/isisfish/datastore/ResultMappedStorage.java
===================================================================
--- trunk/src/main/java/fr/ifremer/isisfish/datastore/ResultMappedStorage.java 2014-06-17 16:17:51 UTC (rev 4025)
+++ trunk/src/main/java/fr/ifremer/isisfish/datastore/ResultMappedStorage.java 2014-06-29 18:44:00 UTC (rev 4026)
@@ -25,61 +25,32 @@
package fr.ifremer.isisfish.datastore;
-import static org.nuiton.i18n.I18n.t;
import java.io.File;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
import java.util.Collections;
-import java.util.HashSet;
import java.util.List;
import java.util.Map;
-import java.util.Set;
import java.util.TreeMap;
-import org.apache.commons.collections4.BidiMap;
-import org.apache.commons.collections4.bidimap.DualHashBidiMap;
import org.apache.commons.io.IOUtils;
-import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.nuiton.math.matrix.DoubleBigMappedVector;
-import org.nuiton.math.matrix.DoubleBigVector;
import org.nuiton.math.matrix.MatrixFactory;
import org.nuiton.math.matrix.MatrixHelper;
-import org.nuiton.math.matrix.MatrixIterator;
import org.nuiton.math.matrix.MatrixND;
import org.nuiton.math.matrix.MatrixSemanticsDecorator;
import org.nuiton.math.matrix.SemanticsDecorator;
import org.nuiton.topia.TopiaContext;
-import org.nuiton.topia.TopiaException;
-import org.nuiton.topia.persistence.TopiaEntity;
-import org.nuiton.util.ArrayUtil;
-import org.nuiton.util.HashList;
import fr.ifremer.isisfish.IsisFish;
-import fr.ifremer.isisfish.IsisFishDAOHelper;
-import fr.ifremer.isisfish.IsisFishException;
import fr.ifremer.isisfish.IsisFishRuntimeException;
-import fr.ifremer.isisfish.entities.ActiveRule;
-import fr.ifremer.isisfish.entities.ActiveRuleDAO;
-import fr.ifremer.isisfish.entities.Population;
-import fr.ifremer.isisfish.export.Export;
-import fr.ifremer.isisfish.export.SensitivityExport;
-import fr.ifremer.isisfish.rule.Rule;
-import fr.ifremer.isisfish.simulator.Objective;
-import fr.ifremer.isisfish.simulator.Optimization;
-import fr.ifremer.isisfish.simulator.SimulationContext;
-import fr.ifremer.isisfish.simulator.SimulationException;
-import fr.ifremer.isisfish.simulator.SimulationPlan;
-import fr.ifremer.isisfish.simulator.SimulationResultGetter;
-import fr.ifremer.isisfish.simulator.SimulationResultListener;
-import fr.ifremer.isisfish.types.Month;
import fr.ifremer.isisfish.types.TimeStep;
import fr.ifremer.isisfish.util.BitUtil;
+import java.util.HashMap;
/**
* Cette classe permet de conserver des résultats de simulation. Elle permet
@@ -93,15 +64,13 @@
* Mise a jour: $Date$
* par : $Author$
*/
-public class ResultMappedStorage implements SimulationResultListener,
- SimulationResultGetter, ResultStorage { // ResultStorage
+public class ResultMappedStorage extends ResultStorageAbstract { // ResultStorage
/** to use log facility, just put in your code: log.info(\"...\"); */
static private Log log = LogFactory.getLog(ResultMappedStorage.class);
- protected MatrixFactory matrixFactory = MatrixFactory.getInstance(DoubleBigVector.class);
-
- protected SimulationStorage simulation = null;
+ protected MatrixFactory matrixFactory;
+
protected RandomAccessFile raf;
protected long offset;
protected Map<TimeStep, Map<String, ResultMapped>> stepNameResults =
@@ -109,91 +78,7 @@
protected Map<String, Map<TimeStep, ResultMapped>> nameStepResults =
new TreeMap<String, Map<TimeStep, ResultMapped>>();
- /** result enabled */
- transient protected Set<String> enabledResult = null;
-
/**
- * Convertie une entite, month, timestep en string et inversement.
- * Entity = "TopiaId:Entity.toString"
- */
- static protected class EntitySemanticsDecorator implements SemanticsDecorator {
- static final private String SEP = ":";
-
- protected TopiaContext tx;
- /** en cle les representation interne (get) en valeur les valeurs decoree (getKey) */
- protected BidiMap<Object, Object> cache = new DualHashBidiMap<>();
-
- public EntitySemanticsDecorator() {
- }
-
- public EntitySemanticsDecorator(TopiaContext tx) {
- this.tx = tx;
- }
-
- public Object decorate(Object internalValue) {
- Object result = cache.get(internalValue);
- if (result == null && internalValue != null) {
- result = internalValue;
- if (internalValue instanceof String) {
- // on retrouve souvent les memes semantiques dans les matrices
- // pour minimiser les chaines en memoire, on prend la representation
- // interne avant de l'utiliser comme cle.
- internalValue = ((String)internalValue).intern();
- result = internalValue;
- if (StringUtils.startsWith((String)internalValue, Month.class.getName())) {
- String val = StringUtils.substringAfter((String)internalValue, SEP);
- int monthNumber = Integer.parseInt(val);
- result = new Month(monthNumber);
- } else if (StringUtils.startsWith((String)internalValue, TimeStep.class.getName())) {
- String val = StringUtils.substringAfter((String)internalValue, SEP);
- int stepNumber = Integer.parseInt(val);
- result = new TimeStep(stepNumber);
- } else if (StringUtils.startsWith((String)internalValue, "fr.ifremer.isisfish.entities.")) {
- if (tx == null) {
- result = StringUtils.substringAfter((String)internalValue, SEP);
- } else {
- try {
- String id = StringUtils.substringBefore((String)internalValue, SEP);
- result = tx.findByTopiaId(id);
- } catch (TopiaException eee) {
- log.info("Fallback use string representation because"
- + " i can't decorate (String->Entity): "
- + internalValue, eee);
- // si on arrive pas a convertir cette fois-ci, on
- // renvoi internalValue pour que le undecorate est toutes les infos
- // et donc que la prochaine fois on y arrive peut etre
- }
- }
- }
- }
- cache.put(internalValue, result);
- }
- return result;
- }
-
- public Object undecorate(Object decoratedValue) {
- Object result = cache.getKey(decoratedValue);
- if (result == null && decoratedValue != null) {
- if (decoratedValue instanceof Month) {
- result = Month.class.getName() + SEP + ((Month)decoratedValue).getMonthNumber();
- } else if (decoratedValue instanceof TimeStep) {
- result = TimeStep.class.getName() + SEP + ((TimeStep)decoratedValue).getStep();
- } else if (decoratedValue instanceof TopiaEntity) {
- result = ((TopiaEntity)decoratedValue).getTopiaId() + SEP + decoratedValue;
- } else {
- result = String.valueOf(decoratedValue);
- }
- // on retrouve souvent les memes semantiques dans les matrices
- // pour minimiser les chaines en memoire, on prend la representation
- // interne avant de l'utiliser comme cle.
- cache.put(((String)result).intern(), decoratedValue);
- }
- return result;
- }
-
- }
-
- /**
* Represente un resultat
* Lors de la construction, si on ne passe que le RandomAccessFile et l'offset, on relie un resultat
* si on passe toutes les infos, on ecrit le resultat.
@@ -418,13 +303,8 @@
* @param simulation storage to get result
*/
public ResultMappedStorage(SimulationStorage simulation) throws IOException {
- this.simulation = simulation;
+ super(simulation);
- // instanciation de la factory avec l'implementation
- // choisie dans la config
- Class vectorClass = IsisFish.config.getMappedResultMatrixVectorClass();
- matrixFactory = MatrixFactory.getInstance(vectorClass);
-
File file = SimulationStorage.getResultFile(simulation.getDirectory());
// il faut toujours ouvrir en 'rw' car sinon les matrices n'arrive pas
@@ -434,13 +314,24 @@
// on lit les donnees deja presente
offset = 0;
while (offset < raf.length()) {
- ResultMapped r = new ResultMapped(matrixFactory, raf, offset);
+ ResultMapped r = new ResultMapped(getMatrixFactory(), raf, offset);
storeResult(r);
offset += r.size();
}
}
@Override
+ protected MatrixFactory getMatrixFactory() {
+ if (matrixFactory == null) {
+ // instanciation de la factory avec l'implementation
+ // choisie dans la config
+ Class vectorClass = IsisFish.config.getMappedResultMatrixVectorClass();
+ matrixFactory = MatrixFactory.getInstance(vectorClass);
+ }
+ return matrixFactory;
+ }
+
+ @Override
protected void finalize() throws Throwable {
try {
raf.close();
@@ -451,7 +342,7 @@
@Override
public void delete() {
- close();
+ super.delete();
File file = SimulationStorage.getResultFile(simulation.getDirectory());
file.delete();
}
@@ -474,12 +365,7 @@
String name = r.getName();
getResult(step).put(name, r);
- Map<TimeStep, ResultMapped> stepResult = nameStepResults.get(name);
- if (stepResult == null) {
- stepResult = new TreeMap<TimeStep, ResultMapped>();
- nameStepResults.put(name, stepResult);
- }
- stepResult.put(step, r);
+ getResult(name).put(step, r);
}
protected Map<String, ResultMapped> getResult(TimeStep step) {
@@ -491,80 +377,42 @@
return result;
}
- protected ResultMapped getResult(TimeStep step, String name) {
- ResultMapped result = getResult(step).get(name);
- return result;
- }
-
- protected ResultMapped getResult(TimeStep step, String name, Population pop) {
- name += " " + pop;
- ResultMapped result = getResult(step, name);
- return result;
- }
-
- protected Map<TimeStep, ResultMapped> getResult(String name, Population pop) {
- name += " " + pop;
- Map<TimeStep, ResultMapped> result = getResult(name);
- return result;
- }
-
protected Map<TimeStep, ResultMapped> getResult(String name) {
Map<TimeStep, ResultMapped> result = nameStepResults.get(name);
if (result == null) {
- // on retourne une map vide, pour ne jamais retourne null
- result = Collections.EMPTY_MAP;
+ result = new TreeMap<TimeStep, ResultMapped>();
+ nameStepResults.put(name, result);
}
return result;
}
+ @Override
+ protected MatrixND readResult(TimeStep step, String name) {
+ MatrixND result = null;
- public void addResult(TimeStep step, MatrixND mat) throws IsisFishException {
- addResult(false, step, mat.getName(), mat);
- }
-
- public void addResult(TimeStep step, Population pop, MatrixND mat) throws IsisFishException {
- addResult(false, step, mat.getName(), pop, mat);
- }
-
- public void addResult(boolean force, TimeStep step, MatrixND mat) throws IsisFishException {
- addResult(force, step, mat.getName(), mat);
- }
-
- public void addResult(boolean force, TimeStep step, Population pop, MatrixND mat) throws IsisFishException {
- addResult(force, step, mat.getName(), pop, mat);
- }
-
- public void addResult(TimeStep step, String name, Population pop, MatrixND mat) throws IsisFishException {
- addResult(false, step, name, pop, mat);
- }
-
- public void addResult(TimeStep step, String name, MatrixND mat) throws IsisFishException {
- addResult(false, step, name, mat);
- }
-
- public void addResult(boolean force, TimeStep step, String name, Population pop, MatrixND mat) throws IsisFishException {
- if (force || isEnabled(name)) {
- doAddResult(step, name + " " + pop, mat);
+ ResultMapped rm = getResult(step).get(name);
+ if (rm != null) {
+ result = rm.getMatrix();
}
- }
- public void addResult(boolean force, TimeStep step, String name, MatrixND mat) throws IsisFishException {
- if (force || isEnabled(name)) {
- doAddResult(step, name, mat);
- }
+ return result;
}
- protected void doAddResult(TimeStep step, String name, MatrixND mat) throws IsisFishException {
- // si la matrice n'a pas de semantique on refuse
- for (int i = 0; i < mat.getDimCount(); i++) {
- // la semantique n'est pas bonne des qu'il y a un null dedans
- if (mat.getSemantic(i).contains(null)) {
- throw new SimulationException(
- "Erreur le résultat que vous souhaitez enregistrer n'a pas d'information convenable pour la dimension: "
- + i + " " + mat.getDimensionName(i));
+ @Override
+ protected Map<TimeStep, MatrixND> readResult(String name) {
+ Map<TimeStep, MatrixND> result = Collections.EMPTY_MAP;
+ Map<TimeStep, ResultMapped> rms = nameStepResults.get(name);
+ if (rms != null) {
+ result = new HashMap<TimeStep, MatrixND>();
+ for (Map.Entry<TimeStep, ResultMapped> e : rms.entrySet()) {
+ result.put(e.getKey(), e.getValue().getMatrix());
}
}
+ return result;
+ }
+ @Override
+ protected void writeResult(TimeStep step, String name, MatrixND mat) {
try {
ResultMapped r = new ResultMapped(raf, offset, step, name, mat);
storeResult(r);
@@ -575,144 +423,15 @@
// temps de simulation, si on ne force pas le sync.
// raf.getFD().sync();
} catch (IOException eee) {
- log.warn("Can't add result '" + name + "' at step " + step, eee);
+ throw new IsisFishRuntimeException("Can't write result", eee);
}
}
-
-
-
-
-
-
- /**
- * Permet de savoir si lorsque l'on ajoutera ce resultat, il sera
- * sauvé ou non.
- *
- * Check for result name returned by :
- * <ul>
- * <li>{@link Export#getNecessaryResult()}</li>
- * <li>{@link SensitivityExport#getNecessaryResult()}</li>
- * <li>{@link Rule#getNecessaryResult()}</li>
- * <li>{@link SimulationPlan#getNecessaryResult()}</li>
- * </ul>
- *
- * @param name result name
- * @return {@code true} if result is enabled
- */
- public boolean isEnabled(String name) {
- name = name.trim();
- if (enabledResult == null && simulation.getSimulationParametersFile().exists()) {
- enabledResult = new HashSet<String>();
-
- Collection<String> resultEnabled = simulation.getParameter()
- .getResultEnabled();
- enabledResult.addAll(resultEnabled);
-
- // test on export
- List<String> exportNames = simulation.getParameter().getExportNames();
- if (exportNames != null) {
- for (String exportName : exportNames) {
- ExportStorage storage = ExportStorage.getExport(exportName);
- try {
- Export export = storage.getNewInstance();
- for (String resultName : export.getNecessaryResult()) {
- enabledResult.add(resultName);
- }
- } catch (IsisFishException eee) {
- if (log.isWarnEnabled()) {
- log.warn(t("isisfish.error.instanciate.export",
- exportName), eee);
- }
- }
- }
- }
-
- // test on sensitivity export
- List<SensitivityExport> sensitivityExports = simulation
- .getParameter().getSensitivityExport();
- if (sensitivityExports != null) {
- for (SensitivityExport sensitivityExport : sensitivityExports) {
- for (String resultName : sensitivityExport.getNecessaryResult()) {
- enabledResult.add(resultName);
- }
- }
- }
-
- // test on rules
- List<Rule> rules = simulation.getParameter().getRules();
- if (rules != null) {
- for (Rule rule : rules) {
- for (String resultName : rule.getNecessaryResult()) {
- enabledResult.add(resultName);
- }
- }
- }
-
- // test on plans
- List<SimulationPlan> plans = simulation.getParameter().getSimulationPlans();
- if (plans != null) {
- for (SimulationPlan plan : plans) {
- for (String resultName : plan.getNecessaryResult()) {
- enabledResult.add(resultName);
- }
- }
- }
-
- // on objective and optimization
- Objective objective = simulation.getParameter().getObjective();
- if (objective != null) {
- for (String resultName : objective.getNecessaryResult()) {
- enabledResult.add(resultName);
- }
- }
-
- Optimization optimization = simulation.getParameter().getOptimization();
- if (optimization != null) {
- for (String resultName : optimization.getNecessaryResult()) {
- enabledResult.add(resultName);
- }
- }
-
- log.info("Enabled result: " + enabledResult);
- }
- // par defaut on dit qu'on conserve le resultat
- boolean result = true;
- if (enabledResult != null) {
- result = enabledResult.contains(name);
- }
- return result;
+ @Override
+ protected void writeActiveRule(TimeStep step, String name, String params) {
+ // TODO
}
-
- public void addActiveRule(TimeStep step, Rule rule) throws IsisFishException {
- try {
- TopiaContext tx = null;
- boolean mustClose = false;
-
- if (simulation == SimulationContext.get().getSimulationStorage()) {
- tx = SimulationContext.get().getDbResult();
- }
- if (tx == null) {
- // not in simulation, create transaction
- tx = simulation.getStorage().beginTransaction();
- mustClose = true;
- }
- ActiveRuleDAO ps = IsisFishDAOHelper.getActiveRuleDAO(tx);
- ActiveRule result = ps.create();
- result.setActiveRuleStep(step);
- result.setName(RuleStorage.getName(rule));
- result.setParam(RuleStorage.getParamAsString(rule));
- ps.update(result);
- if (mustClose) {
- tx.commitTransaction();
- tx.closeContext();
- }
- } catch (TopiaException eee) {
- throw new IsisFishException("Can't add result", eee);
- }
- }
-
/**
* Retourne la liste de tous les résultats. Si le résultat est categorisé
* par une population alors le nom de la population est automatiquement
@@ -722,279 +441,5 @@
List<String> result = new ArrayList<String>(nameStepResults.keySet());
return result;
}
-
- /**
- * Retourne la matrice stocke pour un pas de temps
- * @param step le pas de temps que l'on souhaite
- * @param pop la population pour lequelle on souhaite le resultat
- * @param name le nom des resultats dont on veut la matrice
- * @return La matrice demandée ou null si aucune matrice ne correspond a
- * la demande.
- */
- public MatrixND getMatrix(TimeStep step, Population pop, String name) {
- String newName = name + " " + pop;
- return getMatrix(step, newName, null);
- }
-
- /**
- * Retourne la matrice stocke pour un pas de temps
- * @param step le pas de temps que l'on souhaite
- * @param pop la population pour lequelle on souhaite le resultat
- * @param name le nom des resultats dont on veut la matrice
- * @return La matrice demandée ou null si aucune matrice ne correspond a
- * la demande.
- */
- public MatrixND getMatrix(TimeStep step, Population pop, String name, TopiaContext tx) {
- String newName = name + " " + pop;
- return getMatrix(step, newName, tx);
- }
-
- public MatrixND getMatrix(TimeStep step, String name) {
- return getMatrix(step, name, null);
- }
-
- /**
- * Retourne une matrice contenant tous les pas de temps.
- *
- * @param name le nom des resultats dont on veut une matrice globale.
- */
- public MatrixND getMatrix(TimeStep step, String name, TopiaContext tx) {
- ResultMapped r = getResult(step, name);
- MatrixND mat = null;
- if (r != null) {
- tx = getTx(tx);
- mat = r.getMatrix(tx);
- }
- return mat;
- }
-
- /**
- * Retourne une matrice contenant tous les pas de temps.
- * @param pop la population pour lequel on souhaite la matrice
- * @param name le nom des resultats dont on veut une matrice globale.
- */
- public MatrixND getMatrix(Population pop, String name) {
- String newName = name + " " + pop;
- return getMatrix(newName, null);
- }
- /* (non-Javadoc)
- * @see fr.ifremer.isisfish.datastore.ResultStorage#getMatrix(fr.ifremer.isisfish.entities.Population, java.lang.String, org.nuiton.topia.TopiaContext)
- */
- @Override
- public MatrixND getMatrix(Population pop, String name, TopiaContext tx) {
- String newName = name + " " + pop;
- return getMatrix(newName, tx);
- }
-
- /**
- * Retourne une matrice contenant tous les pas de temps.
- *
- * @param name le nom des resultats dont on veut une matrice globale.
- */
- public MatrixND getMatrix(String name) {
- return getMatrix(name, null);
- }
-
- /**
- * Retourne une matrice contenant tous les pas de temps.
- * @param name le nom des resultats dont on veut une matrice globale.
- */
- public MatrixND getMatrix(String name, TopiaContext tx) {
- log.debug("Get result: " + name);
-
- MatrixND resultMat = null;
- Map<TimeStep, ResultMapped> results = getResult(name);
- // recuperation des resultats qui nous interesse
- if (!results.isEmpty()) {
- // creation de la liste de date
- TimeStep lastStep = getLastStep();
- List<TimeStep> steps = new ArrayList<TimeStep>();
- TimeStep step = new TimeStep(0);
- steps.add(step);
- while (step.before(lastStep)) {
- step = step.next();
- steps.add(step);
- }
-
- if (log.isTraceEnabled()) {
- log.trace("Steps list : " + steps);
- }
-
-
- MatrixND mat = results.values().iterator().next().getMatrix();
-
- // recuperation des noms des dimensions
- String[] dimNames = new String[1 + mat.getDimCount()];
- dimNames[0] = t("isisfish.common.date");
- for (int i = 1; i < dimNames.length; i++) {
- dimNames[i] = mat.getDimensionName(i - 1);
- }
-
- // creation de la semantique pour la matrice resultat. +1 pour les dates
- List[] sem = new List[1 + mat.getDimCount()];
- sem[0] = steps;
-
- for (int i = 1; i < sem.length; i++) {
- sem[i] = new HashList();
- }
-
- for (ResultMapped result : results.values()) {
- MatrixND mattmp = result.getMatrix();
- if (log.isTraceEnabled()) {
- log.trace("Ajout de la semantics: "
- + Arrays.asList(mattmp.getSemantics()));
- }
-
- for (int s = 0; s < mattmp.getDimCount(); s++) {
- sem[s + 1].addAll(mattmp.getSemantic(s));
- }
- }
-
- if (log.isTraceEnabled()) {
- log.trace("La semantique final est: " + Arrays.asList(sem));
- }
-
- // creation de la matrice resultat
- resultMat = matrixFactory.create(name, sem, dimNames);
-
- // recuperation du resultat pour chaque date de la simulation, de Date(0) à lastDate
- for (ResultMapped result : results.values()) {
- TimeStep d = result.getStep();
- mat = result.getMatrix();
- // on met ce resultat dans la matrice result si besoin
- if (mat != null) {
- // on recupere dans la matrice resultat l'endroit on il faut
- // mettre la matrice
- MatrixND submat = resultMat.getSubMatrix(0, d, 1);
- // on met les valeur de mat dans la sous matrice extraite
- for (MatrixIterator mi = mat.iterator(); mi.next();) {
- submat.setValue(
- ArrayUtil.concat(new Object[] { d },
- mi.getSemanticsCoordinates()), mi.getValue());
- }
- }
- }
- }
- if (resultMat != null) {
- // on decore la matrice resultat au dernier moment, tous les calcules
- // ce font avec les strings
- tx = getTx(tx);
- resultMat = new MatrixSemanticsDecorator(resultMat, new EntitySemanticsDecorator(tx));
- }
- return resultMat;
- }
-
- /**
- * Get last simulation date.
- *
- * @return last simulation date
- */
- public TimeStep getLastStep() {
- int monthNumber = simulation.getParameter().getNumberOfYear()
- * Month.NUMBER_OF_MONTH;
- TimeStep result = new TimeStep(monthNumber - 1); // -1 because date begin at 0
- return result;
- }
-
- /*
- * @see fr.ifremer.isisfish.simulator.SimulationResultListener#addResult(fr.ifremer.isisfish.simulator.SimulationContext, fr.ifremer.isisfish.types.TimeStep, java.lang.String, org.nuiton.math.matrix.MatrixND)
- */
- @Override
- public void addResult(SimulationContext context, TimeStep step, String name,
- MatrixND mat) throws IsisFishException {
- doAddResult(step, name, mat);
- }
-
- /*
- * @see fr.ifremer.isisfish.simulator.SimulationResultGetter#getMatrix(fr.ifremer.isisfish.simulator.SimulationContext, fr.ifremer.isisfish.types.TimeStep, java.lang.String)
- */
- @Override
- public MatrixND getMatrix(SimulationContext context, TimeStep step, String name) {
- MatrixND result = null;
- try {
- result = getMatrix(step, name, context.getDB());
- } catch (TopiaException eee) {
- if (log.isWarnEnabled()) {
- log.warn(String.format("Can't get result: %1$s", name), eee);
- }
- }
- return result;
-
- }
-
- /*
- * @see fr.ifremer.isisfish.simulator.SimulationResultGetter#getMatrix(fr.ifremer.isisfish.simulator.SimulationContext, java.lang.String)
- */
- @Override
- public MatrixND getMatrix(SimulationContext context, String name) {
- MatrixND result = null;
- try {
- result = getMatrix(name, context.getDB());
- } catch (TopiaException eee) {
- if (log.isWarnEnabled()) {
- log.warn(String.format("Can't get result: %1$s", name), eee);
- }
- }
- return result;
- }
-
- /**
- * Try to find better tx. If argument is not null, return it. otherwize
- * try to get tx in SimulationContext.
- *
- * @param tx
- * @return
- */
- protected TopiaContext getTx(TopiaContext tx) {
- TopiaContext result = tx;
- if (tx == null) {
- // si on a pas de tx, on recherche si on est dans une simulation
- // pour recuperer la tx de la simulation
- if (simulation == SimulationContext.get().getSimulationStorage()) {
- try {
- result = SimulationContext.get().getDB();
- } catch (TopiaException eee) {
- throw new IsisFishRuntimeException("Can't get database from SimulationContext", eee);
- }
- }
- }
- return result;
- }
-
- /*
- * @see fr.ifremer.isisfish.simulator.SimulationListener#afterSimulation(fr.ifremer.isisfish.simulator.SimulationContext)
- */
- @Override
- public void afterSimulation(SimulationContext context) {
- }
-
- /*
- * @see fr.ifremer.isisfish.simulator.SimulationListener#beforeSimulation(fr.ifremer.isisfish.simulator.SimulationContext)
- */
- @Override
- public void beforeSimulation(SimulationContext context) {
- }
-
- // public void addActivatedRule(ResultStorage self, Date date, RegleParam rule){
- // List rules = (List)activatedRules.get(date);
- // if(rules == null){
- // activatedRules.put(date, rules = new LinkedList());
- // }
- // rules.add(rule);
- // }
-
- // /**
- // * Retourne pour une date données tous les RegleParam qui ont été activé
- // * a la date demandé.
- // * @return une list de {@link fr.ifremer.nodb.RegleParam}
- // */
- // public List getActivatedRule(ResultStorage self, Date date){
- // List rules = (List)activatedRules.get(date);
- // if(rules == null){
- // activatedRules.put(date, rules = new LinkedList());
- // }
- // return rules;
- // }
-
}
Copied: trunk/src/main/java/fr/ifremer/isisfish/datastore/ResultStorageAbstract.java (from rev 4023, trunk/src/main/java/fr/ifremer/isisfish/datastore/ResultMappedStorage.java)
===================================================================
--- trunk/src/main/java/fr/ifremer/isisfish/datastore/ResultStorageAbstract.java (rev 0)
+++ trunk/src/main/java/fr/ifremer/isisfish/datastore/ResultStorageAbstract.java 2014-06-29 18:44:00 UTC (rev 4026)
@@ -0,0 +1,681 @@
+/*
+ * #%L
+ * IsisFish
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2012 Ifremer, Code Lutin, Benjamin Poussin, Chatellier Eric
+ * %%
+ * 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/gpl-3.0.html>.
+ * #L%
+ */
+
+package fr.ifremer.isisfish.datastore;
+
+import static org.nuiton.i18n.I18n.t;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.commons.collections4.BidiMap;
+import org.apache.commons.collections4.bidimap.DualHashBidiMap;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.nuiton.math.matrix.MatrixIterator;
+import org.nuiton.math.matrix.MatrixND;
+import org.nuiton.math.matrix.MatrixSemanticsDecorator;
+import org.nuiton.math.matrix.SemanticsDecorator;
+import org.nuiton.topia.TopiaContext;
+import org.nuiton.topia.TopiaException;
+import org.nuiton.topia.persistence.TopiaEntity;
+import org.nuiton.util.ArrayUtil;
+import org.nuiton.util.HashList;
+
+import fr.ifremer.isisfish.IsisFishException;
+import fr.ifremer.isisfish.IsisFishRuntimeException;
+import fr.ifremer.isisfish.entities.Population;
+import fr.ifremer.isisfish.export.Export;
+import fr.ifremer.isisfish.export.SensitivityExport;
+import fr.ifremer.isisfish.rule.Rule;
+import fr.ifremer.isisfish.simulator.Objective;
+import fr.ifremer.isisfish.simulator.Optimization;
+import fr.ifremer.isisfish.simulator.SimulationContext;
+import fr.ifremer.isisfish.simulator.SimulationException;
+import fr.ifremer.isisfish.simulator.SimulationPlan;
+import fr.ifremer.isisfish.simulator.SimulationResultGetter;
+import fr.ifremer.isisfish.simulator.SimulationResultListener;
+import fr.ifremer.isisfish.types.Month;
+import fr.ifremer.isisfish.types.TimeStep;
+import org.nuiton.math.matrix.MatrixFactory;
+
+/**
+ * Classe abstraite servant a factoriser tous les traitements commun au differente
+ * implantation. Lorsqu'on herite de cette classe il reste a definir la lecture
+ * et l'ecriture reel des resultats (en memoire, en base, binary file, ...)
+ *
+ * Created: 24 juin 2014
+ *
+ * @author Benjamin Poussin : poussin(a)codelutin.com
+ * @version $Revision$
+ *
+ * Mise a jour: $Date$
+ * par : $Author$
+ */
+public abstract class ResultStorageAbstract implements SimulationResultListener,
+ SimulationResultGetter, ResultStorage { // ResultStorage
+
+ /** to use log facility, just put in your code: log.info(\"...\"); */
+ static private Log log = LogFactory.getLog(ResultStorageAbstract.class);
+
+ protected SimulationStorage simulation = null;
+
+ /** result enabled */
+ transient protected Set<String> enabledResult = null;
+
+ /**
+ * Convertie une entite, month, timestep en string et inversement.
+ * Entity = "TopiaId:Entity.toString"
+ */
+ static protected class EntitySemanticsDecorator implements SemanticsDecorator {
+ static final private String SEP = ":";
+
+ protected TopiaContext tx;
+ /** en cle les representation interne (get) en valeur les valeurs decoree (getKey) */
+ protected BidiMap<Object, Object> cache = new DualHashBidiMap<>();
+
+ public EntitySemanticsDecorator() {
+ }
+
+ public EntitySemanticsDecorator(TopiaContext tx) {
+ this.tx = tx;
+ }
+
+ @Override
+ public Object decorate(Object internalValue) {
+ Object result = cache.get(internalValue);
+ if (result == null && internalValue != null) {
+ result = internalValue;
+ if (internalValue instanceof String) {
+ // on retrouve souvent les memes semantiques dans les matrices
+ // pour minimiser les chaines en memoire, on prend la representation
+ // interne avant de l'utiliser comme cle.
+ internalValue = ((String)internalValue).intern();
+ result = internalValue;
+ if (StringUtils.startsWith((String)internalValue, Month.class.getName())) {
+ String val = StringUtils.substringAfter((String)internalValue, SEP);
+ int monthNumber = Integer.parseInt(val);
+ result = new Month(monthNumber);
+ } else if (StringUtils.startsWith((String)internalValue, TimeStep.class.getName())) {
+ String val = StringUtils.substringAfter((String)internalValue, SEP);
+ int stepNumber = Integer.parseInt(val);
+ result = new TimeStep(stepNumber);
+ } else if (StringUtils.startsWith((String)internalValue, "fr.ifremer.isisfish.entities.")) {
+ if (tx == null) {
+ result = StringUtils.substringAfter((String)internalValue, SEP);
+ } else {
+ try {
+ String id = StringUtils.substringBefore((String)internalValue, SEP);
+ result = tx.findByTopiaId(id);
+ } catch (TopiaException eee) {
+ log.info("Fallback use string representation because"
+ + " i can't decorate (String->Entity): "
+ + internalValue, eee);
+ // si on arrive pas a convertir cette fois-ci, on
+ // renvoi internalValue pour que le undecorate est toutes les infos
+ // et donc que la prochaine fois on y arrive peut etre
+ }
+ }
+ }
+ }
+ cache.put(internalValue, result);
+ }
+ return result;
+ }
+
+ @Override
+ public Object undecorate(Object decoratedValue) {
+ Object result = cache.getKey(decoratedValue);
+ if (result == null && decoratedValue != null) {
+ if (decoratedValue instanceof Month) {
+ result = Month.class.getName() + SEP + ((Month)decoratedValue).getMonthNumber();
+ } else if (decoratedValue instanceof TimeStep) {
+ result = TimeStep.class.getName() + SEP + ((TimeStep)decoratedValue).getStep();
+ } else if (decoratedValue instanceof TopiaEntity) {
+ result = ((TopiaEntity)decoratedValue).getTopiaId() + SEP + decoratedValue;
+ } else {
+ result = String.valueOf(decoratedValue);
+ }
+ // on retrouve souvent les memes semantiques dans les matrices
+ // pour minimiser les chaines en memoire, on prend la representation
+ // interne avant de l'utiliser comme cle.
+ cache.put(((String)result).intern(), decoratedValue);
+ }
+ return result;
+ }
+
+ }
+
+ /**
+ * Return one result for step and name
+ *
+ * @param step
+ * @param name
+ * @return
+ */
+ abstract protected MatrixND readResult(TimeStep step, String name);
+ /**
+ * Return all available result for name in argument
+ * @param name
+ * @return
+ */
+ abstract protected Map<TimeStep, MatrixND> readResult(String name);
+ /**
+ * write result
+ * @param step
+ * @param name
+ * @param mat
+ */
+ abstract protected void writeResult(TimeStep step, String name, MatrixND mat);
+ /**
+ * Write active rule
+ * @param step
+ * @param name
+ * @param params
+ */
+ abstract protected void writeActiveRule(TimeStep step, String name, String params);
+ /**
+ * return list of all result name available
+ * @return
+ */
+ abstract public List<String> getResultName();
+
+ /**
+ * sub class can overwrite this method to return specifique factory
+ * @return
+ */
+ protected MatrixFactory getMatrixFactory() {
+ return MatrixFactory.getInstance();
+ }
+
+ protected MatrixND decorate(MatrixND mat, TopiaContext tx) {
+ MatrixND result = null;
+ if (mat != null) {
+ // on decore la matrice resultat au dernier moment, tous les calcules
+ // ce font avec les strings
+ tx = getTx(tx);
+ result = new MatrixSemanticsDecorator(mat, new EntitySemanticsDecorator(tx));
+ }
+ return result;
+ }
+
+ /**
+ * Les ResultStorage ne doivent pas etre instancier directement, mais
+ * recuperer a partir d'un
+ * {@link fr.ifremer.isisfish.datastore.SimulationStorage#getResultStorage()}
+ *
+ * @param simulation storage to get result
+ */
+ public ResultStorageAbstract(SimulationStorage simulation) {
+ this.simulation = simulation;
+ }
+
+ @Override
+ public void delete() {
+ close();
+ }
+
+ @Override
+ public void close() {
+ }
+
+ @Override
+ public void addResult(TimeStep step, MatrixND mat) throws IsisFishException {
+ addResult(false, step, mat.getName(), mat);
+ }
+
+ @Override
+ public void addResult(TimeStep step, Population pop, MatrixND mat) throws IsisFishException {
+ addResult(false, step, mat.getName(), pop, mat);
+ }
+
+ @Override
+ public void addResult(boolean force, TimeStep step, MatrixND mat) throws IsisFishException {
+ addResult(force, step, mat.getName(), mat);
+ }
+
+ @Override
+ public void addResult(boolean force, TimeStep step, Population pop, MatrixND mat) throws IsisFishException {
+ addResult(force, step, mat.getName(), pop, mat);
+ }
+
+ @Override
+ public void addResult(TimeStep step, String name, Population pop, MatrixND mat) throws IsisFishException {
+ addResult(false, step, name, pop, mat);
+ }
+
+ @Override
+ public void addResult(TimeStep step, String name, MatrixND mat) throws IsisFishException {
+ addResult(false, step, name, mat);
+ }
+
+ @Override
+ public void addResult(boolean force, TimeStep step, String name, Population pop, MatrixND mat) throws IsisFishException {
+ if (force || isEnabled(name)) {
+ doAddResult(step, name + " " + pop, mat);
+ }
+ }
+
+ @Override
+ public void addResult(boolean force, TimeStep step, String name, MatrixND mat) throws IsisFishException {
+ if (force || isEnabled(name)) {
+ doAddResult(step, name, mat);
+ }
+ }
+
+ protected void doAddResult(TimeStep step, String name, MatrixND mat) throws IsisFishException {
+ // si la matrice n'a pas de semantique on refuse
+ for (int i = 0; i < mat.getDimCount(); i++) {
+ // la semantique n'est pas bonne des qu'il y a un null dedans
+ if (mat.getSemantic(i).contains(null)) {
+ throw new SimulationException(
+ "Erreur le résultat que vous souhaitez enregistrer n'a pas d'information convenable pour la dimension: "
+ + i + " " + mat.getDimensionName(i));
+ }
+ }
+
+ try {
+ writeResult(step, name, mat);
+ } catch (Exception eee) {
+ log.warn("Can't add result '" + name + "' at step " + step, eee);
+ }
+ }
+
+ /**
+ * Permet de savoir si lorsque l'on ajoutera ce resultat, il sera
+ * sauvé ou non.
+ *
+ * Check for result name returned by :
+ * <ul>
+ * <li>{@link Export#getNecessaryResult()}</li>
+ * <li>{@link SensitivityExport#getNecessaryResult()}</li>
+ * <li>{@link Rule#getNecessaryResult()}</li>
+ * <li>{@link SimulationPlan#getNecessaryResult()}</li>
+ * </ul>
+ *
+ * @param name result name
+ * @return {@code true} if result is enabled
+ */
+ @Override
+ public boolean isEnabled(String name) {
+ name = name.trim();
+ if (enabledResult == null && simulation.getSimulationParametersFile().exists()) {
+ enabledResult = new HashSet<String>();
+
+ Collection<String> resultEnabled = simulation.getParameter()
+ .getResultEnabled();
+ enabledResult.addAll(resultEnabled);
+
+ // test on export
+ List<String> exportNames = simulation.getParameter().getExportNames();
+ if (exportNames != null) {
+ for (String exportName : exportNames) {
+ ExportStorage storage = ExportStorage.getExport(exportName);
+ try {
+ Export export = storage.getNewInstance();
+ Collections.addAll(enabledResult, export.getNecessaryResult());
+ } catch (IsisFishException eee) {
+ if (log.isWarnEnabled()) {
+ log.warn(t("isisfish.error.instanciate.export",
+ exportName), eee);
+ }
+ }
+ }
+ }
+
+ // test on sensitivity export
+ List<SensitivityExport> sensitivityExports = simulation
+ .getParameter().getSensitivityExport();
+ if (sensitivityExports != null) {
+ for (SensitivityExport sensitivityExport : sensitivityExports) {
+ Collections.addAll(enabledResult, sensitivityExport.getNecessaryResult());
+ }
+ }
+
+ // test on rules
+ List<Rule> rules = simulation.getParameter().getRules();
+ if (rules != null) {
+ for (Rule rule : rules) {
+ Collections.addAll(enabledResult, rule.getNecessaryResult());
+ }
+ }
+
+ // test on plans
+ List<SimulationPlan> plans = simulation.getParameter().getSimulationPlans();
+ if (plans != null) {
+ for (SimulationPlan plan : plans) {
+ Collections.addAll(enabledResult, plan.getNecessaryResult());
+ }
+ }
+
+ // on objective and optimization
+ Objective objective = simulation.getParameter().getObjective();
+ if (objective != null) {
+ Collections.addAll(enabledResult, objective.getNecessaryResult());
+ }
+
+ Optimization optimization = simulation.getParameter().getOptimization();
+ if (optimization != null) {
+ Collections.addAll(enabledResult, optimization.getNecessaryResult());
+ }
+
+ log.info("Enabled result: " + enabledResult);
+ }
+ // par defaut on dit qu'on conserve le resultat
+ boolean result = true;
+ if (enabledResult != null) {
+ result = enabledResult.contains(name);
+ }
+ return result;
+ }
+
+
+ @Override
+ public void addActiveRule(TimeStep step, Rule rule) throws IsisFishException {
+ String name = RuleStorage.getName(rule);
+ String params = RuleStorage.getParamAsString(rule);
+ writeActiveRule(step, name, params);
+ }
+
+ /**
+ * Retourne la matrice stocke pour un pas de temps
+ * @param step le pas de temps que l'on souhaite
+ * @param pop la population pour lequelle on souhaite le resultat
+ * @param name le nom des resultats dont on veut la matrice
+ * @return La matrice demandée ou null si aucune matrice ne correspond a
+ * la demande.
+ */
+ @Override
+ public MatrixND getMatrix(TimeStep step, Population pop, String name) {
+ String newName = name + " " + pop;
+ return getMatrix(step, newName, null);
+ }
+
+ /**
+ * Retourne la matrice stocke pour un pas de temps
+ * @param step le pas de temps que l'on souhaite
+ * @param pop la population pour lequelle on souhaite le resultat
+ * @param name le nom des resultats dont on veut la matrice
+ * @return La matrice demandée ou null si aucune matrice ne correspond a
+ * la demande.
+ */
+ public MatrixND getMatrix(TimeStep step, Population pop, String name, TopiaContext tx) {
+ String newName = name + " " + pop;
+ return getMatrix(step, newName, tx);
+ }
+
+ @Override
+ public MatrixND getMatrix(TimeStep step, String name) {
+ return getMatrix(step, name, null);
+ }
+
+ /**
+ * Retourne une matrice contenant tous les pas de temps.
+ *
+ * @param name le nom des resultats dont on veut une matrice globale.
+ */
+ @Override
+ public MatrixND getMatrix(TimeStep step, String name, TopiaContext tx) {
+ MatrixND mat = readResult(step, name);
+ mat = decorate(mat, tx);
+ return mat;
+ }
+
+ /**
+ * Retourne une matrice contenant tous les pas de temps.
+ * @param pop la population pour lequel on souhaite la matrice
+ * @param name le nom des resultats dont on veut une matrice globale.
+ */
+ @Override
+ public MatrixND getMatrix(Population pop, String name) {
+ String newName = name + " " + pop;
+ return getMatrix(newName, null);
+ }
+
+ /* (non-Javadoc)
+ * @see fr.ifremer.isisfish.datastore.ResultStorage#getMatrix(fr.ifremer.isisfish.entities.Population, java.lang.String, org.nuiton.topia.TopiaContext)
+ */
+ @Override
+ public MatrixND getMatrix(Population pop, String name, TopiaContext tx) {
+ String newName = name + " " + pop;
+ return getMatrix(newName, tx);
+ }
+
+ /**
+ * Retourne une matrice contenant tous les pas de temps.
+ *
+ * @param name le nom des resultats dont on veut une matrice globale.
+ */
+ @Override
+ public MatrixND getMatrix(String name) {
+ return getMatrix(name, null);
+ }
+
+ /**
+ * Retourne une matrice contenant tous les pas de temps.
+ * @param name le nom des resultats dont on veut une matrice globale.
+ */
+ @Override
+ public MatrixND getMatrix(String name, TopiaContext tx) {
+ log.debug("Get result: " + name);
+
+ MatrixND resultMat = null;
+ Map<TimeStep, MatrixND> results = readResult(name);
+ // recuperation des resultats qui nous interesse
+ if (!results.isEmpty()) {
+ // creation de la liste de date
+ TimeStep lastStep = getLastStep();
+ List<TimeStep> steps = new ArrayList<TimeStep>();
+ TimeStep step = new TimeStep(0);
+ steps.add(step);
+ while (step.before(lastStep)) {
+ step = step.next();
+ steps.add(step);
+ }
+
+ if (log.isTraceEnabled()) {
+ log.trace("Steps list : " + steps);
+ }
+
+
+ MatrixND mat = results.values().iterator().next();
+
+ // recuperation des noms des dimensions
+ String[] dimNames = new String[1 + mat.getDimCount()];
+ dimNames[0] = t("isisfish.common.date");
+ for (int i = 1; i < dimNames.length; i++) {
+ dimNames[i] = mat.getDimensionName(i - 1);
+ }
+
+ // creation de la semantique pour la matrice resultat. +1 pour les dates
+ List[] sem = new List[1 + mat.getDimCount()];
+ sem[0] = steps;
+
+ for (int i = 1; i < sem.length; i++) {
+ sem[i] = new HashList();
+ }
+
+ for (MatrixND mattmp : results.values()) {
+ if (log.isTraceEnabled()) {
+ log.trace("Ajout de la semantics: "
+ + Arrays.asList(mattmp.getSemantics()));
+ }
+
+ for (int s = 0; s < mattmp.getDimCount(); s++) {
+ sem[s + 1].addAll(mattmp.getSemantic(s));
+ }
+ }
+
+ if (log.isTraceEnabled()) {
+ log.trace("La semantique final est: " + Arrays.asList(sem));
+ }
+
+ // creation de la matrice resultat
+ resultMat = getMatrixFactory().create(name, sem, dimNames);
+
+ // recuperation du resultat pour chaque date de la simulation, de Date(0) à lastDate
+ for (Map.Entry<TimeStep, MatrixND> result : results.entrySet()) {
+ TimeStep d = result.getKey();
+ mat = result.getValue();
+ // on met ce resultat dans la matrice result si besoin
+ if (mat != null) {
+ // on recupere dans la matrice resultat l'endroit on il faut
+ // mettre la matrice
+ MatrixND submat = resultMat.getSubMatrix(0, d, 1);
+ // on met les valeur de mat dans la sous matrice extraite
+ for (MatrixIterator mi = mat.iterator(); mi.next();) {
+ submat.setValue(
+ ArrayUtil.concat(new Object[] { d },
+ mi.getSemanticsCoordinates()), mi.getValue());
+ }
+ }
+ }
+ }
+
+ resultMat = decorate(resultMat, tx);
+ return resultMat;
+ }
+
+ /**
+ * Get last simulation date.
+ *
+ * @return last simulation date
+ */
+ @Override
+ public TimeStep getLastStep() {
+ int monthNumber = simulation.getParameter().getNumberOfYear()
+ * Month.NUMBER_OF_MONTH;
+ TimeStep result = new TimeStep(monthNumber - 1); // -1 because date begin at 0
+ return result;
+ }
+
+ /*
+ * @see fr.ifremer.isisfish.simulator.SimulationResultListener#addResult(fr.ifremer.isisfish.simulator.SimulationContext, fr.ifremer.isisfish.types.TimeStep, java.lang.String, org.nuiton.math.matrix.MatrixND)
+ */
+ @Override
+ public void addResult(SimulationContext context, TimeStep step, String name,
+ MatrixND mat) throws IsisFishException {
+ doAddResult(step, name, mat);
+ }
+
+ /*
+ * @see fr.ifremer.isisfish.simulator.SimulationResultGetter#getMatrix(fr.ifremer.isisfish.simulator.SimulationContext, fr.ifremer.isisfish.types.TimeStep, java.lang.String)
+ */
+ @Override
+ public MatrixND getMatrix(SimulationContext context, TimeStep step, String name) {
+ MatrixND result = null;
+ try {
+ result = getMatrix(step, name, context.getDB());
+ } catch (TopiaException eee) {
+ if (log.isWarnEnabled()) {
+ log.warn(String.format("Can't get result: %1$s", name), eee);
+ }
+ }
+ return result;
+
+ }
+
+ /*
+ * @see fr.ifremer.isisfish.simulator.SimulationResultGetter#getMatrix(fr.ifremer.isisfish.simulator.SimulationContext, java.lang.String)
+ */
+ @Override
+ public MatrixND getMatrix(SimulationContext context, String name) {
+ MatrixND result = null;
+ try {
+ result = getMatrix(name, context.getDB());
+ } catch (TopiaException eee) {
+ if (log.isWarnEnabled()) {
+ log.warn(String.format("Can't get result: %1$s", name), eee);
+ }
+ }
+ return result;
+ }
+
+ /**
+ * Try to find better tx. If argument is not null, return it. otherwize
+ * try to get tx in SimulationContext.
+ *
+ * @param tx
+ * @return
+ */
+ protected TopiaContext getTx(TopiaContext tx) {
+ TopiaContext result = tx;
+ if (tx == null) {
+ // si on a pas de tx, on recherche si on est dans une simulation
+ // pour recuperer la tx de la simulation
+ if (simulation == SimulationContext.get().getSimulationStorage()) {
+ try {
+ result = SimulationContext.get().getDB();
+ } catch (TopiaException eee) {
+ throw new IsisFishRuntimeException("Can't get database from SimulationContext", eee);
+ }
+ }
+ }
+ return result;
+ }
+
+ /*
+ * @see fr.ifremer.isisfish.simulator.SimulationListener#afterSimulation(fr.ifremer.isisfish.simulator.SimulationContext)
+ */
+ @Override
+ public void afterSimulation(SimulationContext context) {
+ }
+
+ /*
+ * @see fr.ifremer.isisfish.simulator.SimulationListener#beforeSimulation(fr.ifremer.isisfish.simulator.SimulationContext)
+ */
+ @Override
+ public void beforeSimulation(SimulationContext context) {
+ }
+
+ // public void addActivatedRule(ResultStorage self, Date date, RegleParam rule){
+ // List rules = (List)activatedRules.get(date);
+ // if(rules == null){
+ // activatedRules.put(date, rules = new LinkedList());
+ // }
+ // rules.add(rule);
+ // }
+
+ // /**
+ // * Retourne pour une date données tous les RegleParam qui ont été activé
+ // * a la date demandé.
+ // * @return une list de {@link fr.ifremer.nodb.RegleParam}
+ // */
+ // public List getActivatedRule(ResultStorage self, Date date){
+ // List rules = (List)activatedRules.get(date);
+ // if(rules == null){
+ // activatedRules.put(date, rules = new LinkedList());
+ // }
+ // return rules;
+ // }
+
+}
Added: trunk/src/main/java/fr/ifremer/isisfish/datastore/ResultStorageCSV.java
===================================================================
--- trunk/src/main/java/fr/ifremer/isisfish/datastore/ResultStorageCSV.java (rev 0)
+++ trunk/src/main/java/fr/ifremer/isisfish/datastore/ResultStorageCSV.java 2014-06-29 18:44:00 UTC (rev 4026)
@@ -0,0 +1,303 @@
+package fr.ifremer.isisfish.datastore;
+
+
+import fr.ifremer.isisfish.IsisFishRuntimeException;
+import fr.ifremer.isisfish.types.TimeStep;
+import fr.ifremer.isisfish.util.SimpleParser;
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.LineNumberReader;
+import java.io.OutputStreamWriter;
+import java.io.PrintWriter;
+import java.nio.charset.Charset;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.zip.GZIPInputStream;
+import java.util.zip.GZIPOutputStream;
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.io.IOUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.nuiton.math.matrix.MatrixIterator;
+import org.nuiton.math.matrix.MatrixND;
+
+/**
+ * Ecrit les resultats dans des fichiers au format pseudo csv compresser (gz)
+ * Seule les valeurs differentes de 0 sont ecrite dans le fichier
+ *
+ * Format d'une matrice:
+ * <pre>
+ * # commentaire
+ * [nom]
+ * [nom dimension1]:[semantique1];[semantique2];...
+ * [nom dimension2]:[semantique1];[semantique2];...
+ * ...
+ * [ligne blanche]
+ * [coordonnee1];[coordonnee2];...;[valeur]
+ * [coordonnee1];[coordonnee2];...;[valeur]
+ * [coordonnee1];[coordonnee2];...;[valeur]
+ * ...
+ * </pre>
+ *
+ * Exemple
+ * <pre>
+ * MaMatrice
+ * Mois:Janvier;Fevrier;Mars
+ * Ville:Nantes;Paris;Nice
+ *
+ * 1;1;2;13.5
+ * 0;2;1;4.2
+ * </pre>
+ *
+ * TODO:
+ * stat du nombre de demande de resultat or pas de temps courant
+ * stat sur max ecart entre pas de temps courant et pas de temps demande
+ *
+ * @author poussin
+ * @version $Revision$
+ *
+ * Last update: $Date$
+ * by : $Author$
+ */
+public class ResultStorageCSV extends ResultStorageAbstract {
+
+ /** to use log facility, just put in your code: log.info(\"...\"); */
+ static private Log log = LogFactory.getLog(ResultStorageCSV.class);
+
+ static final private Charset charset = Charset.forName("UTF-8");
+
+ protected EntitySemanticsDecorator decorator;
+
+ public ResultStorageCSV(SimulationStorage simulation) {
+ super(simulation);
+ decorator = new EntitySemanticsDecorator();
+ }
+
+ /**
+ * donne le repertoire de stockage des resultats
+ * @return
+ */
+ protected File getDirectory() {
+ File file = SimulationStorage.getResultDirectory(simulation.getDirectory());
+ return file;
+ }
+
+ /**
+ * Donne le repertoire de stockage pour un certain type de resultat matriciel
+ * @param name
+ * @return
+ */
+ protected File getMatrixDirectory(String name) {
+ File file = new File(getDirectory(), "matrix" + File.separator + name);
+ return file;
+ }
+
+ protected File getMatrixFile(TimeStep step, String name) {
+ File file = new File(getMatrixDirectory(name), step.getStep() + "-" + name + ".csv.gz");
+ return file;
+ }
+
+ protected MatrixND readMatrix(File file) throws IOException {
+ return readMatrix(file.getPath());
+ }
+
+ protected MatrixND readMatrix(String file) throws IOException {
+ MatrixND result = null;
+ LineNumberReader in = null;
+ try {
+ in = new LineNumberReader(new InputStreamReader(
+ new GZIPInputStream(new FileInputStream(file)), charset));
+
+ SimpleParser sp = new SimpleParser(in, true);
+
+ // lecture du nom de la matrice
+ String name = sp.readString('\n');
+
+
+ // lecture du nom des dimensions et des semantics
+ List<String> dimNames = new ArrayList<String>();
+ List<List<String>> semantics = new ArrayList<List<String>>();
+
+ String dimName = sp.readString(':');
+ while (!sp.isEOL() || StringUtils.isNotBlank(dimName)) {
+ dimNames.add(dimName);
+ List<String> sems = new ArrayList<String>();
+ semantics.add(sems);
+ while (!sp.isEOL()) {
+ String sem = sp.readString(';');
+ sems.add(sem);
+ }
+ dimName = sp.readString(':');
+ }
+
+ // creation de la matrice resultat avec les infos collectes
+ result = getMatrixFactory().create(name,
+ semantics.toArray(new List[semantics.size()]),
+ dimNames.toArray(new String[dimNames.size()]));
+
+
+ // lecture des data
+ int nbDim = dimNames.size();
+ int[] coord = new int[nbDim];
+
+ while (!sp.isEOF()) {
+ for (int i=0; i<nbDim; i++) {
+ coord[i] = sp.readInt(';');
+ }
+ double v = sp.readDouble(';');
+ result.setValue(coord, v);
+ }
+
+ } finally {
+ IOUtils.closeQuietly(in);
+ }
+
+ return result;
+ }
+
+ /**
+ * Extract and create TimeStep from file name. If file name doesn't contains
+ * TimeStep null is returned
+ * @param file
+ * @return
+ */
+ protected TimeStep getTimeStep(String file) {
+ TimeStep result = null;
+ try {
+ String num = StringUtils.substringBefore(file, "-");
+ int step = Integer.parseInt(num);
+ result = new TimeStep(step);
+ } catch(NumberFormatException eee) {
+ log.error("File doesn't contains step information: " + file, eee);
+ }
+ return result;
+ }
+
+ @Override
+ public void delete() {
+ super.delete();
+ try {
+ File file = getDirectory();
+ FileUtils.deleteDirectory(file);
+ } catch (IOException eee) {
+ throw new IsisFishRuntimeException("Can't delete results", eee);
+ }
+ }
+
+ @Override
+ protected MatrixND readResult(TimeStep step, String name) {
+ File file = getMatrixFile(step, name);
+ MatrixND result = null;
+ if (file.exists()) {
+ try {
+ result = readMatrix(file);
+ } catch (IOException eee) {
+ log.error("Can't read result file: " + file, eee);
+ }
+ }
+ return result;
+ }
+
+ @Override
+ protected Map<TimeStep, MatrixND> readResult(String name) {
+ File dir = getMatrixDirectory(name);
+ String[] files = dir.list();
+
+ Map<TimeStep, MatrixND> result = new HashMap<TimeStep, MatrixND>();
+ for(String file : files) {
+ try {
+ TimeStep step = getTimeStep(file);
+ if (step != null) {
+ MatrixND mat = readMatrix(dir + File.separator + file);
+ if (mat != null) {
+ result.put(step, mat);
+ }
+ }
+ } catch (Exception eee) {
+ log.error("Can't read result file: " + file, eee);
+ }
+ }
+ return result;
+ }
+
+ @Override
+ protected void writeResult(TimeStep step, String name, MatrixND mat) {
+ File file = getMatrixFile(step, name);
+ file.getParentFile().mkdirs();
+ PrintWriter out = null;
+ try {
+ out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(
+ new GZIPOutputStream(new FileOutputStream(file)),
+ charset
+ )));
+
+ out.print(name);
+ out.println();
+
+ List[] sems = mat.getSemantics();
+ for (int i=0, maxi=sems.length; i<maxi; i++) {
+ String dimName = mat.getDimensionName(i);
+ out.print(dimName);
+
+ List l = sems[i];
+ char sep = ':';
+ for (Object o : l) {
+ out.print(sep);
+ out.print(decorator.undecorate(o));
+ sep = ';';
+ }
+ out.println();
+ }
+
+ // blank line to separate header and data
+ out.println();
+
+ for (MatrixIterator i = mat.iteratorNotZero(); i.hasNext();) {
+ i.next();
+ int[] pos = i.getCoordinates();
+ double value = i.getValue();
+ for (int p : pos) {
+ out.print(p);
+ out.print(';');
+ }
+ out.print(value);
+ out.println();
+ }
+
+ } catch (Exception eee) {
+ throw new IsisFishRuntimeException("Can't write result: " + file, eee);
+ } finally {
+ IOUtils.closeQuietly(out);
+ }
+
+ }
+
+ @Override
+ protected void writeActiveRule(TimeStep step, String name, String params) {
+ // TODO
+ }
+
+ @Override
+ public List<String> getResultName() {
+ File dir = getMatrixDirectory("");
+ String[] files = dir.list();
+ List<String> result;
+ if (files != null) {
+ Arrays.sort(files);
+ result = Arrays.asList(files);
+ } else {
+ result = Collections.EMPTY_LIST;
+ }
+ return result;
+ }
+
+}
Property changes on: trunk/src/main/java/fr/ifremer/isisfish/datastore/ResultStorageCSV.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Modified: trunk/src/main/java/fr/ifremer/isisfish/datastore/ResultStorageInMemory.java
===================================================================
--- trunk/src/main/java/fr/ifremer/isisfish/datastore/ResultStorageInMemory.java 2014-06-17 16:17:51 UTC (rev 4025)
+++ trunk/src/main/java/fr/ifremer/isisfish/datastore/ResultStorageInMemory.java 2014-06-29 18:44:00 UTC (rev 4026)
@@ -25,37 +25,17 @@
package fr.ifremer.isisfish.datastore;
-import static org.nuiton.i18n.I18n.t;
import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.nuiton.math.matrix.MatrixFactory;
-import org.nuiton.math.matrix.MatrixIterator;
import org.nuiton.math.matrix.MatrixND;
import org.nuiton.topia.TopiaContext;
-import org.nuiton.util.ArrayUtil;
-import org.nuiton.util.HashList;
-
-import fr.ifremer.isisfish.IsisFishException;
-import fr.ifremer.isisfish.entities.Population;
-import fr.ifremer.isisfish.export.Export;
-import fr.ifremer.isisfish.export.SensitivityExport;
-import fr.ifremer.isisfish.rule.Rule;
-import fr.ifremer.isisfish.simulator.Objective;
-import fr.ifremer.isisfish.simulator.Optimization;
-import fr.ifremer.isisfish.simulator.SimulationContext;
-import fr.ifremer.isisfish.simulator.SimulationException;
-import fr.ifremer.isisfish.simulator.SimulationPlan;
-import fr.ifremer.isisfish.simulator.SimulationResultGetter;
import fr.ifremer.isisfish.types.TimeStep;
-import fr.ifremer.isisfish.types.Month;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.LinkedList;
@@ -73,14 +53,13 @@
* Mise a jour: $Date$
* par : $Author$
*/
-public class ResultStorageInMemory implements SimulationResultGetter, ResultStorage {
+public class ResultStorageInMemory extends ResultStorageAbstract {
/** to use log facility, just put in your code: log.info(\"...\"); */
static private Log log = LogFactory.getLog(ResultStorageInMemory.class);
final static public String MAX_TIME_STEP = "ResultStorageInMemory.maxTimeStep";
protected int maxTimeStep = 12; // default to 1 year
- protected SimulationStorage simulation = null;
LinkedHashMap<TimeStep, Map<String, MatrixND>> data = new LinkedHashMap<TimeStep, Map<String, MatrixND>>() {
private static final long serialVersionUID = 1L;
@@ -90,7 +69,7 @@
}
};
- LinkedHashMap<TimeStep, List<Rule>> rules = new LinkedHashMap<TimeStep, List<Rule>>() {
+ LinkedHashMap<TimeStep, List<String>> rules = new LinkedHashMap<TimeStep, List<String>>() {
private static final long serialVersionUID = 1L;
@Override
protected boolean removeEldestEntry(Map.Entry eldest) {
@@ -98,10 +77,6 @@
}
};
-
- /** result enabled */
- transient protected Set<String> enabledResult = null;
-
/**
* Les ResultStorage ne doivent pas etre instancier directement, mais
* recuperer a partir d'un
@@ -110,187 +85,24 @@
* @param simulation storage to get result
*/
public ResultStorageInMemory(SimulationStorage simulation) {
- this.simulation = simulation;
+ super(simulation);
maxTimeStep = Integer.parseInt(simulation.getParameter().getTagValue().get(MAX_TIME_STEP));
}
@Override
public void delete() {
+ super.delete();
data.clear();
}
@Override
- public void close() {
- // do nothing, closed by simulation storage closing
+ protected MatrixND decorate(MatrixND mat, TopiaContext tx) {
+ // for in memory do nothing, matrice has already semantics (not string)
+ return mat;
}
- /* (non-Javadoc)
- * @see fr.ifremer.isisfish.datastore.ResultStorage#isEnabled(java.lang.String)
- */
@Override
- public boolean isEnabled(String name) {
- name = name.trim();
- if (enabledResult == null) {
- enabledResult = new HashSet<String>();
-
- Collection<String> resultEnabled = simulation.getParameter()
- .getResultEnabled();
- enabledResult.addAll(resultEnabled);
-
- // test on export
- List<String> exportNames = simulation.getParameter().getExportNames();
- if (exportNames != null) {
- for (String exportName : exportNames) {
- ExportStorage storage = ExportStorage.getExport(exportName);
- try {
- Export export = storage.getNewInstance();
- for (String resultName : export.getNecessaryResult()) {
- enabledResult.add(resultName);
- }
- } catch (IsisFishException eee) {
- if (log.isWarnEnabled()) {
- log.warn(t("isisfish.error.instanciate.export",
- exportName), eee);
- }
- }
- }
- }
-
- // test on sensitivity export
- List<SensitivityExport> sensitivityExports = simulation
- .getParameter().getSensitivityExport();
- if (sensitivityExports != null) {
- for (SensitivityExport sensitivityExport : sensitivityExports) {
- for (String resultName : sensitivityExport.getNecessaryResult()) {
- enabledResult.add(resultName);
- }
- }
- }
-
- // test on rules
- List<Rule> rules = simulation.getParameter().getRules();
- if (rules != null) {
- for (Rule rule : rules) {
- for (String resultName : rule.getNecessaryResult()) {
- enabledResult.add(resultName);
- }
- }
- }
-
- // test on plans
- List<SimulationPlan> plans = simulation.getParameter().getSimulationPlans();
- if (plans != null) {
- for (SimulationPlan plan : plans) {
- for (String resultName : plan.getNecessaryResult()) {
- enabledResult.add(resultName);
- }
- }
- }
-
- // on objective and optimization
- Objective objective = simulation.getParameter().getObjective();
- if (objective != null) {
- for (String resultName : objective.getNecessaryResult()) {
- enabledResult.add(resultName);
- }
- }
-
- Optimization optimization = simulation.getParameter().getOptimization();
- if (optimization != null) {
- for (String resultName : optimization.getNecessaryResult()) {
- enabledResult.add(resultName);
- }
- }
-
- log.info("Enabled result: " + enabledResult);
- }
- boolean result = enabledResult.contains(name);
- return result;
- }
-
- /* (non-Javadoc)
- * @see fr.ifremer.isisfish.datastore.ResultStorage#addResult(fr.ifremer.isisfish.types.TimeStep, org.nuiton.math.matrix.MatrixND)
- */
- @Override
- public void addResult(TimeStep step, MatrixND mat) throws IsisFishException {
- addResult(false, step, mat.getName(), mat);
- }
-
- /* (non-Javadoc)
- * @see fr.ifremer.isisfish.datastore.ResultStorage#addResult(fr.ifremer.isisfish.types.TimeStep, fr.ifremer.isisfish.entities.Population, org.nuiton.math.matrix.MatrixND)
- */
- @Override
- public void addResult(TimeStep step, Population pop, MatrixND mat) throws IsisFishException {
- addResult(false, step, mat.getName(), pop, mat);
- }
-
- /* (non-Javadoc)
- * @see fr.ifremer.isisfish.datastore.ResultStorage#addResult(boolean, fr.ifremer.isisfish.types.TimeStep, org.nuiton.math.matrix.MatrixND)
- */
- @Override
- public void addResult(boolean force, TimeStep step, MatrixND mat) throws IsisFishException {
- addResult(force, step, mat.getName(), mat);
- }
-
- /* (non-Javadoc)
- * @see fr.ifremer.isisfish.datastore.ResultStorage#addResult(boolean, fr.ifremer.isisfish.types.TimeStep, fr.ifremer.isisfish.entities.Population, org.nuiton.math.matrix.MatrixND)
- */
- @Override
- public void addResult(boolean force, TimeStep step, Population pop, MatrixND mat) throws IsisFishException {
- addResult(force, step, mat.getName(), pop, mat);
- }
-
- /* (non-Javadoc)
- * @see fr.ifremer.isisfish.datastore.ResultStorage#addResult(fr.ifremer.isisfish.types.TimeStep, java.lang.String, fr.ifremer.isisfish.entities.Population, org.nuiton.math.matrix.MatrixND)
- */
- @Override
- public void addResult(TimeStep step, String name, Population pop, MatrixND mat) throws IsisFishException {
- addResult(false, step, name, pop, mat);
- }
-
- /* (non-Javadoc)
- * @see fr.ifremer.isisfish.datastore.ResultStorage#addResult(fr.ifremer.isisfish.types.TimeStep, java.lang.String, org.nuiton.math.matrix.MatrixND)
- */
- @Override
- public void addResult(TimeStep step, String name, MatrixND mat) throws IsisFishException {
- addResult(false, step, name, mat);
- }
-
- /* (non-Javadoc)
- * @see fr.ifremer.isisfish.datastore.ResultStorage#addResult(boolean, fr.ifremer.isisfish.types.TimeStep, java.lang.String, fr.ifremer.isisfish.entities.Population, org.nuiton.math.matrix.MatrixND)
- */
- @Override
- public void addResult(boolean force, TimeStep step, String name, Population pop, MatrixND mat) throws IsisFishException {
- if (force || isEnabled(name)) {
- doAddResult(step, name + " " + pop, mat);
- }
- }
-
- /* (non-Javadoc)
- * @see fr.ifremer.isisfish.datastore.ResultStorage#addResult(boolean, fr.ifremer.isisfish.types.TimeStep, java.lang.String, org.nuiton.math.matrix.MatrixND)
- */
- @Override
- public void addResult(boolean force, TimeStep step, String name, MatrixND mat) throws IsisFishException {
- if (force || isEnabled(name)) {
- doAddResult(step, name, mat);
- }
- }
-
- protected void doAddResult(TimeStep step, String name, MatrixND mat) throws IsisFishException {
- // si la matrice n'a pas de semantique on refuse
- for (int i = 0; i < mat.getDimCount(); i++) {
- // la semantique n'est pas bonne des qu'il y a un null dedans
- if (mat.getSemantic(i).contains(null)) {
- throw new SimulationException(
- "Erreur le résultat que vous souhaitez enregistrer n'a pas d'information convenable pour la dimension: "
- + i + " " + mat.getDimensionName(i));
- }
- }
-
- // on fait une copie pour avoir reellement des resultats independant
- // FIXME echatellier 20120829 : faire une copie optimiser
- // suivant l'implementation du vector plutot qu'un parcourt
- // via un iterateur de semantiques (plus couteux)
+ protected void writeResult(TimeStep step, String name, MatrixND mat) {
MatrixND newMat = mat.copy();
Map<String, MatrixND> mats = data.get(step);
if (mats == null) {
@@ -299,24 +111,17 @@
}
mats.put(name, newMat);
- }
+ }
- /* (non-Javadoc)
- * @see fr.ifremer.isisfish.datastore.ResultStorage#addActiveRule(fr.ifremer.isisfish.types.TimeStep, fr.ifremer.isisfish.rule.Rule)
- */
@Override
- public void addActiveRule(TimeStep step, Rule rule) throws IsisFishException {
- List<Rule> list = rules.get(step);
+ protected void writeActiveRule(TimeStep step, String name, String params) {
+ List<String> list = rules.get(step);
if (list == null) {
- list = new LinkedList<Rule>();
+ list = new LinkedList<String>();
rules.put(step, list);
}
- list.add(rule);
-
-// result.setActiveRuleStep(step);
-// result.setName(RuleStorage.getName(rule));
-// result.setParam(RuleStorage.getParamAsString(rule));
+ list.add(name);
}
/* (non-Javadoc)
@@ -335,19 +140,10 @@
}
/* (non-Javadoc)
- * @see fr.ifremer.isisfish.datastore.ResultStorage#getMatrix(fr.ifremer.isisfish.types.TimeStep, fr.ifremer.isisfish.entities.Population, java.lang.String)
- */
- @Override
- public MatrixND getMatrix(TimeStep step, Population pop, String name) {
- String newName = name + " " + pop;
- return getMatrix(step, newName);
- }
-
- /* (non-Javadoc)
* @see fr.ifremer.isisfish.datastore.ResultStorage#getMatrix(fr.ifremer.isisfish.types.TimeStep, java.lang.String)
*/
@Override
- public MatrixND getMatrix(TimeStep step, String name) {
+ public MatrixND readResult(TimeStep step, String name) {
MatrixND result = null;
Map<String, MatrixND> mats = data.get(step);
if (mats != null) {
@@ -356,160 +152,21 @@
return result;
}
- @Override
- public MatrixND getMatrix(TimeStep step, String name, TopiaContext tx) {
- return getMatrix(step, name);
- }
-
/* (non-Javadoc)
- * @see fr.ifremer.isisfish.datastore.ResultStorage#getMatrix(fr.ifremer.isisfish.entities.Population, java.lang.String)
- */
- @Override
- public MatrixND getMatrix(Population pop, String name) {
- String newName = name + " " + pop;
- return getMatrix(newName);
- }
-
- /* (non-Javadoc)
- * @see fr.ifremer.isisfish.datastore.ResultStorage#getMatrix(fr.ifremer.isisfish.entities.Population, java.lang.String, org.nuiton.topia.TopiaContext)
- */
- @Override
- public MatrixND getMatrix(Population pop, String name, TopiaContext tx) {
- String newName = name + " " + pop;
- return getMatrix(newName, tx);
- }
-
- /* (non-Javadoc)
* @see fr.ifremer.isisfish.datastore.ResultStorage#getMatrix(java.lang.String)
*/
@Override
- public MatrixND getMatrix(String name) {
- MatrixND result = null;
-
- List<TimeStep> steps = new ArrayList<TimeStep>();
- Map<TimeStep, MatrixND> mats = new LinkedHashMap<TimeStep, MatrixND>();
- MatrixND matExample = null;
+ public Map<TimeStep, MatrixND> readResult(String name) {
+ Map<TimeStep, MatrixND> result = new LinkedHashMap<TimeStep, MatrixND>();
for (Map.Entry<TimeStep, Map<String, MatrixND>> e : data.entrySet()) {
TimeStep ts = e.getKey();
MatrixND mat = e.getValue().get(name);
if (mat != null) {
- steps.add(ts);
- mats.put(ts, mat);
- matExample = mat;
+ result.put(ts, mat);
}
}
- if (mats.size() > 0) {
- // recuperation des noms des dimensions
- String[] dimNames = new String[1 + matExample.getDimCount()];
- dimNames[0] = t("isisfish.common.date");
- for (int i = 1; i < dimNames.length; i++) {
- dimNames[i] = matExample.getDimensionName(i - 1);
- }
-
- // creation de la semantique pour la matrice resultat. +1 pour les dates
- List[] sem = new List[1 + matExample.getDimCount()];
- sem[0] = steps;
-
- for (int i = 1; i < sem.length; i++) {
- sem[i] = new HashList();
- }
-
- for (MatrixND mattmp : mats.values()) {
- if (log.isTraceEnabled()) {
- log.trace("Ajout de la semantics: "
- + Arrays.asList(mattmp.getSemantics()));
- }
-
- for (int s = 0; s < mattmp.getDimCount(); s++) {
- sem[s + 1].addAll(mattmp.getSemantic(s));
- }
- }
-
- if (log.isTraceEnabled()) {
- log.trace("La semantique final est: " + Arrays.asList(sem));
- }
-
- // creation de la matrice resultat
- result = MatrixFactory.getInstance().create(name, sem, dimNames);
-
- // recuperation du resultat pour chaque date de la simulation, de Date(0) à lastDate
- for (Map.Entry<TimeStep, MatrixND> e : mats.entrySet()) {
- TimeStep d = e.getKey();
- MatrixND mat = e.getValue();
- // on recupere dans la matrice resultat l'endroit on il faut
- // mettre la matrice
- MatrixND submat = result.getSubMatrix(0, d, 1);
- // on met les valeur de mat dans la sous matrice extraite
- for (MatrixIterator mi = mat.iterator(); mi.next();) {
- submat.setValue(
- ArrayUtil.concat(new Object[] { d },
- mi.getSemanticsCoordinates()), mi.getValue());
- }
- }
- }
-
return result;
}
- /* (non-Javadoc)
- * @see fr.ifremer.isisfish.datastore.ResultStorage#getMatrix(java.lang.String, org.nuiton.topia.TopiaContext)
- */
- @Override
- public MatrixND getMatrix(String name, TopiaContext tx) {
- return getMatrix(name);
- }
-
- /* (non-Javadoc)
- * @see fr.ifremer.isisfish.datastore.ResultStorage#getLastStep()
- */
- @Override
- public TimeStep getLastStep() {
- int monthNumber = simulation.getParameter().getNumberOfYear()
- * Month.NUMBER_OF_MONTH;
- TimeStep result = new TimeStep(monthNumber - 1); // -1 because date begin at 0
- return result;
- }
-
- /*
- * @see fr.ifremer.isisfish.simulator.SimulationResultListener#addResult(fr.ifremer.isisfish.simulator.SimulationContext, fr.ifremer.isisfish.types.TimeStep, java.lang.String, org.nuiton.math.matrix.MatrixND)
- */
- @Override
- public void addResult(SimulationContext context, TimeStep step, String name,
- MatrixND mat) throws IsisFishException {
- doAddResult(step, name, mat);
- }
-
- /*
- * @see fr.ifremer.isisfish.simulator.SimulationResultGetter#getMatrix(fr.ifremer.isisfish.simulator.SimulationContext, fr.ifremer.isisfish.types.TimeStep, java.lang.String)
- */
- @Override
- public MatrixND getMatrix(SimulationContext context, TimeStep step, String name) {
- MatrixND result = getMatrix(step, name);
- return result;
- }
-
- /*
- * @see fr.ifremer.isisfish.simulator.SimulationResultGetter#getMatrix(fr.ifremer.isisfish.simulator.SimulationContext, java.lang.String)
- */
- @Override
- public MatrixND getMatrix(SimulationContext context, String name) {
- MatrixND result = getMatrix(name);
- return result;
- }
-
- /*
- * @see fr.ifremer.isisfish.simulator.SimulationListener#afterSimulation(fr.ifremer.isisfish.simulator.SimulationContext)
- */
- @Override
- public void afterSimulation(SimulationContext context) {
- }
-
- /*
- * @see fr.ifremer.isisfish.simulator.SimulationListener#beforeSimulation(fr.ifremer.isisfish.simulator.SimulationContext)
- */
- @Override
- public void beforeSimulation(SimulationContext context) {
- }
-
}
Modified: trunk/src/main/java/fr/ifremer/isisfish/datastore/SimulationStorage.java
===================================================================
--- trunk/src/main/java/fr/ifremer/isisfish/datastore/SimulationStorage.java 2014-06-17 16:17:51 UTC (rev 4025)
+++ trunk/src/main/java/fr/ifremer/isisfish/datastore/SimulationStorage.java 2014-06-29 18:44:00 UTC (rev 4026)
@@ -78,6 +78,7 @@
public static final String PARAMETERS_FILENAME = "parameters.properties";
public static final String RESULT_XML_FILENAME = "isis-mexico-output.xml";
public static final String RESULT_FILENAME = "results.mapped";
+ public static final String RESULT_DIRECTORY = "results";
public static final String RESULT_EXPORT_DIRECTORY = "resultExports";
public static final String DESIGN_PLAN_FILENAME = "isis-mexico-designplan.xml";
public static final String SENSITIVITY_RESULTS = "sensitivityresults";
@@ -260,6 +261,21 @@
}
/**
+ * Retourne le fichier de stockage des resultats
+ * de la simulation.
+ *
+ * @param root le repertoire de stockage de la simulation
+ * @return
+ */
+ public static File getResultDirectory(File root) {
+ File result = new File(root, RESULT_DIRECTORY);
+ if (!result.exists()) {
+ result.mkdirs();
+ }
+ return result;
+ }
+
+ /**
* Retourne le fichier de stockage des parametres de la simulation courante.
*
* @return parameter file
@@ -523,7 +539,14 @@
resultStorage = new ResultStorageInMemory(this);
} else {
try {
- resultStorage = new ResultMappedStorage(this);
+ if (getResultFile(getDirectory()).exists()) {
+ // if result.mapped exist, use ResultMappedStorage
+ // need to read old simulation
+ resultStorage = new ResultMappedStorage(this);
+ } else {
+ // else use ResultStorageCSV, the new default result storage
+ resultStorage = new ResultStorageCSV(this);
+ }
} catch (IOException ex) {
throw new StorageException("Can't get storage", ex);
}
Modified: trunk/src/main/java/fr/ifremer/isisfish/simulator/SimulationContext.java
===================================================================
--- trunk/src/main/java/fr/ifremer/isisfish/simulator/SimulationContext.java 2014-06-17 16:17:51 UTC (rev 4025)
+++ trunk/src/main/java/fr/ifremer/isisfish/simulator/SimulationContext.java 2014-06-29 18:44:00 UTC (rev 4026)
@@ -25,7 +25,6 @@
package fr.ifremer.isisfish.simulator;
-import fr.ifremer.isisfish.IsisConfig;
import fr.ifremer.isisfish.IsisFish;
import java.io.File;
import java.util.HashMap;
@@ -105,7 +104,10 @@
protected SimulationContext() {
// force matrix backend for this simulation
- MatrixFactory.initMatrixFactoryThreadLocal(IsisFish.config.getSimulationMatrixVectorClass());
+ MatrixFactory.initMatrixFactoryThreadLocal(
+ IsisFish.config.getSimulationMatrixVectorClass(),
+ IsisFish.config.getSimulationMatrixVectorSparseClass(),
+ IsisFish.config.getSimulationMatrixThresholdUseSparse());
}
/**
Modified: trunk/src/main/java/fr/ifremer/isisfish/simulator/launcher/InProcessSimulatorLauncher.java
===================================================================
--- trunk/src/main/java/fr/ifremer/isisfish/simulator/launcher/InProcessSimulatorLauncher.java 2014-06-17 16:17:51 UTC (rev 4025)
+++ trunk/src/main/java/fr/ifremer/isisfish/simulator/launcher/InProcessSimulatorLauncher.java 2014-06-29 18:44:00 UTC (rev 4026)
@@ -423,8 +423,10 @@
//
context.fireBeforeSimulation();
String matrixBackend = MatrixFactory.getInstance().getVectorClass().getName();
+ String matrixSparseBackend = MatrixFactory.getInstance().getSparseVectorClass().getName();
+ int threshold = MatrixFactory.getInstance().getThresholdSparse();
simulation.getInformation().addInformation("Matrix backend: "
- + matrixBackend);
+ + matrixBackend + " and " + matrixSparseBackend + " threshold: " + threshold);
log.info("Matrix backend: " + matrixBackend);
simulatorObject.simulate(context);
Modified: trunk/src/main/java/fr/ifremer/isisfish/ui/WelcomeHandler.java
===================================================================
--- trunk/src/main/java/fr/ifremer/isisfish/ui/WelcomeHandler.java 2014-06-17 16:17:51 UTC (rev 4025)
+++ trunk/src/main/java/fr/ifremer/isisfish/ui/WelcomeHandler.java 2014-06-29 18:44:00 UTC (rev 4026)
@@ -226,6 +226,8 @@
modelBuilder.addOption(IsisConfig.Option.SIMULATOR_SUB_MAXPROCESS);
modelBuilder.addOption(IsisConfig.Option.SIMULATOR_SUB_MAXMEMORY);
modelBuilder.addOption(IsisConfig.Option.SIMULATION_MATRIX_VECTOR_CLASS);
+ modelBuilder.addOption(IsisConfig.Option.SIMULATION_MATRIX_VECTOR_SPARSE_CLASS);
+ modelBuilder.addOption(IsisConfig.Option.SIMULATION_MATRIX_THRESHOLD_USE_SPARSE_CLASS);
modelBuilder.addOption(IsisConfig.Option.MAPPED_RESULT_MATRIX_VECTOR_CLASS);
// category database vcs
Modified: trunk/src/main/java/fr/ifremer/isisfish/util/IsisCacheBackendOnGuava.java
===================================================================
--- trunk/src/main/java/fr/ifremer/isisfish/util/IsisCacheBackendOnGuava.java 2014-06-17 16:17:51 UTC (rev 4025)
+++ trunk/src/main/java/fr/ifremer/isisfish/util/IsisCacheBackendOnGuava.java 2014-06-29 18:44:00 UTC (rev 4026)
@@ -85,12 +85,9 @@
// on prend le nombre de case de la matrice pour sa taille
// on ne tient pas compte des dimensions qui sont des objets
// utilises ailleurs
- int[] dim = ((MatrixND)value).getDim();
- int size = 1;
- for (int i=0; i<dim.length; i++) {
- size *= dim[i];
- }
- result += size * DOUBLE_SIZE; // size is wrong, because depend on matrix type (float or double)
+ int size = ((MatrixND)value).getNumberOfAssignedValue();
+ // size is wrong, because depend on matrix type (float or double), but approximation is acceptable
+ result += size * DOUBLE_SIZE;
} else if (value instanceof Collection) {
// List<Zone|Pop|Str|Metier|Cell>
// on prend la taille de la collection, car la donnees
Added: trunk/src/main/java/fr/ifremer/isisfish/util/SimpleParser.java
===================================================================
--- trunk/src/main/java/fr/ifremer/isisfish/util/SimpleParser.java (rev 0)
+++ trunk/src/main/java/fr/ifremer/isisfish/util/SimpleParser.java 2014-06-29 18:44:00 UTC (rev 4026)
@@ -0,0 +1,131 @@
+package fr.ifremer.isisfish.util;
+
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * Very simple parse write for efficiency. Input stream must be correct no check
+ * is done on data.
+ *
+ * @author poussin
+ * @version $Revision$
+ *
+ * Last update: $Date$
+ * by : $Author$
+ */
+public class SimpleParser {
+
+ /** to use log facility, just put in your code: log.info(\"...\"); */
+ static private Log log = LogFactory.getLog(SimpleParser.class);
+
+ protected boolean intern;
+ protected BufferedReader in;
+ protected StringBuilder sb = new StringBuilder();
+
+ protected boolean eof = false;
+ protected boolean eol = false;
+ /**
+ *
+ * @param in BufferedReader because Reader must support mark and reset
+ */
+ public SimpleParser(BufferedReader in, boolean intern) {
+ this.in = in;
+ this.intern = intern;
+ }
+
+ /**
+ *
+ * @return true if end of file
+ */
+ public boolean isEOF() {
+ return eof;
+ }
+
+ /**
+ *
+ * @return true if end of line
+ */
+ public boolean isEOL() {
+ return eol;
+ }
+
+ protected void read(char sep) throws IOException {
+ eol = false;
+ sb.setLength(0);
+
+ int i;
+ while ((i = in.read()) != -1) {
+ char c = (char)i;
+ if (c == '\r') {
+ // try to eat \n after \r
+ in.mark(1);
+ c = (char)in.read();
+ if (c != '\n') {
+ in.reset();
+ }
+ eol = true;
+ break;
+ } else if (c == '\n') {
+ eol = true;
+ break;
+ } else if (c == sep) {
+ break;
+ } else {
+ sb.append(c);
+ }
+ }
+
+ if (i != -1) {
+ // test if not eof
+ in.mark(1);
+ i = in.read();
+ in.reset();
+ }
+ eof = i == -1;
+ }
+
+ public String readString(char sep) throws IOException {
+ read(sep);
+ String result = sb.toString();
+ if (intern) {
+ result = result.intern();
+ }
+ return result;
+ }
+
+ public int readInt(char sep) throws IOException {
+ read(sep);
+ int result = parseInt(sb);
+ return result;
+ }
+
+ public double readDouble(char sep) throws IOException {
+ read(sep);
+ double result = parseDouble(sb);
+ return result;
+ }
+
+ protected double parseDouble(StringBuilder s) throws IOException {
+ return Double.parseDouble(s.toString());
+ }
+
+ /**
+ * custom parseInt: 4 fois plus performant que Integer.parseInt
+ * ne supporte que les chiffres positif, et la chaine doit forcement etre un nombre valide
+ * @param sb la chaine representant l'entier
+ * @return
+ */
+ protected int parseInt(StringBuilder sb) {
+ int result = 0;
+ for (int i=0, maxi=sb.length(); i<maxi; i++) {
+ char c = sb.charAt(i);
+ result = result * 10 + c - '0';
+ }
+ return result;
+ }
+
+
+}
Property changes on: trunk/src/main/java/fr/ifremer/isisfish/util/SimpleParser.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
1
0
Author: echatellier
Date: 2014-06-17 18:17:51 +0200 (Tue, 17 Jun 2014)
New Revision: 4025
Url: http://forge.codelutin.com/projects/isis-fish/repository/revisions/4025
Log:
Fix nuiton-matrix version
Modified:
trunk/pom.xml
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2014-06-17 15:50:26 UTC (rev 4024)
+++ trunk/pom.xml 2014-06-17 16:17:51 UTC (rev 4025)
@@ -88,7 +88,7 @@
<dependency>
<groupId>org.nuiton.matrix</groupId>
<artifactId>nuiton-matrix-gui</artifactId>
- <version>2.4.1</version>
+ <version>2.4.2-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
1
0
r4024 - in trunk: . src/main/java/fr/ifremer/isisfish src/main/java/fr/ifremer/isisfish/simulator src/main/java/fr/ifremer/isisfish/simulator/launcher src/main/java/fr/ifremer/isisfish/ui
by bpoussin@users.forge.codelutin.com 17 Jun '14
by bpoussin@users.forge.codelutin.com 17 Jun '14
17 Jun '14
Author: bpoussin
Date: 2014-06-17 17:50:26 +0200 (Tue, 17 Jun 2014)
New Revision: 4024
Url: http://forge.codelutin.com/projects/isis-fish/repository/revisions/4024
Log:
add possibility to change matrix backend for simulation in configuration
Modified:
trunk/pom.xml
trunk/src/main/java/fr/ifremer/isisfish/IsisConfig.java
trunk/src/main/java/fr/ifremer/isisfish/simulator/SimulationContext.java
trunk/src/main/java/fr/ifremer/isisfish/simulator/launcher/InProcessSimulatorLauncher.java
trunk/src/main/java/fr/ifremer/isisfish/ui/WelcomeHandler.java
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2014-06-17 15:29:15 UTC (rev 4023)
+++ trunk/pom.xml 2014-06-17 15:50:26 UTC (rev 4024)
@@ -81,7 +81,7 @@
<dependency>
<groupId>org.nuiton.matrix</groupId>
<artifactId>nuiton-matrix</artifactId>
- <version>2.4.1</version>
+ <version>2.4.2-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
Modified: trunk/src/main/java/fr/ifremer/isisfish/IsisConfig.java
===================================================================
--- trunk/src/main/java/fr/ifremer/isisfish/IsisConfig.java 2014-06-17 15:29:15 UTC (rev 4023)
+++ trunk/src/main/java/fr/ifremer/isisfish/IsisConfig.java 2014-06-17 15:50:26 UTC (rev 4024)
@@ -936,7 +936,7 @@
/**
* L'implementation de la class gérant les implémentations de vecteur de
- * matrice pour les fichiers mappés.
+ * matrice pour les fichiers mappés pour le rendu des resultats
*
* @return
* @since 4.2.1.1
@@ -947,6 +947,18 @@
}
/**
+ * L'implementation de la class gérant les implémentations de vecteur de
+ * matrice pour les simulations
+ *
+ * @return
+ * @since 4.2.1.1
+ */
+ public Class getSimulationMatrixVectorClass() {
+ Class result = getOptionAsClass(Option.SIMULATION_MATRIX_VECTOR_CLASS.key);
+ return result;
+ }
+
+ /**
* Retourne la factory a utilise pour le cache
*
* @return factory a utilise pour le backend de cache
@@ -989,6 +1001,10 @@
SIMULATOR_LAUNCHER2(SimulationService.SIMULATION_LAUNCHER + ".1", n("isisfish.config.main.subSimulator.description"), SubProcessSimulationLauncher.class.getName()),
SIMULATOR_LAUNCHER_REMOTE(SimulationService.SIMULATION_LAUNCHER + ".2", n("isisfish.config.main.remoteCaparmor.description"), SSHSimulatorLauncher.class.getName()),
+
+ // pour les simulations
+ SIMULATION_MATRIX_VECTOR_CLASS("simulation.matrix.vector.class", n("isisfish.config.simulation.matrix.vector.class.description"), DoubleBigVector.class.getName()),
+
/** Nombre maximum de thread de simulation in process. */
SIMULATOR_IN_MAXTHREADS("simulation.in.max.threads", n("isisfish.config.main.simulation.in.max.threads.description"), "1"),
Modified: trunk/src/main/java/fr/ifremer/isisfish/simulator/SimulationContext.java
===================================================================
--- trunk/src/main/java/fr/ifremer/isisfish/simulator/SimulationContext.java 2014-06-17 15:29:15 UTC (rev 4023)
+++ trunk/src/main/java/fr/ifremer/isisfish/simulator/SimulationContext.java 2014-06-17 15:50:26 UTC (rev 4024)
@@ -25,6 +25,8 @@
package fr.ifremer.isisfish.simulator;
+import fr.ifremer.isisfish.IsisConfig;
+import fr.ifremer.isisfish.IsisFish;
import java.io.File;
import java.util.HashMap;
import java.util.LinkedHashSet;
@@ -42,6 +44,7 @@
import fr.ifremer.isisfish.types.TimeStep;
import fr.ifremer.isisfish.util.IsisCache;
import fr.ifremer.isisfish.util.Trace;
+import org.nuiton.math.matrix.MatrixFactory;
/**
* Keep all information on one simulation.
@@ -101,7 +104,8 @@
};
protected SimulationContext() {
-
+ // force matrix backend for this simulation
+ MatrixFactory.initMatrixFactoryThreadLocal(IsisFish.config.getSimulationMatrixVectorClass());
}
/**
Modified: trunk/src/main/java/fr/ifremer/isisfish/simulator/launcher/InProcessSimulatorLauncher.java
===================================================================
--- trunk/src/main/java/fr/ifremer/isisfish/simulator/launcher/InProcessSimulatorLauncher.java 2014-06-17 15:29:15 UTC (rev 4023)
+++ trunk/src/main/java/fr/ifremer/isisfish/simulator/launcher/InProcessSimulatorLauncher.java 2014-06-17 15:50:26 UTC (rev 4024)
@@ -70,6 +70,7 @@
import fr.ifremer.isisfish.types.Month;
import fr.ifremer.isisfish.types.TimeStep;
import fr.ifremer.isisfish.util.CompileHelper;
+import org.nuiton.math.matrix.MatrixFactory;
/**
* Fait une simulation dans la meme jvm.
@@ -421,6 +422,10 @@
// Call listener simulation (used per example for prescript)
//
context.fireBeforeSimulation();
+ String matrixBackend = MatrixFactory.getInstance().getVectorClass().getName();
+ simulation.getInformation().addInformation("Matrix backend: "
+ + matrixBackend);
+ log.info("Matrix backend: " + matrixBackend);
simulatorObject.simulate(context);
//
Modified: trunk/src/main/java/fr/ifremer/isisfish/ui/WelcomeHandler.java
===================================================================
--- trunk/src/main/java/fr/ifremer/isisfish/ui/WelcomeHandler.java 2014-06-17 15:29:15 UTC (rev 4023)
+++ trunk/src/main/java/fr/ifremer/isisfish/ui/WelcomeHandler.java 2014-06-17 15:50:26 UTC (rev 4024)
@@ -225,6 +225,7 @@
modelBuilder.addOption(IsisConfig.Option.SIMULATOR_IN_MAXTHREADS);
modelBuilder.addOption(IsisConfig.Option.SIMULATOR_SUB_MAXPROCESS);
modelBuilder.addOption(IsisConfig.Option.SIMULATOR_SUB_MAXMEMORY);
+ modelBuilder.addOption(IsisConfig.Option.SIMULATION_MATRIX_VECTOR_CLASS);
modelBuilder.addOption(IsisConfig.Option.MAPPED_RESULT_MATRIX_VECTOR_CLASS);
// category database vcs
1
0
r4023 - in trunk: . src/main/java/fr/ifremer/isisfish src/main/java/fr/ifremer/isisfish/actions src/main/resources/i18n
by dcosse@users.forge.codelutin.com 17 Jun '14
by dcosse@users.forge.codelutin.com 17 Jun '14
17 Jun '14
Author: dcosse
Date: 2014-06-17 17:29:15 +0200 (Tue, 17 Jun 2014)
New Revision: 4023
Url: http://forge.codelutin.com/projects/isis-fish/repository/revisions/4023
Log:
mise en place d'un mechanisme de validation des simulations
Added:
trunk/src/main/java/fr/ifremer/isisfish/actions/ValidateSimulationAction.java
Modified:
trunk/go.sh
trunk/src/main/java/fr/ifremer/isisfish/IsisConfig.java
trunk/src/main/resources/i18n/isis-fish_en_GB.properties
trunk/src/main/resources/i18n/isis-fish_fr_FR.properties
Modified: trunk/go.sh
===================================================================
--- trunk/go.sh 2014-06-17 14:30:35 UTC (rev 4022)
+++ trunk/go.sh 2014-06-17 15:29:15 UTC (rev 4023)
@@ -3,7 +3,7 @@
# Java executable
JAVA=java
-TEMP=`getopt -o dnt:: --long debug,nosuspend,trace:: \
+TEMP=`getopt -o dnt:: --long debug,nosuspend,cheked,trace:: \
-n 'go.sh' -- "$@"`
if [ $? != 0 ] ; then
@@ -14,26 +14,38 @@
eval set -- "$TEMP"
while true ; do
- case "$1" in
- -d|--debug)
- echo "Debug mode"
- DEBUG="-server -Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,address=38000,server=y"
- shift ;;
- -n|--nosuspend)
- echo "Debug no suspend mode"
- DEBUG="$DEBUG,suspend=n"
- shift ;;
- -t|--trace)
- echo "Trace mode"
- case "$2" in
- "") TRACE_FILE="-Daspectwerkz.definition.file=$rep/src/main/resources/trace-aop.xml" # -Daspectwerkz.transform.verbose=true" # -Daspectwerkz.transform.details=true"
- ;;
- *) TRACE_FILE="-Daspectwerkz.definition.file=$2" # -Daspectwerkz.transform.verbose=true" # -Daspectwerkz.transform.details=true"
- esac
- shift 2 ;;
- --) shift ; break ;;
- *) echo "Bad argument $1!" ; exit 1 ;;
- esac
+ case "$1" in
+ -d|--debug)
+ echo "Debug mode"
+ DEBUG="-server -Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,address=38000,server=y"
+ shift ;;
+ -n|--nosuspend)
+ echo "Debug no suspend mode"
+ DEBUG="$DEBUG,suspend=n"
+ shift ;;
+ -c|--checked)
+ echo "Checked mode"
+ CHECK="-server -Djava.compiler=NONE ,address=38000,server=y"
+ shift ;;
+ -t|--trace)
+ echo "Trace mode"
+
+ case "$2" in
+ "")
+ TRACE_FILE="-Daspectwerkz.definition.file=$rep/src/main/resources/trace-aop.xml" # -Daspectwerkz.transform.verbose=true" # -Daspectwerkz.transform.details=true"
+ ;;
+ *)
+ TRACE_FILE="-Daspectwerkz.definition.file=$2" # -Daspectwerkz.transform.verbose=true" # -Daspectwerkz.transform.details=true"
+ esac
+
+ shift 2 ;;
+ --)
+ shift ;
+ break ;;
+ *)
+ echo "Bad argument $1!";
+ exit 1 ;;
+ esac
done
dir=$(dirname $0)
@@ -67,6 +79,6 @@
done
LOG="-Dlog4j.configuration=file:$rep/src/main/resources/log4j.properties" # -Dlog4j.debug"
-echo $JAVA -Xmx$MX -Xms$MX -classpath $CL $NOaspectwerkz $TRACE_FILE $LOG $JVM_OPT $DEBUG fr.ifremer.isisfish.IsisFish "$@"
-$JAVA -Xmx$MX -Xms$MX -classpath $CL $NOaspectwerkz $TRACE_FILE $LOG $JVM_OPT $DEBUG fr.ifremer.isisfish.IsisFish "$@"
+echo $JAVA -Xmx$MX -Xms$MX -classpath $CL $NOaspectwerkz $TRACE_FILE $LOG $JVM_OPT $DEBUG $CHECK fr.ifremer.isisfish.IsisFish "$@"
+$JAVA -Xmx$MX -Xms$MX -classpath $CL $NOaspectwerkz $TRACE_FILE $LOG $JVM_OPT $DEBUG $CHECK fr.ifremer.isisfish.IsisFish "$@"
#$JAVA -Xmx$MX -Xms$MX -classpath $CL $NOaspectwerkz $TRACE_FILE $LOG $JVM_OPT $DEBUG fr.ifremer.isisfish.ui.update.Counter "$@"
Modified: trunk/src/main/java/fr/ifremer/isisfish/IsisConfig.java
===================================================================
--- trunk/src/main/java/fr/ifremer/isisfish/IsisConfig.java 2014-06-17 14:30:35 UTC (rev 4022)
+++ trunk/src/main/java/fr/ifremer/isisfish/IsisConfig.java 2014-06-17 15:29:15 UTC (rev 4023)
@@ -40,6 +40,7 @@
import java.util.Locale;
import java.util.Map;
+import fr.ifremer.isisfish.actions.ValidateSimulationAction;
import org.apache.commons.beanutils.ConvertUtils;
import org.apache.commons.lang3.time.DurationFormatUtils;
import org.nuiton.math.matrix.DoubleBigVector;
@@ -285,7 +286,7 @@
}
/**
- * Retourne le repertoire ou sont stockes les informations relatives
+ * Retourne le repertoire ou sont stockées les informations relatives
* aux simulations en cours.
*
* @return monitoring directory
@@ -304,7 +305,7 @@
* Get javadoc directory.
*
* Create directory if not exists.
- *
+ *
* @return javadoc directory
*/
public File getJavadocDirectory() {
@@ -1198,7 +1199,9 @@
SIMULATE_WITH_SIMULATION(n(""), SimulationAction.class.getName() + "#simulateWithSimulation", "--simulateWithSimulation"),
SIMULATE_WITH_SIMULATION_AND_SCRIPT(n(""), SimulationAction.class.getName() + "#simulateWithSimulationAndScript", "--simulateWithSimulationAndScript"),
SIMULATE_REMOTELLY(n(""), SimulationAction.class.getName() + "#simulateRemotelly", "--simulateRemotelly"),
- SIMULATE_REMOTELLY_WITH_PRESCRIPT(n(""), SimulationAction.class.getName() + "#simulateRemotellyWithPreScript", "--simulateRemotellyWithPreScript");
+ SIMULATE_REMOTELLY_WITH_PRESCRIPT(n(""), SimulationAction.class.getName() + "#simulateRemotellyWithPreScript", "--simulateRemotellyWithPreScript"),
+
+ VALIDATE_WITH_SIMULATION(n(""), ValidateSimulationAction.class.getName() + "#validateSimulation", "--validate");
protected String description;
protected String action;
Copied: trunk/src/main/java/fr/ifremer/isisfish/actions/ValidateSimulationAction.java (from rev 4014, trunk/src/main/java/fr/ifremer/isisfish/actions/SimulationAction.java)
===================================================================
--- trunk/src/main/java/fr/ifremer/isisfish/actions/ValidateSimulationAction.java (rev 0)
+++ trunk/src/main/java/fr/ifremer/isisfish/actions/ValidateSimulationAction.java 2014-06-17 15:29:15 UTC (rev 4023)
@@ -0,0 +1,180 @@
+/*
+ * #%L
+ * IsisFish
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2002 - 2014 Ifremer, Code Lutin, Benjamin Poussin, Chatellier Eric
+ * %%
+ * 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/gpl-3.0.html>.
+ * #L%
+ */
+
+package fr.ifremer.isisfish.actions;
+
+import fr.ifremer.isisfish.IsisConfig;
+import fr.ifremer.isisfish.IsisFish;
+import fr.ifremer.isisfish.datastore.ResultStorage;
+import fr.ifremer.isisfish.datastore.SimulationStorage;
+import fr.ifremer.isisfish.simulator.SimulationControl;
+import fr.ifremer.isisfish.simulator.launcher.InProcessSimulatorLauncher;
+import fr.ifremer.isisfish.simulator.launcher.SimulationItem;
+import fr.ifremer.isisfish.simulator.launcher.SimulationService;
+import fr.ifremer.isisfish.simulator.launcher.SimulatorLauncher;
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.nuiton.config.ApplicationConfig.Action.Step;
+import org.nuiton.math.matrix.MatrixND;
+
+import java.io.File;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.List;
+
+import static org.nuiton.i18n.I18n.t;
+
+/**
+ * Check that there are no regressions.
+ * Monitor execution.
+ *
+ */
+public class ValidateSimulationAction {
+
+ /** to use log facility, just put in your code: log.info("..."); */
+ private static Log log = LogFactory.getLog(ValidateSimulationAction.class);
+
+ private static final SimpleDateFormat df = new SimpleDateFormat("dd-MM-yy-HH:mm:ss.SS");
+
+ protected IsisConfig config = null;
+
+ /**
+ * results from validated simulation
+ */
+ protected static ResultStorage validatedResultStorage;
+
+ public ValidateSimulationAction(IsisConfig config) {
+ this.config = config;
+ }
+
+
+ /**
+ * Launch a simulation
+ * with simulation params the similutaion at the given path.
+ *
+ * @param simulationName name of the simulation reference.
+ * @throws Exception
+ */
+ @Step(IsisConfig.STEP_AFTER_INIT_VCS)
+ public static void validateSimulation(String simulationName)
+ throws Exception {
+ SimulationStorage simulation = SimulationStorage.getSimulation(simulationName);
+ validatedResultStorage = simulation.getResultStorage();
+
+ simulateWithSimulation("Validate-From-" + simulationName + "-" + df.format(new Date()), simulation.createZip());
+ }
+
+ /**
+ * Launch a simulation with specified simulationId and simulation zip.
+ *
+ * @param simulationId id de simulation
+ * @param simulationZip Zip de la simulation
+ * @throws Exception
+ */
+ @Step(IsisConfig.STEP_AFTER_INIT_VCS)
+ public static void simulateWithSimulation(String simulationId, File simulationZip)
+ throws Exception {
+ // just call with null pre script
+ validateWithSimulationAndScript(simulationId, simulationZip, null);
+ }
+
+ /**
+ * Launch a simulation with specified simulationId, simulationZip
+ * and simulationPrescript.
+ *
+ * @param simulationId id de simulation
+ * @param simulationZip Zip de la simulation
+ * @param simulationPrescript simulation prescript
+ * @throws Exception
+ */
+ @Step(IsisConfig.STEP_AFTER_INIT_VCS)
+ public static void validateWithSimulationAndScript(String simulationId, File simulationZip, File simulationPrescript)
+ throws Exception {
+
+ if (log.isInfoEnabled()) {
+ log.info("Command line action : validateWithSimulationAndScript (" + simulationId + ", " + simulationZip.getAbsolutePath() + ", " + simulationPrescript + ")");
+ }
+
+ // ne pas mettre la date, car le sub process la met deja + " " + new SimpleDateFormat("yyyy-MM-dd-HH-mm").format(new Date());
+ String name = simulationId;
+
+ //SimulationStorage simulation = launcher.simulate(null, control, simulationZip);
+ //simulation.getStorage().closeContext();
+ String generatedPrescriptContent = null;
+ if (simulationPrescript != null && simulationPrescript.canRead()) {
+ generatedPrescriptContent = FileUtils.readFileToString(simulationPrescript);
+ }
+
+ SimulationControl control = new SimulationControl(name);
+ control.setAutoSaveState(true); // needed for remote simulation
+
+ SimulationItem item = new SimulationItem(control, null);
+ item.setSimulationZip(simulationZip);
+ item.setGeneratedPrescriptContent(generatedPrescriptContent);
+
+ // lancement de la simulation
+ SimulatorLauncher launcher = new InProcessSimulatorLauncher();
+ launcher.simulate(SimulationService.getService(), item);
+ SimulationStorage simulation = launcher.getSimulationStorage(SimulationService.getService(), control);
+
+ validateResults(simulation.getResultStorage());
+
+ simulation.getStorage().closeContext();
+
+ // FIXME integrer ca dans le process normal d'init
+ IsisFish.quit();
+ }
+
+ /**
+ * Compare result simulation from the validated ones.
+ * @param newResultStorage
+ * @throws Exception
+ */
+ public static void validateResults(ResultStorage newResultStorage) throws Exception {
+
+ if (newResultStorage.getResultName().size() == validatedResultStorage.getResultName().size()) {
+ log.info(t("isisfish.common.ok") + " nombre de résultats obtenus équivalent :" + newResultStorage.getResultName().size() + "/" + validatedResultStorage.getResultName().size());
+ } else {
+ log.error(t("isisfish.common.ko") + " nombre de résultats obtenus différent :" + newResultStorage.getResultName().size() + "/" + validatedResultStorage.getResultName().size());
+ }
+
+ List<String> simuNames = validatedResultStorage.getResultName();
+ for (String simuName : simuNames) {
+ MatrixND validatedMatrix = validatedResultStorage.getMatrix(simuName);
+ MatrixND newMatrix = newResultStorage.getMatrix(simuName);
+ if (newMatrix == null) {
+ log.error(t("isisfish.common.ko") + " " + t("isisfish.error.validation.matrixNotComputed", validatedMatrix.getName()));
+ } else {
+ if (validatedMatrix.equalsValues(newMatrix)) {
+ log.info(t("isisfish.common.ok") + " MatrixND:" + validatedMatrix.getName());
+ } else {
+ log.error(t("isisfish.common.ko") + " MatrixND:" + validatedMatrix.getName());
+ }
+ }
+ }
+ }
+
+}
Modified: trunk/src/main/resources/i18n/isis-fish_en_GB.properties
===================================================================
--- trunk/src/main/resources/i18n/isis-fish_en_GB.properties 2014-06-17 14:30:35 UTC (rev 4022)
+++ trunk/src/main/resources/i18n/isis-fish_en_GB.properties 2014-06-17 15:29:15 UTC (rev 4023)
@@ -129,6 +129,7 @@
isisfish.common.gear=Gear
isisfish.common.immigration=immigration
isisfish.common.info=info
+isisfish.common.ko=KO
isisfish.common.migration=migration
isisfish.common.module=Module
isisfish.common.month=month %1$s
@@ -406,6 +407,7 @@
isisfish.error.undefined.zone.recruitment=No recrutment's zone defined
isisfish.error.undefined.zone.reproduction=No reprodution's zone defined
isisfish.error.unsupported.equation.langage=Unsupported language '%1$s' for equation\: %2$s
+isisfish.error.validation.matrixNotComputed=matrix not computed %s
isisfish.error.wait.simThread=Can't wait SimThread
isisfish.error.warning.title=Warning
isisfish.error.write.simulation=Can't write information %1$s
Modified: trunk/src/main/resources/i18n/isis-fish_fr_FR.properties
===================================================================
--- trunk/src/main/resources/i18n/isis-fish_fr_FR.properties 2014-06-17 14:30:35 UTC (rev 4022)
+++ trunk/src/main/resources/i18n/isis-fish_fr_FR.properties 2014-06-17 15:29:15 UTC (rev 4023)
@@ -129,6 +129,7 @@
isisfish.common.gear=Engin
isisfish.common.immigration=immigration
isisfish.common.info=Info
+isisfish.common.ko=KO
isisfish.common.migration=migration
isisfish.common.module=Module
isisfish.common.month=mois %1$s
@@ -406,6 +407,7 @@
isisfish.error.undefined.zone.recruitment=il n'y a pas de zone de recrutement de définie
isisfish.error.undefined.zone.reproduction=il n'y a pas de zone de reproduction de définie
isisfish.error.unsupported.equation.langage=unsupported langage '%1$s' for equation\: %2$s
+isisfish.error.validation.matrixNotComputed=matrice non calulée\:%s
isisfish.error.wait.simThread=Can't wait SimThread
isisfish.error.warning.title=Attention
isisfish.error.write.simulation=Can't write information %1$s
1
0
r4022 - trunk/src/main/java/fr/ifremer/isisfish/ui/simulator
by echatellier@users.forge.codelutin.com 17 Jun '14
by echatellier@users.forge.codelutin.com 17 Jun '14
17 Jun '14
Author: echatellier
Date: 2014-06-17 16:30:35 +0200 (Tue, 17 Jun 2014)
New Revision: 4022
Url: http://forge.codelutin.com/projects/isis-fish/repository/revisions/4022
Log:
fixes #3955: quand recharge ancienne simulation, isis ne garde pas le simulateur associ?\195?\169
Modified:
trunk/src/main/java/fr/ifremer/isisfish/ui/simulator/AdvancedParamsUI.jaxx
trunk/src/main/java/fr/ifremer/isisfish/ui/simulator/OptimizationHandler.java
trunk/src/main/java/fr/ifremer/isisfish/ui/simulator/OptimizationUI.jaxx
trunk/src/main/java/fr/ifremer/isisfish/ui/simulator/ParamsUI.jaxx
trunk/src/main/java/fr/ifremer/isisfish/ui/simulator/PreScriptsUI.jaxx
trunk/src/main/java/fr/ifremer/isisfish/ui/simulator/ResultChoiceUI.jaxx
Modified: trunk/src/main/java/fr/ifremer/isisfish/ui/simulator/AdvancedParamsUI.jaxx
===================================================================
--- trunk/src/main/java/fr/ifremer/isisfish/ui/simulator/AdvancedParamsUI.jaxx 2014-06-17 12:50:25 UTC (rev 4021)
+++ trunk/src/main/java/fr/ifremer/isisfish/ui/simulator/AdvancedParamsUI.jaxx 2014-06-17 14:30:35 UTC (rev 4022)
@@ -55,6 +55,25 @@
}
public void refresh() {
+ fieldSimulAdvParamsSimulatorSelect.setSelectedItem(getContextValue(SimulAction.class).getSimulationParameter().getSimulatorName());
+ fieldSimulationStatistique.setSelected(getContextValue(SimulAction.class).getSimulationParameter().getUseStatistic());
+ fieldSimulationCache.setSelected(getContextValue(SimulAction.class).getSimulationParameter().getUseCache());
+
+ fieldSimulAdvParamsSimulLoggerError.setSelected(getContextValue(SimulAction.class).getSimulationParameter().isSimulErrorLevel());
+ fieldSimulAdvParamsSimulLoggerWarn.setSelected(getContextValue(SimulAction.class).getSimulationParameter().isSimulWarnLevel());
+ fieldSimulAdvParamsSimulLoggerInfo.setSelected(getContextValue(SimulAction.class).getSimulationParameter().isSimulInfoLevel());
+ fieldSimulAdvParamsSimulLoggerDebug.setSelected(getContextValue(SimulAction.class).getSimulationParameter().isSimulDebugLevel());
+
+ fieldSimulAdvParamsScriptLoggerError.setSelected(getContextValue(SimulAction.class).getSimulationParameter().isScriptErrorLevel());
+ fieldSimulAdvParamsScriptLoggerWarn.setSelected(getContextValue(SimulAction.class).getSimulationParameter().isScriptWarnLevel());
+ fieldSimulAdvParamsScriptLoggerInfo.setSelected(getContextValue(SimulAction.class).getSimulationParameter().isScriptInfoLevel());
+ fieldSimulAdvParamsScriptLoggerDebug.setSelected(getContextValue(SimulAction.class).getSimulationParameter().isScriptDebugLevel());
+
+ fieldSimulAdvParamsLibLoggerError.setSelected(getContextValue(SimulAction.class).getSimulationParameter().isLibErrorLevel());
+ fieldSimulAdvParamsLibLoggerWarn.setSelected(getContextValue(SimulAction.class).getSimulationParameter().isLibWarnLevel());
+ fieldSimulAdvParamsLibLoggerInfo.setSelected(getContextValue(SimulAction.class).getSimulationParameter().isLibInfoLevel());
+ fieldSimulAdvParamsLibLoggerDebug.setSelected(getContextValue(SimulAction.class).getSimulationParameter().isLibDebugLevel());
+
setTableTagValues();
}
@@ -123,7 +142,8 @@
<JLabel text="isisfish.advancedParams.simulatorUse"/>
</cell>
<cell columns="4" fill="horizontal">
- <JComboBox id="fieldSimulAdvParamsSimulatorSelect" model='{new DefaultComboBoxModel(getContextValue(SimulAction.class).getSimulatorNames().toArray())}' onActionPerformed='setSimulatorName()'/>
+ <JComboBox id="fieldSimulAdvParamsSimulatorSelect" model='{new DefaultComboBoxModel(getContextValue(SimulAction.class).getSimulatorNames().toArray())}'
+ onActionPerformed='setSimulatorName()'/>
</cell>
</row>
<row>
Modified: trunk/src/main/java/fr/ifremer/isisfish/ui/simulator/OptimizationHandler.java
===================================================================
--- trunk/src/main/java/fr/ifremer/isisfish/ui/simulator/OptimizationHandler.java 2014-06-17 12:50:25 UTC (rev 4021)
+++ trunk/src/main/java/fr/ifremer/isisfish/ui/simulator/OptimizationHandler.java 2014-06-17 14:30:35 UTC (rev 4022)
@@ -64,14 +64,17 @@
import fr.ifremer.isisfish.ui.sensitivity.SensitivityTabUI;
import fr.ifremer.isisfish.ui.widget.editor.FactorEditorListener;
-
public class OptimizationHandler {
private static final Log log = LogFactory.getLog(OptimizationHandler.class);
protected FactorEditorListener factorEditorListener;
- public void init(OptimizationUI view) {
+ public void init(final OptimizationUI view) {
+
+ }
+
+ public void refresh(OptimizationUI view) {
// get info
SimulAction simulAction = view.getContextValue(SimulAction.class);
SimulationParameter param = simulAction.getSimulationParameter();
Modified: trunk/src/main/java/fr/ifremer/isisfish/ui/simulator/OptimizationUI.jaxx
===================================================================
--- trunk/src/main/java/fr/ifremer/isisfish/ui/simulator/OptimizationUI.jaxx 2014-06-17 12:50:25 UTC (rev 4021)
+++ trunk/src/main/java/fr/ifremer/isisfish/ui/simulator/OptimizationUI.jaxx 2014-06-17 14:30:35 UTC (rev 4022)
@@ -24,17 +24,17 @@
-->
<Table>
<script><![CDATA[
- /*protected void $afterCompleteSetup() {
+ protected void $afterCompleteSetup() {
handler.init(this);
- }*/
+ }
// application will be refreshed by regionStorage change
protected void regionStorageChanged() {
- handler.init(this);
+ //handler.refresh(this);
}
public void refresh() {
- //handler.refresh(this);
+ handler.refresh(this);
}
]]></script>
Modified: trunk/src/main/java/fr/ifremer/isisfish/ui/simulator/ParamsUI.jaxx
===================================================================
--- trunk/src/main/java/fr/ifremer/isisfish/ui/simulator/ParamsUI.jaxx 2014-06-17 12:50:25 UTC (rev 4021)
+++ trunk/src/main/java/fr/ifremer/isisfish/ui/simulator/ParamsUI.jaxx 2014-06-17 14:30:35 UTC (rev 4022)
@@ -120,7 +120,7 @@
@Override
public void run() {
simulAction.regionChange(ParamsUI.this, selected);
- refresh();
+ getParentContainer(SimulUI.class).refresh();
setSensitivityTabRegion();
getParentContainer(WelcomePanelUI.class).setStatusMessage(t("isisfish.message.region.loaded"));
}
@@ -188,8 +188,10 @@
@Override
public void run() {
simulAction.loadOldSimulation(selected);
- //refresh();
fieldSimulParamsRegion.setSelectedItem(getContextValue(SimulAction.class).getSimulationParameter().getRegionName());
+
+ getParentContainer(SimulUI.class).refresh();
+
// mise a jour des années
fieldSimulParamsNbAnnees.setText(String.valueOf(simulAction.getNumberOfYear()));
initSimulationParams();
Modified: trunk/src/main/java/fr/ifremer/isisfish/ui/simulator/PreScriptsUI.jaxx
===================================================================
--- trunk/src/main/java/fr/ifremer/isisfish/ui/simulator/PreScriptsUI.jaxx 2014-06-17 12:50:25 UTC (rev 4021)
+++ trunk/src/main/java/fr/ifremer/isisfish/ui/simulator/PreScriptsUI.jaxx 2014-06-17 14:30:35 UTC (rev 4022)
@@ -42,7 +42,8 @@
}*/
]]></script>
<org.fife.ui.rtextarea.RTextScrollPane constraints='BorderLayout.CENTER'>
- <org.fife.ui.rsyntaxtextarea.RSyntaxTextArea id="fieldSimulPreScript" syntaxEditingStyle="{org.fife.ui.rsyntaxtextarea.SyntaxConstants.SYNTAX_STYLE_JAVA}" />
+ <org.fife.ui.rsyntaxtextarea.RSyntaxTextArea id="fieldSimulPreScript" onFocusLost='save()'
+ syntaxEditingStyle="{org.fife.ui.rsyntaxtextarea.SyntaxConstants.SYNTAX_STYLE_JAVA}" />
</org.fife.ui.rtextarea.RTextScrollPane>
<JButton constraints='BorderLayout.SOUTH' text="isisfish.preScript.backParameter"
onActionPerformed='getParentContainer(fr.ifremer.isisfish.ui.SimulationUI.class).selectParametersTab()'/>
Modified: trunk/src/main/java/fr/ifremer/isisfish/ui/simulator/ResultChoiceUI.jaxx
===================================================================
--- trunk/src/main/java/fr/ifremer/isisfish/ui/simulator/ResultChoiceUI.jaxx 2014-06-17 12:50:25 UTC (rev 4021)
+++ trunk/src/main/java/fr/ifremer/isisfish/ui/simulator/ResultChoiceUI.jaxx 2014-06-17 14:30:35 UTC (rev 4022)
@@ -47,10 +47,10 @@
return getContextValue(SimulAction.class);
}
- protected void setListSimulResultChooseModel(){
+ protected void setListSimulResultChooseModel() {
- java.util.List<String> availableResults = getSimulAction().getResultNames();
- java.util.List<String> userResults = getSimulAction().getDefaultResultNames();
+ List<String> availableResults = getSimulAction().getResultNames();
+ List<String> userResults = getSimulAction().getDefaultResultNames();
// userResults = intersection(userResults,availableResult)
userResults.retainAll(availableResults);
1
0
17 Jun '14
Author: echatellier
Date: 2014-06-17 14:50:25 +0200 (Tue, 17 Jun 2014)
New Revision: 4021
Url: http://forge.codelutin.com/projects/isis-fish/repository/revisions/4021
Log:
Update dates
Modified:
trunk/src/main/resources/i18n/isis-fish_en_GB.properties
trunk/src/main/resources/i18n/isis-fish_fr_FR.properties
Modified: trunk/src/main/resources/i18n/isis-fish_en_GB.properties
===================================================================
--- trunk/src/main/resources/i18n/isis-fish_en_GB.properties 2014-06-17 12:46:50 UTC (rev 4020)
+++ trunk/src/main/resources/i18n/isis-fish_en_GB.properties 2014-06-17 12:50:25 UTC (rev 4021)
@@ -89,7 +89,7 @@
directory\ %s\ must\ be\ a\ directory=
dlnorm=
filter\ loaded\ in\ %1$s\ ms\ \:\ found\ %2$s\ lines.=filter loaded in %1$s ms \: found %2$s lines.
-isisfish.about.abouthtmltext=<html><b>ISIS-Fish (%s)</b><br /><br />Copyright IFREMER-MAERHA 2000-2013.<br /><br /><a href\="http\://www.isis-fish.org">http\://www.isis-fish.org</a><br /><br />Please, report any bug you can found.<html>
+isisfish.about.abouthtmltext=<html><b>ISIS-Fish (%s)</b><br /><br />Copyright IFREMER-MAERHA 2000-2014.<br /><br /><a href\="http\://www.isis-fish.org">http\://www.isis-fish.org</a><br /><br />Please, report any bug you can found.<html>
isisfish.about.licensetext=You can modify and redistribute the program under the conditions of the GNU General Public License (version 2 or later). A copy of the GPL is in the file "LICENSE.txt" provided with ISIS-Fish. All rights reserved. No guarantees are provided for use of this program.
isisfish.about.title=About ISIS-Fish...
isisfish.advancedParameters.title=Advanced parameters
Modified: trunk/src/main/resources/i18n/isis-fish_fr_FR.properties
===================================================================
--- trunk/src/main/resources/i18n/isis-fish_fr_FR.properties 2014-06-17 12:46:50 UTC (rev 4020)
+++ trunk/src/main/resources/i18n/isis-fish_fr_FR.properties 2014-06-17 12:50:25 UTC (rev 4021)
@@ -89,7 +89,7 @@
directory\ %s\ must\ be\ a\ directory=
dlnorm=
filter\ loaded\ in\ %1$s\ ms\ \:\ found\ %2$s\ lines.=filter loaded in %1$s ms \: found %2$s lines.
-isisfish.about.abouthtmltext=<html><b>ISIS-Fish (%s)</b><br /><br />Copyright IFREMER-MAERHA 2000-2013.<br /><br /><a href\="http\://www.isis-fish.org">http\://www.isis-fish.org</a><br /><br />Merci de rapporter les bugs.<html>
+isisfish.about.abouthtmltext=<html><b>ISIS-Fish (%s)</b><br /><br />Copyright IFREMER-MAERHA 2000-2014.<br /><br /><a href\="http\://www.isis-fish.org">http\://www.isis-fish.org</a><br /><br />Merci de rapporter les bugs.<html>
isisfish.about.licensetext=Vous pouvez modifier et redistribuer ce programme sous les conditions énoncées par la licence GNU GPL (version 2 ou ultérieure). Une copie de la licence GPL est dans le fichier « LICENSE.txt » fourni avec ISIS-Fish. Tous droits réservés. Aucune garantie n'est fournie pour l'utilisation de ce programme.
isisfish.about.title=À propos de ISIS-Fish...
isisfish.advancedParameters.title=Paramètres avancés
1
0
r4020 - trunk/src/main/java/fr/ifremer/isisfish/mexico/xml
by echatellier@users.forge.codelutin.com 17 Jun '14
by echatellier@users.forge.codelutin.com 17 Jun '14
17 Jun '14
Author: echatellier
Date: 2014-06-17 14:46:50 +0200 (Tue, 17 Jun 2014)
New Revision: 4020
Url: http://forge.codelutin.com/projects/isis-fish/repository/revisions/4020
Log:
fixes #5239: les groupes de facteurs continus se "d?\195?\169groupent" en chargeant une ancienne AS
Modified:
trunk/src/main/java/fr/ifremer/isisfish/mexico/xml/DomXMLParser.java
Modified: trunk/src/main/java/fr/ifremer/isisfish/mexico/xml/DomXMLParser.java
===================================================================
--- trunk/src/main/java/fr/ifremer/isisfish/mexico/xml/DomXMLParser.java 2014-06-17 12:34:23 UTC (rev 4019)
+++ trunk/src/main/java/fr/ifremer/isisfish/mexico/xml/DomXMLParser.java 2014-06-17 12:46:50 UTC (rev 4020)
@@ -716,7 +716,7 @@
// add factor to existing or new group
FactorGroup group = rootGroup;
if (StringUtils.isNotBlank(groupName)) {
- group = groups.get(group);
+ group = groups.get(groupName);
if (group == null) {
group = new FactorGroup(groupName, "continuous".equals(groupType));
groups.put(groupName, group);
1
0
r4019 - in trunk/src/main/java/fr/ifremer/isisfish: simulator/sensitivity simulator/sensitivity/domain ui/sensitivity/wizard
by echatellier@users.forge.codelutin.com 17 Jun '14
by echatellier@users.forge.codelutin.com 17 Jun '14
17 Jun '14
Author: echatellier
Date: 2014-06-17 14:34:23 +0200 (Tue, 17 Jun 2014)
New Revision: 4019
Url: http://forge.codelutin.com/projects/isis-fish/repository/revisions/4019
Log:
fixes #5245: R?\195?\169introduire la possibilit?\195?\169 de d?\195?\169finir des facteurs continus sur des matrices
Modified:
trunk/src/main/java/fr/ifremer/isisfish/simulator/sensitivity/SensitivityUtils.java
trunk/src/main/java/fr/ifremer/isisfish/simulator/sensitivity/domain/ContinuousDomain.java
trunk/src/main/java/fr/ifremer/isisfish/ui/sensitivity/wizard/ContinuousDistributionPanel.java
trunk/src/main/java/fr/ifremer/isisfish/ui/sensitivity/wizard/SensitivityWizardHandler.java
Modified: trunk/src/main/java/fr/ifremer/isisfish/simulator/sensitivity/SensitivityUtils.java
===================================================================
--- trunk/src/main/java/fr/ifremer/isisfish/simulator/sensitivity/SensitivityUtils.java 2014-06-17 09:02:25 UTC (rev 4018)
+++ trunk/src/main/java/fr/ifremer/isisfish/simulator/sensitivity/SensitivityUtils.java 2014-06-17 12:34:23 UTC (rev 4019)
@@ -30,6 +30,7 @@
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.nuiton.math.matrix.MatrixND;
import fr.ifremer.isisfish.entities.Equation;
import fr.ifremer.isisfish.types.RangeOfValues;
@@ -134,6 +135,8 @@
result = true;
} else if (value instanceof Equation) {
result = true;
+ } else if (value instanceof MatrixND) {
+ result = true;
} else if (value instanceof RangeOfValues) {
RangeOfValues rangeOfValues = (RangeOfValues)value;
if (rangeOfValues.getType().equals("Float")) {
Modified: trunk/src/main/java/fr/ifremer/isisfish/simulator/sensitivity/domain/ContinuousDomain.java
===================================================================
--- trunk/src/main/java/fr/ifremer/isisfish/simulator/sensitivity/domain/ContinuousDomain.java 2014-06-17 09:02:25 UTC (rev 4018)
+++ trunk/src/main/java/fr/ifremer/isisfish/simulator/sensitivity/domain/ContinuousDomain.java 2014-06-17 12:34:23 UTC (rev 4019)
@@ -35,6 +35,7 @@
import org.apache.commons.beanutils.MethodUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.nuiton.math.matrix.MatrixND;
import fr.ifremer.isisfish.IsisFishRuntimeException;
import fr.ifremer.isisfish.simulator.sensitivity.Distribution;
@@ -178,19 +179,19 @@
args.add(identifier);
// build distribution param args list
- Class distClass = distribution.getDistClass();
+ // QUNIFPC est un cas particulier dans toutes les distributions possibles
if (distribution == Distribution.QUNIFPC) {
// special management : % to min/max
Object reference = distributionParameters.get(Distribution.QUNIFPC.getDistibutionParams()[0].getName());
double coef = (Double)distributionParameters.get(Distribution.QUNIFPC.getDistibutionParams()[1].getName());
- double ref = (Double)reference;
- args.add(ref * (1.0 - coef)); // min
- args.add(ref * (1.0 + coef)); // max
- } else if (distribution == Distribution.QUNIFMM) {
- Object min = distributionParameters.get(Distribution.QUNIFMM.getDistibutionParams()[0].getName());
- args.add(min);
- Object max = distributionParameters.get(Distribution.QUNIFMM.getDistibutionParams()[1].getName());
- args.add(max);
+ if (reference instanceof MatrixND) {
+ args.add(1.0 - coef); // min
+ args.add(1.0 + coef); // max
+ } else {
+ double ref = (Double)reference;
+ args.add(ref * (1.0 - coef)); // min
+ args.add(ref * (1.0 + coef)); // max
+ }
} else {
for (DistributionParam param : distribution.getDistibutionParams()) {
String name = param.getName();
@@ -199,11 +200,13 @@
}
}
- // add default value for lower.tail = TRUE, log.p = FALSE
+ // add default value for lower.tail = TRUE
args.add(true);
+ // add default value forlog.p = FALSE
args.add(false);
// invoke quantile method
+ Class distClass = distribution.getDistClass();
Object result = null;
try {
result = MethodUtils.invokeStaticMethod(distClass, "quantile", args.toArray());
@@ -213,6 +216,14 @@
}
}
+ // pour les matrices, on retourne la matrice multipliée par la valeur données par R
+ if (distribution == Distribution.QUNIFPC) {
+ Object reference = distributionParameters.get(Distribution.QUNIFPC.getDistibutionParams()[0].getName());
+ if (reference instanceof MatrixND) {
+ MatrixND ref = ((MatrixND)reference).copy();
+ result = ref.mults((Double)result);
+ }
+ }
return result;
}
Modified: trunk/src/main/java/fr/ifremer/isisfish/ui/sensitivity/wizard/ContinuousDistributionPanel.java
===================================================================
--- trunk/src/main/java/fr/ifremer/isisfish/ui/sensitivity/wizard/ContinuousDistributionPanel.java 2014-06-17 09:02:25 UTC (rev 4018)
+++ trunk/src/main/java/fr/ifremer/isisfish/ui/sensitivity/wizard/ContinuousDistributionPanel.java 2014-06-17 12:34:23 UTC (rev 4019)
@@ -44,6 +44,8 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.nuiton.math.matrix.MatrixND;
+import org.nuiton.math.matrix.gui.MatrixPanelEditor;
import fr.ifremer.isisfish.simulator.sensitivity.Distribution;
import fr.ifremer.isisfish.simulator.sensitivity.Distribution.DistributionParam;
@@ -89,8 +91,16 @@
GridBagConstraints.WEST, GridBagConstraints.NONE,
new Insets(0, 0, 0, 0), 0, 0));
+ // values possibility depending on input type
+ Distribution[] values;
+ if (originalValue instanceof MatrixND) {
+ values = new Distribution[]{Distribution.QUNIFPC};
+ } else {
+ values = Distribution.values();
+ }
+
// combobox
- distributionCombo = new JComboBox<Distribution>(Distribution.values());
+ distributionCombo = new JComboBox<Distribution>(values);
// important : for setSelectedItem to fire event
distributionCombo.setSelectedItem(null);
distributionCombo.addItemListener(this);
@@ -128,7 +138,11 @@
if (value != null) {
JComponent comp = paramComponents.get(paramComponentIndex);
- ((JTextComponent)comp).setText(value.toString());
+ if (comp instanceof MatrixPanelEditor) {
+ ((MatrixPanelEditor)comp).setMatrix((MatrixND)value);
+ } else {
+ ((JTextComponent)comp).setText(value.toString());
+ }
} else {
if (log.isWarnEnabled()) {
log.warn("Param " + param.getName() + " not found during init");
@@ -180,16 +194,28 @@
JComponent paramField = getParamField(param);
paramField.setToolTipText(param.getDescription());
- // rendu simple
- dynamicPanel.add(paramLabel, new GridBagConstraints(0, index, 1, 1, 0, 0,
- GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL,
- new Insets(0, 0, 0, 0), 0, 0));
+ // rendu étendu pour les matrix panels
+ if (paramField instanceof MatrixPanelEditor) {
+ dynamicPanel.add(paramLabel, new GridBagConstraints(0, index, 2, 1, 0, 0,
+ GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL,
+ new Insets(0, 0, 0, 0), 0, 0));
+ index++;
+ dynamicPanel.add(paramField, new GridBagConstraints(0, index, 2, 1, 1, 1,
+ GridBagConstraints.NORTH, GridBagConstraints.BOTH,
+ new Insets(0, 0, 0, 0), 0, 0));
+ index++;
+ } else {
+ // rendu simple
+ dynamicPanel.add(paramLabel, new GridBagConstraints(0, index, 1, 1, 0, 0,
+ GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL,
+ new Insets(0, 0, 0, 0), 0, 0));
+
+ dynamicPanel.add(paramField, new GridBagConstraints(1, index, 1, 1, 1, 0,
+ GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL,
+ new Insets(0, 0, 0, 0), 0, 0));
+ index++;
+ }
- dynamicPanel.add(paramField, new GridBagConstraints(1, index, 1, 1, 1, 0,
- GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL,
- new Insets(0, 0, 0, 0), 0, 0));
- index++;
-
paramComponents.add(paramField);
}
@@ -211,7 +237,12 @@
JComponent result;
if (param.isOriginalValue()) {
- result = new JTextField(originalValue.toString());
+ if (originalValue instanceof MatrixND) {
+ result = new MatrixPanelEditor();
+ ((MatrixPanelEditor)result).setMatrix((MatrixND)originalValue);
+ } else {
+ result = new JTextField(originalValue.toString());
+ }
} else {
result = new JTextField();
}
@@ -250,9 +281,13 @@
for (DistributionParam param : params) {
JComponent comp = paramComponents.get(paramComponentIndex);
- // XXX echatellier 20131201 : always double type ?
- String strValue = ((JTextComponent)comp).getText().trim();
- domain.addDistributionParam(param.getName(), Double.parseDouble(strValue));
+ if (comp instanceof MatrixPanelEditor) {
+ domain.addDistributionParam(param.getName(), ((MatrixPanelEditor)comp).getMatrix());
+ } else {
+ // XXX echatellier 20131201 : always double type ?
+ String strValue = ((JTextComponent)comp).getText().trim();
+ domain.addDistributionParam(param.getName(), Double.parseDouble(strValue));
+ }
paramComponentIndex++;
}
Modified: trunk/src/main/java/fr/ifremer/isisfish/ui/sensitivity/wizard/SensitivityWizardHandler.java
===================================================================
--- trunk/src/main/java/fr/ifremer/isisfish/ui/sensitivity/wizard/SensitivityWizardHandler.java 2014-06-17 09:02:25 UTC (rev 4018)
+++ trunk/src/main/java/fr/ifremer/isisfish/ui/sensitivity/wizard/SensitivityWizardHandler.java 2014-06-17 12:34:23 UTC (rev 4019)
@@ -372,6 +372,9 @@
ui.setBeanProperty(property);
ui.setBean(bean);
result = ui;
+ } else if (value instanceof MatrixND) {
+ MatrixND matrix = (MatrixND)value;
+ result = new ContinuousDistributionPanel(matrix.clone());
} else if (value instanceof TimeUnit) {
TimeUnit timeUnit = (TimeUnit)value;
//DefaultContinuousPanelUI ui = new DefaultContinuousPanelUI();
@@ -580,6 +583,9 @@
ui.setBeanProperty(property);
ui.setBean(entity);
result = ui;
+ } else if (value instanceof MatrixND) {
+ MatrixND matrix = (MatrixND)value;
+ result = new ContinuousDistributionPanel(matrix.clone());
} else if (value instanceof TimeUnit) {
TimeUnit timeUnit = (TimeUnit)value;
//DefaultContinuousPanelUI ui = new DefaultContinuousPanelUI();
@@ -597,7 +603,24 @@
topiaContext.closeContext();
} else {
- if (factorPath.startsWith("parameters.rule.")) {
+ if (factorPath.startsWith("parameters.population.")) {
+ // la seule facon d'avoir les parametres ici est d'aller
+ // les chercher dans les parametres de simulation
+ Pattern pattern = Pattern.compile("^parameters\\.population\\.(\\w+)(\\.(.+)?)$");
+ Matcher matcher = pattern.matcher(factorPath);
+ if (matcher.matches()) {
+ String populationName = matcher.group(1);
+ if (log.isDebugEnabled()) {
+ log.debug("Loading population : " + populationName);
+ }
+ TopiaContext topiaContext = getTopiaContext(factorWizardUI);
+ Population pop = IsisFishDAOHelper.getPopulationDAO(topiaContext).findByName(populationName);
+ SimulAction action = factorWizardUI.getContextValue(SimulAction.class);
+ MatrixND N = action.getSimulationParameter().getNumberOf(pop);
+ result = new ContinuousDistributionPanel(N.clone());
+ topiaContext.closeContext();
+ }
+ } else if (factorPath.startsWith("parameters.rule.")) {
Pattern pattern = Pattern.compile("^parameters\\.rule\\.(\\d+)\\.parameter\\.(\\w+)(\\..+)?$");
Matcher matcher = pattern.matcher(factorPath);
if (matcher.matches()) {
1
0
r4018 - in trunk/src/main: java/fr/ifremer/isisfish/datastore java/fr/ifremer/isisfish/ui/input resources/i18n
by echatellier@users.forge.codelutin.com 17 Jun '14
by echatellier@users.forge.codelutin.com 17 Jun '14
17 Jun '14
Author: echatellier
Date: 2014-06-17 11:02:25 +0200 (Tue, 17 Jun 2014)
New Revision: 4018
Url: http://forge.codelutin.com/projects/isis-fish/repository/revisions/4018
Log:
Remove import from v2
Removed:
trunk/src/main/java/fr/ifremer/isisfish/datastore/update/
Modified:
trunk/src/main/java/fr/ifremer/isisfish/ui/input/InputHandler.java
trunk/src/main/java/fr/ifremer/isisfish/ui/input/InputUI.jaxx
trunk/src/main/resources/i18n/isis-fish_en_GB.properties
trunk/src/main/resources/i18n/isis-fish_fr_FR.properties
Modified: trunk/src/main/java/fr/ifremer/isisfish/ui/input/InputHandler.java
===================================================================
--- trunk/src/main/java/fr/ifremer/isisfish/ui/input/InputHandler.java 2014-06-16 16:04:46 UTC (rev 4017)
+++ trunk/src/main/java/fr/ifremer/isisfish/ui/input/InputHandler.java 2014-06-17 09:02:25 UTC (rev 4018)
@@ -61,7 +61,6 @@
import fr.ifremer.isisfish.datastore.RegionStorage;
import fr.ifremer.isisfish.datastore.SimulationStorage;
import fr.ifremer.isisfish.datastore.StorageException;
-import fr.ifremer.isisfish.datastore.update.ImportFromV2;
import fr.ifremer.isisfish.entities.Cell;
import fr.ifremer.isisfish.entities.FisheryRegion;
import fr.ifremer.isisfish.entities.Gear;
@@ -314,29 +313,6 @@
}
/**
- * Importer la region depuis un fichier XML de la version 2.
- *
- * @param inputUI inputUI
- */
- public void importV2Region(InputUI inputUI) {
-
- setStatusMessage(inputUI, t("isisfish.message.import.xml.v2.file"), true);
-
- try {
- File file = FileUtil.getFile(".*.xml$", t("isisfish.message.import.region.xml"));
- if (file != null) {
- new ImportFromV2(true).importXML(file);
-
- refreshRegionList(inputUI, null);
- }
- } catch (Exception eee) {
- throw new IsisFishRuntimeException(t("isisfish.error.region.import"), eee);
- }
-
- setStatusMessage(inputUI, t("isisfish.message.import.finished"));
- }
-
- /**
* Extract from a simulation the region, and rename it with name given
* by user.
*
Modified: trunk/src/main/java/fr/ifremer/isisfish/ui/input/InputUI.jaxx
===================================================================
--- trunk/src/main/java/fr/ifremer/isisfish/ui/input/InputUI.jaxx 2014-06-16 16:04:46 UTC (rev 4017)
+++ trunk/src/main/java/fr/ifremer/isisfish/ui/input/InputUI.jaxx 2014-06-17 09:02:25 UTC (rev 4018)
@@ -32,7 +32,6 @@
<JMenu text="isisfish.common.region">
<JMenuItem text="isisfish.input.menu.importRegion" onActionPerformed="getHandler().importRegion(this)" />
<JMenuItem text="isisfish.input.menu.importRenameRegion" onActionPerformed="getHandler().importRegionAndRename(this)" />
- <JMenuItem text="isisfish.input.menu.importRegionV2" onActionPerformed="getHandler().importV2Region(this)" />
<JMenuItem text="isisfish.input.menu.importRegionSimulation" onActionPerformed="getHandler().importRegionFromSimulation(this)" />
<JMenuItem text="isisfish.input.menu.exportRegion" enabled='{isRegionLoaded()}' onActionPerformed="getHandler().exportRegion(this)" />
<JMenuItem text="isisfish.input.menu.copyRegion" enabled='{isRegionLoaded()}' onActionPerformed="getHandler().copyRegion(this)" />
Modified: trunk/src/main/resources/i18n/isis-fish_en_GB.properties
===================================================================
--- trunk/src/main/resources/i18n/isis-fish_en_GB.properties 2014-06-16 16:04:46 UTC (rev 4017)
+++ trunk/src/main/resources/i18n/isis-fish_en_GB.properties 2014-06-17 09:02:25 UTC (rev 4018)
@@ -211,6 +211,7 @@
isisfish.config.main.simulation.ssh.pbsbinpath.description=PBS executables (qsub, qdel...) directory
isisfish.config.main.simulation.ssh.pbsqsuboptions=Qsub arguments
isisfish.config.main.simulation.ssh.pbsqsuboptions.description=Arguments used at qsub job sumbit. Default to '-m n' don't send mail.
+isisfish.config.main.simulation.ssh.proxy.command.description=
isisfish.config.main.simulation.ssh.server=Simulation server
isisfish.config.main.simulation.ssh.server.description=Simulation server address
isisfish.config.main.simulation.ssh.tmppath=Server temp directory
Modified: trunk/src/main/resources/i18n/isis-fish_fr_FR.properties
===================================================================
--- trunk/src/main/resources/i18n/isis-fish_fr_FR.properties 2014-06-16 16:04:46 UTC (rev 4017)
+++ trunk/src/main/resources/i18n/isis-fish_fr_FR.properties 2014-06-17 09:02:25 UTC (rev 4018)
@@ -211,6 +211,7 @@
isisfish.config.main.simulation.ssh.pbsbinpath.description=Emplacement des commandes PBS (qsub, qdel...) sur le serveur
isisfish.config.main.simulation.ssh.pbsqsuboptions=Arguments qsub
isisfish.config.main.simulation.ssh.pbsqsuboptions.description=Arguments utilisés lors de la soumission des jobs. Par défaut '-m n' pas d'envoi de mails.
+isisfish.config.main.simulation.ssh.proxy.command.description=
isisfish.config.main.simulation.ssh.server=Serveur de simulation
isisfish.config.main.simulation.ssh.server.description=Adresse du serveur de simulation
isisfish.config.main.simulation.ssh.tmppath=Dossier temporaire
1
0