Skip to content

Commit

Permalink
Fix time gap issues
Browse files Browse the repository at this point in the history
  • Loading branch information
jmMeessen authored Sep 25, 2020
1 parent 2e1313a commit 884631a
Show file tree
Hide file tree
Showing 6 changed files with 308 additions and 51 deletions.
7 changes: 4 additions & 3 deletions doc/whats_new.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
* Date can have several delimiter ("-", "/", ".", or " ")
* Partial dates can be entered ("20-9-6" => "2020-09-06")
* The new (FLE v3) "DAY" keyword is now supported (increment is 10 max)
* Date, band, and mode can be specified on a same line, even with a QSO
* Correctly process of optional WWFF keyword
* Correct some typos
* Date, band, and mode can be specified on a same line, even within a QSO line
* Correct processing of optional WWFF keyword
* Time is now correctly inferred when start and end of gap is in the same minute
* Correct some typos and bugs

## Previous releases

Expand Down
13 changes: 11 additions & 2 deletions docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,18 @@

## Running the container

To start and execute the `<FLEcli command>` use : `docker run --rm -i --user $(id -u):$(id -g) -v $(pwd):/FLEcli_data on4kjm/flecli <FLEcli command>`. If no command is specified, help is displayed.
To start and execute the `<FLEcli command>` use : `docker run --rm -i --user $(id -u):$(id -g) -v "$(pwd)":/FLEcli_data on4kjm/flecli <FLEcli command>`. If no command is specified, help is displayed.

This little command will create an alias that avoids typing the whole command: `alias FLEcli="docker run --rm --user $(id -u):$(id -g) -v $(pwd):/FLEcli_data on4kjm/flecli"`. To use it, type `FLEcli version` for example.
This bash script (MAC OS or Linux) will do the trick:

````
#!/bin/bash
CURRENT_UID=$(id -u):$(id -g)
docker run --rm -t --user ${CURRENT_UID} -v "$(pwd)":/FLEcli_data on4kjm/flecli:latest "$@"
````

By creating an alias like here after, this command can be called from everywhere. `alias FLEcli="~/myDir/docker-FLEcli.sh"`. To use it, type `FLEcli version` for example.

Important note: when specifying the path of a file (input or output), it must be relative to the directory the container was started in.

Expand Down
34 changes: 19 additions & 15 deletions fleprocess/inferTime.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,23 +54,10 @@ func (tb *InferTimeBlock) String() string {
//finalizeTimeGap makes the necessary checks and computation
func (tb *InferTimeBlock) finalizeTimeGap() error {

//Check that lastRecordedTime and nextValidTime are not null
if tb.lastRecordedTime.IsZero() {
return errors.New("Gap start time is empty")
}
if tb.nextValidTime.IsZero() {
return errors.New("Gap end time is empty")
}

//Are the two times equal?
if tb.nextValidTime == tb.lastRecordedTime {
return errors.New("The start and end gap times are equal")
if err :=tb.validateTimeGap(); err != nil {
return err
}

//Fail if we have a negative time difference
if tb.nextValidTime.Before(tb.lastRecordedTime) {
return errors.New("Gap start time is later than the Gap end time")
}

//Compute the gap
diff := tb.nextValidTime.Sub(tb.lastRecordedTime)
Expand All @@ -86,6 +73,23 @@ func (tb *InferTimeBlock) finalizeTimeGap() error {
return nil
}

//validateTimeGap checks some important assumptions
func (tb *InferTimeBlock) validateTimeGap() error{
//Check that lastRecordedTime and nextValidTime are not null
if tb.lastRecordedTime.IsZero() {
return errors.New("Gap start time is empty")
}
if tb.nextValidTime.IsZero() {
return errors.New("Gap end time is empty")
}

//Fail if we have a negative time difference
if tb.nextValidTime.Before(tb.lastRecordedTime) {
return errors.New("Gap start time is later than the Gap end time")
}
return nil
}

//storeTimeGap updates an InferTimeBLock (last valid time, nbr of records without time). It returns true if we reached the end of the time gap.
func (tb *InferTimeBlock) storeTimeGap(logline LogLine, position int) (bool, error) {
var err error
Expand Down
8 changes: 3 additions & 5 deletions fleprocess/inferTime_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,16 +168,14 @@ func TestInferTimeBlock_computeGaps_noDifference(t *testing.T) {
tb := InferTimeBlock{}
tb.lastRecordedTime = time.Date(2020, time.May, 24, 14, 00, 0, 0, time.UTC)
tb.nextValidTime = time.Date(2020, time.May, 24, 14, 00, 00, 0, time.UTC)
tb.noTimeCount = 2

//When
err := tb.finalizeTimeGap()

//Then
if err == nil {
t.Error("Should have failed with an error")
}
if err.Error() != "The start and end gap times are equal" {
t.Errorf("Did not not fail with the expected error. Failed with %s", err)
if err != nil {
t.Errorf("Should not have failed with an error (%s)", err)
}
}

Expand Down
56 changes: 31 additions & 25 deletions fleprocess/load_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
"time"
)

//LoadFile FIXME
//LoadFile FIXME:
//returns nill if failure to process
func LoadFile(inputFilename string, isInterpolateTime bool) (filleFullLog []LogLine, isProcessedOK bool) {
file, err := os.Open(inputFilename)
Expand All @@ -49,6 +49,9 @@ func LoadFile(inputFilename string, isInterpolateTime bool) (filleFullLog []LogL

file.Close()

//isInferTimeFatalError is set to true is something bad happened while storing time gaps.
isInferTimeFatalError := false

regexpLineComment := regexp.MustCompile("^[[:blank:]]*#")
regexpOnlySpaces := regexp.MustCompile("^\\s+$")
regexpSingleMultiLineComment := regexp.MustCompile("^[[:blank:]]*{.+}$")
Expand Down Expand Up @@ -258,7 +261,6 @@ func LoadFile(inputFilename string, isInterpolateTime bool) (filleFullLog []LogL
previousLogLine.MyGrid = headerMyGrid
previousLogLine.QSLmsg = headerQslMsg //previousLogLine.QslMsg is redundant
previousLogLine.Nickname = headerNickname
//previousLogLine.Date = headerDate

//parse a line
logline, errorLine := ParseLine(eachline, previousLogLine)
Expand All @@ -268,26 +270,22 @@ func LoadFile(inputFilename string, isInterpolateTime bool) (filleFullLog []LogL
fullLog = append(fullLog, logline)

//store time inference data
if isInterpolateTime {
if isInterpolateTime && !isInferTimeFatalError {
var isEndOfGap bool
if isEndOfGap, err = wrkTimeBlock.storeTimeGap(logline, len(fullLog)); err != nil {
fmt.Println("\nProcessing errors:")
for _, errorLogLine := range errorLog {
fmt.Println(errorLogLine)
}
log.Println("Fatal error: ", err)
os.Exit(1)
errorLog = append(errorLog, fmt.Sprintf("Fatal error at line %d: %s", lineCount, err))
isInferTimeFatalError = true
}
//If we reached the end of the time gap, we make the necessary checks and make our gap calculation
if isEndOfGap {
if err := wrkTimeBlock.finalizeTimeGap(); err != nil {
//If an error occured it is a fatal error
fmt.Println("\nProcessing errors:")
for _, errorLogLine := range errorLog {
fmt.Println(errorLogLine)
}
log.Println("Fatal error: ", err)
os.Exit(1)
errorLog = append(errorLog, fmt.Sprintf("Fatal error at line %d: %s", lineCount, err))
isInferTimeFatalError = true
}

if isInferTimeFatalError {
break
}

//add it to the gap collection
Expand Down Expand Up @@ -320,16 +318,24 @@ func LoadFile(inputFilename string, isInterpolateTime bool) (filleFullLog []LogL

//if asked to infer the date, lets update the loaded logfile accordingly
if isInterpolateTime {
for _, timeBlock := range missingTimeBlockList {
for i := 0; i < timeBlock.noTimeCount; i++ {
position := timeBlock.logFilePosition + i
pLogLine := &fullLog[position]

// durationOffset := time.Second * time.Duration(timeBlock.deltatime*(i+1))
durationOffset := timeBlock.deltatime * time.Duration(i+1)
newTime := timeBlock.lastRecordedTime.Add(durationOffset)
updatedTimeString := newTime.Format("1504")
pLogLine.Time = updatedTimeString
//Do we have an open timeBlok that has not been closed.
if (wrkTimeBlock.noTimeCount > 0) && (wrkTimeBlock.nextValidTime.IsZero()) {
errorLog = append(errorLog, fmt.Sprint("Fatal error: missing new time to infer time"))
} else {
for _, timeBlock := range missingTimeBlockList {
if err := timeBlock.validateTimeGap(); err != nil {
errorLog = append(errorLog, fmt.Sprintf("Fatal error: %s", err))
break
}
for i := 0; i < timeBlock.noTimeCount; i++ {
position := timeBlock.logFilePosition + i
pLogLine := &fullLog[position]

durationOffset := timeBlock.deltatime * time.Duration(i+1)
newTime := timeBlock.lastRecordedTime.Add(durationOffset)
updatedTimeString := newTime.Format("1504")
pLogLine.Time = updatedTimeString
}
}
}
}
Expand Down
Loading

0 comments on commit 884631a

Please sign in to comment.