Add distance from report to image data
This commit is contained in:
parent
d3f554db92
commit
4cd0e05996
3 changed files with 41 additions and 12 deletions
|
|
@ -57,7 +57,7 @@ func EnsureAddress(ctx context.Context, txn bob.Tx, a types.Address, l types.Loc
|
|||
row, err := bob.One(ctx, txn, psql.Insert(
|
||||
im.Into("address", "country", "created", "h3cell", "id", "locality", "location", "number_", "postal_code", "region", "street", "unit"),
|
||||
im.Values(
|
||||
psql.Arg(a.Country),
|
||||
psql.Arg(a.CountryEnum()),
|
||||
psql.Arg(created),
|
||||
psql.Arg(cell),
|
||||
psql.Raw("DEFAULT"),
|
||||
|
|
|
|||
|
|
@ -33,8 +33,9 @@ func loadImagesForReportNuisance(ctx context.Context, org_id int32, report_ids [
|
|||
rows, err := bob.All(ctx, db.PGInstance.BobDB, psql.Select(
|
||||
sm.Columns(
|
||||
"i.storage_uuid AS uuid",
|
||||
"COALESCE(ST_X(location), 0) AS \"location.longitude\"",
|
||||
"COALESCE(ST_Y(location), 0) AS \"location.latitude\"",
|
||||
"COALESCE(ST_X(i.location), 0) AS \"location.longitude\"",
|
||||
"COALESCE(ST_Y(i.location), 0) AS \"location.latitude\"",
|
||||
"ST_Distance(i.location::geography, n.location::geography) AS \"distance_to_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",
|
||||
|
|
@ -49,11 +50,15 @@ func loadImagesForReportNuisance(ctx context.Context, org_id int32, report_ids [
|
|||
psql.Quote("ni", "image_id"),
|
||||
psql.Quote("i", "id"),
|
||||
),
|
||||
sm.InnerJoin("publicreport.nuisance").As("n").OnEQ(
|
||||
psql.Quote("ni", "nuisance_id"),
|
||||
psql.Quote("n", "id"),
|
||||
),
|
||||
sm.Where(psql.Quote("ni", "nuisance_id").EQ(psql.Any(report_ids))),
|
||||
sm.GroupBy(
|
||||
//psql.Quote("i", "id"),
|
||||
//psql.Quote("ni", "nuisance_id"),
|
||||
psql.Raw("i.id, ni.nuisance_id"),
|
||||
psql.Raw("i.id, ni.nuisance_id, n.location"),
|
||||
),
|
||||
), scan.StructMapper[types.Image]())
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@ package types
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/Gleipnir-Technology/nidus-sync/config"
|
||||
"github.com/google/uuid"
|
||||
|
|
@ -12,7 +14,28 @@ type Exif struct {
|
|||
Make string `json:"make"`
|
||||
Model string `json:"model"`
|
||||
}
|
||||
|
||||
func (e *Exif) MarshalJSON() ([]byte, error) {
|
||||
to_marshal := make(map[string]interface{}, 0)
|
||||
if e.Created != "" {
|
||||
layout := "2006:01:02 15:04:05"
|
||||
|
||||
t, err := time.Parse(layout, e.Created)
|
||||
if err != nil {
|
||||
fmt.Println("Error parsing date:", err)
|
||||
return nil, fmt.Errorf("parse created exif: %w", err)
|
||||
}
|
||||
to_marshal["created"] = t
|
||||
} else {
|
||||
to_marshal["created"] = e.Created
|
||||
}
|
||||
to_marshal["make"] = e.Make
|
||||
to_marshal["model"] = e.Model
|
||||
return json.Marshal(to_marshal)
|
||||
}
|
||||
|
||||
type Image struct {
|
||||
DistanceToReporterMeters float64 `db:"distance_to_reporter_meters"`
|
||||
Exif Exif `db:"-" json:"exif"`
|
||||
ExifMake string `db:"exif_make" json:"-"`
|
||||
ExifModel string `db:"exif_model" json:"-"`
|
||||
|
|
@ -25,6 +48,7 @@ type Image struct {
|
|||
|
||||
func (i *Image) MarshalJSON() ([]byte, error) {
|
||||
to_marshal := make(map[string]interface{}, 0)
|
||||
to_marshal["distance_to_reporter_meters"] = i.DistanceToReporterMeters
|
||||
to_marshal["exif"] = Exif{
|
||||
Created: i.ExifDateTime,
|
||||
Make: i.ExifMake,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue