fixed Band Parsing

pull/2/head
Jean-Marc MEESSEN 4 years ago
parent 6cef57acba
commit 4fdbb50aca

@ -0,0 +1,18 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Launch",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${fileDirname}",
"env": {},
"args": []
}
]
}

@ -33,6 +33,8 @@ type LogLine struct {
Nickname string Nickname string
Mode string Mode string
Band string Band string
BandLowerLimit float32
BandUpperLimit float32
Frequency string Frequency string
Time string Time string
Call string Call string
@ -107,8 +109,11 @@ func ParseLine(inputStr string, previousLine LogLine) (logLine LogLine, errorMsg
} }
// Is it a band? // Is it a band?
if regexpIsBand.MatchString(element) { isBandElement, bandLowerLimit, bandUpperLimit := IsBand(element)
logLine.Band = element if isBandElement {
logLine.Band = strings.ToLower(element)
logLine.BandLowerLimit = bandLowerLimit
logLine.BandUpperLimit = bandUpperLimit
continue continue
} }
@ -184,6 +189,8 @@ func SprintLogRecord(logLine LogLine) (output string){
output = output + "Nickname " + logLine.Nickname + "\n" output = output + "Nickname " + logLine.Nickname + "\n"
output = output + "Mode " + logLine.Mode + "\n" output = output + "Mode " + logLine.Mode + "\n"
output = output + "Band " + logLine.Band + "\n" output = output + "Band " + logLine.Band + "\n"
output = output + " Lower " + fmt.Sprintf("%f", logLine.BandLowerLimit) + "\n"
output = output + " Upper " + fmt.Sprintf("%f", logLine.BandLowerLimit) + "\n"
output = output + "Frequency " + logLine.Frequency + "\n" output = output + "Frequency " + logLine.Frequency + "\n"
output = output + "Time " + logLine.Time + "\n" output = output + "Time " + logLine.Time + "\n"
output = output + "Call " + logLine.Call + "\n" output = output + "Call " + logLine.Call + "\n"
@ -258,51 +265,3 @@ func lookupMode(lookup string) bool {
// func lookupBand(lookup string) bool {
// switch lookup {
// case
// "900898296857",
// "900898302052",
// "900898296492",
// "900898296850",
// "900898296703",
// "900898296633",
// "900898296613",
// "900898296615",
// "900898296620",
// "900898296636":
// return true
// }
// return false
// }
// 2190m .1357 .1378
// 630m .472 .479
// 560m .501 .504
// 160m 1.8 2.0
// 80m 3.5 4.0
// 60m 5.06 5.45
// 40m 7.0 7.3
// 30m 10.1 10.15
// 20m 14.0 14.35
// 17m 18.068 18.168
// 15m 21.0 21.45
// 12m 24.890 24.99
// 10m 28.0 29.7
// 6m 50 54
// 4m 70 71
// 2m 144 148
// 1.25m 222 225
// 70cm 420 450
// 33cm 902 928
// 23cm 1240 1300
// 13cm 2300 2450
// 9cm 3300 3500
// 6cm 5650 5925
// 3cm 10000 10500
// 1.25cm 24000 24250
// 6mm 47000 47200
// 4mm 75500 81000
// 2.5mm 119980 120020
// 2mm 142000 149000
// 1mm 241000 250000

@ -19,8 +19,8 @@ func TestParseLine(t *testing.T) {
}{ }{
{ {
"Parse band and mode only", "Parse band and mode only",
args{ inputStr: "40m cw", previousLine: LogLine{ Mode: "SSB", }}, args{ inputStr: "40M cw", previousLine: LogLine{ Mode: "SSB", }},
LogLine{ Band: "40m", Mode: "CW", RSTsent: "599", RSTrcvd: "599"}, "", LogLine{ Band: "40m", BandLowerLimit: 7, BandUpperLimit: 7.3, Mode: "CW", RSTsent: "599", RSTrcvd: "599"}, "",
}, },
{ {
"Parse for time", "Parse for time",

@ -113,3 +113,71 @@ func ValidateDate(inputStr string) (ref, errorMsg string) {
return wrongInputStr, fmt.Sprint(err) return wrongInputStr, fmt.Sprint(err)
} }
//IsBand retuns true if the passed input string is a valid string
//TODO: return the frequencies
func IsBand(inputStr string) (result bool, lowerLimit, upperLimit float32) {
switch strings.ToLower(inputStr) {
case "2190m":
return true, 0.1357, 0.1378
case "630m":
return true, 0.472, 0.479
case "560m":
return true, 0.501, 0.504
case "160m":
return true, 1.8, 2.0
case "80m":
return true, 3.5, 4.0
case "60m":
return true, 5.06, 5.45
case "40m":
return true, 7.0, 7.3
case "30m":
return true, 10.1, 10.15
case "20m":
return true, 14.0, 14.35
case "17m":
return true, 18.068, 18.168
case "15m":
return true, 21.0, 21.45
case "12m":
return true, 24.890, 24.99
case "10m":
return true, 28.0, 29.7
case "6m":
return true, 50, 54
case "4m":
return true, 70, 71
case "2m":
return true, 144, 148
case "1.25m":
return true, 222, 225
case "70cm":
return true, 420, 450
case "33cm":
return true, 902, 928
case "23cm":
return true, 1240, 1300
case "13cm":
return true, 2300, 2450
case "9cm":
return true, 3300, 3500
case "6cm":
return true, 5650, 5925
case "3cm":
return true, 10000, 10500
case "1.25cm":
return true, 24000, 24250
case "6mm":
return true, 47000, 47200
case "4mm":
return true, 75500, 81000
case "2.5mm":
return true, 119980, 120020
case "2mm":
return true, 142000, 149000
case "1mm":
return true, 241000, 250000
}
return false, 0, 0
}

@ -1,6 +1,8 @@
package cmd package cmd
import "testing" import (
"testing"
)
func TestValidateWwff(t *testing.T) { func TestValidateWwff(t *testing.T) {
type args struct { type args struct {
@ -14,40 +16,39 @@ func TestValidateWwff(t *testing.T) {
}{ }{
{ {
"Good ref (simple)", "Good ref (simple)",
args{ inputStr: "onff-0258", }, args{inputStr: "onff-0258"},
"ONFF-0258", "", "ONFF-0258", "",
}, },
{ {
"Good ref (single digit country)", "Good ref (single digit country)",
args{ inputStr: "fff-0258", }, args{inputStr: "fff-0258"},
"FFF-0258", "", "FFF-0258", "",
}, },
{ {
"Good ref (Numerical country)", "Good ref (Numerical country)",
args{ inputStr: "4xff-0258", }, args{inputStr: "4xff-0258"},
"4XFF-0258", "", "4XFF-0258", "",
}, },
{ {
"Bad ref (no country prefix)", "Bad ref (no country prefix)",
args{ inputStr: "ff-0258", }, args{inputStr: "ff-0258"},
"*FF-0258", "Invalid WWFF reference", "*FF-0258", "Invalid WWFF reference",
}, },
{ {
"Bad ref (wrong separator)", "Bad ref (wrong separator)",
args{ inputStr: "gff/0258", }, args{inputStr: "gff/0258"},
"*GFF/0258", "Invalid WWFF reference", "*GFF/0258", "Invalid WWFF reference",
}, },
{ {
"Bad ref (reference too short)", "Bad ref (reference too short)",
args{ inputStr: "onff-258", }, args{inputStr: "onff-258"},
"*ONFF-258", "Invalid WWFF reference", "*ONFF-258", "Invalid WWFF reference",
}, },
{ {
"Bad ref (no country prefix)", "Bad ref (no country prefix)",
args{ inputStr: "onff-02589", }, args{inputStr: "onff-02589"},
"*ONFF-02589", "Invalid WWFF reference", "*ONFF-02589", "Invalid WWFF reference",
}, },
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
@ -74,57 +75,57 @@ func TestValidateSota(t *testing.T) {
}{ }{
{ {
"Good ref (simple)", "Good ref (simple)",
args{ inputStr: "on/ON-001", }, args{inputStr: "on/ON-001"},
"ON/ON-001", "", "ON/ON-001", "",
}, },
{ {
"Good ref (single digit prefix)", "Good ref (single digit prefix)",
args{ inputStr: "g/ON-001", }, args{inputStr: "g/ON-001"},
"G/ON-001", "", "G/ON-001", "",
}, },
{ {
"Good ref (numerical prefix)", "Good ref (numerical prefix)",
args{ inputStr: "4x/ON-001", }, args{inputStr: "4x/ON-001"},
"4X/ON-001", "", "4X/ON-001", "",
}, },
{ {
"Good ref (american style)", "Good ref (american style)",
args{ inputStr: "w4z/ON-001", }, args{inputStr: "w4z/ON-001"},
"W4Z/ON-001", "", "W4Z/ON-001", "",
}, },
{ {
"Bad ref (long prefix)", "Bad ref (long prefix)",
args{ inputStr: "xxxx/ON-001", }, args{inputStr: "xxxx/ON-001"},
"*XXXX/ON-001", "Invalid SOTA reference", "*XXXX/ON-001", "Invalid SOTA reference",
}, },
{ {
"Bad ref (missing slash)", "Bad ref (missing slash)",
args{ inputStr: "on ON-001", }, args{inputStr: "on ON-001"},
"*ON ON-001", "Invalid SOTA reference", "*ON ON-001", "Invalid SOTA reference",
}, },
{ {
"Bad ref (numerical region)", "Bad ref (numerical region)",
args{ inputStr: "on/9N-001", }, args{inputStr: "on/9N-001"},
"*ON/9N-001", "Invalid SOTA reference", "*ON/9N-001", "Invalid SOTA reference",
}, },
{ {
"Bad ref (too long region)", "Bad ref (too long region)",
args{ inputStr: "on/ONA-001", }, args{inputStr: "on/ONA-001"},
"*ON/ONA-001", "Invalid SOTA reference", "*ON/ONA-001", "Invalid SOTA reference",
}, },
{ {
"Bad ref (no dash)", "Bad ref (no dash)",
args{ inputStr: "on/ON/001", }, args{inputStr: "on/ON/001"},
"*ON/ON/001", "Invalid SOTA reference", "*ON/ON/001", "Invalid SOTA reference",
}, },
{ {
"Bad ref (number too short)", "Bad ref (number too short)",
args{ inputStr: "on/ON-01", }, args{inputStr: "on/ON-01"},
"*ON/ON-01", "Invalid SOTA reference", "*ON/ON-01", "Invalid SOTA reference",
}, },
{ {
"Bad ref (Number too long)", "Bad ref (Number too long)",
args{ inputStr: "on/ON-9001", }, args{inputStr: "on/ON-9001"},
"*ON/ON-9001", "Invalid SOTA reference", "*ON/ON-9001", "Invalid SOTA reference",
}, },
} }
@ -147,69 +148,69 @@ func TestValidateCall(t *testing.T) {
} }
tests := []struct { tests := []struct {
name string name string
args args args args
wantCall string wantCall string
wantErrorMsg string wantErrorMsg string
}{ }{
{ {
"Good call (simple)", "Good call (simple)",
args{ sign: "on4kjm", }, args{sign: "on4kjm"},
"ON4KJM", "", "ON4KJM", "",
}, },
{ {
"Good call (suffix)", "Good call (suffix)",
args{ sign: "on4kjm/p", }, args{sign: "on4kjm/p"},
"ON4KJM/P", "", "ON4KJM/P", "",
}, },
{ {
"Good call (prefix only)", "Good call (prefix only)",
args{ sign: "DL/on4KJm", }, args{sign: "DL/on4KJm"},
"DL/ON4KJM", "", "DL/ON4KJM", "",
}, },
{ {
"Good call (prefix and suffix)", "Good call (prefix and suffix)",
args{ sign: "DL/on4KJm/p", }, args{sign: "DL/on4KJm/p"},
"DL/ON4KJM/P", "", "DL/ON4KJM/P", "",
}, },
{ {
"Good call (Numerical prefix)", "Good call (Numerical prefix)",
args{ sign: "4x/on4KJm/p", }, args{sign: "4x/on4KJm/p"},
"4X/ON4KJM/P", "", "4X/ON4KJM/P", "",
}, },
{ {
"Good call (prefix and long suffix)", "Good call (prefix and long suffix)",
args{ sign: "DL/on4KJm/qrpp ", }, args{sign: "DL/on4KJm/qrpp "},
"DL/ON4KJM/QRPP", "", "DL/ON4KJM/QRPP", "",
}, },
//Error cases //Error cases
{ {
"Pure junk passed", "Pure junk passed",
args{ sign: "aaaaaa", }, args{sign: "aaaaaa"},
"*AAAAAA", "Invalid call", "*AAAAAA", "Invalid call",
}, },
{ {
"empty string", "empty string",
args{ sign: "", }, args{sign: ""},
"*", "Invalid call", "*", "Invalid call",
}, },
{ {
"string with spaces", "string with spaces",
args{ sign: " ", }, args{sign: " "},
"*", "Invalid call", "*", "Invalid call",
}, },
{ {
"invalid prefix", "invalid prefix",
args{ sign: "xyz/on4kjm", }, args{sign: "xyz/on4kjm"},
"*XYZ/ON4KJM", "Invalid prefix", "*XYZ/ON4KJM", "Invalid prefix",
}, },
{ {
"Too many /", "Too many /",
args{ sign: "F/on4kjm/p/x", }, args{sign: "F/on4kjm/p/x"},
"*F/ON4KJM/P/X", "Too many '/'", "*F/ON4KJM/P/X", "Too many '/'",
}, },
{ {
"signe /", "signe /",
args{ sign: "/", }, args{sign: "/"},
"*/", "Invalid call", "*/", "Invalid call",
}, },
} }
@ -238,7 +239,7 @@ func TestValidateDate(t *testing.T) {
}{ }{
{ {
"Good date (simple)", "Good date (simple)",
args{ inputStr: "2020-06-10", }, args{inputStr: "2020-06-10"},
"2020-06-10", "", "2020-06-10", "",
}, },
// { // {
@ -248,10 +249,9 @@ func TestValidateDate(t *testing.T) {
// }, // },
{ {
"Bad date (simple)", "Bad date (simple)",
args{ inputStr: "2020-13-10", }, args{inputStr: "2020-13-10"},
"*2020-13-10", "parsing time \"2020-13-10\": month out of range", "*2020-13-10", "parsing time \"2020-13-10\": month out of range",
}, },
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
@ -265,3 +265,46 @@ func TestValidateDate(t *testing.T) {
}) })
} }
} }
func TestIsBand(t *testing.T) {
type args struct {
inputStr string
}
tests := []struct {
name string
args args
wantResult bool
wantLowerLimit float32
wantUpperLimit float32
}{
{
"invalid band",
args{inputStr: "zzzz"},
false, 0, 0,
},
{
"valid band",
args{inputStr: "40m"},
true, 7.0, 7.3,
},
{
"valid band but uppercase",
args{inputStr: "40M"},
true, 7.0, 7.3,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
gotResult, gotLowerLimit, gotUpperLimit := IsBand(tt.args.inputStr)
if gotResult != tt.wantResult {
t.Errorf("IsBand() gotResult = %v, want %v", gotResult, tt.wantResult)
}
if gotLowerLimit != tt.wantLowerLimit {
t.Errorf("IsBand() gotLowerLimit = %v, want %v", gotLowerLimit, tt.wantLowerLimit)
}
if gotUpperLimit != tt.wantUpperLimit {
t.Errorf("IsBand() gotUpperLimit = %v, want %v", gotUpperLimit, tt.wantUpperLimit)
}
})
}
}

Loading…
Cancel
Save