# HG changeset patch # User Raimund Renkert # Date 1338982532 0 # Node ID b388d888330d2d840e82099eff2c000ad7bd1475 # Parent 842502b3913aecb50ac72e5b7348e5d5a70d3f82 Implemented facets and splitted up the event facet.Implemented facets and splitted up the event facet. flys-artifacts/trunk@4604 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 842502b3913a -r b388d888330d flys-artifacts/ChangeLog --- a/flys-artifacts/ChangeLog Wed Jun 06 10:26:28 2012 +0000 +++ b/flys-artifacts/ChangeLog Wed Jun 06 11:35:32 2012 +0000 @@ -1,3 +1,24 @@ +2012-06-06 Raimund Renkert + + Implemented facets and splitted up the event facet. + + * src/main/java/de/intevation/flys/artifacts/model/fixings/FixEventsFacet.java: + Removed. + + * src/main/java/de/intevation/flys/artifacts/model/fixings/FixAnalysisEventsFacet.java, + src/main/java/de/intevation/flys/artifacts/model/fixings/FixReferenceEventsFacet.java: + New. Facets for events. + + * src/main/java/de/intevation/flys/artifacts/model/fixings/FixWQCurveFacet.java, + src/main/java/de/intevation/flys/artifacts/model/fixings/FixOutlierFacet.java: + Implemented getData(). + + * src/main/java/de/intevation/flys/artifacts/states/fixation/FixationCompute.java: + Add new event facets. + + * src/main/java/de/intevation/flys/artifacts/model/fixings/FixAvSectorFacet.java: + Fixed return value. + 2012-06-06 Sascha L. Teichmann * src/main/java/de/intevation/flys/jfree/Function2DAdapter.java: diff -r 842502b3913a -r b388d888330d flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixAnalysisEventsFacet.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixAnalysisEventsFacet.java Wed Jun 06 11:35:32 2012 +0000 @@ -0,0 +1,97 @@ +package de.intevation.flys.artifacts.model.fixings; + +import org.apache.log4j.Logger; + +import de.intevation.artifacts.Artifact; +import de.intevation.artifacts.CallContext; + +import de.intevation.flys.utils.KMIndex; + +import de.intevation.flys.artifacts.FLYSArtifact; +import de.intevation.flys.artifacts.FixationArtifactAccess; + +import de.intevation.flys.artifacts.model.FacetTypes; +import de.intevation.flys.artifacts.model.DataFacet; +import de.intevation.flys.artifacts.model.CalculationResult; + +import de.intevation.flys.artifacts.states.DefaultState.ComputeType; + + +/** + * Facet to show W values for Q values at km for a date. + * + * @author Raimund Renkert + */ +public class FixAnalysisEventsFacet +extends DataFacet +implements FacetTypes { + + /** House logger. */ + private static Logger logger = Logger.getLogger(FixAnalysisEventsFacet.class); + + /** Trivial Constructor. */ + public FixAnalysisEventsFacet() { + } + + + /** + * @param name + */ + public FixAnalysisEventsFacet(int index, String description) { + super(index, FIX_EVENTS, description, ComputeType.ADVANCE, null, null); + } + + + /** + * Returns the data this facet requires. + * + * @param artifact the owner artifact. + * @param context the CallContext (ignored). + * + * @return the data. + */ + @Override + public Object getData(Artifact artifact, CallContext context) { + logger.debug("FixAnalysisEventsFacet.getData"); + + if (artifact instanceof FLYSArtifact) { + FLYSArtifact flys = (FLYSArtifact)artifact; + FixationArtifactAccess access = new FixationArtifactAccess(flys); + + CalculationResult res = + (CalculationResult) flys.compute(context, + ComputeType.ADVANCE, + false); + + FixResult result = (FixResult) res.getData(); + + double km = access.getCurrentKm(); + + KMIndex kmPeriods = result.getAnalysisPeriods(); + AnalysisPeriod[] periods = kmPeriods.binarySearch(km).getValue(); + + if (periods == null) { + return null; + } + QWD[] qwdData = periods[index].getQWDs(); + return qwdData; + } + else { + logger.debug("Not an instance of FixationArtifact."); + return null; + } + } + + + /** + * Create a deep copy of this Facet. + * @return a deep copy. + */ + @Override + public FixAnalysisEventsFacet deepCopy() { + FixAnalysisEventsFacet copy = new FixAnalysisEventsFacet(); + copy.set(this); + return copy; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r 842502b3913a -r b388d888330d flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixAvSectorFacet.java --- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixAvSectorFacet.java Wed Jun 06 10:26:28 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixAvSectorFacet.java Wed Jun 06 11:35:32 2012 +0000 @@ -77,7 +77,7 @@ return null; } QWD[] qwdData = periods[index].getQSectorAverages(); - return periods; + return qwdData; } else { logger.debug("Not an instance of FixationArtifact."); diff -r 842502b3913a -r b388d888330d flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixEventsFacet.java --- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixEventsFacet.java Wed Jun 06 10:26:28 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,66 +0,0 @@ -package de.intevation.flys.artifacts.model.fixings; - -import org.apache.log4j.Logger; - -import de.intevation.artifacts.Artifact; -import de.intevation.artifacts.CallContext; - -import de.intevation.flys.artifacts.FLYSArtifact; -import de.intevation.flys.artifacts.model.FacetTypes; -import de.intevation.flys.artifacts.model.DataFacet; - -import de.intevation.flys.artifacts.states.DefaultState.ComputeType; - - -/** - * Facet to show W values for Q values at km for a date. - * - * @author Raimund Renkert - */ -public class FixEventsFacet -extends DataFacet -implements FacetTypes { - - /** House logger. */ - private static Logger logger = Logger.getLogger(FixEventsFacet.class); - - /** Trivial Constructor. */ - public FixEventsFacet() { - } - - - /** - * @param name - */ - public FixEventsFacet(int index, String description) { - super(index, FIX_EVENTS, description, ComputeType.ADVANCE, null, null); - } - - - /** - * Returns the data this facet requires. - * - * @param artifact the owner artifact. - * @param context the CallContext (ignored). - * - * @return the data. - */ - @Override - public Object getData(Artifact artifact, CallContext context) { - logger.debug("FixEventsFacet.getData"); - return null; - } - - - /** - * Create a deep copy of this Facet. - * @return a deep copy. - */ - @Override - public FixEventsFacet deepCopy() { - FixEventsFacet copy = new FixEventsFacet(); - copy.set(this); - return copy; - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r 842502b3913a -r b388d888330d flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixFunction.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixFunction.java Wed Jun 06 11:35:32 2012 +0000 @@ -0,0 +1,45 @@ +package de.intevation.flys.artifacts.model.fixings; + +import de.intevation.flys.artifacts.math.Function; + +import java.io.Serializable; + +public class FixFunction +implements Serializable +{ + protected String name; + protected String description; + protected Function mathFunction; + protected double maxQ; + + + public FixFunction ( + String name, + String description, + Function f, + double maxQ) { + this.name = name; + this.description = description; + this.mathFunction = f; + this.maxQ = maxQ; + } + + public String getName() { + return this.name; + } + + + public String getDescription() { + return this.description; + } + + + public Function getFunction() { + return this.mathFunction; + } + + + public double getMaxQ() { + return this.maxQ; + } +} diff -r 842502b3913a -r b388d888330d flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixOutlierFacet.java --- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixOutlierFacet.java Wed Jun 06 10:26:28 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixOutlierFacet.java Wed Jun 06 11:35:32 2012 +0000 @@ -5,9 +5,14 @@ import de.intevation.artifacts.Artifact; import de.intevation.artifacts.CallContext; +import de.intevation.flys.utils.KMIndex; + import de.intevation.flys.artifacts.FLYSArtifact; +import de.intevation.flys.artifacts.FixationArtifactAccess; + import de.intevation.flys.artifacts.model.FacetTypes; import de.intevation.flys.artifacts.model.DataFacet; +import de.intevation.flys.artifacts.model.CalculationResult; import de.intevation.flys.artifacts.states.DefaultState.ComputeType; @@ -48,7 +53,31 @@ @Override public Object getData(Artifact artifact, CallContext context) { logger.debug("FixOutlierFacet.getData"); - return null; + + if (artifact instanceof FLYSArtifact) { + FLYSArtifact flys = (FLYSArtifact)artifact; + FixationArtifactAccess access = new FixationArtifactAccess(flys); + + CalculationResult res = + (CalculationResult) flys.compute(context, + ComputeType.ADVANCE, + false); + + FixResult result = (FixResult) res.getData(); + + double km = access.getCurrentKm(); + KMIndex kmQWs = result.getOutliers(); + + QW[] qws = kmQWs.binarySearch(km).getValue(); + if (qws == null) { + return null; + } + return qws; + } + else { + logger.debug("Not an instance of FixationArtifact."); + return null; + } } diff -r 842502b3913a -r b388d888330d flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixReferenceEventsFacet.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixReferenceEventsFacet.java Wed Jun 06 11:35:32 2012 +0000 @@ -0,0 +1,95 @@ +package de.intevation.flys.artifacts.model.fixings; + +import org.apache.log4j.Logger; + +import de.intevation.artifacts.Artifact; +import de.intevation.artifacts.CallContext; + +import de.intevation.flys.utils.KMIndex; + +import de.intevation.flys.artifacts.FLYSArtifact; +import de.intevation.flys.artifacts.FixationArtifactAccess; + +import de.intevation.flys.artifacts.model.FacetTypes; +import de.intevation.flys.artifacts.model.DataFacet; +import de.intevation.flys.artifacts.model.CalculationResult; + +import de.intevation.flys.artifacts.states.DefaultState.ComputeType; + + +/** + * Facet to show W values for Q values at km for a date. + * + * @author Raimund Renkert + */ +public class FixReferenceEventsFacet +extends DataFacet +implements FacetTypes { + + /** House logger. */ + private static Logger logger = Logger.getLogger(FixReferenceEventsFacet.class); + + /** Trivial Constructor. */ + public FixReferenceEventsFacet() { + } + + + /** + * @param name + */ + public FixReferenceEventsFacet(int index, String description) { + super(index, FIX_EVENTS, description, ComputeType.ADVANCE, null, null); + } + + + /** + * Returns the data this facet requires. + * + * @param artifact the owner artifact. + * @param context the CallContext (ignored). + * + * @return the data. + */ + @Override + public Object getData(Artifact artifact, CallContext context) { + logger.debug("FixReferenceEventsFacet.getData"); + + if (artifact instanceof FLYSArtifact) { + FLYSArtifact flys = (FLYSArtifact)artifact; + FixationArtifactAccess access = new FixationArtifactAccess(flys); + + CalculationResult res = + (CalculationResult) flys.compute(context, + ComputeType.ADVANCE, + false); + + FixResult result = (FixResult) res.getData(); + + double km = access.getCurrentKm(); + KMIndex kmQWs = result.getReferenced(); + + QW[] qws = kmQWs.binarySearch(km).getValue(); + if (qws == null) { + return null; + } + return qws; + } + else { + logger.debug("Not an instance of FixationArtifact."); + return null; + } + } + + + /** + * Create a deep copy of this Facet. + * @return a deep copy. + */ + @Override + public FixReferenceEventsFacet deepCopy() { + FixReferenceEventsFacet copy = new FixReferenceEventsFacet(); + copy.set(this); + return copy; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r 842502b3913a -r b388d888330d flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixWQCurveFacet.java --- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixWQCurveFacet.java Wed Jun 06 10:26:28 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixWQCurveFacet.java Wed Jun 06 11:35:32 2012 +0000 @@ -5,9 +5,18 @@ import de.intevation.artifacts.Artifact; import de.intevation.artifacts.CallContext; +import de.intevation.flys.utils.KMIndex; + import de.intevation.flys.artifacts.FLYSArtifact; +import de.intevation.flys.artifacts.FixationArtifactAccess; + import de.intevation.flys.artifacts.model.FacetTypes; import de.intevation.flys.artifacts.model.DataFacet; +import de.intevation.flys.artifacts.model.CalculationResult; +import de.intevation.flys.artifacts.model.Parameters; + +import de.intevation.flys.artifacts.math.fitting.FunctionFactory; +import de.intevation.flys.artifacts.math.fitting.Function; import de.intevation.flys.artifacts.states.DefaultState.ComputeType; @@ -48,10 +57,81 @@ @Override public Object getData(Artifact artifact, CallContext context) { logger.debug("FixWQCurveFacet.getData"); - return null; + if (artifact instanceof FLYSArtifact) { + FLYSArtifact flys = (FLYSArtifact)artifact; + FixationArtifactAccess access = new FixationArtifactAccess(flys); + + CalculationResult res = + (CalculationResult) flys.compute(context, + ComputeType.ADVANCE, + false); + + FixResult result = (FixResult) res.getData(); + + double km = access.getCurrentKm(); + + String function = access.getFunction(); + Function ff = FunctionFactory.getInstance().getFunction(function); + + Parameters params = result.getParameters(); + int row = params.binarySearch("km", km, Math.pow(10, -4)); + String[] paramNames = ff.getParameterNames(); + int[] paramInd = params.columnIndices(paramNames); + double[] coeffs = new double[paramNames.length]; + params.get(row, paramInd, coeffs); + + de.intevation.flys.artifacts.math.Function mf = + ff.instantiate(coeffs); + + double maxQ = getMaxQ(result, km); + + FixFunction fix = new FixFunction( + ff.getName(), + ff.getDescription(), + mf, + maxQ); + + return fix; + } + else { + logger.debug("Not an instance of FixationArtifact."); + return null; + } } + protected double getMaxQ(FixResult result, double km) { + double maxQ = 0; + + KMIndex kmQWRef = result.getReferenced(); + + QW[] qwRef = kmQWRef.binarySearch(km).getValue(); + if (qwRef != null) { + for (int i = 0; i < qwRef.length; i++) { + if (qwRef[i].getQ() > maxQ) { + maxQ = qwRef[i].getQ(); + } + } + } + + KMIndex kmQWDAna = result.getAnalysisPeriods(); + AnalysisPeriod[] periods = kmQWDAna.binarySearch(km).getValue(); + + if(periods != null) { + for (int i = 0; i < periods.length; i++) { + QWD[] qwdAna = periods[i].getQWDs(); + if (qwdAna != null) { + for (int j = 0; j < qwdAna.length; j++) { + if (qwdAna[j].getQ() > maxQ) { + maxQ = qwdAna[j].getQ(); + } + } + } + } + } + return maxQ; + } + /** * Create a deep copy of this Facet. * @return a deep copy. diff -r 842502b3913a -r b388d888330d flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/fixation/FixationCompute.java --- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/fixation/FixationCompute.java Wed Jun 06 10:26:28 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/fixation/FixationCompute.java Wed Jun 06 11:35:32 2012 +0000 @@ -15,7 +15,8 @@ import de.intevation.flys.artifacts.model.fixings.FixCalculation; import de.intevation.flys.artifacts.model.fixings.FixAvSectorFacet; -import de.intevation.flys.artifacts.model.fixings.FixEventsFacet; +import de.intevation.flys.artifacts.model.fixings.FixAnalysisEventsFacet; +import de.intevation.flys.artifacts.model.fixings.FixReferenceEventsFacet; import de.intevation.flys.artifacts.model.fixings.FixOutlierFacet; import de.intevation.flys.artifacts.model.fixings.FixWQCurveFacet; @@ -98,9 +99,9 @@ String eventDesc = period.getFrom().toString() + " - " + period.getTo().toString(); - facets.add(new FixEventsFacet(i, eventDesc)); + facets.add(new FixAnalysisEventsFacet(i, eventDesc)); } - facets.add(new FixEventsFacet(0, "Referenceperiod")); + facets.add(new FixReferenceEventsFacet(0, "Referenceperiod")); facets.add(new FixWQCurveFacet("W/Q")); facets.add(new FixOutlierFacet("Outlier"));