annotate backend/src/main/java/org/dive4elements/river/importer/sinfo/parsers/DailyDischargeParser.java @ 9663:7c1da1b3f6b8

Importer (s/u-info) extensions: further year/date checks for collision files
author mschaefer
date Fri, 03 Apr 2020 11:56:45 +0200
parents d86c7cb68b41
children
rev   line source
8971
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
1 /* Copyright (C) 2017 by Bundesanstalt für Gewässerkunde
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
2 * Software engineering by
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
3 * Björnsen Beratende Ingenieure GmbH
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
4 * Dr. Schumacher Ingenieurbüro für Wasser und Umwelt
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
5 *
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
6 * This file is Free Software under the GNU AGPL (>=v3)
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
7 * and comes with ABSOLUTELY NO WARRANTY! Check out the
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
8 * documentation coming with Dive4Elements River for details.
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
9 */
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
10
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
11 package org.dive4elements.river.importer.sinfo.parsers;
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
12
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
13 import java.io.File;
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
14 import java.text.DateFormat;
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
15 import java.text.SimpleDateFormat;
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
16 import java.util.ArrayList;
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
17 import java.util.Date;
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
18 import java.util.List;
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
19 import java.util.regex.Matcher;
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
20 import java.util.regex.Pattern;
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
21
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
22 import org.apache.log4j.Logger;
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
23 import org.dive4elements.river.importer.Config;
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
24 import org.dive4elements.river.importer.ImportRiver;
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
25 import org.dive4elements.river.importer.common.AbstractParser;
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
26 import org.dive4elements.river.importer.common.ParsingState;
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
27 import org.dive4elements.river.importer.sinfo.importitem.DailyDischargeDayLineImport;
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
28 import org.dive4elements.river.importer.sinfo.importitem.DailyDischargeSeriesImport;
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
29 import org.dive4elements.river.model.sinfo.DailyDischarge;
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
30 import org.dive4elements.river.model.sinfo.DailyDischargeValue;
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
31
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
32 /**
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
33 * Reads and parses a daily discharge file
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
34 *
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
35 * @author Matthias Schäfer
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
36 *
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
37 */
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
38 public class DailyDischargeParser extends AbstractParser<DailyDischarge, DailyDischargeValue, DailyDischargeDayLineImport, DailyDischargeSeriesImport> {
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
39
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
40 /***** FIELDS *****/
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
41
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
42 private static final Logger log = Logger.getLogger(DailyDischargeParser.class);
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
43
9658
d86c7cb68b41 Importer (s/u-info) extensions: daily discharge: detecting, logging and skipping lines with missing date or q, or duplicate date,
mschaefer
parents: 9012
diff changeset
44 static final Pattern IMPORT_FILENAME = Pattern.compile("^(.+)_mittlerer_Tagesabfluss\\.csv", Pattern.CASE_INSENSITIVE);
8971
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
45
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
46 private static final Pattern META_GAUGENAME = Pattern.compile("^#\\s*Stations-*Name:\\s*(\\S[^;]*).*", Pattern.CASE_INSENSITIVE);
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
47
9658
d86c7cb68b41 Importer (s/u-info) extensions: daily discharge: detecting, logging and skipping lines with missing date or q, or duplicate date,
mschaefer
parents: 9012
diff changeset
48 // private static final Pattern META_GAUGENUMBER = Pattern.compile("^#\\s*Stations-*Nummer:\\s*(\\S[^;]*).*",
d86c7cb68b41 Importer (s/u-info) extensions: daily discharge: detecting, logging and skipping lines with missing date or q, or duplicate date,
mschaefer
parents: 9012
diff changeset
49 // Pattern.CASE_INSENSITIVE);
8971
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
50
9658
d86c7cb68b41 Importer (s/u-info) extensions: daily discharge: detecting, logging and skipping lines with missing date or q, or duplicate date,
mschaefer
parents: 9012
diff changeset
51 private static final Pattern META_BETREIBER = Pattern.compile("^#\\s*Betreiber:.*", Pattern.CASE_INSENSITIVE);
d86c7cb68b41 Importer (s/u-info) extensions: daily discharge: detecting, logging and skipping lines with missing date or q, or duplicate date,
mschaefer
parents: 9012
diff changeset
52 private static final Pattern META_PARAMETER = Pattern.compile("^#\\s*Parameter-Name:.*", Pattern.CASE_INSENSITIVE);
d86c7cb68b41 Importer (s/u-info) extensions: daily discharge: detecting, logging and skipping lines with missing date or q, or duplicate date,
mschaefer
parents: 9012
diff changeset
53 private static final Pattern META_ZEITREIHE = Pattern.compile("^#\\s*# Zeitreihe.*", Pattern.CASE_INSENSITIVE);
d86c7cb68b41 Importer (s/u-info) extensions: daily discharge: detecting, logging and skipping lines with missing date or q, or duplicate date,
mschaefer
parents: 9012
diff changeset
54 private static final Pattern META_REIHEBEGINN = Pattern.compile("^#\\s*Beginn der Zeitreihe:.*", Pattern.CASE_INSENSITIVE);
d86c7cb68b41 Importer (s/u-info) extensions: daily discharge: detecting, logging and skipping lines with missing date or q, or duplicate date,
mschaefer
parents: 9012
diff changeset
55 private static final Pattern META_REIHEENDE = Pattern.compile("^#\\s*Ende der Zeitreihe:.*", Pattern.CASE_INSENSITIVE);
d86c7cb68b41 Importer (s/u-info) extensions: daily discharge: detecting, logging and skipping lines with missing date or q, or duplicate date,
mschaefer
parents: 9012
diff changeset
56
d86c7cb68b41 Importer (s/u-info) extensions: daily discharge: detecting, logging and skipping lines with missing date or q, or duplicate date,
mschaefer
parents: 9012
diff changeset
57 private static final Pattern META_COLUMNTITLES = Pattern.compile("^#*\\s*(Datum)\\s*;\\s*(Q[^;]*)", Pattern.CASE_INSENSITIVE);
8971
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
58
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
59 private static final DateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy");
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
60
9658
d86c7cb68b41 Importer (s/u-info) extensions: daily discharge: detecting, logging and skipping lines with missing date or q, or duplicate date,
mschaefer
parents: 9012
diff changeset
61 private final List<Date> dates;
d86c7cb68b41 Importer (s/u-info) extensions: daily discharge: detecting, logging and skipping lines with missing date or q, or duplicate date,
mschaefer
parents: 9012
diff changeset
62
8971
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
63
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
64 /***** CONSTRUCTORS *****/
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
65
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
66 public DailyDischargeParser(final File importPath, final File rootRelativePath, final ImportRiver river) {
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
67 super(importPath, rootRelativePath, river);
9658
d86c7cb68b41 Importer (s/u-info) extensions: daily discharge: detecting, logging and skipping lines with missing date or q, or duplicate date,
mschaefer
parents: 9012
diff changeset
68 this.dates = new ArrayList<>();
8971
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
69 }
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
70
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
71
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
72 /***** METHODS *****/
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
73
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
74 @Override
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
75 protected Logger getLog() {
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
76 return log;
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
77 }
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
78
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
79 /**
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
80 * Whether this import type shall be skipped
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
81 */
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
82 public static boolean shallSkip() {
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
83 return Config.INSTANCE.skipSInfoDailyDischarge();
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
84 }
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
85
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
86 /**
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
87 * Creates a list of parsers for all daily discharge import files in a directory
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
88 */
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
89 public static List<DailyDischargeParser> createParsers(final File importDir, final File relativeDir, final ImportRiver river) {
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
90 final List<DailyDischargeParser> parsers = new ArrayList<>();
8988
ae76f618d990 Checks added for missing import directory
mschaefer
parents: 8971
diff changeset
91 if (importDir.exists()) {
9658
d86c7cb68b41 Importer (s/u-info) extensions: daily discharge: detecting, logging and skipping lines with missing date or q, or duplicate date,
mschaefer
parents: 9012
diff changeset
92 for (final File file : listFiles(importDir, IMPORT_FILENAME))
8988
ae76f618d990 Checks added for missing import directory
mschaefer
parents: 8971
diff changeset
93 parsers.add(new DailyDischargeParser(file, new File(relativeDir, file.getName()), river));
ae76f618d990 Checks added for missing import directory
mschaefer
parents: 8971
diff changeset
94 }
8971
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
95 return parsers;
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
96 }
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
97
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
98 @Override
9012
abe069eb180c Import of vegetation zones added
mschaefer
parents: 8988
diff changeset
99 protected KmMode kmMode() {
abe069eb180c Import of vegetation zones added
mschaefer
parents: 8988
diff changeset
100 return KmMode.NONE;
8971
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
101 }
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
102
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
103 @Override
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
104 protected DailyDischargeSeriesImport createSeriesImport(final String filename) {
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
105 return new DailyDischargeSeriesImport(filename);
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
106 }
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
107
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
108 @Override
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
109 protected DailyDischargeDayLineImport createKmLineImport(final Double km, final String[] values) {
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
110 Date day = null;
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
111 try {
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
112 day = dateFormat.parse(values[0]);
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
113 }
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
114 catch (final Exception e) {
9658
d86c7cb68b41 Importer (s/u-info) extensions: daily discharge: detecting, logging and skipping lines with missing date or q, or duplicate date,
mschaefer
parents: 9012
diff changeset
115 logLineWarning("Invalid date");
8971
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
116 return null;
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
117 }
9658
d86c7cb68b41 Importer (s/u-info) extensions: daily discharge: detecting, logging and skipping lines with missing date or q, or duplicate date,
mschaefer
parents: 9012
diff changeset
118 final Number q = parseDoubleCheckNull(values, 1);
d86c7cb68b41 Importer (s/u-info) extensions: daily discharge: detecting, logging and skipping lines with missing date or q, or duplicate date,
mschaefer
parents: 9012
diff changeset
119 if ((q == null) || Double.isNaN(q.doubleValue())) {
d86c7cb68b41 Importer (s/u-info) extensions: daily discharge: detecting, logging and skipping lines with missing date or q, or duplicate date,
mschaefer
parents: 9012
diff changeset
120 logLineWarning(INVALID_VALUE_ERROR_FORMAT, "discharge");
8971
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
121 return null;
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
122 }
9658
d86c7cb68b41 Importer (s/u-info) extensions: daily discharge: detecting, logging and skipping lines with missing date or q, or duplicate date,
mschaefer
parents: 9012
diff changeset
123 if (this.dates.contains(day)) {
d86c7cb68b41 Importer (s/u-info) extensions: daily discharge: detecting, logging and skipping lines with missing date or q, or duplicate date,
mschaefer
parents: 9012
diff changeset
124 logLineWarning("Duplicate date");
d86c7cb68b41 Importer (s/u-info) extensions: daily discharge: detecting, logging and skipping lines with missing date or q, or duplicate date,
mschaefer
parents: 9012
diff changeset
125 return null;
d86c7cb68b41 Importer (s/u-info) extensions: daily discharge: detecting, logging and skipping lines with missing date or q, or duplicate date,
mschaefer
parents: 9012
diff changeset
126 }
d86c7cb68b41 Importer (s/u-info) extensions: daily discharge: detecting, logging and skipping lines with missing date or q, or duplicate date,
mschaefer
parents: 9012
diff changeset
127 this.dates.add(day);
d86c7cb68b41 Importer (s/u-info) extensions: daily discharge: detecting, logging and skipping lines with missing date or q, or duplicate date,
mschaefer
parents: 9012
diff changeset
128 return new DailyDischargeDayLineImport(day, q.doubleValue());
8971
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
129 }
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
130
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
131 @Override
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
132 protected boolean handleMetaOther() {
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
133 if (handleMetaGaugeName())
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
134 return true;
9658
d86c7cb68b41 Importer (s/u-info) extensions: daily discharge: detecting, logging and skipping lines with missing date or q, or duplicate date,
mschaefer
parents: 9012
diff changeset
135 // else if (handleMetaGaugeNumber())
d86c7cb68b41 Importer (s/u-info) extensions: daily discharge: detecting, logging and skipping lines with missing date or q, or duplicate date,
mschaefer
parents: 9012
diff changeset
136 // return true;
d86c7cb68b41 Importer (s/u-info) extensions: daily discharge: detecting, logging and skipping lines with missing date or q, or duplicate date,
mschaefer
parents: 9012
diff changeset
137 else if (META_BETREIBER.matcher(this.currentLine).matches())
d86c7cb68b41 Importer (s/u-info) extensions: daily discharge: detecting, logging and skipping lines with missing date or q, or duplicate date,
mschaefer
parents: 9012
diff changeset
138 return true;
d86c7cb68b41 Importer (s/u-info) extensions: daily discharge: detecting, logging and skipping lines with missing date or q, or duplicate date,
mschaefer
parents: 9012
diff changeset
139 else if (META_PARAMETER.matcher(this.currentLine).matches())
d86c7cb68b41 Importer (s/u-info) extensions: daily discharge: detecting, logging and skipping lines with missing date or q, or duplicate date,
mschaefer
parents: 9012
diff changeset
140 return true;
d86c7cb68b41 Importer (s/u-info) extensions: daily discharge: detecting, logging and skipping lines with missing date or q, or duplicate date,
mschaefer
parents: 9012
diff changeset
141 else if (META_ZEITREIHE.matcher(this.currentLine).matches())
d86c7cb68b41 Importer (s/u-info) extensions: daily discharge: detecting, logging and skipping lines with missing date or q, or duplicate date,
mschaefer
parents: 9012
diff changeset
142 return true;
d86c7cb68b41 Importer (s/u-info) extensions: daily discharge: detecting, logging and skipping lines with missing date or q, or duplicate date,
mschaefer
parents: 9012
diff changeset
143 else if (META_REIHEBEGINN.matcher(this.currentLine).matches())
d86c7cb68b41 Importer (s/u-info) extensions: daily discharge: detecting, logging and skipping lines with missing date or q, or duplicate date,
mschaefer
parents: 9012
diff changeset
144 return true;
d86c7cb68b41 Importer (s/u-info) extensions: daily discharge: detecting, logging and skipping lines with missing date or q, or duplicate date,
mschaefer
parents: 9012
diff changeset
145 else if (META_REIHEENDE.matcher(this.currentLine).matches())
8971
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
146 return true;
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
147 else
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
148 return false;
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
149 }
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
150
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
151 private boolean handleMetaGaugeName() {
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
152 final Matcher m = META_GAUGENAME.matcher(this.currentLine);
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
153 if (m.matches()) {
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
154 this.metaPatternsMatched.add(META_GAUGENAME);
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
155 this.seriesHeader.setGaugeName(m.group(1).trim());
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
156 return true;
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
157 }
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
158 return false;
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
159 }
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
160
9658
d86c7cb68b41 Importer (s/u-info) extensions: daily discharge: detecting, logging and skipping lines with missing date or q, or duplicate date,
mschaefer
parents: 9012
diff changeset
161 // private boolean handleMetaGaugeNumber() {
d86c7cb68b41 Importer (s/u-info) extensions: daily discharge: detecting, logging and skipping lines with missing date or q, or duplicate date,
mschaefer
parents: 9012
diff changeset
162 // final Matcher m = META_GAUGENUMBER.matcher(this.currentLine);
d86c7cb68b41 Importer (s/u-info) extensions: daily discharge: detecting, logging and skipping lines with missing date or q, or duplicate date,
mschaefer
parents: 9012
diff changeset
163 // if (m.matches()) {
d86c7cb68b41 Importer (s/u-info) extensions: daily discharge: detecting, logging and skipping lines with missing date or q, or duplicate date,
mschaefer
parents: 9012
diff changeset
164 // this.metaPatternsMatched.add(META_GAUGENUMBER);
d86c7cb68b41 Importer (s/u-info) extensions: daily discharge: detecting, logging and skipping lines with missing date or q, or duplicate date,
mschaefer
parents: 9012
diff changeset
165 // this.seriesHeader.setGaugeNumber(Long.parseLong(m.group(1)));
d86c7cb68b41 Importer (s/u-info) extensions: daily discharge: detecting, logging and skipping lines with missing date or q, or duplicate date,
mschaefer
parents: 9012
diff changeset
166 // return true;
d86c7cb68b41 Importer (s/u-info) extensions: daily discharge: detecting, logging and skipping lines with missing date or q, or duplicate date,
mschaefer
parents: 9012
diff changeset
167 // }
d86c7cb68b41 Importer (s/u-info) extensions: daily discharge: detecting, logging and skipping lines with missing date or q, or duplicate date,
mschaefer
parents: 9012
diff changeset
168 // return false;
d86c7cb68b41 Importer (s/u-info) extensions: daily discharge: detecting, logging and skipping lines with missing date or q, or duplicate date,
mschaefer
parents: 9012
diff changeset
169 // }
8971
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
170
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
171 @Override
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
172 protected boolean handleMetaColumnTitles() {
9658
d86c7cb68b41 Importer (s/u-info) extensions: daily discharge: detecting, logging and skipping lines with missing date or q, or duplicate date,
mschaefer
parents: 9012
diff changeset
173 final Matcher m = META_COLUMNTITLES.matcher(this.currentLine);
d86c7cb68b41 Importer (s/u-info) extensions: daily discharge: detecting, logging and skipping lines with missing date or q, or duplicate date,
mschaefer
parents: 9012
diff changeset
174 if (!m.matches()) {
8971
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
175 return false;
9658
d86c7cb68b41 Importer (s/u-info) extensions: daily discharge: detecting, logging and skipping lines with missing date or q, or duplicate date,
mschaefer
parents: 9012
diff changeset
176 }
8971
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
177 this.metaPatternsMatched.add(META_COLUMNTITLES);
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
178 this.columnTitles.clear();
9658
d86c7cb68b41 Importer (s/u-info) extensions: daily discharge: detecting, logging and skipping lines with missing date or q, or duplicate date,
mschaefer
parents: 9012
diff changeset
179 this.columnTitles.add(m.group(1));
d86c7cb68b41 Importer (s/u-info) extensions: daily discharge: detecting, logging and skipping lines with missing date or q, or duplicate date,
mschaefer
parents: 9012
diff changeset
180 this.columnTitles.add(m.group(2));
d86c7cb68b41 Importer (s/u-info) extensions: daily discharge: detecting, logging and skipping lines with missing date or q, or duplicate date,
mschaefer
parents: 9012
diff changeset
181 return true;
d86c7cb68b41 Importer (s/u-info) extensions: daily discharge: detecting, logging and skipping lines with missing date or q, or duplicate date,
mschaefer
parents: 9012
diff changeset
182 }
d86c7cb68b41 Importer (s/u-info) extensions: daily discharge: detecting, logging and skipping lines with missing date or q, or duplicate date,
mschaefer
parents: 9012
diff changeset
183
d86c7cb68b41 Importer (s/u-info) extensions: daily discharge: detecting, logging and skipping lines with missing date or q, or duplicate date,
mschaefer
parents: 9012
diff changeset
184 /**
d86c7cb68b41 Importer (s/u-info) extensions: daily discharge: detecting, logging and skipping lines with missing date or q, or duplicate date,
mschaefer
parents: 9012
diff changeset
185 * Check meta data after all meta lines (#) have been read
d86c7cb68b41 Importer (s/u-info) extensions: daily discharge: detecting, logging and skipping lines with missing date or q, or duplicate date,
mschaefer
parents: 9012
diff changeset
186 */
d86c7cb68b41 Importer (s/u-info) extensions: daily discharge: detecting, logging and skipping lines with missing date or q, or duplicate date,
mschaefer
parents: 9012
diff changeset
187 @Override
d86c7cb68b41 Importer (s/u-info) extensions: daily discharge: detecting, logging and skipping lines with missing date or q, or duplicate date,
mschaefer
parents: 9012
diff changeset
188 protected boolean checkMetaData() {
d86c7cb68b41 Importer (s/u-info) extensions: daily discharge: detecting, logging and skipping lines with missing date or q, or duplicate date,
mschaefer
parents: 9012
diff changeset
189 if (!super.checkRiverExists())
d86c7cb68b41 Importer (s/u-info) extensions: daily discharge: detecting, logging and skipping lines with missing date or q, or duplicate date,
mschaefer
parents: 9012
diff changeset
190 return false;
8971
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
191 this.seriesHeader.setGauge(this.river.getPeer().findGauge(this.seriesHeader.getGaugeNumber(), this.seriesHeader.getGaugeName()));
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
192 if (this.seriesHeader.getGauge() == null) {
9658
d86c7cb68b41 Importer (s/u-info) extensions: daily discharge: detecting, logging and skipping lines with missing date or q, or duplicate date,
mschaefer
parents: 9012
diff changeset
193 logError("Gauge not found (%s)", this.seriesHeader.getGaugeName());
8971
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
194 this.headerParsingState = ParsingState.STOP;
9658
d86c7cb68b41 Importer (s/u-info) extensions: daily discharge: detecting, logging and skipping lines with missing date or q, or duplicate date,
mschaefer
parents: 9012
diff changeset
195 return false;
d86c7cb68b41 Importer (s/u-info) extensions: daily discharge: detecting, logging and skipping lines with missing date or q, or duplicate date,
mschaefer
parents: 9012
diff changeset
196 }
d86c7cb68b41 Importer (s/u-info) extensions: daily discharge: detecting, logging and skipping lines with missing date or q, or duplicate date,
mschaefer
parents: 9012
diff changeset
197 if (super.checkMetaData() == false)
d86c7cb68b41 Importer (s/u-info) extensions: daily discharge: detecting, logging and skipping lines with missing date or q, or duplicate date,
mschaefer
parents: 9012
diff changeset
198 return false;
d86c7cb68b41 Importer (s/u-info) extensions: daily discharge: detecting, logging and skipping lines with missing date or q, or duplicate date,
mschaefer
parents: 9012
diff changeset
199 if (this.columnTitles.size() <= 1) {
d86c7cb68b41 Importer (s/u-info) extensions: daily discharge: detecting, logging and skipping lines with missing date or q, or duplicate date,
mschaefer
parents: 9012
diff changeset
200 logError("No valid column title line (Datum, Q) found");
d86c7cb68b41 Importer (s/u-info) extensions: daily discharge: detecting, logging and skipping lines with missing date or q, or duplicate date,
mschaefer
parents: 9012
diff changeset
201 this.headerParsingState = ParsingState.STOP;
d86c7cb68b41 Importer (s/u-info) extensions: daily discharge: detecting, logging and skipping lines with missing date or q, or duplicate date,
mschaefer
parents: 9012
diff changeset
202 return false;
8971
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
203 }
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
204 return true;
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
205 }
9658
d86c7cb68b41 Importer (s/u-info) extensions: daily discharge: detecting, logging and skipping lines with missing date or q, or duplicate date,
mschaefer
parents: 9012
diff changeset
206
8971
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
207 }

http://dive4elements.wald.intevation.org