Initial render of standing water reports from the public
This commit is contained in:
parent
cd47aaba94
commit
ce6c6c1cc1
6 changed files with 246 additions and 176 deletions
|
|
@ -28,7 +28,7 @@ LEFT JOIN publicreport.image_exif e ON i.id = e.image_id
|
|||
WHERE i.id IN (1, 2, 3, 4)
|
||||
GROUP BY i.id;
|
||||
*/
|
||||
// Get all the images that belong to the list of report IDs
|
||||
// Get all the images that belong to the list of nuisance report IDs
|
||||
func loadImagesForReportNuisance(ctx context.Context, org_id int32, report_ids []int32) (results map[int32][]types.Image, err error) {
|
||||
rows, err := bob.All(ctx, db.PGInstance.BobDB, psql.Select(
|
||||
sm.Columns(
|
||||
|
|
@ -39,7 +39,7 @@ func loadImagesForReportNuisance(ctx context.Context, org_id int32, report_ids [
|
|||
"COALESCE(MAX(e.value) FILTER (WHERE e.name = 'Make'), '') AS exif_make",
|
||||
"COALESCE(MAX(e.value) FILTER (WHERE e.name = 'Model'), '') AS exif_model",
|
||||
"COALESCE(MAX(e.value) FILTER (WHERE e.name = 'DateTime'), '') AS exif_datetime",
|
||||
"ni.nuisance_id AS nuisance_id",
|
||||
"ni.nuisance_id AS report_id",
|
||||
),
|
||||
sm.From("publicreport.image").As("i"),
|
||||
sm.LeftJoin("publicreport.image_exif").As("e").OnEQ(
|
||||
|
|
@ -66,12 +66,60 @@ func loadImagesForReportNuisance(ctx context.Context, org_id int32, report_ids [
|
|||
}
|
||||
results = make(map[int32][]types.Image, len(report_ids))
|
||||
for _, row := range rows {
|
||||
r, ok := results[row.NuisanceID]
|
||||
r, ok := results[row.ReportID]
|
||||
if !ok {
|
||||
r = make([]types.Image, 0)
|
||||
}
|
||||
r = append(r, row)
|
||||
results[row.NuisanceID] = r
|
||||
results[row.ReportID] = r
|
||||
}
|
||||
return results, nil
|
||||
}
|
||||
|
||||
// Get all the images that belong to the list of water report IDs
|
||||
func loadImagesForReportWater(ctx context.Context, org_id int32, report_ids []int32) (results map[int32][]types.Image, err error) {
|
||||
rows, err := bob.All(ctx, db.PGInstance.BobDB, psql.Select(
|
||||
sm.Columns(
|
||||
"i.storage_uuid AS uuid",
|
||||
"COALESCE(ST_X(i.location), 0) AS \"location.longitude\"",
|
||||
"COALESCE(ST_Y(i.location), 0) AS \"location.latitude\"",
|
||||
"ST_Distance(i.location::geography, w.location::geography) AS \"distance_from_reporter_meters\"",
|
||||
"COALESCE(MAX(e.value) FILTER (WHERE e.name = 'Make'), '') AS exif_make",
|
||||
"COALESCE(MAX(e.value) FILTER (WHERE e.name = 'Model'), '') AS exif_model",
|
||||
"COALESCE(MAX(e.value) FILTER (WHERE e.name = 'DateTime'), '') AS exif_datetime",
|
||||
"wi.water_id AS report_id",
|
||||
),
|
||||
sm.From("publicreport.image").As("i"),
|
||||
sm.LeftJoin("publicreport.image_exif").As("e").OnEQ(
|
||||
psql.Quote("i", "id"),
|
||||
psql.Quote("e", "image_id"),
|
||||
),
|
||||
sm.InnerJoin("publicreport.water_image").As("wi").OnEQ(
|
||||
psql.Quote("wi", "image_id"),
|
||||
psql.Quote("i", "id"),
|
||||
),
|
||||
sm.InnerJoin("publicreport.water").As("w").OnEQ(
|
||||
psql.Quote("wi", "water_id"),
|
||||
psql.Quote("w", "id"),
|
||||
),
|
||||
sm.Where(psql.Quote("wi", "water_id").EQ(psql.Any(report_ids))),
|
||||
sm.GroupBy(
|
||||
//psql.Quote("i", "id"),
|
||||
//psql.Quote("ni", "nuisance_id"),
|
||||
psql.Raw("i.id, wi.water_id, w.location"),
|
||||
),
|
||||
), scan.StructMapper[types.Image]())
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("get images: %w", err)
|
||||
}
|
||||
results = make(map[int32][]types.Image, len(report_ids))
|
||||
for _, row := range rows {
|
||||
r, ok := results[row.ReportID]
|
||||
if !ok {
|
||||
r = make([]types.Image, 0)
|
||||
}
|
||||
r = append(r, row)
|
||||
results[row.ReportID] = r
|
||||
}
|
||||
return results, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import (
|
|||
|
||||
"github.com/Gleipnir-Technology/nidus-sync/config"
|
||||
"github.com/google/uuid"
|
||||
//"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
type Exif struct {
|
||||
|
|
@ -35,13 +36,13 @@ func (e Exif) MarshalJSON() ([]byte, error) {
|
|||
}
|
||||
|
||||
type Image struct {
|
||||
DistanceToReporterMeters float64 `db:"distance_from_reporter_meters"`
|
||||
DistanceToReporterMeters *float64 `db:"distance_from_reporter_meters"`
|
||||
Exif Exif `db:"-" json:"exif"`
|
||||
ExifMake string `db:"exif_make" json:"-"`
|
||||
ExifModel string `db:"exif_model" json:"-"`
|
||||
ExifDateTime string `db:"exif_datetime" json:"-"`
|
||||
Location Location `db:"location"`
|
||||
NuisanceID int32 `db:"nuisance_id"`
|
||||
ReportID int32 `db:"report_id" json:"-"`
|
||||
URLContent string `db:"-" json:"url_content"`
|
||||
UUID uuid.UUID `db:"uuid"`
|
||||
}
|
||||
|
|
@ -55,7 +56,7 @@ func (i *Image) MarshalJSON() ([]byte, error) {
|
|||
Model: i.ExifModel,
|
||||
}
|
||||
to_marshal["location"] = i.Location
|
||||
to_marshal["nuisance_id"] = i.NuisanceID
|
||||
//to_marshal["report_id"] = i.ReportID
|
||||
to_marshal["url_content"] = config.MakeURLNidus("/api/image/%s/content", i.UUID.String())
|
||||
to_marshal["uuid"] = i.UUID
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue