Add migration to calculate and store the h3 cell
I'm only doing this for now on the tables we need to return to Nidus, eventually we'll add them to more tables as we need, probably.
This commit is contained in:
parent
113e73a8b9
commit
6517d50802
2 changed files with 66 additions and 59 deletions
114
api/types.go
114
api/types.go
|
|
@ -4,9 +4,9 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/aarondl/opt/null"
|
|
||||||
"github.com/Gleipnir-Technology/nidus-sync/db/models"
|
"github.com/Gleipnir-Technology/nidus-sync/db/models"
|
||||||
"github.com/Gleipnir-Technology/nidus-sync/platform"
|
"github.com/Gleipnir-Technology/nidus-sync/platform"
|
||||||
|
"github.com/aarondl/opt/null"
|
||||||
"github.com/go-chi/render"
|
"github.com/go-chi/render"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -78,9 +78,9 @@ type ResponseMosquitoSource struct {
|
||||||
Comments string `json:"comments"`
|
Comments string `json:"comments"`
|
||||||
Created string `json:"created"`
|
Created string `json:"created"`
|
||||||
Description string `json:"description"`
|
Description string `json:"description"`
|
||||||
|
H3Cell int64 `json:"h3cell"`
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
LastInspectionDate string `json:"last_inspection_date"`
|
LastInspectionDate string `json:"last_inspection_date"`
|
||||||
Location ResponseLocation `json:"location"`
|
|
||||||
Habitat string `json:"habitat"`
|
Habitat string `json:"habitat"`
|
||||||
Inspections []ResponseMosquitoInspection `json:"inspections"`
|
Inspections []ResponseMosquitoInspection `json:"inspections"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
|
|
@ -91,7 +91,6 @@ type ResponseMosquitoSource struct {
|
||||||
Zone string `json:"zone"`
|
Zone string `json:"zone"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
type NoteAudioBreadcrumbPayload struct {
|
type NoteAudioBreadcrumbPayload struct {
|
||||||
Cell H3Cell `json:"cell"`
|
Cell H3Cell `json:"cell"`
|
||||||
Created time.Time `json:"created"`
|
Created time.Time `json:"created"`
|
||||||
|
|
@ -101,20 +100,20 @@ type NoteAudioBreadcrumbPayload struct {
|
||||||
type NidusNotePayload struct {
|
type NidusNotePayload struct {
|
||||||
UUID string `json:"uuid"`
|
UUID string `json:"uuid"`
|
||||||
Timestamp time.Time `json:"timestamp"`
|
Timestamp time.Time `json:"timestamp"`
|
||||||
|
H3Cell int64 `json:"h3cell"`
|
||||||
Images []string `json:"images"`
|
Images []string `json:"images"`
|
||||||
Location Location `json:"location"`
|
|
||||||
Text string `json:"text"`
|
Text string `json:"text"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
type ResponseFieldseeker struct {
|
type ResponseFieldseeker struct {
|
||||||
MosquitoSources []ResponseMosquitoSource `json:"sources"`
|
MosquitoSources []ResponseMosquitoSource `json:"sources"`
|
||||||
ServiceRequests []ResponseServiceRequest `json:"requests"`
|
ServiceRequests []ResponseServiceRequest `json:"requests"`
|
||||||
TrapData []ResponseTrapData `json:"traps"`
|
TrapData []ResponseTrapData `json:"traps"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// ResponseErr renderer type for handling all sorts of errors.
|
// ResponseErr renderer type for handling all sorts of errors.
|
||||||
type ResponseClientIos struct {
|
type ResponseClientIos struct {
|
||||||
Fieldseeker ResponseFieldseeker `json:"fieldseeker"`
|
Fieldseeker ResponseFieldseeker `json:"fieldseeker"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i ResponseClientIos) Render(w http.ResponseWriter, r *http.Request) error {
|
func (i ResponseClientIos) Render(w http.ResponseWriter, r *http.Request) error {
|
||||||
|
|
@ -195,14 +194,14 @@ func (rtd ResponseMosquitoSource) Render(w http.ResponseWriter, r *http.Request)
|
||||||
func NewResponseMosquitoSource(ms *platform.MosquitoSource) ResponseMosquitoSource {
|
func NewResponseMosquitoSource(ms *platform.MosquitoSource) ResponseMosquitoSource {
|
||||||
pl := ms.PointLocation
|
pl := ms.PointLocation
|
||||||
return ResponseMosquitoSource{
|
return ResponseMosquitoSource{
|
||||||
Active: toBool16(pl.Active),
|
Active: toBool16(pl.Active),
|
||||||
Access: pl.Accessdesc.GetOr(""),
|
Access: pl.Accessdesc.GetOr(""),
|
||||||
Comments: pl.Comments.GetOr(""),
|
Comments: pl.Comments.GetOr(""),
|
||||||
Created: formatTime(pl.Creationdate),
|
Created: formatTime(pl.Creationdate),
|
||||||
Description: pl.Description.GetOr(""),
|
Description: pl.Description.GetOr(""),
|
||||||
|
//H3Cell: pl.H3Cell,
|
||||||
ID: pl.Globalid.String(),
|
ID: pl.Globalid.String(),
|
||||||
LastInspectionDate: formatTime(pl.Lastinspectdate),
|
LastInspectionDate: formatTime(pl.Lastinspectdate),
|
||||||
//Location: NewResponseLocation(ms.Location),
|
|
||||||
Habitat: pl.Habitat.GetOr(""),
|
Habitat: pl.Habitat.GetOr(""),
|
||||||
Inspections: NewResponseMosquitoInspections(ms.Inspections),
|
Inspections: NewResponseMosquitoInspections(ms.Inspections),
|
||||||
Name: pl.Name.GetOr(""),
|
Name: pl.Name.GetOr(""),
|
||||||
|
|
@ -242,17 +241,17 @@ func (rtd ResponseMosquitoTreatment) Render(w http.ResponseWriter, r *http.Reque
|
||||||
func NewResponseMosquitoTreatment(i *models.FieldseekerTreatment) ResponseMosquitoTreatment {
|
func NewResponseMosquitoTreatment(i *models.FieldseekerTreatment) ResponseMosquitoTreatment {
|
||||||
return ResponseMosquitoTreatment{
|
return ResponseMosquitoTreatment{
|
||||||
/*
|
/*
|
||||||
Comments: i.Comments(),
|
Comments: i.Comments(),
|
||||||
Created: i.Created().Format("2006-01-02T15:04:05.000Z"),
|
Created: i.Created().Format("2006-01-02T15:04:05.000Z"),
|
||||||
FieldTechnician: i.FieldTechnician(),
|
FieldTechnician: i.FieldTechnician(),
|
||||||
Habitat: i.Habitat(),
|
Habitat: i.Habitat(),
|
||||||
ID: i.ID(),
|
ID: i.ID(),
|
||||||
Product: i.Product(),
|
Product: i.Product(),
|
||||||
Quantity: i.Quantity(),
|
Quantity: i.Quantity(),
|
||||||
QuantityUnit: i.QuantityUnit(),
|
QuantityUnit: i.QuantityUnit(),
|
||||||
SiteCondition: i.SiteCondition(),
|
SiteCondition: i.SiteCondition(),
|
||||||
TreatAcres: i.TreatAcres(),
|
TreatAcres: i.TreatAcres(),
|
||||||
TreatHectares: i.TreatHectares(),
|
TreatHectares: i.TreatHectares(),
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -268,9 +267,9 @@ type ResponseNote struct {
|
||||||
CategoryName string `json:"categoryName"`
|
CategoryName string `json:"categoryName"`
|
||||||
Content string `json:"content"`
|
Content string `json:"content"`
|
||||||
|
|
||||||
ID string `json:"id"`
|
H3Cell int64 `json:"h3cell"`
|
||||||
Location ResponseLocation `json:"location"`
|
ID string `json:"id"`
|
||||||
Timestamp string `json:"timestamp"`
|
Timestamp string `json:"timestamp"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rtd ResponseNote) Render(w http.ResponseWriter, r *http.Request) error {
|
func (rtd ResponseNote) Render(w http.ResponseWriter, r *http.Request) error {
|
||||||
|
|
@ -278,20 +277,20 @@ func (rtd ResponseNote) Render(w http.ResponseWriter, r *http.Request) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
type ResponseServiceRequest struct {
|
type ResponseServiceRequest struct {
|
||||||
Address string `json:"address"`
|
Address string `json:"address"`
|
||||||
AssignedTechnician string `json:"assigned_technician"`
|
AssignedTechnician string `json:"assigned_technician"`
|
||||||
City string `json:"city"`
|
City string `json:"city"`
|
||||||
Created string `json:"created"`
|
Created string `json:"created"`
|
||||||
HasDog *bool `json:"has_dog"`
|
H3Cell int64 `json:"h3cell"`
|
||||||
HasSpanishSpeaker *bool `json:"has_spanish_speaker"`
|
HasDog *bool `json:"has_dog"`
|
||||||
ID string `json:"id"`
|
HasSpanishSpeaker *bool `json:"has_spanish_speaker"`
|
||||||
Location ResponseLocation `json:"location"`
|
ID string `json:"id"`
|
||||||
Priority string `json:"priority"`
|
Priority string `json:"priority"`
|
||||||
RecordedDate string `json:"recorded_date"`
|
RecordedDate string `json:"recorded_date"`
|
||||||
Source string `json:"source"`
|
Source string `json:"source"`
|
||||||
Status string `json:"status"`
|
Status string `json:"status"`
|
||||||
Target string `json:"target"`
|
Target string `json:"target"`
|
||||||
Zip string `json:"zip"`
|
Zip string `json:"zip"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (srr ResponseServiceRequest) Render(w http.ResponseWriter, r *http.Request) error {
|
func (srr ResponseServiceRequest) Render(w http.ResponseWriter, r *http.Request) error {
|
||||||
|
|
@ -304,15 +303,15 @@ func NewResponseServiceRequest(sr *models.FieldseekerServicerequest) ResponseSer
|
||||||
AssignedTechnician: sr.Assignedtech.GetOr(""),
|
AssignedTechnician: sr.Assignedtech.GetOr(""),
|
||||||
City: sr.Reqcity.GetOr(""),
|
City: sr.Reqcity.GetOr(""),
|
||||||
Created: formatTime(sr.Creationdate),
|
Created: formatTime(sr.Creationdate),
|
||||||
HasDog: toBool(sr.Dog),
|
//H3Cell: sr.H3Cell,
|
||||||
HasSpanishSpeaker: toBool(sr.Spanish),
|
HasDog: toBool(sr.Dog),
|
||||||
ID: sr.Globalid.String(),
|
HasSpanishSpeaker: toBool(sr.Spanish),
|
||||||
//Location: NewResponseLocation(sr.Location()),
|
ID: sr.Globalid.String(),
|
||||||
Priority: sr.Priority.GetOr(""),
|
Priority: sr.Priority.GetOr(""),
|
||||||
Status: sr.Status.GetOr(""),
|
Status: sr.Status.GetOr(""),
|
||||||
Source: sr.Source.GetOr(""),
|
Source: sr.Source.GetOr(""),
|
||||||
Target: sr.Reqtarget.GetOr(""),
|
Target: sr.Reqtarget.GetOr(""),
|
||||||
Zip: sr.Reqzip.GetOr(""),
|
Zip: sr.Reqzip.GetOr(""),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
func NewResponseServiceRequests(requests *models.FieldseekerServicerequestSlice) []ResponseServiceRequest {
|
func NewResponseServiceRequests(requests *models.FieldseekerServicerequestSlice) []ResponseServiceRequest {
|
||||||
|
|
@ -324,11 +323,11 @@ func NewResponseServiceRequests(requests *models.FieldseekerServicerequestSlice)
|
||||||
}
|
}
|
||||||
|
|
||||||
type ResponseTrapData struct {
|
type ResponseTrapData struct {
|
||||||
Created string `json:"created"`
|
Created string `json:"created"`
|
||||||
Description string `json:"description"`
|
Description string `json:"description"`
|
||||||
ID string `json:"id"`
|
H3Cell int64 `json:"h3cell"`
|
||||||
Location ResponseLocation `json:"location"`
|
ID string `json:"id"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rtd ResponseTrapData) Render(w http.ResponseWriter, r *http.Request) error {
|
func (rtd ResponseTrapData) Render(w http.ResponseWriter, r *http.Request) error {
|
||||||
|
|
@ -339,8 +338,8 @@ func NewResponseTrapDatum(td *models.FieldseekerTraplocation) ResponseTrapData {
|
||||||
Created: formatTime(td.Creationdate),
|
Created: formatTime(td.Creationdate),
|
||||||
Description: td.Description.GetOr(""),
|
Description: td.Description.GetOr(""),
|
||||||
ID: td.Globalid.String(),
|
ID: td.Globalid.String(),
|
||||||
//Location: NewResponseLocation(td.Location),
|
//H3Cell: td.H3Cell,
|
||||||
Name: td.Name.GetOr(""),
|
Name: td.Name.GetOr(""),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
func NewResponseTrapData(data *models.FieldseekerTraplocationSlice) []ResponseTrapData {
|
func NewResponseTrapData(data *models.FieldseekerTraplocationSlice) []ResponseTrapData {
|
||||||
|
|
@ -352,8 +351,7 @@ func NewResponseTrapData(data *models.FieldseekerTraplocationSlice) []ResponseTr
|
||||||
}
|
}
|
||||||
|
|
||||||
func toResponseFieldseeker(csync platform.ClientSync) ResponseFieldseeker {
|
func toResponseFieldseeker(csync platform.ClientSync) ResponseFieldseeker {
|
||||||
return ResponseFieldseeker{
|
return ResponseFieldseeker{}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func formatTime(t null.Val[time.Time]) string {
|
func formatTime(t null.Val[time.Time]) string {
|
||||||
|
|
|
||||||
9
db/migrations/00022_h3cell_fieldseeker_tables.sql
Normal file
9
db/migrations/00022_h3cell_fieldseeker_tables.sql
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
-- +goose Up
|
||||||
|
ALTER TABLE fieldseeker.pointlocation ADD COLUMN h3cell h3index GENERATED ALWAYS AS (h3_latlng_to_cell(geospatial, 15)) STORED;
|
||||||
|
ALTER TABLE fieldseeker.servicerequest ADD COLUMN h3cell h3index GENERATED ALWAYS AS (h3_latlng_to_cell(geospatial, 15)) STORED;
|
||||||
|
ALTER TABLE fieldseeker.treatment ADD COLUMN h3cell h3index GENERATED ALWAYS AS (h3_latlng_to_cell(geospatial, 15)) STORED;
|
||||||
|
|
||||||
|
-- +goose Down
|
||||||
|
ALTER TABLE fieldseeker.pointlocation DROP COLUMN h3cell;
|
||||||
|
ALTER TABLE fieldseeker.servicerequest DROP COLUMN h3cell;
|
||||||
|
ALTER TABLE fieldseeker.treatment DROP COLUMN h3cell;
|
||||||
Loading…
Add table
Add a link
Reference in a new issue