From f859e372c61de1896e92ca185f0df8cd977ccd78 Mon Sep 17 00:00:00 2001 From: Eli Ribble Date: Mon, 16 Feb 2026 15:26:41 +0000 Subject: [PATCH] Fill in correct data about the district --- db/dbinfo/import.district.bob.go | 12 +- db/factory/bobfactory_main.bob.go | 1 + db/factory/import.district.bob.go | 58 ++++++++ db/models/import.district.bob.go | 7 +- html/template/sync/setting-district.html | 182 ++++++++++++++++------- html/template/sync/settings.html | 10 +- platform/csv/pool.go | 2 +- sync/setting.go | 37 ++++- tools/drop-and-recreate.sql | 1 + 9 files changed, 244 insertions(+), 66 deletions(-) diff --git a/db/dbinfo/import.district.bob.go b/db/dbinfo/import.district.bob.go index 27415c50..30f44017 100644 --- a/db/dbinfo/import.district.bob.go +++ b/db/dbinfo/import.district.bob.go @@ -240,6 +240,15 @@ var ImportDistricts = Table[ Generated: true, AutoIncr: false, }, + Area4326SQM: column{ + Name: "area_4326_sqm", + DBType: "numeric", + Default: "GENERATED", + Comment: "", + Nullable: true, + Generated: true, + AutoIncr: false, + }, }, Indexes: importDistrictIndexes{ DistrictPkey: index{ @@ -312,11 +321,12 @@ type importDistrictColumns struct { Geom4326 column Centroid4326 column Extent4326 column + Area4326SQM column } func (c importDistrictColumns) AsSlice() []column { return []column{ - c.Gid, c.ID, c.Website, c.Contact, c.Address, c.Regionid, c.PostalCod, c.Phone1, c.Fax1, c.Agency, c.Code1, c.City1, c.ShapeLeng, c.Address2, c.GeneralMG, c.City2, c.PostalC1, c.Fax2, c.Phone2, c.ShapeLe1, c.ShapeArea, c.Geom, c.Geom4326, c.Centroid4326, c.Extent4326, + c.Gid, c.ID, c.Website, c.Contact, c.Address, c.Regionid, c.PostalCod, c.Phone1, c.Fax1, c.Agency, c.Code1, c.City1, c.ShapeLeng, c.Address2, c.GeneralMG, c.City2, c.PostalC1, c.Fax2, c.Phone2, c.ShapeLe1, c.ShapeArea, c.Geom, c.Geom4326, c.Centroid4326, c.Extent4326, c.Area4326SQM, } } diff --git a/db/factory/bobfactory_main.bob.go b/db/factory/bobfactory_main.bob.go index 767a1715..14359b78 100644 --- a/db/factory/bobfactory_main.bob.go +++ b/db/factory/bobfactory_main.bob.go @@ -2624,6 +2624,7 @@ func (f *Factory) FromExistingImportDistrict(m *models.ImportDistrict) *ImportDi o.Geom4326 = func() null.Val[string] { return m.Geom4326 } o.Centroid4326 = func() null.Val[string] { return m.Centroid4326 } o.Extent4326 = func() null.Val[string] { return m.Extent4326 } + o.Area4326SQM = func() null.Val[decimal.Decimal] { return m.Area4326SQM } ctx := context.Background() if m.R.ImportDistrictGidOrganization != nil { diff --git a/db/factory/import.district.bob.go b/db/factory/import.district.bob.go index 73952b69..20891cc3 100644 --- a/db/factory/import.district.bob.go +++ b/db/factory/import.district.bob.go @@ -62,6 +62,7 @@ type ImportDistrictTemplate struct { Geom4326 func() null.Val[string] Centroid4326 func() null.Val[string] Extent4326 func() null.Val[string] + Area4326SQM func() null.Val[decimal.Decimal] r importDistrictR f *Factory @@ -285,6 +286,9 @@ func (o ImportDistrictTemplate) Build() *models.ImportDistrict { if o.Extent4326 != nil { m.Extent4326 = o.Extent4326() } + if o.Area4326SQM != nil { + m.Area4326SQM = o.Area4326SQM() + } o.setModelRels(m) @@ -449,6 +453,7 @@ func (m importDistrictMods) RandomizeAllColumns(f *faker.Faker) ImportDistrictMo ImportDistrictMods.RandomGeom4326(f), ImportDistrictMods.RandomCentroid4326(f), ImportDistrictMods.RandomExtent4326(f), + ImportDistrictMods.RandomArea4326SQM(f), } } @@ -1755,6 +1760,59 @@ func (m importDistrictMods) RandomExtent4326NotNull(f *faker.Faker) ImportDistri }) } +// Set the model columns to this value +func (m importDistrictMods) Area4326SQM(val null.Val[decimal.Decimal]) ImportDistrictMod { + return ImportDistrictModFunc(func(_ context.Context, o *ImportDistrictTemplate) { + o.Area4326SQM = func() null.Val[decimal.Decimal] { return val } + }) +} + +// Set the Column from the function +func (m importDistrictMods) Area4326SQMFunc(f func() null.Val[decimal.Decimal]) ImportDistrictMod { + return ImportDistrictModFunc(func(_ context.Context, o *ImportDistrictTemplate) { + o.Area4326SQM = f + }) +} + +// Clear any values for the column +func (m importDistrictMods) UnsetArea4326SQM() ImportDistrictMod { + return ImportDistrictModFunc(func(_ context.Context, o *ImportDistrictTemplate) { + o.Area4326SQM = nil + }) +} + +// Generates a random value for the column using the given faker +// if faker is nil, a default faker is used +// The generated value is sometimes null +func (m importDistrictMods) RandomArea4326SQM(f *faker.Faker) ImportDistrictMod { + return ImportDistrictModFunc(func(_ context.Context, o *ImportDistrictTemplate) { + o.Area4326SQM = func() null.Val[decimal.Decimal] { + if f == nil { + f = &defaultFaker + } + + val := random_decimal_Decimal(f) + return null.From(val) + } + }) +} + +// Generates a random value for the column using the given faker +// if faker is nil, a default faker is used +// The generated value is never null +func (m importDistrictMods) RandomArea4326SQMNotNull(f *faker.Faker) ImportDistrictMod { + return ImportDistrictModFunc(func(_ context.Context, o *ImportDistrictTemplate) { + o.Area4326SQM = func() null.Val[decimal.Decimal] { + if f == nil { + f = &defaultFaker + } + + val := random_decimal_Decimal(f) + return null.From(val) + } + }) +} + func (m importDistrictMods) WithParentsCascading() ImportDistrictMod { return ImportDistrictModFunc(func(ctx context.Context, o *ImportDistrictTemplate) { if isDone, _ := importDistrictWithParentsCascadingCtx.Value(ctx); isDone { diff --git a/db/models/import.district.bob.go b/db/models/import.district.bob.go index 725b78e4..4821c30c 100644 --- a/db/models/import.district.bob.go +++ b/db/models/import.district.bob.go @@ -51,6 +51,7 @@ type ImportDistrict struct { Geom4326 null.Val[string] `db:"geom_4326,generated" ` Centroid4326 null.Val[string] `db:"centroid_4326,generated" ` Extent4326 null.Val[string] `db:"extent_4326,generated" ` + Area4326SQM null.Val[decimal.Decimal] `db:"area_4326_sqm,generated" ` R importDistrictR `db:"-" ` } @@ -73,7 +74,7 @@ type importDistrictR struct { func buildImportDistrictColumns(alias string) importDistrictColumns { return importDistrictColumns{ ColumnsExpr: expr.NewColumnsExpr( - "gid", "id", "website", "contact", "address", "regionid", "postal_cod", "phone1", "fax1", "agency", "code1", "city1", "shape_leng", "address2", "general_mg", "city2", "postal_c_1", "fax2", "phone2", "shape_le_1", "shape_area", "geom", "geom_4326", "centroid_4326", "extent_4326", + "gid", "id", "website", "contact", "address", "regionid", "postal_cod", "phone1", "fax1", "agency", "code1", "city1", "shape_leng", "address2", "general_mg", "city2", "postal_c_1", "fax2", "phone2", "shape_le_1", "shape_area", "geom", "geom_4326", "centroid_4326", "extent_4326", "area_4326_sqm", ).WithParent("import.district"), tableAlias: alias, Gid: psql.Quote(alias, "gid"), @@ -101,6 +102,7 @@ func buildImportDistrictColumns(alias string) importDistrictColumns { Geom4326: psql.Quote(alias, "geom_4326"), Centroid4326: psql.Quote(alias, "centroid_4326"), Extent4326: psql.Quote(alias, "extent_4326"), + Area4326SQM: psql.Quote(alias, "area_4326_sqm"), } } @@ -132,6 +134,7 @@ type importDistrictColumns struct { Geom4326 psql.Expression Centroid4326 psql.Expression Extent4326 psql.Expression + Area4326SQM psql.Expression } func (c importDistrictColumns) Alias() string { @@ -944,6 +947,7 @@ type importDistrictWhere[Q psql.Filterable] struct { Geom4326 psql.WhereNullMod[Q, string] Centroid4326 psql.WhereNullMod[Q, string] Extent4326 psql.WhereNullMod[Q, string] + Area4326SQM psql.WhereNullMod[Q, decimal.Decimal] } func (importDistrictWhere[Q]) AliasedAs(alias string) importDistrictWhere[Q] { @@ -977,6 +981,7 @@ func buildImportDistrictWhere[Q psql.Filterable](cols importDistrictColumns) imp Geom4326: psql.WhereNull[Q, string](cols.Geom4326), Centroid4326: psql.WhereNull[Q, string](cols.Centroid4326), Extent4326: psql.WhereNull[Q, string](cols.Extent4326), + Area4326SQM: psql.WhereNull[Q, decimal.Decimal](cols.Area4326SQM), } } diff --git a/html/template/sync/setting-district.html b/html/template/sync/setting-district.html index 97632f31..60a62d83 100644 --- a/html/template/sync/setting-district.html +++ b/html/template/sync/setting-district.html @@ -19,84 +19,167 @@
-

