view flys-backend/src/main/java/de/intevation/flys/importer/parsers/FlowVelocityMeasurementParser.java @ 4198:1cdbd8a0c994

Added two new tables ClickableQDTable and ClickableWTable and made Ws and Qs clickable in historical discharge calculation. The new tables define listener interfaces (clicked lower or upper icon) to listen to user clicks. In addition to this, there is an enum ClickMode with NONE, SINGLE and RANGE options, which allows to specifiy, which icons are displayed in the tables. NONE means no icon for user clicks, SINGLE has 1 icon, RANGE 2 icons for lower and upper.
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Mon, 22 Oct 2012 13:31:25 +0200
parents f63b39799d2d
children b3dd14fc13a6
line wrap: on
line source
package de.intevation.flys.importer.parsers;

import de.intevation.flys.importer.ImportFlowVelocityMeasurement;
import de.intevation.flys.importer.ImportFlowVelocityMeasurementValue;

import java.math.BigDecimal;

import java.text.DateFormat;
import java.text.NumberFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;

import java.util.ArrayList;
import java.util.List;

import org.apache.log4j.Logger;
public class FlowVelocityMeasurementParser extends LineParser {

    private static final Logger log =
        Logger.getLogger(FlowVelocityMeasurementParser.class);

    private static final NumberFormat nf =
        NumberFormat.getInstance(DEFAULT_LOCALE);

    private static final DateFormat df =
        new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");


    private List<ImportFlowVelocityMeasurement> measurements;

    private ImportFlowVelocityMeasurement current;


    public FlowVelocityMeasurementParser() {
        measurements = new ArrayList<ImportFlowVelocityMeasurement>();
    }


    public List<ImportFlowVelocityMeasurement> getMeasurements() {
        return measurements;
    }

    @Override
    protected void reset() {
        current = new ImportFlowVelocityMeasurement();
    }


    @Override
    protected void finish() {
        measurements.add(current);
    }


    @Override
    protected void handleLine(int lineNum, String line) {
        if (line.startsWith(START_META_CHAR)) {
            handleMetaLine(stripMetaLine(line));
        }
        else {
            handleDataLine(line);
        }
    }


    public void handleMetaLine(String line) {
        line = line.replace(";", "");
        current.setDescription(line);
    }


    public void handleDataLine(String line) {
        String[] cols = line.split(SEPERATOR_CHAR);

        if (cols.length < 8) {
            log.warn("skip invalid data line: '" + line + "'");
            return;
        }

        try {
            double km     = nf.parse(cols[1]).doubleValue();
            double w      = nf.parse(cols[5]).doubleValue();
            double q      = nf.parse(cols[6]).doubleValue();
            double v      = nf.parse(cols[7]).doubleValue();

            String timestr     = cols[3] + " " + cols[4];
            String description = cols.length > 8 ? cols[8] : null;

            current.addValue(new ImportFlowVelocityMeasurementValue(
                df.parse(timestr),
                new BigDecimal(km),
                new BigDecimal(w),
                new BigDecimal(q),
                new BigDecimal(v),
                description
            ));
        }
        catch (ParseException pe) {
            log.warn("Error while parsing flow velocity values.", pe);
        }
    }
}
// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org