QRG rounding (#75)

* support frequency up to the 100hz while default resolution is to the Khz
pull/76/head
Jean-Marc MEESSEN 3 years ago committed by GitHub
parent 61c42d1c75
commit fe7836fdb5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -150,7 +150,6 @@ func Test_validateDataforAdif2(t *testing.T) {
} }
} }
func TestProcessAdifCommand(t *testing.T) { func TestProcessAdifCommand(t *testing.T) {
type args struct { type args struct {
adifParams AdifParams adifParams AdifParams
@ -164,10 +163,10 @@ func TestProcessAdifCommand(t *testing.T) {
"Bad output filename (directory)", "Bad output filename (directory)",
args{ args{
adifParams: AdifParams{ adifParams: AdifParams{
InputFilename: "../test/data/fle-4-no-qso.txt", InputFilename: "../test/data/fle-4-no-qso.txt",
OutputFilename: "../test/data", OutputFilename: "../test/data",
IsInterpolateTime: false, IsInterpolateTime: false,
IsOverwrite: false, IsOverwrite: false,
}, },
}, },
true, true,
@ -176,10 +175,10 @@ func TestProcessAdifCommand(t *testing.T) {
"input file parsing errors (missing band)", "input file parsing errors (missing band)",
args{ args{
adifParams: AdifParams{ adifParams: AdifParams{
InputFilename: "../test/data/fle-3-error.txt", InputFilename: "../test/data/fle-3-error.txt",
OutputFilename: "", OutputFilename: "",
IsInterpolateTime: false, IsInterpolateTime: false,
IsOverwrite: false, IsOverwrite: false,
}, },
}, },
true, true,
@ -188,10 +187,10 @@ func TestProcessAdifCommand(t *testing.T) {
"input file parsing errors (wrong call)", "input file parsing errors (wrong call)",
args{ args{
adifParams: AdifParams{ adifParams: AdifParams{
InputFilename: "../test/data/fle-5-wrong-call.txt", InputFilename: "../test/data/fle-5-wrong-call.txt",
OutputFilename: "", OutputFilename: "",
IsInterpolateTime: false, IsInterpolateTime: false,
IsOverwrite: false, IsOverwrite: false,
}, },
}, },
true, true,
@ -200,10 +199,10 @@ func TestProcessAdifCommand(t *testing.T) {
"No QSO in loaded file", "No QSO in loaded file",
args{ args{
adifParams: AdifParams{ adifParams: AdifParams{
InputFilename: "../test/data/fle-4-no-qso.txt", InputFilename: "../test/data/fle-4-no-qso.txt",
OutputFilename: "", OutputFilename: "",
IsInterpolateTime: false, IsInterpolateTime: false,
IsOverwrite: false, IsOverwrite: false,
}, },
}, },
true, true,

@ -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>", "<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{ 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: "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"}, {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 { type args struct {
fullLog []LogLine fullLog []LogLine
adifParams AdifParams adifParams AdifParams
} }
tests := []struct { tests := []struct {
@ -135,7 +134,7 @@ func Test_buildAdif(t *testing.T) {
{ {
"Happy case-WWFF", "Happy case-WWFF",
args{ args{
fullLog: sampleFilledLog1, fullLog: sampleFilledLog1,
adifParams: AdifParams{IsWWFF: true, IsSOTA: false}, adifParams: AdifParams{IsWWFF: true, IsSOTA: false},
}, },
expectedOutput1, expectedOutput1,
@ -143,7 +142,7 @@ func Test_buildAdif(t *testing.T) {
{ {
"Happy case-POTA", "Happy case-POTA",
args{ args{
fullLog: sampleFilledLogPOTA, fullLog: sampleFilledLogPOTA,
adifParams: AdifParams{IsPOTA: true}, adifParams: AdifParams{IsPOTA: true},
}, },
expectedOutputPOTA, expectedOutputPOTA,
@ -151,14 +150,14 @@ func Test_buildAdif(t *testing.T) {
{ {
"Happy case-Grid", "Happy case-Grid",
args{fullLog: sampleFilledLog2, args{fullLog: sampleFilledLog2,
adifParams: AdifParams{IsWWFF: true, IsSOTA: false}, adifParams: AdifParams{IsWWFF: true, IsSOTA: false},
}, },
expectedOutput2, expectedOutput2,
}, },
{ {
"Happy case-WWFF2WWFF", "Happy case-WWFF2WWFF",
args{ args{
fullLog: sampleFilledLog3, fullLog: sampleFilledLog3,
adifParams: AdifParams{IsWWFF: true}, adifParams: AdifParams{IsWWFF: true},
}, },
expectedOutput3, expectedOutput3,
@ -166,7 +165,7 @@ func Test_buildAdif(t *testing.T) {
{ {
"Happy case-POTA2POTA", "Happy case-POTA2POTA",
args{ args{
fullLog: sampleFilledLogPOTA2, fullLog: sampleFilledLogPOTA2,
adifParams: AdifParams{IsPOTA: true}, adifParams: AdifParams{IsPOTA: true},
}, },
expectedOutputPOTA2, expectedOutputPOTA2,

@ -21,7 +21,6 @@ import (
"regexp" "regexp"
"strconv" "strconv"
"strings" "strings"
//"fmt"
) )
// LogLine is used to store all the data of a single log line // 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 regexpIsDateKeyWord = regexp.MustCompile(`(?i)^date$`)
var regexpDayIncrementPattern = regexp.MustCompile(`^\+*$`) var regexpDayIncrementPattern = regexp.MustCompile(`^\+*$`)
var regexpIsDayKeyword = regexp.MustCompile(`(?i)^day$`) var regexpIsDayKeyword = regexp.MustCompile(`(?i)^day$`)
var regexpKhzPartOfQrg = regexp.MustCompile(`\.\d+`)
// ParseLine cuts a FLE line into useful bits // ParseLine cuts a FLE line into useful bits
func ParseLine(inputStr string, previousLine LogLine) (logLine LogLine, errorMsg string) { 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.Band = strings.ToLower(element)
logLine.BandLowerLimit = bandLowerLimit logLine.BandLowerLimit = bandLowerLimit
logLine.BandUpperLimit = bandUpperLimit 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 continue
} }
// Is it a Frequency? // Is it a Frequency?
if regexpIsFreq.MatchString(element) { if regexpIsFreq.MatchString(element) {
khzPart := regexpKhzPartOfQrg.FindStringSubmatch(element)
var qrg float64 var qrg float64
qrg, _ = strconv.ParseFloat(element, 32) qrg, _ = strconv.ParseFloat(element, 32)
if (logLine.BandLowerLimit != 0.0) && (logLine.BandUpperLimit != 0.0) { if (logLine.BandLowerLimit != 0.0) && (logLine.BandUpperLimit != 0.0) {
if (qrg >= logLine.BandLowerLimit) && (qrg <= logLine.BandUpperLimit) { if (qrg >= logLine.BandLowerLimit) && (qrg <= logLine.BandUpperLimit) {
//TODO: print 3f or more is available //Increase precision to half Khz if data is available
logLine.Frequency = fmt.Sprintf("%.3f", qrg) 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 { } else {
logLine.Frequency = "" logLine.Frequency = ""
errorMsg = errorMsg + "Frequency [" + element + "] is invalid for " + logLine.Band + " band." 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 ? // Is it a call sign ?
//FIXME: //FIXME: (don't remember what)
if validCallRegexp.MatchString(strings.ToUpper(element)) { if validCallRegexp.MatchString(strings.ToUpper(element)) {
//If it starts with "#",it is a grid definition and not a call //If it starts with "#",it is a grid definition and not a call
if element[0] != '#' { if element[0] != '#' {

@ -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}}, 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"}, "", 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", "Parse frequency out of limit",
args{inputStr: "14.453 on4kjm", previousLine: LogLine{Mode: "SSB", Band: "20m", BandLowerLimit: 14.0, BandUpperLimit: 14.35}}, args{inputStr: "14.453 on4kjm", previousLine: LogLine{Mode: "SSB", Band: "20m", BandLowerLimit: 14.0, BandUpperLimit: 14.35}},

@ -14,7 +14,7 @@ date 2016-04-24
8 gw0tlk/m 8 gw0tlk/m
date 2016-06-03 date 2016-06-03
40m cw 40m 7.0356 cw
1404 gm0aaa 3 7 1404 gm0aaa 3 7
5 on4ck/p 2 5 on4ck/p 2
7 dl0dan/p 7 dl0dan/p

@ -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: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: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: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: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 <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: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 <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: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> <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>

Loading…
Cancel
Save