sascha@2725: package de.intevation.flys.artifacts; sascha@2725: sascha@3003: import de.intevation.artifactdatabase.data.StateData; sascha@3003: sascha@3003: import de.intevation.flys.artifacts.model.fixings.DateRange; sascha@3003: sascha@3003: import de.intevation.flys.utils.FLYSUtils; sascha@3003: sascha@3003: import gnu.trove.TDoubleArrayList; sascha@3003: sascha@3001: import java.util.ArrayList; sascha@2725: import java.util.Arrays; sascha@3003: import java.util.Date; sascha@2725: sascha@2725: import org.apache.log4j.Logger; sascha@2725: sascha@2725: public class FixationArtifactAccess sascha@2725: { sascha@2725: private static Logger log = Logger.getLogger(FixationArtifactAccess.class); sascha@2725: sascha@2725: protected FLYSArtifact artifact; sascha@2725: sascha@2725: protected String river; sascha@2725: sascha@2725: protected String calculationMode; sascha@2725: sascha@2725: protected Double from; sascha@2725: protected Double to; sascha@2725: protected Double step; sascha@2725: sascha@2725: protected Long start; sascha@2725: protected Long end; sascha@2725: sascha@2725: protected Integer qSectorStart; sascha@2725: protected Integer qSectorEnd; sascha@2725: sascha@2725: protected Long referenceStart; sascha@2725: protected Long referenceEnd; sascha@2725: sascha@3003: protected DateRange [] analysisPeriods; sascha@2725: sascha@2725: protected int [] events; sascha@2725: sascha@2725: protected Boolean preprocessing; sascha@2725: sascha@2725: protected String function; sascha@2725: sascha@2725: protected double [] qs; sascha@2725: sascha@2725: public FixationArtifactAccess() { sascha@2725: } sascha@2725: sascha@2725: public FixationArtifactAccess(FLYSArtifact artifact) { sascha@2725: this.artifact = artifact; sascha@2725: } sascha@2725: sascha@2725: public FLYSArtifact getArtifact() { sascha@2725: return artifact; sascha@2725: } sascha@2725: sascha@2725: public String getRiver() { sascha@2725: if (river == null) { sascha@2725: StateData sd = artifact.getData("river"); sascha@2725: if (sd == null) { sascha@2725: log.warn("missing 'river' value"); sascha@2725: return null; sascha@2725: } sascha@2725: river = (String)sd.getValue(); sascha@2725: } sascha@2725: if (log.isDebugEnabled()) { sascha@2725: log.debug("river: '" + river + "'"); sascha@2725: } sascha@2725: return river; sascha@2725: } sascha@2725: sascha@2725: public String getCalculationMode() { sascha@2725: if (calculationMode == null) { sascha@2725: StateData sd = artifact.getData("calculation.mode"); sascha@2725: if (sd == null) { sascha@2725: log.warn("missing 'calculation.mode' value"); sascha@2725: return null; sascha@2725: } sascha@2725: calculationMode = (String)sd.getValue(); sascha@2725: } sascha@2725: sascha@2725: if (log.isDebugEnabled()) { sascha@2725: log.debug("calculationMode: '" + calculationMode + "'"); sascha@2725: } sascha@2725: return calculationMode; sascha@2725: } sascha@2725: sascha@2725: public Double getFrom() { sascha@2725: sascha@2725: if (from == null) { sascha@2725: StateData sd = artifact.getData("from"); sascha@2725: if (sd == null) { sascha@2725: log.warn("missing 'from' value"); sascha@2725: return null; sascha@2725: } sascha@2725: try { sascha@2725: from = Double.valueOf((String)sd.getValue()); sascha@2725: } sascha@2725: catch (NumberFormatException nfe) { sascha@2725: log.warn("from '" + sd.getValue() + "' is not numeric."); sascha@2725: } sascha@2725: } sascha@2725: sascha@2725: if (log.isDebugEnabled()) { sascha@2725: log.debug("from: '" + from + "'"); sascha@2725: } sascha@2725: sascha@2725: return from; sascha@2725: } sascha@2725: sascha@2725: public Double getTo() { sascha@2725: sascha@2725: if (to == null) { sascha@2725: StateData sd = artifact.getData("to"); sascha@2725: if (sd == null) { sascha@2725: log.warn("missing 'to' value"); sascha@2725: return null; sascha@2725: } sascha@2725: try { sascha@2725: to = Double.valueOf((String)sd.getValue()); sascha@2725: } sascha@2725: catch (NumberFormatException nfe) { sascha@2725: log.warn("to '" + sd.getValue() + "' is not numeric."); sascha@2725: } sascha@2725: } sascha@2725: sascha@2725: if (log.isDebugEnabled()) { sascha@2725: log.debug("to: '" + to + "'"); sascha@2725: } sascha@2725: sascha@2725: return to; sascha@2725: } sascha@2725: sascha@2725: public Double getStep() { sascha@2725: sascha@2725: if (step == null) { sascha@2725: StateData sd = artifact.getData("step"); sascha@2725: if (sd == null) { sascha@2725: log.warn("missing 'step' value"); sascha@2725: return null; sascha@2725: } sascha@2725: try { sascha@2725: step = Double.valueOf((String)sd.getValue()); sascha@2725: } sascha@2725: catch (NumberFormatException nfe) { sascha@2725: log.warn("step '" + sd.getValue() + "' is not numeric."); sascha@2725: } sascha@2725: } sascha@2725: sascha@2725: if (log.isDebugEnabled()) { sascha@2725: log.debug("step: '" + step + "'"); sascha@2725: } sascha@2725: sascha@2725: return step; sascha@2725: } sascha@2725: sascha@2725: public Long getStart() { sascha@2725: sascha@2725: if (start == null) { sascha@2725: StateData sd = artifact.getData("start"); sascha@2725: if (sd == null) { sascha@2725: log.warn("missing 'start' value"); sascha@2725: return null; sascha@2725: } sascha@2725: try { sascha@2725: start = Long.valueOf((String)sd.getValue()); sascha@2725: } sascha@2725: catch (NumberFormatException nfe) { sascha@2725: log.warn("start '" + sd.getValue() + "' is not an integer."); sascha@2725: } sascha@2725: } sascha@2725: sascha@2725: if (log.isDebugEnabled()) { sascha@2725: log.debug("start: '" + start + "'"); sascha@2725: } sascha@2725: sascha@2725: return start; sascha@2725: } sascha@2725: sascha@2725: public Long getEnd() { sascha@2725: sascha@2725: if (end == null) { sascha@2725: StateData sd = artifact.getData("end"); sascha@2725: if (sd == null) { sascha@2725: log.warn("missing 'end' value"); sascha@2725: return null; sascha@2725: } sascha@2725: try { sascha@2725: end = Long.valueOf((String)sd.getValue()); sascha@2725: } sascha@2725: catch (NumberFormatException nfe) { sascha@2725: log.warn("end '" + sd.getValue() + "' is not an integer."); sascha@2725: } sascha@2725: } sascha@2725: sascha@2725: if (log.isDebugEnabled()) { sascha@2725: log.debug("end: '" + end + "'"); sascha@2725: } sascha@2725: sascha@2725: return end; sascha@2725: } sascha@2725: sascha@2725: public Integer getQSectorStart() { sascha@2725: sascha@2725: if (qSectorStart == null) { sascha@2725: StateData sd = artifact.getData("q1"); sascha@2725: if (sd == null) { sascha@2725: log.warn("missing 'q1' value"); sascha@2725: return null; sascha@2725: } sascha@2725: try { sascha@2725: qSectorStart = Integer.valueOf((String)sd.getValue()); sascha@2725: } sascha@2725: catch (NumberFormatException nfe) { sascha@2725: log.warn("q1 '" + sd.getValue() + "' is not an integer."); sascha@2725: } sascha@2725: } sascha@2725: sascha@2725: return qSectorStart; sascha@2725: } sascha@2725: sascha@2725: public Integer getQSectorEnd() { sascha@2725: sascha@2725: if (qSectorEnd == null) { sascha@2725: StateData sd = artifact.getData("q2"); sascha@2725: if (sd == null) { sascha@2725: log.warn("missing 'q2' value"); sascha@2725: return null; sascha@2725: } sascha@2725: try { sascha@2725: qSectorEnd = Integer.valueOf((String)sd.getValue()); sascha@2725: } sascha@2725: catch (NumberFormatException nfe) { sascha@2725: log.warn("q2 '" + sd.getValue() + "' is not an integer."); sascha@2725: } sascha@2725: } sascha@2725: sascha@2725: return qSectorEnd; sascha@2725: } sascha@2725: sascha@2725: public int [] getEvents() { sascha@2725: if (events == null) { sascha@2725: StateData sd = artifact.getData("events"); sascha@2725: if (sd == null) { sascha@2725: log.warn("missing 'events' value"); sascha@2725: return null; sascha@2725: } sascha@2725: events = FLYSUtils.intArrayFromString((String)sd.getValue()); sascha@2725: } sascha@2725: return events; sascha@2725: } sascha@2725: sascha@2725: public Long getReferenceStart() { sascha@2725: if (referenceStart == null) { sascha@2725: StateData sd = artifact.getData("ref_start"); sascha@2725: if (sd == null) { sascha@2725: log.warn("missing 'ref_start' value"); sascha@2725: return null; sascha@2725: } sascha@2725: try { sascha@2725: referenceStart = Long.valueOf((String)sd.getValue()); sascha@2725: } sascha@2725: catch (NumberFormatException nfe) { sascha@2725: log.warn("ref_start '" sascha@2725: + sd.getValue() + "' is not an integer."); sascha@2725: } sascha@2725: } sascha@2725: sascha@2725: if (log.isDebugEnabled()) { sascha@2725: log.debug("referenceStart: '" + referenceStart + "'"); sascha@2725: } sascha@2725: sascha@2725: return referenceStart; sascha@2725: } sascha@2725: sascha@2725: public Long getReferenceEnd() { sascha@2725: if (referenceEnd == null) { sascha@2725: StateData sd = artifact.getData("ref_end"); sascha@2725: if (sd == null) { sascha@2725: log.warn("missing 'ref_end' value"); sascha@2725: return null; sascha@2725: } sascha@2725: try { sascha@2725: referenceEnd = Long.valueOf((String)sd.getValue()); sascha@2725: } sascha@2725: catch (NumberFormatException nfe) { sascha@2725: log.warn("ref_end '" sascha@2725: + sd.getValue() + "' is not an integer."); sascha@2725: } sascha@2725: } sascha@2725: sascha@2725: if (log.isDebugEnabled()) { sascha@2725: log.debug("referenceEnd: '" + referenceEnd + "'"); sascha@2725: } sascha@2725: sascha@2725: return referenceEnd; sascha@2725: } sascha@2725: sascha@3003: public DateRange [] getAnalysisPeriods() { sascha@2725: if (analysisPeriods == null) { raimund@3000: StateData sd = artifact.getData("ana_data"); sascha@2725: raimund@3000: if (sd == null) { raimund@3000: log.warn("missing 'ana_data'"); sascha@2725: return null; sascha@2725: } sascha@2725: sascha@3001: String data = (String)sd.getValue(); sascha@3003: String[] pairs = data.split("\\s*;\\s*"); sascha@3001: sascha@3003: ArrayList aPs = new ArrayList(pairs.length); sascha@3001: sascha@3001: for (int i = 0; i < pairs.length; i++) { sascha@3003: String[] fromTo = pairs[i].split("\\s*,\\s*"); sascha@3001: if (fromTo.length >= 2) { sascha@3001: try { sascha@3003: Date from = new Date(Long.parseLong(fromTo[0])); sascha@3003: Date to = new Date(Long.parseLong(fromTo[1])); sascha@3025: DateRange aP = new DateRange(from, to); sascha@3025: if (!aPs.contains(aP)) { sascha@3025: aPs.add(aP); sascha@3025: } sascha@3001: } sascha@3001: catch (NumberFormatException nfe) { sascha@3001: log.warn("ana_data contains no long values.", nfe); sascha@3001: } raimund@3000: } sascha@2725: } sascha@3001: sascha@3003: analysisPeriods = aPs.toArray(new DateRange[aPs.size()]); sascha@2725: } sascha@2725: sascha@2725: if (log.isDebugEnabled()) { sascha@2725: for (int i = 0; i < analysisPeriods.length; ++i) { sascha@3003: DateRange ap = analysisPeriods[i]; sascha@3003: log.debug("analysis period " + sascha@3003: ap.getFrom() + " - " + ap.getTo()); sascha@2725: } sascha@2725: } sascha@2725: sascha@2725: return analysisPeriods; sascha@2725: } sascha@2725: sascha@2725: public Boolean getPreprocessing() { sascha@2725: if (preprocessing == null) { sascha@2725: StateData sd = artifact.getData("preprocessing"); sascha@2725: if (sd == null) { sascha@2725: log.warn("missing 'preprocessing'"); sascha@2725: return null; sascha@2725: } sascha@2725: preprocessing = Boolean.valueOf((String)sd.getValue()); sascha@2725: } sascha@2725: return preprocessing; sascha@2725: } sascha@2725: sascha@2725: public String getFunction() { sascha@2725: if (function == null) { sascha@2725: StateData sd = artifact.getData("function"); sascha@2725: if (sd == null) { sascha@2725: log.warn("missing 'function'"); sascha@2725: return null; sascha@2725: } sascha@2725: function = (String)sd.getValue(); sascha@2725: } sascha@2726: if (log.isDebugEnabled()) { sascha@2726: log.debug("function: " + function); sascha@2726: } sascha@2725: return function; sascha@2725: } sascha@2725: sascha@2725: public double [] getQs() { sascha@2725: if (qs == null) { sascha@2725: StateData sd = artifact.getData("qs"); sascha@2725: if (sd == null) { sascha@2725: log.warn("missing 'qs'"); sascha@2725: return null; sascha@2725: } sascha@2725: String [] parts = ((String)sd.getValue()).split("[\\s;]"); sascha@2725: TDoubleArrayList list = new TDoubleArrayList(parts.length); sascha@2725: for (String part: parts) { sascha@2725: try { sascha@2725: list.add(Double.parseDouble(part)); sascha@2725: } sascha@2725: catch (NumberFormatException nfe) { sascha@2725: log.warn("'" + part + "' is not numeric."); sascha@2725: } sascha@2725: } sascha@2725: qs = list.toNativeArray(); sascha@2725: } sascha@2725: if (log.isDebugEnabled()) { sascha@2725: log.debug("qs: " + Arrays.toString(qs)); sascha@2725: } sascha@2725: return qs; sascha@2725: } raimund@3028: raimund@3028: raimund@3028: public double getCurrentKm() { raimund@3028: //TODO: get the current km. raimund@3028: return this.from.doubleValue(); raimund@3028: } sascha@2725: } sascha@2725: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :