diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..5d07c42 --- /dev/null +++ b/.vscode/launch.json @@ -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": [] + } + ] +} \ No newline at end of file diff --git a/cmd/parse_line.go b/cmd/parse_line.go index 91320a4..c9f9362 100644 --- a/cmd/parse_line.go +++ b/cmd/parse_line.go @@ -33,6 +33,8 @@ type LogLine struct { Nickname string Mode string Band string + BandLowerLimit float32 + BandUpperLimit float32 Frequency string Time string Call string @@ -107,8 +109,11 @@ func ParseLine(inputStr string, previousLine LogLine) (logLine LogLine, errorMsg } // Is it a band? - if regexpIsBand.MatchString(element) { - logLine.Band = element + isBandElement, bandLowerLimit, bandUpperLimit := IsBand(element) + if isBandElement { + logLine.Band = strings.ToLower(element) + logLine.BandLowerLimit = bandLowerLimit + logLine.BandUpperLimit = bandUpperLimit continue } @@ -184,6 +189,8 @@ func SprintLogRecord(logLine LogLine) (output string){ output = output + "Nickname " + logLine.Nickname + "\n" output = output + "Mode " + logLine.Mode + "\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 + "Time " + logLine.Time + "\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 \ No newline at end of file diff --git a/cmd/parse_line_test.go b/cmd/parse_line_test.go index cf9d041..2c3600d 100644 --- a/cmd/parse_line_test.go +++ b/cmd/parse_line_test.go @@ -19,8 +19,8 @@ func TestParseLine(t *testing.T) { }{ { "Parse band and mode only", - args{ inputStr: "40m cw", previousLine: LogLine{ Mode: "SSB", }}, - LogLine{ Band: "40m", Mode: "CW", RSTsent: "599", RSTrcvd: "599"}, "", + args{ inputStr: "40M cw", previousLine: LogLine{ Mode: "SSB", }}, + LogLine{ Band: "40m", BandLowerLimit: 7, BandUpperLimit: 7.3, Mode: "CW", RSTsent: "599", RSTrcvd: "599"}, "", }, { "Parse for time", diff --git a/cmd/validate.go b/cmd/validate.go index 13aa094..be516b7 100644 --- a/cmd/validate.go +++ b/cmd/validate.go @@ -112,4 +112,72 @@ func ValidateDate(inputStr string) (ref, errorMsg string) { } 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 } \ No newline at end of file diff --git a/cmd/validate_test.go b/cmd/validate_test.go index 3de8969..234e71b 100644 --- a/cmd/validate_test.go +++ b/cmd/validate_test.go @@ -1,6 +1,8 @@ package cmd -import "testing" +import ( + "testing" +) func TestValidateWwff(t *testing.T) { type args struct { @@ -13,41 +15,40 @@ func TestValidateWwff(t *testing.T) { wantErrorMsg string }{ { - "Good ref (simple)", - args{ inputStr: "onff-0258", }, + "Good ref (simple)", + args{inputStr: "onff-0258"}, "ONFF-0258", "", }, { - "Good ref (single digit country)", - args{ inputStr: "fff-0258", }, + "Good ref (single digit country)", + args{inputStr: "fff-0258"}, "FFF-0258", "", }, { - "Good ref (Numerical country)", - args{ inputStr: "4xff-0258", }, + "Good ref (Numerical country)", + args{inputStr: "4xff-0258"}, "4XFF-0258", "", }, { - "Bad ref (no country prefix)", - args{ inputStr: "ff-0258", }, + "Bad ref (no country prefix)", + args{inputStr: "ff-0258"}, "*FF-0258", "Invalid WWFF reference", }, { - "Bad ref (wrong separator)", - args{ inputStr: "gff/0258", }, + "Bad ref (wrong separator)", + args{inputStr: "gff/0258"}, "*GFF/0258", "Invalid WWFF reference", }, { - "Bad ref (reference too short)", - args{ inputStr: "onff-258", }, + "Bad ref (reference too short)", + args{inputStr: "onff-258"}, "*ONFF-258", "Invalid WWFF reference", }, { - "Bad ref (no country prefix)", - args{ inputStr: "onff-02589", }, + "Bad ref (no country prefix)", + args{inputStr: "onff-02589"}, "*ONFF-02589", "Invalid WWFF reference", }, - } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { @@ -73,60 +74,60 @@ func TestValidateSota(t *testing.T) { wantErrorMsg string }{ { - "Good ref (simple)", - args{ inputStr: "on/ON-001", }, + "Good ref (simple)", + args{inputStr: "on/ON-001"}, "ON/ON-001", "", }, { - "Good ref (single digit prefix)", - args{ inputStr: "g/ON-001", }, + "Good ref (single digit prefix)", + args{inputStr: "g/ON-001"}, "G/ON-001", "", }, { - "Good ref (numerical prefix)", - args{ inputStr: "4x/ON-001", }, + "Good ref (numerical prefix)", + args{inputStr: "4x/ON-001"}, "4X/ON-001", "", - }, + }, { - "Good ref (american style)", - args{ inputStr: "w4z/ON-001", }, + "Good ref (american style)", + args{inputStr: "w4z/ON-001"}, "W4Z/ON-001", "", - }, + }, { - "Bad ref (long prefix)", - args{ inputStr: "xxxx/ON-001", }, + "Bad ref (long prefix)", + args{inputStr: "xxxx/ON-001"}, "*XXXX/ON-001", "Invalid SOTA reference", - }, + }, { - "Bad ref (missing slash)", - args{ inputStr: "on ON-001", }, + "Bad ref (missing slash)", + args{inputStr: "on ON-001"}, "*ON ON-001", "Invalid SOTA reference", - }, + }, { - "Bad ref (numerical region)", - args{ inputStr: "on/9N-001", }, + "Bad ref (numerical region)", + args{inputStr: "on/9N-001"}, "*ON/9N-001", "Invalid SOTA reference", - }, + }, { - "Bad ref (too long region)", - args{ inputStr: "on/ONA-001", }, + "Bad ref (too long region)", + args{inputStr: "on/ONA-001"}, "*ON/ONA-001", "Invalid SOTA reference", - }, + }, { - "Bad ref (no dash)", - args{ inputStr: "on/ON/001", }, + "Bad ref (no dash)", + args{inputStr: "on/ON/001"}, "*ON/ON/001", "Invalid SOTA reference", - }, + }, { - "Bad ref (number too short)", - args{ inputStr: "on/ON-01", }, + "Bad ref (number too short)", + args{inputStr: "on/ON-01"}, "*ON/ON-01", "Invalid SOTA reference", - }, + }, { - "Bad ref (Number too long)", - args{ inputStr: "on/ON-9001", }, + "Bad ref (Number too long)", + args{inputStr: "on/ON-9001"}, "*ON/ON-9001", "Invalid SOTA reference", - }, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { @@ -147,69 +148,69 @@ func TestValidateCall(t *testing.T) { } tests := []struct { name string - args args + args args wantCall string wantErrorMsg string }{ { - "Good call (simple)", - args{ sign: "on4kjm", }, + "Good call (simple)", + args{sign: "on4kjm"}, "ON4KJM", "", }, { - "Good call (suffix)", - args{ sign: "on4kjm/p", }, + "Good call (suffix)", + args{sign: "on4kjm/p"}, "ON4KJM/P", "", }, { - "Good call (prefix only)", - args{ sign: "DL/on4KJm", }, + "Good call (prefix only)", + args{sign: "DL/on4KJm"}, "DL/ON4KJM", "", }, { - "Good call (prefix and suffix)", - args{ sign: "DL/on4KJm/p", }, + "Good call (prefix and suffix)", + args{sign: "DL/on4KJm/p"}, "DL/ON4KJM/P", "", }, { - "Good call (Numerical prefix)", - args{ sign: "4x/on4KJm/p", }, + "Good call (Numerical prefix)", + args{sign: "4x/on4KJm/p"}, "4X/ON4KJM/P", "", }, { - "Good call (prefix and long suffix)", - args{ sign: "DL/on4KJm/qrpp ", }, + "Good call (prefix and long suffix)", + args{sign: "DL/on4KJm/qrpp "}, "DL/ON4KJM/QRPP", "", }, //Error cases { - "Pure junk passed", - args{ sign: "aaaaaa", }, + "Pure junk passed", + args{sign: "aaaaaa"}, "*AAAAAA", "Invalid call", }, { - "empty string", - args{ sign: "", }, + "empty string", + args{sign: ""}, "*", "Invalid call", }, { - "string with spaces", - args{ sign: " ", }, + "string with spaces", + args{sign: " "}, "*", "Invalid call", - }, + }, { - "invalid prefix", - args{ sign: "xyz/on4kjm", }, + "invalid prefix", + args{sign: "xyz/on4kjm"}, "*XYZ/ON4KJM", "Invalid prefix", }, { - "Too many /", - args{ sign: "F/on4kjm/p/x", }, + "Too many /", + args{sign: "F/on4kjm/p/x"}, "*F/ON4KJM/P/X", "Too many '/'", }, { - "signe /", - args{ sign: "/", }, + "signe /", + args{sign: "/"}, "*/", "Invalid call", }, } @@ -237,21 +238,20 @@ func TestValidateDate(t *testing.T) { wantErrorMsg string }{ { - "Good date (simple)", - args{ inputStr: "2020-06-10", }, + "Good date (simple)", + args{inputStr: "2020-06-10"}, "2020-06-10", "", }, // { - // "Good date (extrapolate, different delimiter)", - // args{ inputStr: "16-2-1", }, + // "Good date (extrapolate, different delimiter)", + // args{ inputStr: "16-2-1", }, // "2020-06-10", "", // }, { - "Bad date (simple)", - args{ inputStr: "2020-13-10", }, + "Bad date (simple)", + args{inputStr: "2020-13-10"}, "*2020-13-10", "parsing time \"2020-13-10\": month out of range", }, - } for _, tt := range tests { 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) + } + }) + } +}