Added parsing of OM name and grid locator

pull/2/head
Jean-Marc MEESSEN 5 years ago
parent a397f229fc
commit d80981aa11

@ -38,11 +38,15 @@ type LogLine struct {
Call string Call string
Comment string Comment string
QSLmsg string QSLmsg string
OMname string
GridLoc string
} }
var regexpIsBand = regexp.MustCompile("m$") var regexpIsBand = regexp.MustCompile("m$")
var regexpIsFullTime = regexp.MustCompile("^[0-2]{1}[0-9]{3}$") var regexpIsFullTime = regexp.MustCompile("^[0-2]{1}[0-9]{3}$")
var regexpIsTimePart = regexp.MustCompile("^[0-5]{1}[0-9]{1}$|^[1-9]{1}$") var regexpIsTimePart = regexp.MustCompile("^[0-5]{1}[0-9]{1}$|^[1-9]{1}$")
var regexpIsOMname = regexp.MustCompile("^@")
var regexpIsGridLoc = regexp.MustCompile("^#")
// 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){
@ -107,6 +111,18 @@ func ParseLine(inputStr string, previousLine LogLine) (logLine LogLine, errorMsg
continue continue
} }
// Is it the OM's name (starting with "@")
if regexpIsOMname.MatchString(element) {
logLine.OMname = strings.TrimLeft(element, "@")
continue
}
// Is it the Grid Locator (starting with "#")
if regexpIsGridLoc.MatchString(element) {
logLine.GridLoc = strings.TrimLeft(element, "#")
continue
}
//If we come here, we could not make sense of what we found //If we come here, we could not make sense of what we found
errorMsg = errorMsg + "Unable to parse " + element + " " errorMsg = errorMsg + "Unable to parse " + element + " "
@ -137,6 +153,8 @@ func SprintLogRecord(logLine LogLine) (output string){
output = output + "Call " + logLine.Call + "\n" output = output + "Call " + logLine.Call + "\n"
output = output + "Comment " + logLine.Comment + "\n" output = output + "Comment " + logLine.Comment + "\n"
output = output + "QSLmsg " + logLine.QSLmsg + "\n" output = output + "QSLmsg " + logLine.QSLmsg + "\n"
output = output + "OMname " + logLine.OMname + "\n"
output = output + "GridLoc " + logLine.GridLoc + "\n"
return output return output
} }

@ -30,7 +30,7 @@ func TestParseLine(t *testing.T) {
{ {
"Parse partial time - 1", "Parse partial time - 1",
args{ inputStr: "4 g3noh", previousLine: LogLine{ Time: "", Mode: "SSB", }}, args{ inputStr: "4 g3noh", previousLine: LogLine{ Time: "", Mode: "SSB", }},
LogLine{ Time: "4", Call: "G3NOH", Mode: "SSB",}, "", LogLine{ Time: "4", Call: "G3NOH", Mode: "SSB",}, "", //TODO: should fail
}, },
{ {
"Parse partial time - 2", "Parse partial time - 2",
@ -57,6 +57,16 @@ func TestParseLine(t *testing.T) {
args{ inputStr: "cww", previousLine: LogLine{ Mode: "SSB", }}, args{ inputStr: "cww", previousLine: LogLine{ Mode: "SSB", }},
LogLine{ Mode: "SSB",}, "Unable to parse cww ", LogLine{ Mode: "SSB",}, "Unable to parse cww ",
}, },
{
"Parse OM name",
args{ inputStr: "@Jean", previousLine: LogLine{ Mode: "SSB", }},
LogLine{ OMname: "Jean", Mode: "SSB",}, "",
},
{
"Parse Grid locator",
args{ inputStr: "#grid", previousLine: LogLine{ Mode: "SSB", }},
LogLine{ GridLoc: "grid", Mode: "SSB",}, "",
},
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {

@ -241,6 +241,11 @@ func TestValidateDate(t *testing.T) {
args{ inputStr: "2020-06-10", }, args{ inputStr: "2020-06-10", },
"2020-06-10", "", "2020-06-10", "",
}, },
// {
// "Good date (extrapolate, different delimiter)",
// args{ inputStr: "16-2-1", },
// "2020-06-10", "",
// },
{ {
"Bad date (simple)", "Bad date (simple)",
args{ inputStr: "2020-13-10", }, args{ inputStr: "2020-13-10", },

@ -11,8 +11,10 @@
## Input processing ## Input processing
* [x] Read the file into array
* [x] Parse every line
* [x] Load structured data
* [X] Create structured data storage
* [ ] Create the logic to take over from the previous line * [ ] Create the logic to take over from the previous line
* [ ] Support different date delimiter
* [ ] Support extrapolated date
* [ ] Support date not prefixed by "date" (non header mode)
* [ ] Support date increment
* [ ] decode and check frequency
* [ ] infer rst

Loading…
Cancel
Save