Mercurial > gemma
view contrib/gmaggregate/matcher.rl @ 5615:f6179b31e0a9 erdms2
Use a type alias on date type to not loose XML serialisation.
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Thu, 10 Nov 2022 19:19:21 +0100 |
parents | 02c2d0edeb2a |
children |
line wrap: on
line source
// This is Free Software under GNU Affero General Public License v >= 3.0 // without warranty, see README.md and license for details. // // SPDX-License-Identifier: AGPL-3.0-or-later // License-Filename: LICENSE // // Copyright (C) 2021 by via donau // - Österreichische Wasserstraßen-Gesellschaft mbH // Software engineering by Intevation GmbH // // Author(s): // * Sascha L. Teichmann <sascha.teichmann@intevation.de> package main import "strconv" %%{ machine expression; write data; }%% func (agg *aggregator) match(data string, l *line) bool { // data := []rune(line) var cs int p, pe := 0, len(data) stack := agg.stack[:0] var pos int var g *gauge var v int current := func() string { return string(data[pos+1:p+1]) } pop := func() string { s := stack[len(stack)-1] stack = stack[:len(stack)-1] return s } %%{ action mark { pos = p } action push { stack = append(stack, current()) } action foundMeasure { agg.current = current() return true } action insertedMeas { g = agg.find(current()) v, _ = strconv.Atoi(pop()) g.measurements += v return true } action insertedPreds { g = agg.find(current()) v , _ = strconv.Atoi(pop()) g.predictions += v return true } action referenceCodeNotSpecified { agg.find(agg.current).assumeZPG = true return true } action ignoredMeassurements { v, _ = strconv.Atoi(pop()) agg.find(agg.current).badValues += v return true } action cannotFindGauge { agg.find(pop()).unknown = true return true } action unitNotSpecified { agg.find(agg.current).assumeCM++ return true } action ignoredMessage { g = agg.find(agg.current) g.ignMeasCodes = extend(g.ignMeasCodes, current()) return true } action missingMandatoryValue { g = agg.find(agg.current) g.missingValues = extend(g.missingValues, pop()) return true } action unknownUnit { g = agg.find(agg.current) g.rescaleErrors = extend(g.rescaleErrors, pop()) return true } action holdBack { agg.hold = l return true } expr := 'Found measurements/predictions for ' @mark any{20} @foundMeasure | 'Inserted ' @mark digit+ @push ' measurements for ' @mark any{20} @insertedMeas | 'Inserted ' @mark digit+ @push ' predictions for ' @mark any{20} @insertedPreds | '\'Reference_code\' not specified. Assuming \'ZPG\'' @referenceCodeNotSpecified | 'Ignored ' @mark digit+ @push ' measurements with value -99999' @ignoredMeassurements | 'Cannot find gauge "' @mark any{20} @push '"' @cannotFindGauge | '\'Unit\' not specified. Assuming \'cm\'' @unitNotSpecified | 'Ignored message with measure_code ' @mark any+ @ignoredMessage | 'Missing mandatory value at ' @mark [^.]+ @push '.' @missingMandatoryValue | 'unknown unit \'' @mark [^']* @push '\'' @unknownUnit | 'Importing gauge measurements took ' @holdBack | 'error in import: ' @holdBack ; }%% %% write init; %% write exec; return false }