File parsing and display log in colums

pull/2/head
Jean-Marc MEESSEN 4 years ago
parent b2aafa63e7
commit 10ca0b86e0

@ -0,0 +1,101 @@
package cmd
/*
Copyright © 2020 Jean-Marc Meessen, ON4KJM <on4kjm@gmail.com>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
import (
"fmt"
)
// SprintLogRecord outputs the content of a logline
func SprintLogRecord(logLine LogLine) (output string){
output = ""
output = output + "Date " + logLine.Date + "\n"
output = output + "MyCall " + logLine.MyCall + "\n"
output = output + "Operator " + logLine.Operator + "\n"
output = output + "MyWWFF " + logLine.MyWWFF + "\n"
output = output + "MySOTA " + logLine.MySOTA + "\n"
output = output + "QslMsg " + logLine.QslMsg + "\n"
output = output + "Nickname " + logLine.Nickname + "\n"
output = output + "Mode " + logLine.Mode + "\n"
output = output + "ModeType " + logLine.ModeType + "\n"
output = output + "Band " + logLine.Band + "\n"
output = output + " Lower " + fmt.Sprintf("%f", logLine.BandLowerLimit) + "\n"
output = output + " Upper " + fmt.Sprintf("%f", logLine.BandUpperLimit) + "\n"
output = output + "Frequency " + logLine.Frequency + "\n"
output = output + "Time " + logLine.Time + "\n"
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"
output = output + "RSTsent " + logLine.RSTsent + "\n"
output = output + "RSTrcvd " + logLine.RSTrcvd + "\n"
output = output + "SOTA " + logLine.SOTA + "\n"
output = output + "WWFF " + logLine.WWFF + "\n"
return output
}
// SprintHeaderValues displays the header values
func SprintHeaderValues(logLine LogLine) (output string){
output = ""
output = output + "MyCall " + logLine.MyCall
if logLine.Operator != "" {
output = output + " (" + logLine.Operator + ")"
}
output = output + "\n"
output = output + "MyWWFF " + logLine.MyWWFF + "\n"
output = output + "MySOTA " + logLine.MySOTA + "\n"
return output
}
// Date, Time, band, mode, call, report sent, report rcvd, Notes
var logLineFormat = "%10s %4s %4s %4s %10s %4s %4s %s \n"
// SprintColumnTitles displays the column titles for a log line
func SprintColumnTitles(logLine LogLine) (output string){
output = fmt.Sprintf(logLineFormat, "Date", "Time", "Band", "Mode", "Call", "Sent", "Rcvd", "Notes")
output = output + fmt.Sprintf(logLineFormat, "----", "----", "----", "----", "----", "----", "----", "----")
return output
}
// SprintLogInColumn displays the logLine in column mode
func SprintLogInColumn(logLine LogLine) (output string){
notes := ""
if logLine.Comment != "" {
notes = notes + "[" + logLine.Comment + "] "
}
if logLine.QSLmsg != "" {
notes = notes + "[" + logLine.QSLmsg + "] "
}
if logLine.OMname != "" {
notes = notes + logLine.OMname + " "
}
if logLine.GridLoc != "" {
notes = notes + logLine.GridLoc + " "
}
if logLine.WWFF != "" {
notes = notes + logLine.WWFF + " "
}
if logLine.SOTA != "" {
notes = notes + logLine.SOTA + " "
}
output = fmt.Sprintf(logLineFormat, logLine.Date, logLine.Time, logLine.Band, logLine.Mode, logLine.Call, logLine.RSTsent, logLine.RSTrcvd, notes)
return output
}

@ -100,6 +100,8 @@ func loadFile() {
var cleanedInput []string
var errorLog []string
var previousLogLine LogLine
var fullLog []LogLine
//Loop through all the stored lined
@ -227,7 +229,6 @@ func loadFile() {
myDateList := regexpHeaderDate.Split(eachline,-1)
if(len(myDateList[1]) > 0) {
headerDate, errorMsg = ValidateDate(myDateList[1])
cleanedInput = append(cleanedInput, fmt.Sprintf("Date: %s", headerDate))
if(len(errorMsg) != 0) {
errorLog = append(errorLog, fmt.Sprintf("Invalid Date at line %d: %s (%s)",lineCount, myDateList[1], errorMsg))
}
@ -239,15 +240,43 @@ func loadFile() {
// ****
// ** Process the data block
// ****
cleanedInput = append(cleanedInput,eachline)
// Load the header values in the previousLogLine
previousLogLine.MyCall = headerMyCall
previousLogLine.Operator = headerOperator
previousLogLine.MyWWFF = headerMyWWFF
previousLogLine.MySOTA = headerMySOTA
previousLogLine.QSLmsg = headerQslMsg //previousLogLine.QslMsg is redundant
previousLogLine.Nickname = headerNickname
previousLogLine.Date = headerDate
//
logline, errorLine := ParseLine(eachline, previousLogLine)
if logline.Call != "" {
fullLog = append(fullLog, logline)
}
if errorLine != "" {
errorLog = append(errorLog, fmt.Sprintf("Parsing error at line %d: %s ",lineCount,errorLine))
}
previousLogLine = logline
//Go back to the top (Continue not necessary)
}
//*****
//** display results
//*****
for _, cleanedInputLine := range cleanedInput {
fmt.Println(cleanedInputLine)
// for _, filledLofLine := range fullLog {
// fmt.Println(SprintLogRecord(filledLofLine))
// }
firstLine := true
for _, filledLogLine := range fullLog {
if firstLine {
fmt.Println(SprintHeaderValues(filledLogLine))
fmt.Print(SprintColumnTitles(filledLogLine))
firstLine = false
}
fmt.Print(SprintLogInColumn(filledLogLine))
}
if(len(errorLog) != 0){

@ -22,6 +22,9 @@ import (
"fmt"
)
//TODO: validate a record for minimal values
// LogLine is used to store all the data of a single log line
type LogLine struct {
Date string
@ -235,36 +238,6 @@ func ParseLine(inputStr string, previousLine LogLine) (logLine LogLine, errorMsg
return logLine, errorMsg
}
// SprintLogRecord outputs the content of a logline
func SprintLogRecord(logLine LogLine) (output string){
output = ""
output = output + "Date " + logLine.Date + "\n"
output = output + "MyCall " + logLine.MyCall + "\n"
output = output + "Operator " + logLine.Operator + "\n"
output = output + "MyWWFF " + logLine.MyWWFF + "\n"
output = output + "MySOTA " + logLine.MySOTA + "\n"
output = output + "QslMsg " + logLine.QslMsg + "\n"
output = output + "Nickname " + logLine.Nickname + "\n"
output = output + "Mode " + logLine.Mode + "\n"
output = output + "ModeType " + logLine.ModeType + "\n"
output = output + "Band " + logLine.Band + "\n"
output = output + " Lower " + fmt.Sprintf("%f", logLine.BandLowerLimit) + "\n"
output = output + " Upper " + fmt.Sprintf("%f", logLine.BandUpperLimit) + "\n"
output = output + "Frequency " + logLine.Frequency + "\n"
output = output + "Time " + logLine.Time + "\n"
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"
output = output + "RSTsent " + logLine.RSTsent + "\n"
output = output + "RSTrcvd " + logLine.RSTrcvd + "\n"
output = output + "SOTA " + logLine.SOTA + "\n"
output = output + "WWFF " + logLine.WWFF + "\n"
return output
}
func lookupMode(lookup string) bool {
switch lookup {

Loading…
Cancel
Save