From 54488d1ea47cee7a67ec588a002fbc49842a2bb9 Mon Sep 17 00:00:00 2001 From: Jean-Marc Meessen Date: Sat, 30 Dec 2023 16:57:13 +0100 Subject: [PATCH 1/6] Adding multi-SOTA test file --- test/data/multi-SOTA-summits.txt | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 test/data/multi-SOTA-summits.txt diff --git a/test/data/multi-SOTA-summits.txt b/test/data/multi-SOTA-summits.txt new file mode 100644 index 0000000..795c276 --- /dev/null +++ b/test/data/multi-SOTA-summits.txt @@ -0,0 +1,17 @@ +#Header +mycall MW0PJE/P +mysota GW/NW-001 +#Log +2m FM +1000 mw0abc +01 mw0abd + +# New summit +mysota GW/NW-002 +1200 mm0abe +01 mm0abf + +# third summit +mysota GW/NW-003 +1400 mi0abg +01 mi0abh \ No newline at end of file From a8f90031a266f1f4346ec454dc2650af1ab8ae0a Mon Sep 17 00:00:00 2001 From: Jean-Marc Meessen Date: Sun, 31 Dec 2023 14:41:30 +0100 Subject: [PATCH 2/6] WIP --- fleprocess/load_file.go | 22 +++++++++------ fleprocess/load_file_test.go | 47 ++++++++++++++++++++++++++++++-- fleprocess/parse_line.go | 1 + test/data/multi-SOTA-summits.txt | 7 ++++- 4 files changed, 65 insertions(+), 12 deletions(-) diff --git a/fleprocess/load_file.go b/fleprocess/load_file.go index 2fd9bac..05d96b0 100644 --- a/fleprocess/load_file.go +++ b/fleprocess/load_file.go @@ -75,6 +75,7 @@ func LoadFile(inputFilename string, isInterpolateTime bool) (filleFullLog []LogL headerMyGrid := "" headerQslMsg := "" headerNickname := "" + headerIsFirstLine := true //headerDate := "" lineCount := 0 @@ -207,11 +208,12 @@ func LoadFile(inputFilename string, isInterpolateTime bool) (filleFullLog []LogL //My Sota if regexpHeaderMySota.MatchString(eachline) { - //Attempt to redefine value - if headerMySOTA != "" { - errorLog = append(errorLog, fmt.Sprintf("Attempt to redefine MySOTA at line %d", lineCount)) - continue - } + oldHeaderMySOTA := headerMySOTA + // //FIXME: enhancement for issue #101 + // if headerMySOTA != "" { + // errorLog = append(errorLog, fmt.Sprintf("Warning: redefining MySOTA at line %d", lineCount)) + // continue + // } errorMsg := "" mySotaList := regexpHeaderMySota.Split(eachline, -1) if len(strings.TrimSpace(mySotaList[1])) > 0 { @@ -221,6 +223,10 @@ func LoadFile(inputFilename string, isInterpolateTime bool) (filleFullLog []LogL errorLog = append(errorLog, fmt.Sprintf("Invalid \"My SOTA\" at line %d: %s (%s)", lineCount, mySotaList[1], errorMsg)) } } + if oldHeaderMySOTA != headerMySOTA { + // New SOTA reference defined + headerIsFirstLine = true + } //If there is no data after the marker, we just skip the data. continue } @@ -279,6 +285,7 @@ func LoadFile(inputFilename string, isInterpolateTime bool) (filleFullLog []LogL // Load the header values in the previousLogLine previousLogLine.MyCall = headerMyCall previousLogLine.Operator = headerOperator + previousLogLine.isFirstLine = headerIsFirstLine previousLogLine.MyWWFF = headerMyWWFF previousLogLine.MyPOTA = headerMyPOTA previousLogLine.MySOTA = headerMySOTA @@ -336,6 +343,7 @@ func LoadFile(inputFilename string, isInterpolateTime bool) (filleFullLog []LogL //store the current logline so that it can be used as a model when parsing the next line previousLogLine = logline + //FIXME: we need to reset the first line //We go back to the top to process the next loaded log line (Continue not necessary here) } @@ -388,12 +396,10 @@ func LoadFile(inputFilename string, isInterpolateTime bool) (filleFullLog []LogL // displayLogSimple will print to stdout a simplified dump of a full log func displayLogSimple(fullLog []LogLine) { - firstLine := true for _, filledLogLine := range fullLog { - if firstLine { + if filledLogLine.isFirstLine { fmt.Println(SprintHeaderValues(filledLogLine)) fmt.Print(SprintColumnTitles()) - firstLine = false } fmt.Print(SprintLogInColumn(filledLogLine)) } diff --git a/fleprocess/load_file_test.go b/fleprocess/load_file_test.go index 29e984e..bd094c5 100644 --- a/fleprocess/load_file_test.go +++ b/fleprocess/load_file_test.go @@ -455,7 +455,8 @@ func TestLoadFile_redefining_myWWFF_must_fail(t *testing.T) { os.Remove(temporaryDataFileName) } -func TestLoadFile_redefining_mySOTA_must_fail(t *testing.T) { +// FIXME: See issue #101 +func TestLoadFile_redefining_mySOTA(t *testing.T) { //Given dataArray := make([]string, 0) @@ -470,6 +471,7 @@ func TestLoadFile_redefining_mySOTA_must_fail(t *testing.T) { dataArray = append(dataArray, "20/5/23") dataArray = append(dataArray, "40m cw 0950 ik5zve/5 9 5") dataArray = append(dataArray, "mySota on/on-111") + dataArray = append(dataArray, "40m cw 0955 ik5zzz 9 5") temporaryDataFileName := createTestFile(dataArray) @@ -477,8 +479,47 @@ func TestLoadFile_redefining_mySOTA_must_fail(t *testing.T) { loadedLogFile, isLoadedOK := LoadFile(temporaryDataFileName, true) //Then - if isLoadedOK { - t.Error("Test file processing should return with an error") + if !isLoadedOK { + t.Error("Test file processing should not fail") + } + if len(loadedLogFile) == 0 { + t.Error("No data loaded") + } + + expectedValue := "ON/ON-001" + if loadedLogFile[0].MySOTA != expectedValue { + t.Errorf("Not the expected MySOTA value: %s (expecting %s)", loadedLogFile[0].MySOTA, expectedValue) + } + + //Clean Up + os.Remove(temporaryDataFileName) +} + +// FIXME: See issue #101 +func TestLoadFile_redefining_mySOTA_no_data(t *testing.T) { + + //Given + dataArray := make([]string, 0) + dataArray = append(dataArray, "# Header") + dataArray = append(dataArray, "myCall on4kjm/p") + dataArray = append(dataArray, "operator on4kjm") + dataArray = append(dataArray, "nickname Portable") + dataArray = append(dataArray, "myWwff onff-0258") + dataArray = append(dataArray, "mySota on/on-001") + dataArray = append(dataArray, " ") + dataArray = append(dataArray, " #Log") + dataArray = append(dataArray, "20/5/23") + dataArray = append(dataArray, "40m cw 0950 ik5zve/5 9 5") + dataArray = append(dataArray, "mySota on/on-111") + + temporaryDataFileName := createTestFile(dataArray) + + //When + loadedLogFile, isLoadedOK := LoadFile(temporaryDataFileName, true) + + //Then + if !isLoadedOK { + t.Error("Test file processing should not fail") } if len(loadedLogFile) == 0 { t.Error("No data loaded") diff --git a/fleprocess/parse_line.go b/fleprocess/parse_line.go index c0e4181..0d16d9f 100644 --- a/fleprocess/parse_line.go +++ b/fleprocess/parse_line.go @@ -28,6 +28,7 @@ type LogLine struct { Date string MyCall string Operator string + isFirstLine bool MyWWFF string MyPOTA string MySOTA string diff --git a/test/data/multi-SOTA-summits.txt b/test/data/multi-SOTA-summits.txt index 795c276..f9ce29b 100644 --- a/test/data/multi-SOTA-summits.txt +++ b/test/data/multi-SOTA-summits.txt @@ -1,7 +1,12 @@ #Header mycall MW0PJE/P -mysota GW/NW-001 + + #Log + +#First summit +mysota GW/NW-001 +date 2016-04-24 2m FM 1000 mw0abc 01 mw0abd From 5cb43666c547227859b1c93aaeaecbf757cd8bec Mon Sep 17 00:00:00 2001 From: Jean-Marc Meessen Date: Mon, 1 Jan 2024 11:44:50 +0100 Subject: [PATCH 3/6] First implementation (SOTA) --- fleprocess/load_file.go | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/fleprocess/load_file.go b/fleprocess/load_file.go index 05d96b0..c301d77 100644 --- a/fleprocess/load_file.go +++ b/fleprocess/load_file.go @@ -209,11 +209,6 @@ func LoadFile(inputFilename string, isInterpolateTime bool) (filleFullLog []LogL //My Sota if regexpHeaderMySota.MatchString(eachline) { oldHeaderMySOTA := headerMySOTA - // //FIXME: enhancement for issue #101 - // if headerMySOTA != "" { - // errorLog = append(errorLog, fmt.Sprintf("Warning: redefining MySOTA at line %d", lineCount)) - // continue - // } errorMsg := "" mySotaList := regexpHeaderMySota.Split(eachline, -1) if len(strings.TrimSpace(mySotaList[1])) > 0 { @@ -226,6 +221,7 @@ func LoadFile(inputFilename string, isInterpolateTime bool) (filleFullLog []LogL if oldHeaderMySOTA != headerMySOTA { // New SOTA reference defined headerIsFirstLine = true + } //If there is no data after the marker, we just skip the data. continue @@ -342,8 +338,9 @@ func LoadFile(inputFilename string, isInterpolateTime bool) (filleFullLog []LogL } //store the current logline so that it can be used as a model when parsing the next line + // and reset the firstline flag previousLogLine = logline - //FIXME: we need to reset the first line + headerIsFirstLine = false //We go back to the top to process the next loaded log line (Continue not necessary here) } @@ -396,12 +393,14 @@ func LoadFile(inputFilename string, isInterpolateTime bool) (filleFullLog []LogL // displayLogSimple will print to stdout a simplified dump of a full log func displayLogSimple(fullLog []LogLine) { + isFirstLogLine := true for _, filledLogLine := range fullLog { - if filledLogLine.isFirstLine { + if (filledLogLine.isFirstLine || isFirstLogLine) { + fmt.Print("\n\n") fmt.Println(SprintHeaderValues(filledLogLine)) fmt.Print(SprintColumnTitles()) + isFirstLogLine = false } fmt.Print(SprintLogInColumn(filledLogLine)) } - } From da537ea85e73f4852226ba1de89004903594b097 Mon Sep 17 00:00:00 2001 From: Jean-Marc Meessen Date: Mon, 1 Jan 2024 11:49:32 +0100 Subject: [PATCH 4/6] Correct spelling errors --- fleprocess/braketedData.go | 2 +- fleprocess/braketedData_test.go | 2 +- fleprocess/load_file.go | 2 +- fleprocess/parse_line.go | 12 ++++++------ 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/fleprocess/braketedData.go b/fleprocess/braketedData.go index 01c4d11..340e859 100644 --- a/fleprocess/braketedData.go +++ b/fleprocess/braketedData.go @@ -29,7 +29,7 @@ const ( QSL ) -func getBraketedData(inputLine string, braketType BraketType) (braketedData, cleanedLine string) { +func getBracketedData(inputLine string, braketType BraketType) (braketedData, cleanedLine string) { // Get substring between two strings. a := "" b := "" diff --git a/fleprocess/braketedData_test.go b/fleprocess/braketedData_test.go index a6d3afa..4841720 100644 --- a/fleprocess/braketedData_test.go +++ b/fleprocess/braketedData_test.go @@ -74,7 +74,7 @@ func Test_getBraketedData(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - gotBraketedData, gotCleanedLine := getBraketedData(tt.args.inputLine, tt.args.braketType) + gotBraketedData, gotCleanedLine := getBracketedData(tt.args.inputLine, tt.args.braketType) if gotBraketedData != tt.wantBraketedData { t.Errorf("getBraketedData() gotBraketedData = %v, want %v", gotBraketedData, tt.wantBraketedData) } diff --git a/fleprocess/load_file.go b/fleprocess/load_file.go index c301d77..f5aeccf 100644 --- a/fleprocess/load_file.go +++ b/fleprocess/load_file.go @@ -338,7 +338,7 @@ func LoadFile(inputFilename string, isInterpolateTime bool) (filleFullLog []LogL } //store the current logline so that it can be used as a model when parsing the next line - // and reset the firstline flag + // and reset the FirstLine flag previousLogLine = logline headerIsFirstLine = false diff --git a/fleprocess/parse_line.go b/fleprocess/parse_line.go index 0d16d9f..5ab3265 100644 --- a/fleprocess/parse_line.go +++ b/fleprocess/parse_line.go @@ -98,12 +98,12 @@ func ParseLine(inputStr string, previousLine LogLine) (logLine LogLine, errorMsg //TODO: what happens when we have <> or when there are multiple comments //TODO: Refactor this! it is ugly - comment, inputStr := getBraketedData(inputStr, COMMENT) + comment, inputStr := getBracketedData(inputStr, COMMENT) if comment != "" { logLine.Comment = comment } - QSLmsg, inputStr := getBraketedData(inputStr, QSL) + QSLmsg, inputStr := getBracketedData(inputStr, QSL) if QSLmsg != "" { logLine.QSLmsg = QSLmsg } @@ -125,7 +125,7 @@ func ParseLine(inputStr string, previousLine LogLine) (logLine LogLine, errorMsg logLine.RSTrcvd = defaultReport } else { - errorMsg = errorMsg + "Double definitiion of RST" + errorMsg = errorMsg + "Double definition of RST" } continue } @@ -295,7 +295,7 @@ func ParseLine(inputStr string, previousLine LogLine) (logLine LogLine, errorMsg // If the "wwff" keyword is used, skip it if regexpIsWwffKeyWord.MatchString(element) { - // this keyword is not requiered anymore with FLE 3 and doesn't add any value + // this keyword is not required anymore with FLE 3 and doesn't add any value continue } @@ -308,7 +308,7 @@ func ParseLine(inputStr string, previousLine LogLine) (logLine LogLine, errorMsg // If the "pota" keyword is used, skip it if regexpIsPotaKeyWord.MatchString(element) { - // this keyword is not requiered anymore with FLE 3 and doesn't add any value + // this keyword is not required anymore with FLE 3 and doesn't add any value continue } @@ -321,7 +321,7 @@ func ParseLine(inputStr string, previousLine LogLine) (logLine LogLine, errorMsg // If the "sota" keyword is used, skip it if regexpIsSotaKeyWord.MatchString(element) { - // this keyword is not requiered anymore with FLE 3 and doesn't add any value + // this keyword is not required anymore with FLE 3 and doesn't add any value continue } From 3b00a19f77e7573ece86365936aff172e180b5fb Mon Sep 17 00:00:00 2001 From: Jean-Marc Meessen Date: Sat, 20 Jan 2024 17:45:28 +0100 Subject: [PATCH 5/6] Add test --- fleprocess/load_file_test.go | 5 +++++ test/data/multi-SOTA-summits.adi | 10 ++++++++++ 2 files changed, 15 insertions(+) create mode 100644 test/data/multi-SOTA-summits.adi diff --git a/fleprocess/load_file_test.go b/fleprocess/load_file_test.go index bd094c5..5533836 100644 --- a/fleprocess/load_file_test.go +++ b/fleprocess/load_file_test.go @@ -491,6 +491,11 @@ func TestLoadFile_redefining_mySOTA(t *testing.T) { t.Errorf("Not the expected MySOTA value: %s (expecting %s)", loadedLogFile[0].MySOTA, expectedValue) } + expectedValue = "ON/ON-111" + if loadedLogFile[1].MySOTA != expectedValue { + t.Errorf("Not the expected MySOTA value: %s (expecting %s)", loadedLogFile[0].MySOTA, expectedValue) + } + //Clean Up os.Remove(temporaryDataFileName) } diff --git a/test/data/multi-SOTA-summits.adi b/test/data/multi-SOTA-summits.adi new file mode 100644 index 0000000..8ea44a3 --- /dev/null +++ b/test/data/multi-SOTA-summits.adi @@ -0,0 +1,10 @@ +ADIF Export for Fast Log Entry by DF3CB +FLE +3.1.0 + +MW0PJE/P MW0ABC 20160424 1000 2m FM 59 59 GW/NW-001 +MW0PJE/P MW0ABD 20160424 1001 2m FM 59 59 GW/NW-001 +MW0PJE/P MM0ABE 20160424 1200 2m FM 59 59 GW/NW-002 +MW0PJE/P MM0ABF 20160424 1201 2m FM 59 59 GW/NW-002 +MW0PJE/P MI0ABG 20160424 1400 2m FM 59 59 GW/NW-003 +MW0PJE/P MI0ABH 20160424 1401 2m FM 59 59 GW/NW-003 From 2abc3a670292ab055045d1ebd4c7bcf1fce32b52 Mon Sep 17 00:00:00 2001 From: Jean-Marc Meessen Date: Wed, 20 Mar 2024 20:36:57 +0100 Subject: [PATCH 6/6] wip --- fleprocess/load_file_test.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/fleprocess/load_file_test.go b/fleprocess/load_file_test.go index b88a747..401366c 100644 --- a/fleprocess/load_file_test.go +++ b/fleprocess/load_file_test.go @@ -22,6 +22,8 @@ import ( "testing" ) +//TODO: Add tests for POTA + func TestLoadFile_happyCase(t *testing.T) { //Given @@ -422,7 +424,7 @@ func TestLoadFile_redefining_myCall_must_fail(t *testing.T) { os.Remove(temporaryDataFileName) } -func TestLoadFile_redefining_myWWFF_must_fail(t *testing.T) { +func TestLoadFile_redefining_myWWFF(t *testing.T) { //Given dataArray := make([]string, 0) @@ -437,6 +439,7 @@ func TestLoadFile_redefining_myWWFF_must_fail(t *testing.T) { dataArray = append(dataArray, "20/5/23") dataArray = append(dataArray, "40m cw 0950 ik5zve/5 9 5") dataArray = append(dataArray, "myWWFF onff-0001") + dataArray = append(dataArray, "40m cw 0955 ik5zzz 9 5") temporaryDataFileName := createTestFile(dataArray) @@ -456,11 +459,15 @@ func TestLoadFile_redefining_myWWFF_must_fail(t *testing.T) { t.Errorf("Not the expected MyWWFF value: %s (expecting %s)", loadedLogFile[0].MyWWFF, expectedValue) } + expectedValue = "ONFF-0001" + if loadedLogFile[1].MyWWFF != expectedValue { + t.Errorf("Not the expected MyWWFF value: %s (expecting %s)", loadedLogFile[0].MyWWFF, expectedValue) + } + //Clean Up os.Remove(temporaryDataFileName) } -// FIXME: See issue #101 func TestLoadFile_redefining_mySOTA(t *testing.T) { //Given