fix(adif): CNTY must be STATE,COUNTY
ADIF defines CNTY as "STATE,COUNTY" — "GA,BARROW". OpsLog wrote the bare county name, which a receiving logger cannot resolve: county names repeat across states, and there is a Washington County in thirty of them. The award engine here was never affected, since it reads the columns rather than the ADIF; the damage was to every file we hand to someone else. One writer covers everything — writeRecord — so this fixes file exports and the LoTW, Club Log, HRDLog and QRZ uploads together. MY_CNTY gets the same treatment. The county alone is still written when no state is known: a bare name is worth more than nothing, and inventing a prefix would be worse than either. A value that already carries a comma passes through untouched, so re-exporting an imported record cannot double the prefix. Import is the mirror: "GA,BARROW" fills both columns, and a file carrying the bare county — as OpsLog's own older exports do — still imports unchanged. The state parsed out of CNTY only fills a blank STATE, never overrides it: STATE is the dedicated field and the more specific statement.
This commit is contained in:
+4
-2
@@ -9,7 +9,8 @@
|
|||||||
"Entry form: a narrower left column, State beside the locator, and a new line with County, CQ, ITU and DXCC.",
|
"Entry form: a narrower left column, State beside the locator, and a new line with County, CQ, ITU and DXCC.",
|
||||||
"Station Control: the short and long path headings are repeated under the compass, at a readable size and clickable.",
|
"Station Control: the short and long path headings are repeated under the compass, at a readable size and clickable.",
|
||||||
"Compact mode: the window now fits the entry strip instead of leaving a band of empty space below it.",
|
"Compact mode: the window now fits the entry strip instead of leaving a band of empty space below it.",
|
||||||
"HRDLog: an ON AIR option publishes your live frequency, mode and rig on hrdlog.net."
|
"HRDLog: an ON AIR option publishes your live frequency, mode and rig on hrdlog.net.",
|
||||||
|
"ADIF: the county is exported as STATE,COUNTY as the standard requires, and a county imported that way now fills the state too."
|
||||||
],
|
],
|
||||||
"fr": [
|
"fr": [
|
||||||
"Cluster : « Masquer les contactés » ne masque plus un spot qui est un nouveau préfixe, comté, carré ou parc dans une contrée déjà faite.",
|
"Cluster : « Masquer les contactés » ne masque plus un spot qui est un nouveau préfixe, comté, carré ou parc dans une contrée déjà faite.",
|
||||||
@@ -18,7 +19,8 @@
|
|||||||
"Saisie : colonne de gauche plus étroite, État à côté du locator, et une nouvelle ligne Comté, CQ, ITU et DXCC.",
|
"Saisie : colonne de gauche plus étroite, État à côté du locator, et une nouvelle ligne Comté, CQ, ITU et DXCC.",
|
||||||
"Contrôle station : les azimuts court et long chemin sont repris sous la boussole, lisibles et cliquables.",
|
"Contrôle station : les azimuts court et long chemin sont repris sous la boussole, lisibles et cliquables.",
|
||||||
"Mode compact : la fenêtre épouse la bande de saisie au lieu de laisser une bande vide en dessous.",
|
"Mode compact : la fenêtre épouse la bande de saisie au lieu de laisser une bande vide en dessous.",
|
||||||
"HRDLog : une option ON AIR publie ta fréquence, ton mode et ta radio en direct sur hrdlog.net."
|
"HRDLog : une option ON AIR publie ta fréquence, ton mode et ta radio en direct sur hrdlog.net.",
|
||||||
|
"ADIF : le comté est exporté sous la forme ÉTAT,COMTÉ comme l exige le standard, et un comté importé ainsi remplit aussi l état."
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -0,0 +1,46 @@
|
|||||||
|
package adif
|
||||||
|
|
||||||
|
import "testing"
|
||||||
|
|
||||||
|
// ADIF defines CNTY as "STATE,COUNTY" — "GA,BARROW". OpsLog exported the bare
|
||||||
|
// county, which a receiving logger cannot resolve: county names repeat across
|
||||||
|
// states, and there is a Washington County in thirty of them.
|
||||||
|
func TestADIFCountyFormat(t *testing.T) {
|
||||||
|
for _, tc := range []struct{ state, county, want string }{
|
||||||
|
{"GA", "BARROW", "GA,BARROW"},
|
||||||
|
{"ga", "Barrow", "GA,Barrow"}, // the state is a code, upper-cased; the name is not touched
|
||||||
|
{"", "BARROW", "BARROW"}, // no state known: a bare name beats nothing
|
||||||
|
{"GA", "", ""}, // no county: nothing to write
|
||||||
|
{"GA", "GA,BARROW", "GA,BARROW"}, // already formatted — never double the prefix
|
||||||
|
{" GA ", " BARROW ", "GA,BARROW"},
|
||||||
|
} {
|
||||||
|
if got := adifCounty(tc.state, tc.county); got != tc.want {
|
||||||
|
t.Errorf("adifCounty(%q, %q) = %q, want %q", tc.state, tc.county, got, tc.want)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// And the mirror: a file from a logger that follows the standard must fill both
|
||||||
|
// columns, while a file carrying the bare county still imports unchanged.
|
||||||
|
func TestSplitADIFCounty(t *testing.T) {
|
||||||
|
for _, tc := range []struct{ in, county, state string }{
|
||||||
|
{"GA,BARROW", "BARROW", "GA"},
|
||||||
|
{"ga, Barrow", "Barrow", "GA"},
|
||||||
|
{"BARROW", "BARROW", ""}, // the old OpsLog form, and many other loggers
|
||||||
|
{"", "", ""},
|
||||||
|
{" ", "", ""},
|
||||||
|
} {
|
||||||
|
c, s := splitADIFCounty(tc.in)
|
||||||
|
if c != tc.county || s != tc.state {
|
||||||
|
t.Errorf("splitADIFCounty(%q) = (%q, %q), want (%q, %q)", tc.in, c, s, tc.county, tc.state)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Round trip: what OpsLog writes, OpsLog reads back to the same two values.
|
||||||
|
func TestCountyRoundTrip(t *testing.T) {
|
||||||
|
c, s := splitADIFCounty(adifCounty("GA", "BARROW"))
|
||||||
|
if c != "BARROW" || s != "GA" {
|
||||||
|
t.Errorf("round trip gave (%q, %q), want (BARROW, GA)", c, s)
|
||||||
|
}
|
||||||
|
}
|
||||||
+24
-2
@@ -221,7 +221,7 @@ func writeRecord(bw *bufio.Writer, q qso.QSO, includeApp bool, allow map[string]
|
|||||||
w("VUCC_GRIDS", q.VUCCGrids)
|
w("VUCC_GRIDS", q.VUCCGrids)
|
||||||
w("COUNTRY", q.Country)
|
w("COUNTRY", q.Country)
|
||||||
w("STATE", q.State)
|
w("STATE", q.State)
|
||||||
w("CNTY", q.County)
|
w("CNTY", adifCounty(q.State, q.County))
|
||||||
wi("DXCC", q.DXCC)
|
wi("DXCC", q.DXCC)
|
||||||
w("CONT", q.Continent)
|
w("CONT", q.Continent)
|
||||||
wi("CQZ", q.CQZ)
|
wi("CQZ", q.CQZ)
|
||||||
@@ -285,7 +285,7 @@ func writeRecord(bw *bufio.Writer, q qso.QSO, includeApp bool, allow map[string]
|
|||||||
w("MY_GRIDSQUARE_EXT", q.MyGridExt)
|
w("MY_GRIDSQUARE_EXT", q.MyGridExt)
|
||||||
w("MY_COUNTRY", q.MyCountry)
|
w("MY_COUNTRY", q.MyCountry)
|
||||||
w("MY_STATE", q.MyState)
|
w("MY_STATE", q.MyState)
|
||||||
w("MY_CNTY", q.MyCounty)
|
w("MY_CNTY", adifCounty(q.MyState, q.MyCounty))
|
||||||
w("MY_IOTA", q.MyIOTA)
|
w("MY_IOTA", q.MyIOTA)
|
||||||
w("MY_SOTA_REF", q.MySOTARef)
|
w("MY_SOTA_REF", q.MySOTARef)
|
||||||
w("MY_POTA_REF", q.MyPOTARef)
|
w("MY_POTA_REF", q.MyPOTARef)
|
||||||
@@ -413,3 +413,25 @@ func modeForExport(mode, submode string) (string, string) {
|
|||||||
}
|
}
|
||||||
return mode, ""
|
return mode, ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// adifCounty renders CNTY the way ADIF specifies: "STATE,COUNTY", e.g.
|
||||||
|
// "GA,BARROW".
|
||||||
|
//
|
||||||
|
// OpsLog stores the two apart, and exported only the county — which a receiving
|
||||||
|
// logger cannot resolve, since county names repeat across states (there is a
|
||||||
|
// Washington County in thirty of them). The award engine here was never
|
||||||
|
// affected because it reads the columns, not the ADIF; the damage was to
|
||||||
|
// everyone we send a file to.
|
||||||
|
//
|
||||||
|
// The county alone is still written when no state is known: a bare name is
|
||||||
|
// worth more than nothing, and inventing a prefix would be worse than either.
|
||||||
|
// A county that ALREADY carries a comma is passed through — it has been
|
||||||
|
// formatted once, and doubling the prefix would corrupt it.
|
||||||
|
func adifCounty(state, county string) string {
|
||||||
|
c := strings.TrimSpace(county)
|
||||||
|
s := strings.TrimSpace(state)
|
||||||
|
if c == "" || s == "" || strings.Contains(c, ",") {
|
||||||
|
return c
|
||||||
|
}
|
||||||
|
return strings.ToUpper(s) + "," + c
|
||||||
|
}
|
||||||
|
|||||||
+29
-2
@@ -428,7 +428,12 @@ func recordToQSO(rec Record) (qso.QSO, bool) {
|
|||||||
q.VUCCGrids = strings.ToUpper(rec["vucc_grids"])
|
q.VUCCGrids = strings.ToUpper(rec["vucc_grids"])
|
||||||
q.Country = rec["country"]
|
q.Country = rec["country"]
|
||||||
q.State = strings.ToUpper(rec["state"])
|
q.State = strings.ToUpper(rec["state"])
|
||||||
q.County = rec["cnty"]
|
q.County, _ = splitADIFCounty(rec["cnty"])
|
||||||
|
if st := rec["state"]; strings.TrimSpace(st) == "" {
|
||||||
|
if _, fromCnty := splitADIFCounty(rec["cnty"]); fromCnty != "" {
|
||||||
|
q.State = fromCnty
|
||||||
|
}
|
||||||
|
}
|
||||||
if v, ok := parseInt(rec["dxcc"]); ok {
|
if v, ok := parseInt(rec["dxcc"]); ok {
|
||||||
q.DXCC = &v
|
q.DXCC = &v
|
||||||
}
|
}
|
||||||
@@ -515,7 +520,12 @@ func recordToQSO(rec Record) (qso.QSO, bool) {
|
|||||||
q.MyGridExt = strings.ToUpper(rec["my_gridsquare_ext"])
|
q.MyGridExt = strings.ToUpper(rec["my_gridsquare_ext"])
|
||||||
q.MyCountry = rec["my_country"]
|
q.MyCountry = rec["my_country"]
|
||||||
q.MyState = strings.ToUpper(rec["my_state"])
|
q.MyState = strings.ToUpper(rec["my_state"])
|
||||||
q.MyCounty = rec["my_cnty"]
|
q.MyCounty, _ = splitADIFCounty(rec["my_cnty"])
|
||||||
|
if st := rec["my_state"]; strings.TrimSpace(st) == "" {
|
||||||
|
if _, fromCnty := splitADIFCounty(rec["my_cnty"]); fromCnty != "" {
|
||||||
|
q.MyState = fromCnty
|
||||||
|
}
|
||||||
|
}
|
||||||
q.MyIOTA = strings.ToUpper(rec["my_iota"])
|
q.MyIOTA = strings.ToUpper(rec["my_iota"])
|
||||||
q.MySOTARef = strings.ToUpper(rec["my_sota_ref"])
|
q.MySOTARef = strings.ToUpper(rec["my_sota_ref"])
|
||||||
q.MyPOTARef = strings.ToUpper(rec["my_pota_ref"])
|
q.MyPOTARef = strings.ToUpper(rec["my_pota_ref"])
|
||||||
@@ -698,3 +708,20 @@ var promotableSubmodes = map[string]bool{
|
|||||||
func submodeSubsumesParent(submode string) bool {
|
func submodeSubsumesParent(submode string) bool {
|
||||||
return promotableSubmodes[submode]
|
return promotableSubmodes[submode]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// splitADIFCounty reads CNTY, which ADIF defines as "STATE,COUNTY".
|
||||||
|
//
|
||||||
|
// Returns the county on its own plus the state the field carried, so an import
|
||||||
|
// from a logger that follows the standard fills BOTH columns here. Files that
|
||||||
|
// write the bare county — as OpsLog itself used to — still import unchanged.
|
||||||
|
//
|
||||||
|
// The state from the field never overrides an explicit STATE tag: STATE is the
|
||||||
|
// dedicated field and the more specific statement. It only fills a blank.
|
||||||
|
func splitADIFCounty(cnty string) (county, state string) {
|
||||||
|
cnty = strings.TrimSpace(cnty)
|
||||||
|
i := strings.Index(cnty, ",")
|
||||||
|
if i < 0 {
|
||||||
|
return cnty, ""
|
||||||
|
}
|
||||||
|
return strings.TrimSpace(cnty[i+1:]), strings.ToUpper(strings.TrimSpace(cnty[:i]))
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user