District Settings

- +

+ District + Settings +

+
- + - + district-id="{{ .District.GID }}" + centroid="{{ .District.Centroid|json }}" + xmin="{{ .District.XMin }}" + ymin="{{ .District.YMin }}" + xmax="{{ .District.XMax }}" + ymax="{{ .District.YMax }}" + tegola="{{ .URL.Tegola }}" + > +
-
Organization Information
+
+ Organization Information +
- - + +
- - + +
- - + +
- - + +
- +
-
Contact Information
+
+ Contact Information +
- - + +
- - + +
- - + +
- - + +
- - + +
- - + +
- +
@@ -106,30 +189,27 @@
- - -
-
- - - Hold Ctrl (or Cmd) to select multiple counties + +
- -
+ +
diff --git a/html/template/sync/settings.html b/html/template/sync/settings.html index 764fc83f..d4f65c9f 100644 --- a/html/template/sync/settings.html +++ b/html/template/sync/settings.html @@ -32,7 +32,6 @@ Manage Users - 23 users @@ -57,7 +56,6 @@ Manage Products - 12 active products @@ -83,7 +81,6 @@ Manage Integrations - 3 active connections @@ -101,7 +98,10 @@ Manage your district location and information.

- + Manage District @@ -127,7 +127,6 @@ Manage Notifications - 5 active alerts
@@ -149,7 +148,6 @@ Manage Settings - Updated yesterday diff --git a/platform/csv/pool.go b/platform/csv/pool.go index a6114d1b..aa0207a2 100644 --- a/platform/csv/pool.go +++ b/platform/csv/pool.go @@ -150,7 +150,7 @@ func bulkGeocode(ctx context.Context, txn bob.Tx, file models.FileuploadFile, po FROM import.district d JOIN organization o ON d.gid = o.import_district_gid WHERE o.id = p.organization_id - AND ST_Contains(d.geom, p.geom) + AND ST_Contains(d.geom_4326, p.geom) ) ) WHERE p.geom IS NOT NULL;` diff --git a/sync/setting.go b/sync/setting.go index ba796e5c..95ec80ec 100644 --- a/sync/setting.go +++ b/sync/setting.go @@ -15,12 +15,25 @@ import ( ) type contentDistrict struct { - Centroid string `db:"st_asgeojson"` - GID int32 `db:"gid"` - XMin float32 `db:"st_xmin"` - YMin float32 `db:"st_ymin"` - XMax float32 `db:"st_xmax"` - YMax float32 `db:"st_ymax"` + Address string `db:"address"` + Agency string `db:"agency"` + Centroid string `db:"st_asgeojson"` + Contact string `db:"contact"` + City1 string `db:"city1"` + City2 string `db:"city2"` + Fax string `db:"fax1"` + GID int32 `db:"gid"` + Phone1 string `db:"phone1"` + Phone2 string `db:"phone2"` + GeneralManager string `db:"general_mg"` + PostalCode string `db:"postal_c_1"` + ShapeArea string `db:"shape_area"` + SurfaceAreaMetersSquare string `db:"area_4326_sqm"` + Website string `db:"website"` + XMin float32 `db:"st_xmin"` + XMax float32 `db:"st_xmax"` + YMin float32 `db:"st_ymin"` + YMax float32 `db:"st_ymax"` } type contentSettingDistrict struct { District contentDistrict @@ -61,7 +74,19 @@ func getSettingDistrict(w http.ResponseWriter, r *http.Request, u *models.User) district, err = bob.One[contentDistrict](ctx, db.PGInstance.BobDB, psql.Select( sm.From("import.district"), sm.Columns( + "address", + "agency", + "area_4326_sqm", + "city1", + "city2", + "contact", + "fax1", + "general_mg", "gid", + "phone1", + "phone2", + "postal_c_1", + "website", psql.F("ST_AsGeoJSON", "centroid_4326"), psql.F("ST_XMin", "extent_4326"), psql.F("ST_YMin", "extent_4326"), diff --git a/tools/drop-and-recreate.sql b/tools/drop-and-recreate.sql index d2c37fce..5fadc8ce 100644 --- a/tools/drop-and-recreate.sql +++ b/tools/drop-and-recreate.sql @@ -20,3 +20,4 @@ GRANT ALL PRIVILEGES ON SCHEMA public TO $1; ALTER TABLE import.district ADD COLUMN geom_4326 geometry(MultiPolygon,4326) GENERATED ALWAYS AS (ST_Transform(geom, 4326)) STORED; ALTER TABLE import.district ADD COLUMN centroid_4326 geometry(Point,4326) GENERATED ALWAYS AS (ST_Transform(ST_Centroid(geom), 4326)) STORED; ALTER TABLE import.district ADD COLUMN extent_4326 geometry(Polygon,4326) GENERATED ALWAYS AS (ST_Transform(ST_Envelope(geom), 4326)) STORED; +ALTER TABLE import.district ADD COLUMN area_4326_sqm numeric GENERATED ALWAYS AS (ST_Area(ST_Transform(geom, 4326)::geography)) STORED;