sascha@3408: package de.intevation.flys.artifacts.access; sascha@3408: sascha@3408: import de.intevation.artifactdatabase.data.StateData; sascha@3411: sascha@3408: import de.intevation.flys.artifacts.FLYSArtifact; sascha@3411: sascha@3408: import de.intevation.flys.artifacts.model.DateRange; sascha@3408: sascha@3408: import java.util.Arrays; sascha@3408: import java.util.Date; sascha@3408: sascha@3408: import org.apache.log4j.Logger; sascha@3408: sascha@3408: public class FixAnalysisAccess sascha@3418: extends FixAccess sascha@3408: { sascha@3408: private static Logger log = Logger.getLogger(FixAnalysisAccess.class); sascha@3408: sascha@3408: protected DateRange referencePeriod; sascha@3408: protected DateRange [] analysisPeriods; sascha@3408: sascha@3408: protected double [] qs; sascha@3408: sascha@3408: public FixAnalysisAccess() { sascha@3408: } sascha@3408: sascha@3408: public FixAnalysisAccess(FLYSArtifact artifact) { sascha@3408: super(artifact); sascha@3408: } sascha@3408: sascha@3408: public DateRange getReferencePeriod() { sascha@3408: if (referencePeriod == null) { sascha@3408: StateData refStart = artifact.getData("ref_start"); sascha@3408: StateData refEnd = artifact.getData("ref_end"); sascha@3408: sascha@3408: if (refStart == null || refEnd == null) { sascha@3408: log.warn("missing 'ref_start' or 'ref_start' value"); sascha@3408: return null; sascha@3408: } sascha@3408: sascha@3408: try { sascha@3408: long rs = Long.parseLong((String)refStart.getValue()); sascha@3408: long re = Long.parseLong((String)refEnd .getValue()); sascha@3408: sascha@3408: if (rs > re) { long t = rs; rs = re; re = t; } sascha@3408: sascha@3408: Date from = new Date(rs); sascha@3408: Date to = new Date(re); sascha@3408: referencePeriod = new DateRange(from, to); sascha@3408: } sascha@3408: catch (NumberFormatException nfe) { sascha@3408: log.warn("ref_start or ref_end is not an integer."); sascha@3408: } sascha@3408: } sascha@3408: sascha@3408: return referencePeriod; sascha@3408: } sascha@3408: sascha@3408: public DateRange [] getAnalysisPeriods() { sascha@3408: if (analysisPeriods == null) { sascha@3408: analysisPeriods = getDateRange("ana_data"); sascha@3408: } sascha@3408: sascha@3408: return analysisPeriods; sascha@3408: } sascha@3408: sascha@3408: /** sascha@3408: * @return DateRange object ranging from eldest to youngest date sascha@3408: * of analysis and reference periods. sascha@3408: */ sascha@3408: public DateRange getDateRange() { sascha@3408: DateRange refP = getReferencePeriod(); sascha@3408: sascha@3408: Date from = refP.getFrom(); sascha@3408: Date to = refP.getTo(); sascha@3408: sascha@3408: DateRange[] rs = getAnalysisPeriods(); sascha@3418: for (DateRange r: rs) { sascha@3418: if (r.getFrom().before(from)) { sascha@3408: from = r.getFrom(); sascha@3408: } sascha@3418: if (r.getTo().after(to)) { sascha@3408: to = r.getTo(); sascha@3408: } sascha@3408: } sascha@3408: sascha@3408: return new DateRange(from, to); sascha@3408: } sascha@3408: sascha@3408: public double [] getQs() { sascha@3408: if (qs == null) { sascha@3408: qs = getDoubleArray("qs"); sascha@3408: } sascha@3408: sascha@3408: if (log.isDebugEnabled() && qs != null) { sascha@3408: log.debug("qs: " + Arrays.toString(qs)); sascha@3408: } sascha@3408: return qs; sascha@3408: } sascha@3408: } sascha@3408: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :