diff --git a/cmd/parse_line.go b/cmd/parse_line.go index ac9dda7..02027ea 100644 --- a/cmd/parse_line.go +++ b/cmd/parse_line.go @@ -38,11 +38,15 @@ type LogLine struct { Call string Comment string QSLmsg string + OMname string + GridLoc string } var regexpIsBand = regexp.MustCompile("m$") var regexpIsFullTime = regexp.MustCompile("^[0-2]{1}[0-9]{3}$") 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 func ParseLine(inputStr string, previousLine LogLine) (logLine LogLine, errorMsg string){ @@ -107,6 +111,18 @@ func ParseLine(inputStr string, previousLine LogLine) (logLine LogLine, errorMsg 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 errorMsg = errorMsg + "Unable to parse " + element + " " @@ -137,6 +153,8 @@ func SprintLogRecord(logLine LogLine) (output string){ output = output + "Call " + logLine.Call + "\n" output = output + "Comment " + logLine.Comment + "\n" output = output + "QSLmsg " + logLine.QSLmsg + "\n" + output = output + "OMname " + logLine.OMname + "\n" + output = output + "GridLoc " + logLine.GridLoc + "\n" return output } diff --git a/cmd/parse_line_test.go b/cmd/parse_line_test.go index eaee1a7..154dca9 100644 --- a/cmd/parse_line_test.go +++ b/cmd/parse_line_test.go @@ -30,7 +30,7 @@ func TestParseLine(t *testing.T) { { "Parse partial time - 1", 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", @@ -57,6 +57,16 @@ func TestParseLine(t *testing.T) { args{ inputStr: "cww", previousLine: LogLine{ Mode: "SSB", }}, 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 { t.Run(tt.name, func(t *testing.T) { diff --git a/cmd/validate_test.go b/cmd/validate_test.go index e8f8d7c..3de8969 100644 --- a/cmd/validate_test.go +++ b/cmd/validate_test.go @@ -241,6 +241,11 @@ func TestValidateDate(t *testing.T) { args{ inputStr: "2020-06-10", }, "2020-06-10", "", }, + // { + // "Good date (extrapolate, different delimiter)", + // args{ inputStr: "16-2-1", }, + // "2020-06-10", "", + // }, { "Bad date (simple)", args{ inputStr: "2020-13-10", }, diff --git a/todo.md b/todo.md index cc4f978..bb0c350 100644 --- a/todo.md +++ b/todo.md @@ -11,8 +11,10 @@ ## 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 +* [ ] 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