feat: Added support for US Counties in OpsLog / Extra feature with DXHunter
This commit is contained in:
@@ -643,6 +643,59 @@ func InScope(d Def, q *qso.QSO) bool { return inScope(&d, q) }
|
||||
// EmissionOf maps an ADIF mode to its broad category (CW|PHONE|DIGITAL).
|
||||
func EmissionOf(mode string) string { return emissionOf(mode) }
|
||||
|
||||
// USCountyKey normalises a QSO's state + cnty into the canonical "STATE,COUNTY"
|
||||
// match code used by the US Counties (USA-CA) award, so the reference list (in
|
||||
// that same form) matches whatever shape the logbook holds. It is the SINGLE
|
||||
// source of truth: cmd/cntygen builds the reference codes by calling it, so the
|
||||
// two sides can never drift.
|
||||
//
|
||||
// Real logs are a mess — "MA,MIDDLESEX", bare "Middlesex" with the state in its
|
||||
// own column, mixed case, county-type suffixes, the odd "0", plus the FIPS list
|
||||
// abbreviating "Saint"→"St." and hyphenating "Matanuska-Susitna". The rules:
|
||||
// - if cnty already carries "ST,County", split on the first comma; else take
|
||||
// the state from the STATE column;
|
||||
// - upper-case; drop periods and apostrophes; hyphens→space; strip a trailing
|
||||
// County/Parish/Borough/Census Area/Municipality; fold Saint(e)→St(e);
|
||||
// collapse whitespace;
|
||||
// - require a 2-letter state and a non-empty county, else no match ("").
|
||||
func USCountyKey(state, cnty string) string {
|
||||
s := strings.TrimSpace(cnty)
|
||||
if s == "" || s == "0" {
|
||||
return ""
|
||||
}
|
||||
var st, co string
|
||||
if i := strings.IndexByte(s, ','); i >= 0 {
|
||||
st, co = strings.TrimSpace(s[:i]), strings.TrimSpace(s[i+1:])
|
||||
} else {
|
||||
st, co = strings.TrimSpace(state), s
|
||||
}
|
||||
co = strings.ToUpper(co)
|
||||
co = strings.ReplaceAll(co, ".", "")
|
||||
co = strings.ReplaceAll(co, "'", "")
|
||||
co = strings.ReplaceAll(co, "-", " ")
|
||||
for _, suf := range []string{" COUNTY", " PARISH", " BOROUGH", " CENSUS AREA", " MUNICIPALITY"} {
|
||||
if strings.HasSuffix(co, suf) {
|
||||
co = strings.TrimSuffix(co, suf)
|
||||
break
|
||||
}
|
||||
}
|
||||
switch {
|
||||
case strings.HasPrefix(co, "SAINTE "):
|
||||
co = "STE " + co[len("SAINTE "):]
|
||||
case strings.HasPrefix(co, "SAINT "):
|
||||
co = "ST " + co[len("SAINT "):]
|
||||
}
|
||||
// Drop ALL internal spaces last: FIPS writes DeKalb/DuPage/LaSalle as one
|
||||
// word, logs often split them ("De Kalb"). Removing spaces on both sides
|
||||
// folds those together and can't collide two real counties in one state.
|
||||
co = strings.ReplaceAll(co, " ", "")
|
||||
st = strings.ToUpper(st)
|
||||
if len(st) != 2 || co == "" {
|
||||
return ""
|
||||
}
|
||||
return st + "," + co
|
||||
}
|
||||
|
||||
// labelRef fills a worked reference's name/group from the reference list (or the
|
||||
// name resolver as a fallback).
|
||||
func labelRef(rf *Ref, d *Def, code string, rl refList, hasList bool, nameOf NameResolver) {
|
||||
@@ -1145,6 +1198,8 @@ func fieldRaw(field string, q *qso.QSO) string {
|
||||
return q.Callsign
|
||||
case "state":
|
||||
return q.State
|
||||
case "us_county":
|
||||
return USCountyKey(q.State, q.County)
|
||||
case "cont":
|
||||
return q.Continent
|
||||
case "country":
|
||||
|
||||
Reference in New Issue
Block a user