mirror of
https://github.com/taigrr/most-specific-period.git
synced 2026-04-02 03:38:41 -07:00
feat: Initial changes to handline generating a timeline
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package msp
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sort"
|
||||
"time"
|
||||
)
|
||||
@@ -58,3 +59,26 @@ func FlattenPeriods(periods ...Period) (ids []string) {
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func GenerateTimeline(periods ...Period) (out []string) {
|
||||
periodsByID := make(map[string]Period)
|
||||
ids := FlattenPeriods(periods...)
|
||||
for _, val := range periods {
|
||||
id := val.GetIdentifier()
|
||||
periodsByID[id] = val
|
||||
}
|
||||
start := periodsByID[ids[0]].GetStartTime()
|
||||
for _, val := range ids {
|
||||
next, err := GetNextChangeOver(start, periods...)
|
||||
if err == nil {
|
||||
if next.Equal(periodsByID[val].GetStartTime()) {
|
||||
start = periodsByID[val].GetStartTime()
|
||||
next = periodsByID[val].GetEndTime()
|
||||
}
|
||||
frame := fmt.Sprintf("%s\t%s\t%s\n", val, start, next)
|
||||
out = append(out, frame)
|
||||
start = next
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user