raimund@3058: package de.intevation.flys.artifacts.states;
raimund@3058:
sascha@3222: import de.intevation.artifactdatabase.state.Facet;
raimund@3058:
ingo@3072: import de.intevation.artifacts.CallContext;
ingo@3116: import de.intevation.artifacts.CallMeta;
ingo@3072:
sascha@3222: import de.intevation.flys.artifacts.FLYSArtifact;
ingo@3072:
sascha@3222: import de.intevation.flys.artifacts.access.SQRelationAccess;
sascha@3222:
sascha@3222: import de.intevation.flys.artifacts.model.CalculationResult;
ingo@3072: import de.intevation.flys.artifacts.model.DataFacet;
ingo@3072: import de.intevation.flys.artifacts.model.FacetTypes;
sascha@3222:
ingo@3072: import de.intevation.flys.artifacts.model.sq.SQCurveFacet;
ingo@3101: import de.intevation.flys.artifacts.model.sq.SQFractionResult;
ingo@3072: import de.intevation.flys.artifacts.model.sq.SQMeasurementFacet;
ingo@3072: import de.intevation.flys.artifacts.model.sq.SQOutlierFacet;
ingo@3072: import de.intevation.flys.artifacts.model.sq.SQRelationCalculation;
ingo@3079: import de.intevation.flys.artifacts.model.sq.SQResult;
raimund@3296: import de.intevation.flys.artifacts.model.sq.SQOverviewFacet;
sascha@3222:
ingo@3116: import de.intevation.flys.artifacts.resources.Resources;
sascha@3222:
sascha@3222: import java.util.List;
sascha@3222:
sascha@3222: import org.apache.log4j.Logger;
sascha@3222:
raimund@3058: /**
raimund@3058: * @author Raimund Renkert
raimund@3058: */
ingo@3072: public class SQRelation extends DefaultState implements FacetTypes {
raimund@3058:
sascha@3222: private static Logger log = Logger.getLogger(SQRelation.class);
raimund@3058:
raimund@3058:
ingo@3116: public static final String I18N_FACET_CURVE =
ingo@3116: "facet.sq_relation.curve";
ingo@3116:
ingo@3116: public static final String I18N_FACET_MEASUREMENTS =
ingo@3116: "facet.sq_relation.measurements";
ingo@3116:
ingo@3116: public static final String I18N_FACET_OUTLIERS =
ingo@3116: "facet.sq_relation.outliers";
ingo@3116:
ingo@3116:
raimund@3058: public SQRelation() {
raimund@3058: }
raimund@3058:
ingo@3072:
raimund@3058: @Override
ingo@3072: public Object computeAdvance(
ingo@3072: FLYSArtifact artifact,
ingo@3072: String hash,
ingo@3072: CallContext context,
ingo@3072: List facets,
ingo@3072: Object old
ingo@3072: ) {
sascha@3222: log.debug("SQRelation.computeAdvance");
ingo@3072:
ingo@3072: CalculationResult res = old instanceof CalculationResult
sascha@3222: ? (CalculationResult)old
sascha@3222: : new SQRelationCalculation(
sascha@3222: new SQRelationAccess(artifact)).calculate();
ingo@3072:
sascha@3222: if (facets == null) {
ingo@3072: return res;
ingo@3072: }
ingo@3072:
sascha@3222: SQResult [] sqr = (SQResult [])res.getData();
sascha@3222: if (sqr == null) {
sascha@3222: return res;
sascha@3222: }
ingo@3101:
sascha@3222: createFacets(context, facets, sqr, hash);
ingo@3072:
ingo@3072: Facet csv = new DataFacet(
ingo@3072: CSV, "CSV data", ComputeType.ADVANCE, hash, id);
ingo@3072:
ingo@3072: Facet pdf = new DataFacet(
ingo@3072: PDF, "PDF data", ComputeType.ADVANCE, hash, id);
ingo@3072:
sascha@3222: facets.add(csv);
sascha@3222: facets.add(pdf);
ingo@3072:
ingo@3072: return res;
raimund@3058: }
raimund@3058:
ingo@3072:
ingo@3079: protected void createFacets(
ingo@3116: CallContext context,
ingo@3079: List container,
ingo@3079: SQResult[] sqr,
ingo@3079: String hash
ingo@3079: ) {
ingo@3116: CallMeta meta = context.getMeta();
ingo@3116: String stateId = getID();
raimund@3296: for (int i = 0; i < 6; i++) {
raimund@3296: container.add(new SQOverviewFacet(
raimund@3296: i,
raimund@3296: i,
raimund@3296: "sq_chart_overview",
raimund@3296: Resources.getMsg(
raimund@3296: context.getMeta(),
raimund@3296: I18N_FACET_CURVE,
raimund@3296: I18N_FACET_CURVE
raimund@3296: ),
raimund@3296: hash,
raimund@3296: getID()
raimund@3296: ));
raimund@3296: }
ingo@3101: for (int res = 0, n = sqr.length; res < n; res++) {
ingo@3099:
ingo@3101: for (int i = 0; i < 6; i++) {
ingo@3101: SQFractionResult result = sqr[res].getFraction(i);
ingo@3072:
ingo@3101: if (result == null) {
sascha@3222: log.warn("Fraction at index " + i + " is empty!");
ingo@3101: continue;
ingo@3101: }
ingo@3101:
ingo@3101: container.add(new SQMeasurementFacet(
ingo@3101: res,
ingo@3101: i,
ingo@3101: getFractionFacetname(1, i),
ingo@3116: Resources.getMsg(
ingo@3116: meta,
ingo@3116: I18N_FACET_MEASUREMENTS,
ingo@3116: I18N_FACET_MEASUREMENTS
ingo@3116: ),
ingo@3101: hash,
ingo@3101: stateId
ingo@3101: ));
ingo@3101:
ingo@3101: container.add(new SQCurveFacet(
ingo@3101: res,
ingo@3101: i,
ingo@3101: getFractionFacetname(0, i),
ingo@3116: Resources.getMsg(
ingo@3116: meta,
ingo@3116: I18N_FACET_CURVE,
ingo@3116: I18N_FACET_CURVE
ingo@3116: ),
ingo@3101: hash,
ingo@3101: stateId
ingo@3101: ));
ingo@3101:
ingo@3101: for (int j = 0, C = result.getOutliersCount(); j < C; j++) {
ingo@3119: int index = res;
ingo@3119: index = index << 16;
ingo@3119: index = index + j;
ingo@3119:
sascha@3222: if (log.isDebugEnabled()) {
sascha@3222: log.debug("new outliers facet (index=" +index+ ")");
sascha@3222: log.debug(" result index = " + res);
sascha@3222: log.debug(" fraction idx = " + i);
sascha@3222: log.debug(" iteration = " + j);
ingo@3119: }
ingo@3119:
ingo@3101: container.add(new SQOutlierFacet(
ingo@3119: index,
ingo@3101: i,
ingo@3101: getFractionFacetname(2, i),
ingo@3116: Resources.getMsg(
ingo@3116: meta,
ingo@3116: I18N_FACET_OUTLIERS,
ingo@3116: I18N_FACET_OUTLIERS,
ingo@3116: new Object[] { j }
ingo@3116: ),
ingo@3101: hash,
ingo@3101: stateId
ingo@3101: ));
ingo@3101: }
ingo@3101: }
ingo@3079: }
ingo@3072: }
ingo@3101:
ingo@3101:
ingo@3101: protected String getFractionFacetname(int type, int fractionIdx) {
sascha@3222: log.debug("getFractionFacetname(): " + type + " | " + fractionIdx);
ingo@3101:
ingo@3101: switch (type) {
ingo@3101: case 0:
ingo@3101: switch (fractionIdx) {
ingo@3101: case 0: return SQ_A_CURVE;
ingo@3101: case 1: return SQ_B_CURVE;
ingo@3101: case 2: return SQ_C_CURVE;
ingo@3101: case 3: return SQ_D_CURVE;
ingo@3101: case 4: return SQ_E_CURVE;
ingo@3101: case 5: return SQ_F_CURVE;
ingo@3101: }
ingo@3101: case 1:
ingo@3101: switch (fractionIdx) {
ingo@3101: case 0: return SQ_A_MEASUREMENT;
ingo@3101: case 1: return SQ_B_MEASUREMENT;
ingo@3101: case 2: return SQ_C_MEASUREMENT;
ingo@3101: case 3: return SQ_D_MEASUREMENT;
ingo@3101: case 4: return SQ_E_MEASUREMENT;
ingo@3101: case 5: return SQ_F_MEASUREMENT;
ingo@3101: }
ingo@3101: case 2:
ingo@3101: switch (fractionIdx) {
ingo@3101: case 0: return SQ_A_OUTLIER;
ingo@3101: case 1: return SQ_B_OUTLIER;
ingo@3101: case 2: return SQ_C_OUTLIER;
ingo@3101: case 3: return SQ_D_OUTLIER;
ingo@3101: case 4: return SQ_E_OUTLIER;
ingo@3101: case 5: return SQ_F_OUTLIER;
ingo@3101: }
ingo@3101: }
ingo@3101:
ingo@3101: return null;
ingo@3101: }
raimund@3058: }
raimund@3058: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :