Skip to content

Commit

Permalink
reduce tide to lows and highs and use cell merging to clean up tide view
Browse files Browse the repository at this point in the history
  • Loading branch information
mhelmetag committed Apr 18, 2018
1 parent 79179aa commit 14d3829
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ func tideToTable(t surflinef.Tide) {
table.SetHeader([]string{"Date", "Time", "Description", "Height"})
table.SetAutoMergeCells(true)

filtered := filterTides(t.DataPoints)
filtered := filterPoints(t.DataPoints)

tf := "2006-01-02 15:04:05"

Expand All @@ -329,27 +329,27 @@ func tideToTable(t surflinef.Tide) {
}

td := fmt.Sprintf("%d/%d/%d", tt.Month(), tt.Day(), tt.Year())
ttt := fmt.Sprintf("%d:%d", tt.Hour(), tt.Minute())
ttt := fmt.Sprintf("%02d:%02d", tt.Hour(), tt.Minute())
h := strconv.FormatFloat(float64(t.Height), 'f', 2, 32)
table.Append([]string{td, ttt, t.Type, h})
}

table.Render()
}

func filterTides(ts []surflinef.DataPoint) []surflinef.DataPoint {
validTides := []surflinef.DataPoint{}
for i := range ts {
t := ts[i]
func filterPoints(ps []surflinef.DataPoint) []surflinef.DataPoint {
vps := []surflinef.DataPoint{}
for i := range ps {
p := ps[i]

if validTide(t) {
validTides = append(validTides, t)
if validPoint(p) {
vps = append(vps, p)
}
}

return validTides
return vps
}

func validTide(t surflinef.DataPoint) bool {
return t.Type == "Low" || t.Type == "High" || t.Type == "Sunrise" || t.Type == "Sunset"
func validPoint(p surflinef.DataPoint) bool {
return p.Type == "Low" || p.Type == "High"
}

0 comments on commit 14d3829

Please sign in to comment.