fix: Better matching of the counties for the USA-CA

This commit is contained in:
2026-07-17 16:28:32 +02:00
parent eb2ff8ed59
commit 8e088576c7
3 changed files with 49 additions and 11 deletions
+42 -6
View File
@@ -4707,7 +4707,9 @@ var bulkFieldColumns = map[string]string{
"prop_mode": "prop_mode",
"sat_name": "sat_name",
"sat_mode": "sat_mode",
// Contacted station activation refs / SIG
// Contacted station location + activation refs / SIG
"state": "state",
"cnty": "cnty",
"pota_ref": "pota_ref",
"sota_ref": "sota_ref",
"wwff_ref": "wwff_ref",
@@ -7925,6 +7927,15 @@ func (a *App) BackfillUSCounties() (BackfillUSCountiesResult, error) {
if err != nil {
return res, err
}
// Set of valid USA-CA county keys, so we can tell a good county from a bad one
// (a wrong county for the state, a bare city, "0", …) and re-resolve only the
// bad ones.
validRef := map[string]bool{}
if refs, ok := awardref.BuiltinRefs("USA-CA"); ok {
for _, r := range refs {
validRef[r.Code] = true
}
}
for i := range rows {
q := &rows[i]
if q.DXCC == nil {
@@ -7936,7 +7947,12 @@ func (a *App) BackfillUSCounties() (BackfillUSCountiesResult, error) {
continue
}
res.Scanned++
needCounty := strings.TrimSpace(q.County) == ""
// A county "needs" filling when it maps to NO valid USA-CA county: empty,
// garbage, or a wrong county for the state. A legitimate DC operation
// (state=DC) is left alone — DC simply isn't a USA-CA county, not an error.
curKey := award.USCountyKey(q.State, q.County)
stateUp := strings.ToUpper(strings.TrimSpace(q.State))
needCounty := !validRef[curKey] && stateUp != "DC"
needGrid := strings.TrimSpace(q.Grid) == ""
if !needCounty && !needGrid {
continue
@@ -7946,14 +7962,34 @@ func (a *App) BackfillUSCounties() (BackfillUSCountiesResult, error) {
continue
}
changed := false
if needCounty && loc.CNTY() != "" {
q.County = loc.CNTY()
if strings.TrimSpace(q.State) == "" {
q.State = loc.State
if needCounty {
// The logged county maps to no real USA-CA county (wrong state, wrong
// county, empty…). Fix it from the ULS, PREFERRING to keep the operator's
// county and correct only the state — their county often came from QRZ
// and is finer than the ZIP-derived one (e.g. K1LZ logged ME,Middlesex →
// Middlesex is a MA county, so → MA,Middlesex). Fall back to the ULS
// county when even that is invalid. Never stamp an unrecognised value
// (e.g. a Connecticut 2022 "planning region" GeoNames now returns). A
// portable op keeps a suffix that won't resolve in the ULS, so only
// fixed-station bad data is ever touched.
name := q.County
if i := strings.IndexByte(name, ','); i >= 0 {
name = name[i+1:]
}
name = strings.TrimSpace(name)
var stState, stName string
if name != "" && validRef[award.USCountyKey(loc.State, name)] {
stState, stName = loc.State, name
} else if validRef[award.USCountyKey(loc.State, loc.County)] {
stState, stName = loc.State, loc.County
}
if stName != "" {
q.State = stState
q.County = stState + "," + stName
res.County++
changed = true
}
}
if needGrid && loc.Grid != "" {
q.Grid = loc.Grid
res.Grid++
+3 -1
View File
@@ -64,7 +64,9 @@ const FIELDS: FieldDef[] = [
{ id: 'prop_mode', label: 'bulk.fPropMode', group: 'Propagation', kind: 'text', upper: true },
{ id: 'sat_name', label: 'bulk.fSatName', group: 'Propagation', kind: 'text', upper: true },
{ id: 'sat_mode', label: 'bulk.fSatMode', group: 'Propagation', kind: 'text', upper: true },
// Contacted station (activation refs / SIG)
// Contacted station (location / activation refs / SIG)
{ id: 'state', label: 'bulk.fState', group: 'Contacted station', kind: 'text', upper: true },
{ id: 'cnty', label: 'bulk.fCnty', group: 'Contacted station', kind: 'text' },
{ id: 'pota_ref', label: 'bulk.fPotaRef', group: 'Contacted station', kind: 'text', upper: true },
{ id: 'sota_ref', label: 'bulk.fSotaRef', group: 'Contacted station', kind: 'text', upper: true },
{ id: 'wwff_ref', label: 'bulk.fWwffRef', group: 'Contacted station', kind: 'text', upper: true },
File diff suppressed because one or more lines are too long