comparison pkg/imports/sr.go @ 5560:f2204f91d286

Join the log lines of imports to the log exports to recover data from them. Used in SR export to extract information that where in the meta json but now are only found in the log.
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Wed, 09 Feb 2022 18:34:40 +0100
parents 728b58946c34
children b91716d2acc6
comparison
equal deleted inserted replaced
5559:ce9a9a1bf92f 5560:f2204f91d286
26 "io" 26 "io"
27 "math" 27 "math"
28 "os" 28 "os"
29 "path" 29 "path"
30 "path/filepath" 30 "path/filepath"
31 "regexp"
31 "strconv" 32 "strconv"
32 "strings" 33 "strings"
34 "sync"
33 "time" 35 "time"
34 36
35 shp "github.com/jonas-p/go-shp" 37 shp "github.com/jonas-p/go-shp"
36 38
37 "gemma.intevation.de/gemma/pkg/common" 39 "gemma.intevation.de/gemma/pkg/common"
40 "gemma.intevation.de/gemma/pkg/log"
38 "gemma.intevation.de/gemma/pkg/mesh" 41 "gemma.intevation.de/gemma/pkg/mesh"
39 "gemma.intevation.de/gemma/pkg/models" 42 "gemma.intevation.de/gemma/pkg/models"
40 "gemma.intevation.de/gemma/pkg/wkb" 43 "gemma.intevation.de/gemma/pkg/wkb"
41 ) 44 )
42 45
237 best_utm(CAST(ST_Transform(ST_GeomFromWKB($1, $2::integer), 4326) AS geography)))), 240 best_utm(CAST(ST_Transform(ST_GeomFromWKB($1, $2::integer), 4326) AS geography)))),
238 best_utm(CAST(ST_Transform(ST_GeomFromWKB($1, $2::integer), 4326) AS geography)) 241 best_utm(CAST(ST_Transform(ST_GeomFromWKB($1, $2::integer), 4326) AS geography))
239 ` 242 `
240 ) 243 )
241 244
245 var (
246 bottleneckRe,
247 surveyTypeRe,
248 dateRe,
249 negateZRe *regexp.Regexp
250 recoverRegsOnce sync.Once
251 )
252
253 func compileRecoverRegs() {
254 bottleneckRe = regexp.MustCompile(`Bottleneck:\s*(.+)\s*$`)
255 surveyTypeRe = regexp.MustCompile(`Processing as\s+([^\s]+)\s+beam scan.`)
256 dateRe = regexp.MustCompile(`Survey date:\s*(\d{4}-\d{2}-\d{2}).`)
257 negateZRe = regexp.MustCompile(`Z values will be negated.`)
258 }
259
242 // Description gives a short info about relevant facts of this import. 260 // Description gives a short info about relevant facts of this import.
243 func (sr *SoundingResult) Description() (string, error) { 261 func (sr *SoundingResult) Description(msgs []string) (string, error) {
262
263 recoverRegsOnce.Do(compileRecoverRegs)
264
265 //log.Debugln(strings.Join(msgs, "\n") + "\n\n")
266
267 var (
268 bottleneck, st, date string
269 negZ *bool
270 )
271
272 for _, msg := range msgs {
273 if m := bottleneckRe.FindStringSubmatch(msg); m != nil {
274 bottleneck = m[1]
275 continue
276 }
277 if m := surveyTypeRe.FindStringSubmatch(msg); m != nil {
278 st = m[1]
279 continue
280 }
281 if m := dateRe.FindStringSubmatch(msg); m != nil {
282 date = m[1]
283 continue
284 }
285 if negateZRe.MatchString(msg) {
286 t := true
287 negZ = &t
288 }
289 }
244 290
245 var descs []string 291 var descs []string
246 292
247 if sr.Bottleneck != nil { 293 if sr.Bottleneck != nil {
248 descs = append(descs, *sr.Bottleneck) 294 descs = append(descs, *sr.Bottleneck)
249 } 295 } else if bottleneck != "" {
296 log.Debugf("bottleneck recovered: %s\n", bottleneck)
297 descs = append(descs, bottleneck)
298 }
299
250 if sr.Date != nil { 300 if sr.Date != nil {
251 descs = append(descs, (*sr).Date.Format(common.DateFormat)) 301 descs = append(descs, (*sr).Date.Format(common.DateFormat))
252 } 302 } else if date != "" {
303 log.Debugf("date recovered: %s\n", date)
304 descs = append(descs, date)
305 }
306
253 if sr.NegateZ != nil && *sr.NegateZ { 307 if sr.NegateZ != nil && *sr.NegateZ {
308 } else if negZ != nil && *negZ {
309 log.Debugln("negateZ recovered")
254 descs = append(descs, "negateZ") 310 descs = append(descs, "negateZ")
255 } 311 }
312
256 if sr.SurveyType != nil { 313 if sr.SurveyType != nil {
257 descs = append(descs, string(*sr.SurveyType)) 314 descs = append(descs, string(*sr.SurveyType))
258 } 315 } else if st != "" {
316 log.Debugf("survey type recovered: %s\n", st)
317 descs = append(descs, st)
318 }
319
259 return strings.Join(descs, "|"), nil 320 return strings.Join(descs, "|"), nil
260 } 321 }
261 322
262 func (sr *SoundingResult) negateZ() bool { 323 func (sr *SoundingResult) negateZ() bool {
263 return sr.NegateZ != nil && *sr.NegateZ 324 return sr.NegateZ != nil && *sr.NegateZ