changeset 1898:8a56a64e4410

Summarize the result of fairway dimension import for review.
author Raimund Renkert <raimund.renkert@intevation.de>
date Fri, 18 Jan 2019 13:58:05 +0100
parents 5f2510523b9c
children 272133cd65da
files pkg/imports/fd.go
diffstat 1 files changed, 26 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/pkg/imports/fd.go	Fri Jan 18 12:17:07 2019 +0100
+++ b/pkg/imports/fd.go	Fri Jan 18 13:58:05 2019 +0100
@@ -104,6 +104,12 @@
 	HydroSorDat fdTime `json:"hydro_sordat"`
 }
 
+type fdSummary struct {
+	Lat float64 `json:"lat"`
+	Lon float64 `json:"lon"`
+	ID  int64   `json:"id"`
+}
+
 const (
 	fdStageDoneSQL = `
 UPDATE waterway.fairway_dimensions SET staging_done = true
@@ -147,7 +153,10 @@
      )).geom AS geom
   ) AS clipped
   WHERE clipped.geom IS NOT NULL
-RETURNING id`
+RETURNING id,
+  ST_X(ST_Centroid(area::geometry)),
+  ST_Y(ST_Centroid(area::geometry))
+ `
 )
 
 // Do executes the actual fairway dimension import.
@@ -206,6 +215,7 @@
 		missingProperties int
 		badProperties     int
 		features          int
+		fds               []fdSummary
 	)
 
 	if err := wfs.DownloadURLs(urls, func(r io.Reader) error {
@@ -247,6 +257,7 @@
 					return err
 				}
 				var fdid int64
+				var lat, lon float64
 				if err := insertStmt.QueryRowContext(
 					ctx,
 					p.asWKB(),
@@ -257,7 +268,7 @@
 					fd.Depth,
 					props.HydroSorDat.Time,
 					fd.SourceOrganization,
-				).Scan(&fdid); err != nil {
+				).Scan(&fdid, &lat, &lon); err != nil {
 					feedback.Error("error: %s", err)
 					return err
 				}
@@ -265,6 +276,7 @@
 				if err = track(ctx, tx, importID, "waterway.fairway_dimensions", fdid); err != nil {
 					return err
 				}
+				fds = append(fds, fdSummary{ID: fdid, Lat: lat, Lon: lon})
 
 				features++
 			default:
@@ -300,5 +312,16 @@
 			features, time.Since(start))
 	}
 
-	return nil, err
+	summary := struct {
+		Date               time.Time   `json:"date"`
+		LOS                int         `json:"los"`
+		SourceOrganization string      `json:"source-organization"`
+		FdArea             []fdSummary `json:"fd-area"`
+	}{
+		Date:               time.Now(),
+		LOS:                fd.LOS,
+		SourceOrganization: fd.SourceOrganization,
+		FdArea:             fds,
+	}
+	return &summary, err
 }