Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Qrg rounding #75

Merged
merged 2 commits into from
Dec 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 13 additions & 14 deletions fleprocess/adif_process_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func Test_validateDataforAdif2(t *testing.T) {
},
},
fmt.Errorf("missing MyCall"),
},
},
{
"Missing MySota",
args{
Expand Down Expand Up @@ -150,7 +150,6 @@ func Test_validateDataforAdif2(t *testing.T) {
}
}


func TestProcessAdifCommand(t *testing.T) {
type args struct {
adifParams AdifParams
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down
17 changes: 8 additions & 9 deletions fleprocess/adif_write_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ func Test_buildAdif(t *testing.T) {
"<STATION_CALLSIGN:8>ON4KJM/P <CALL:5>ON4LY <QSO_DATE:8>20200524 <TIME_ON:4>1312 <BAND:3>20m <MODE:2>CW <RST_SENT:3>559 <RST_RCVD:3>599 <MY_SIG:4>POTA <MY_SIG_INFO:8>ON-00259 <OPERATOR:6>ON4KJM <EOR>",
}


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"},
Expand All @@ -124,7 +123,7 @@ func Test_buildAdif(t *testing.T) {
}

type args struct {
fullLog []LogLine
fullLog []LogLine
adifParams AdifParams
}
tests := []struct {
Expand All @@ -135,38 +134,38 @@ 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,
},
{
"Happy case-POTA2POTA",
args{
fullLog: sampleFilledLogPOTA2,
fullLog: sampleFilledLogPOTA2,
adifParams: AdifParams{IsPOTA: true},
},
expectedOutputPOTA2,
Expand Down
17 changes: 13 additions & 4 deletions fleprocess/parse_line.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"regexp"
"strconv"
"strings"
//"fmt"
)

// LogLine is used to store all the data of a single log line
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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."
Expand All @@ -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] != '#' {
Expand Down
5 changes: 5 additions & 0 deletions fleprocess/parse_line_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}},
Expand Down
2 changes: 1 addition & 1 deletion test/data/sample_pota.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions test/output/POTA/sample_pota.adif
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ ADIF Export for Fast Log Entry by DF3CB
<STATION_CALLSIGN:5>G3WGV <CALL:5>G3NOH <QSO_DATE:8>20160424 <TIME_ON:4>1204 <BAND:3>40m <MODE:2>CW <RST_SENT:3>599 <RST_RCVD:3>599 <COMMENT:14>PSE QSL Direct <MY_SIG:4>POTA <MY_SIG_INFO:6>G-0014 <OPERATOR:5>G3WGV <EOR>
<STATION_CALLSIGN:5>G3WGV <CALL:6>GW4GTE <QSO_DATE:8>20160424 <TIME_ON:4>1227 <BAND:2>2m <MODE:2>FM <RST_SENT:2>59 <RST_RCVD:2>59 <COMMENT:4>Dave <MY_SIG:4>POTA <MY_SIG_INFO:6>G-0014 <OPERATOR:5>G3WGV <EOR>
<STATION_CALLSIGN:5>G3WGV <CALL:8>GW0TLK/M <QSO_DATE:8>20160424 <TIME_ON:4>1228 <BAND:2>2m <MODE:2>FM <RST_SENT:2>59 <RST_RCVD:2>59 <MY_SIG:4>POTA <MY_SIG_INFO:6>G-0014 <OPERATOR:5>G3WGV <EOR>
<STATION_CALLSIGN:5>G3WGV <CALL:6>GM0AAA <QSO_DATE:8>20160603 <TIME_ON:4>1404 <BAND:3>40m <MODE:2>CW <RST_SENT:3>539 <RST_RCVD:3>579 <MY_SIG:4>POTA <MY_SIG_INFO:6>G-0014 <OPERATOR:5>G3WGV <EOR>
<STATION_CALLSIGN:5>G3WGV <CALL:7>ON4CK/P <QSO_DATE:8>20160603 <TIME_ON:4>1405 <BAND:3>40m <MODE:2>CW <RST_SENT:3>529 <RST_RCVD:3>599 <MY_SIG:4>POTA <MY_SIG_INFO:6>G-0014 <OPERATOR:5>G3WGV <EOR>
<STATION_CALLSIGN:5>G3WGV <CALL:8>DL0DAN/P <QSO_DATE:8>20160603 <TIME_ON:4>1407 <BAND:3>40m <MODE:2>CW <RST_SENT:3>599 <RST_RCVD:3>599 <MY_SIG:4>POTA <MY_SIG_INFO:6>G-0014 <OPERATOR:5>G3WGV <EOR>
<STATION_CALLSIGN:5>G3WGV <CALL:6>GM0AAA <QSO_DATE:8>20160603 <TIME_ON:4>1404 <BAND:3>40m <MODE:2>CW <FREQ:6>7.0356 <RST_SENT:3>539 <RST_RCVD:3>579 <MY_SIG:4>POTA <MY_SIG_INFO:6>G-0014 <OPERATOR:5>G3WGV <EOR>
<STATION_CALLSIGN:5>G3WGV <CALL:7>ON4CK/P <QSO_DATE:8>20160603 <TIME_ON:4>1405 <BAND:3>40m <MODE:2>CW <FREQ:6>7.0356 <RST_SENT:3>529 <RST_RCVD:3>599 <MY_SIG:4>POTA <MY_SIG_INFO:6>G-0014 <OPERATOR:5>G3WGV <EOR>
<STATION_CALLSIGN:5>G3WGV <CALL:8>DL0DAN/P <QSO_DATE:8>20160603 <TIME_ON:4>1407 <BAND:3>40m <MODE:2>CW <FREQ:6>7.0356 <RST_SENT:3>599 <RST_RCVD:3>599 <MY_SIG:4>POTA <MY_SIG_INFO:6>G-0014 <OPERATOR:5>G3WGV <EOR>
<STATION_CALLSIGN:5>G3WGV <CALL:5>YU7LS <QSO_DATE:8>20160603 <TIME_ON:4>1410 <BAND:3>20m <MODE:2>CW <RST_SENT:3>599 <RST_RCVD:3>599 <MY_SIG:4>POTA <MY_SIG_INFO:6>G-0014 <OPERATOR:5>G3WGV <EOR>