Mercurial > gemma
changeset 4049:4a7c2140e44b
AGM import: Generate entries for deleted items.
To detect them: Array with two lines. The second is null.
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Wed, 24 Jul 2019 17:09:30 +0200 |
parents | edb1d11e14cd |
children | d7e85b85918f 1ecfe5d015b0 |
files | pkg/imports/agm.go pkg/models/isrs.go |
diffstat | 2 files changed, 66 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/pkg/imports/agm.go Wed Jul 24 16:11:51 2019 +0200 +++ b/pkg/imports/agm.go Wed Jul 24 17:09:30 2019 +0200 @@ -26,6 +26,7 @@ "math" "os" "path/filepath" + "sort" "strconv" "strings" "time" @@ -497,9 +498,10 @@ var removed int // Issue deletes - for _, old := range oldGMLines { + for _, key := range sortByLocationCode(oldGMLines) { + old := oldGMLines[key] removed += len(old) - for _, line := range old { + for _, line := range sortByMeasureDate(old) { if _, err := txTrackStmt.ExecContext( ctx, importID, "waterway.gauge_measurements", line.id, @@ -507,6 +509,11 @@ ); err != nil { return nil, err } + entries = append(entries, &agmSummaryEntry{ + FKGaugeID: line.Location, + MeasureDate: line.MeasureDate, + Versions: []*agmLine{line, nil}, + }) } } @@ -528,6 +535,32 @@ return entries, nil } +func sortByLocationCode(data map[models.Isrs]map[int64]*agmLine) []models.Isrs { + keys := make([]models.Isrs, len(data)) + var i int + for key := range data { + keys[i] = key + i++ + } + sort.Slice(keys, func(i, j int) bool { + return keys[i].Less(&keys[j]) + }) + return keys +} + +func sortByMeasureDate(data map[int64]*agmLine) []*agmLine { + lines := make([]*agmLine, len(data)) + var i int + for _, line := range data { + lines[i] = line + i++ + } + sort.Slice(lines, func(i, j int) bool { + return lines[i].MeasureDate.Before(lines[j].MeasureDate.Time) + }) + return lines +} + func getOldGMLines( ctx context.Context, stmt *sql.Stmt,
--- a/pkg/models/isrs.go Wed Jul 24 16:11:51 2019 +0200 +++ b/pkg/models/isrs.go Wed Jul 24 17:09:30 2019 +0200 @@ -43,6 +43,37 @@ return nil } +func (isrs *Isrs) Less(other *Isrs) bool { + if isrs.Hectometre < other.Hectometre { + return true + } + if isrs.Hectometre > other.Hectometre { + return false + } + if isrs.CountryCode < other.CountryCode { + return true + } + if isrs.CountryCode > other.CountryCode { + return false + } + if isrs.LoCode < other.LoCode { + return true + } + if isrs.LoCode > other.LoCode { + return false + } + if isrs.FairwaySection < other.FairwaySection { + return true + } + if isrs.FairwaySection > other.FairwaySection { + return false + } + if isrs.Orc < other.Orc { + return true + } + return false +} + func (isrs *Isrs) MarshalJSON() ([]byte, error) { if isrs == nil { return nil, nil