Get much more data about signals to send to the planning dash

This commit is contained in:
Eli Ribble 2026-03-05 03:17:45 +00:00
parent 78a35e5d1f
commit 1a22b9233d
No known key found for this signature in database
4 changed files with 126 additions and 20 deletions

View file

@ -65,7 +65,13 @@ func JobCommit(ctx context.Context, file_id int32) error {
}
address, err := geocode.EnsureAddress(ctx, txn, org, a)
if err != nil {
return fmt.Errorf("ensure address: %w", err)
//return fmt.Errorf("ensure address: %w", err)
if address == nil {
log.Warn().Err(err).Msg("ensure address failure")
} else {
log.Warn().Err(err).Int32("address.id", address.ID).Msg("ensure address failure")
}
continue
}
parcel, err := geocode.GetParcel(ctx, txn, address)
if err != nil {
@ -135,13 +141,16 @@ func JobCommit(ctx context.Context, file_id int32) error {
if err != nil {
return fmt.Errorf("insert signal: %w", err)
}
_, err = bob.Exec(ctx, db.PGInstance.BobDB, psql.Insert(
im.Into("signa_pool", "pool_id", "signal_id"),
_, err = bob.Exec(ctx, txn, psql.Insert(
im.Into("signal_pool", "pool_id", "signal_id"),
im.Values(
psql.Arg(pool.ID),
psql.Arg(signal.ID),
),
))
if err != nil {
return fmt.Errorf("insert signal pool: %w", err)
}
/*
Not sure why SignalPools doesn't have an Insert method
_, err = models.SignalPools.Insert(&models.SignalPoolSetter{

View file

@ -130,10 +130,15 @@ func Geocode(ctx context.Context, org *models.Organization, a Address) (GeocodeR
if err != nil {
return GeocodeResult{}, fmt.Errorf("client structured geocode failure on %s: %w", a.String(), err)
}
if len(resp.Features) > 1 {
return GeocodeResult{}, fmt.Errorf("%s matched more than one location", a.String())
if len(resp.Features) < 1 {
return GeocodeResult{}, fmt.Errorf("%s matched no locations", a.String())
}
feature := resp.Features[0]
if len(resp.Features) > 1 {
if !allFeaturesIdenticalEnough(resp.Features) {
return GeocodeResult{}, fmt.Errorf("%s matched more than one location, and they differ a lot", a.String())
}
}
if feature.Geometry.Type != "Point" {
return GeocodeResult{}, fmt.Errorf("wrong type %s from %s", feature.Geometry.Type, a.String())
}
@ -179,6 +184,22 @@ func GetParcel(ctx context.Context, txn bob.Tx, a *models.Address) (*models.Parc
}
return result, nil
}
func allFeaturesIdenticalEnough(features []stadia.GeocodeFeature) bool {
if len(features) < 2 {
return true
}
f := features[0].Properties
for _, feature := range features {
if feature.Properties.CountryCode != f.CountryCode ||
feature.Properties.County != f.County ||
feature.Properties.HouseNumber != f.HouseNumber ||
feature.Properties.Locality != f.Locality ||
feature.Properties.RegionA != f.RegionA {
return false
}
}
return true
}
func maybeAddServiceArea(req *stadia.StructuredGeocodeRequest, org *models.Organization) {
if org.ServiceAreaXmax.IsNull() ||
org.ServiceAreaYmax.IsNull() ||