From fe7836fdb52e3619fbeba74e07e0e96044b98bf2 Mon Sep 17 00:00:00 2001 From: Jean-Marc MEESSEN Date: Sun, 5 Dec 2021 15:54:39 +0100 Subject: [PATCH] QRG rounding (#75) * support frequency up to the 100hz while default resolution is to the Khz --- fleprocess/adif_process_test.go | 27 +++++++++++++-------------- fleprocess/adif_write_test.go | 17 ++++++++--------- fleprocess/parse_line.go | 17 +++++++++++++---- fleprocess/parse_line_test.go | 5 +++++ test/data/sample_pota.txt | 2 +- test/output/POTA/sample_pota.adif | 6 +++--- 6 files changed, 43 insertions(+), 31 deletions(-) diff --git a/fleprocess/adif_process_test.go b/fleprocess/adif_process_test.go index 7d4609d..520cc00 100644 --- a/fleprocess/adif_process_test.go +++ b/fleprocess/adif_process_test.go @@ -70,7 +70,7 @@ func Test_validateDataforAdif2(t *testing.T) { }, }, fmt.Errorf("missing MyCall"), - }, + }, { "Missing MySota", args{ @@ -150,7 +150,6 @@ func Test_validateDataforAdif2(t *testing.T) { } } - func TestProcessAdifCommand(t *testing.T) { type args struct { adifParams AdifParams @@ -164,10 +163,10 @@ func TestProcessAdifCommand(t *testing.T) { "Bad output filename (directory)", args{ adifParams: AdifParams{ - InputFilename: "../test/data/fle-4-no-qso.txt", - OutputFilename: "../test/data", + InputFilename: "../test/data/fle-4-no-qso.txt", + OutputFilename: "../test/data", IsInterpolateTime: false, - IsOverwrite: false, + IsOverwrite: false, }, }, true, @@ -176,10 +175,10 @@ func TestProcessAdifCommand(t *testing.T) { "input file parsing errors (missing band)", args{ adifParams: AdifParams{ - InputFilename: "../test/data/fle-3-error.txt", - OutputFilename: "", + InputFilename: "../test/data/fle-3-error.txt", + OutputFilename: "", IsInterpolateTime: false, - IsOverwrite: false, + IsOverwrite: false, }, }, true, @@ -188,10 +187,10 @@ func TestProcessAdifCommand(t *testing.T) { "input file parsing errors (wrong call)", args{ adifParams: AdifParams{ - InputFilename: "../test/data/fle-5-wrong-call.txt", - OutputFilename: "", + InputFilename: "../test/data/fle-5-wrong-call.txt", + OutputFilename: "", IsInterpolateTime: false, - IsOverwrite: false, + IsOverwrite: false, }, }, true, @@ -200,10 +199,10 @@ func TestProcessAdifCommand(t *testing.T) { "No QSO in loaded file", args{ adifParams: AdifParams{ - InputFilename: "../test/data/fle-4-no-qso.txt", - OutputFilename: "", + InputFilename: "../test/data/fle-4-no-qso.txt", + OutputFilename: "", IsInterpolateTime: false, - IsOverwrite: false, + IsOverwrite: false, }, }, true, diff --git a/fleprocess/adif_write_test.go b/fleprocess/adif_write_test.go index 193e721..bd27398 100644 --- a/fleprocess/adif_write_test.go +++ b/fleprocess/adif_write_test.go @@ -108,7 +108,6 @@ func Test_buildAdif(t *testing.T) { "ON4KJM/P ON4LY 20200524 1312 20m CW 559 599 POTA ON-00259 ON4KJM ", } - sampleFilledLogPOTA2 := []LogLine{ {MyCall: "ON4KJM/P", Call: "S57LC", Date: "2020-05-24", MyGrid: "JO40eu", Time: "1310", Band: "20m", Frequency: "14.045", Mode: "CW", RSTsent: "599", RSTrcvd: "599", GridLoc: "JO50", MyPOTA: "ON-00259", Operator: "ON4KJM", Nickname: "ON-00259-1"}, {MyCall: "ON4KJM/P", Call: "ON4LY", Date: "2020-05-24", MyGrid: "JO40eu", Time: "1312", Band: "20m", Mode: "CW", RSTsent: "559", RSTrcvd: "599", MyPOTA: "ON-00259", Operator: "ON4KJM", POTA: "DL-00001"}, @@ -124,7 +123,7 @@ func Test_buildAdif(t *testing.T) { } type args struct { - fullLog []LogLine + fullLog []LogLine adifParams AdifParams } tests := []struct { @@ -135,30 +134,30 @@ func Test_buildAdif(t *testing.T) { { "Happy case-WWFF", args{ - fullLog: sampleFilledLog1, + fullLog: sampleFilledLog1, adifParams: AdifParams{IsWWFF: true, IsSOTA: false}, }, expectedOutput1, }, { - "Happy case-POTA", + "Happy case-POTA", args{ - fullLog: sampleFilledLogPOTA, + fullLog: sampleFilledLogPOTA, adifParams: AdifParams{IsPOTA: true}, }, expectedOutputPOTA, }, { "Happy case-Grid", - args{fullLog: sampleFilledLog2, - adifParams: AdifParams{IsWWFF: true, IsSOTA: false}, + args{fullLog: sampleFilledLog2, + adifParams: AdifParams{IsWWFF: true, IsSOTA: false}, }, expectedOutput2, }, { "Happy case-WWFF2WWFF", args{ - fullLog: sampleFilledLog3, + fullLog: sampleFilledLog3, adifParams: AdifParams{IsWWFF: true}, }, expectedOutput3, @@ -166,7 +165,7 @@ func Test_buildAdif(t *testing.T) { { "Happy case-POTA2POTA", args{ - fullLog: sampleFilledLogPOTA2, + fullLog: sampleFilledLogPOTA2, adifParams: AdifParams{IsPOTA: true}, }, expectedOutputPOTA2, diff --git a/fleprocess/parse_line.go b/fleprocess/parse_line.go index 66dee75..029efba 100644 --- a/fleprocess/parse_line.go +++ b/fleprocess/parse_line.go @@ -21,7 +21,6 @@ import ( "regexp" "strconv" "strings" - //"fmt" ) // LogLine is used to store all the data of a single log line @@ -70,6 +69,7 @@ var regexpDatePattern = regexp.MustCompile(`^(\d{2}|\d{4})[-/ .]\d{1,2}[-/ .]\d{ var regexpIsDateKeyWord = regexp.MustCompile(`(?i)^date$`) var regexpDayIncrementPattern = regexp.MustCompile(`^\+*$`) var regexpIsDayKeyword = regexp.MustCompile(`(?i)^day$`) +var regexpKhzPartOfQrg = regexp.MustCompile(`\.\d+`) // ParseLine cuts a FLE line into useful bits func ParseLine(inputStr string, previousLine LogLine) (logLine LogLine, errorMsg string) { @@ -174,17 +174,26 @@ func ParseLine(inputStr string, previousLine LogLine) (logLine LogLine, errorMsg logLine.Band = strings.ToLower(element) logLine.BandLowerLimit = bandLowerLimit logLine.BandUpperLimit = bandUpperLimit + //As a new band is defined, we reset the stored frequency (from previous lines) + // This assumes that the band is defined before frequency + logLine.Frequency = "" continue } // Is it a Frequency? if regexpIsFreq.MatchString(element) { + khzPart := regexpKhzPartOfQrg.FindStringSubmatch(element) var qrg float64 qrg, _ = strconv.ParseFloat(element, 32) if (logLine.BandLowerLimit != 0.0) && (logLine.BandUpperLimit != 0.0) { if (qrg >= logLine.BandLowerLimit) && (qrg <= logLine.BandUpperLimit) { - //TODO: print 3f or more is available - logLine.Frequency = fmt.Sprintf("%.3f", qrg) + //Increase precision to half Khz if data is available + if len(khzPart[0]) > 4 { + //The "." is part of the returned string + logLine.Frequency = fmt.Sprintf("%.4f", qrg) + } else { + logLine.Frequency = fmt.Sprintf("%.3f", qrg) + } } else { logLine.Frequency = "" errorMsg = errorMsg + "Frequency [" + element + "] is invalid for " + logLine.Band + " band." @@ -196,7 +205,7 @@ func ParseLine(inputStr string, previousLine LogLine) (logLine LogLine, errorMsg } // Is it a call sign ? - //FIXME: + //FIXME: (don't remember what) if validCallRegexp.MatchString(strings.ToUpper(element)) { //If it starts with "#",it is a grid definition and not a call if element[0] != '#' { diff --git a/fleprocess/parse_line_test.go b/fleprocess/parse_line_test.go index 2204975..7c6f012 100644 --- a/fleprocess/parse_line_test.go +++ b/fleprocess/parse_line_test.go @@ -98,6 +98,11 @@ func TestParseLine(t *testing.T) { args{inputStr: "14.153 on4kjm", previousLine: LogLine{Mode: "SSB", Band: "20m", BandLowerLimit: 14.0, BandUpperLimit: 14.35}}, LogLine{Band: "20m", BandLowerLimit: 14.0, BandUpperLimit: 14.35, Frequency: "14.153", Call: "ON4KJM", Mode: "SSB", RSTsent: "59", RSTrcvd: "59"}, "", }, + { + "Parse frequency (0.5 Khz)", + args{inputStr: "14.1535 on4kjm", previousLine: LogLine{Mode: "SSB", Band: "20m", BandLowerLimit: 14.0, BandUpperLimit: 14.35}}, + LogLine{Band: "20m", BandLowerLimit: 14.0, BandUpperLimit: 14.35, Frequency: "14.1535", Call: "ON4KJM", Mode: "SSB", RSTsent: "59", RSTrcvd: "59"}, "", + }, { "Parse frequency out of limit", args{inputStr: "14.453 on4kjm", previousLine: LogLine{Mode: "SSB", Band: "20m", BandLowerLimit: 14.0, BandUpperLimit: 14.35}}, diff --git a/test/data/sample_pota.txt b/test/data/sample_pota.txt index 2c0185a..8917f70 100644 --- a/test/data/sample_pota.txt +++ b/test/data/sample_pota.txt @@ -14,7 +14,7 @@ date 2016-04-24 8 gw0tlk/m date 2016-06-03 -40m cw +40m 7.0356 cw 1404 gm0aaa 3 7 5 on4ck/p 2 7 dl0dan/p diff --git a/test/output/POTA/sample_pota.adif b/test/output/POTA/sample_pota.adif index 6312a2b..f4c92d0 100644 --- a/test/output/POTA/sample_pota.adif +++ b/test/output/POTA/sample_pota.adif @@ -6,7 +6,7 @@ ADIF Export for Fast Log Entry by DF3CB G3WGV G3NOH 20160424 1204 40m CW 599 599 PSE QSL Direct POTA G-0014 G3WGV G3WGV GW4GTE 20160424 1227 2m FM 59 59 Dave POTA G-0014 G3WGV G3WGV GW0TLK/M 20160424 1228 2m FM 59 59 POTA G-0014 G3WGV -G3WGV GM0AAA 20160603 1404 40m CW 539 579 POTA G-0014 G3WGV -G3WGV ON4CK/P 20160603 1405 40m CW 529 599 POTA G-0014 G3WGV -G3WGV DL0DAN/P 20160603 1407 40m CW 599 599 POTA G-0014 G3WGV +G3WGV GM0AAA 20160603 1404 40m CW 7.0356 539 579 POTA G-0014 G3WGV +G3WGV ON4CK/P 20160603 1405 40m CW 7.0356 529 599 POTA G-0014 G3WGV +G3WGV DL0DAN/P 20160603 1407 40m CW 7.0356 599 599 POTA G-0014 G3WGV G3WGV YU7LS 20160603 1410 20m CW 599 599 POTA G-0014 G3WGV