spaniel: github.com/senseyeio/spaniel Index | Examples | Files

package spaniel

import "github.com/senseyeio/spaniel"

Index

Examples

Package Files

interval.go timespan.go

func IsInstant Uses

func IsInstant(a Span) bool

IsInstant returns true if the interval is deemed instantaneous

type ByEnd Uses

type ByEnd Spans

ByEnd sorts a list of spans by their end point

Code:

sort.Stable(spaniel.ByEnd(input))

for i := range input {
    fmt.Println(input[i].End())
}

Output:

2018-01-30 01:00:00 +0000 UTC
2018-01-30 01:30:00 +0000 UTC
2018-01-30 01:34:00 +0000 UTC
2018-01-30 01:35:00 +0000 UTC

func (ByEnd) Len Uses

func (s ByEnd) Len() int

func (ByEnd) Less Uses

func (s ByEnd) Less(i, j int) bool

func (ByEnd) Swap Uses

func (s ByEnd) Swap(i, j int)

type ByStart Uses

type ByStart Spans

ByStart sorts a list of spans by their start point

Code:

sort.Stable(spaniel.ByStart(input))

for i := range input {
    fmt.Println(input[i].Start())
}

Output:

2018-01-30 00:00:00 +0000 UTC
2018-01-30 00:30:00 +0000 UTC
2018-01-30 01:31:00 +0000 UTC
2018-01-30 01:33:00 +0000 UTC

func (ByStart) Len Uses

func (s ByStart) Len() int

func (ByStart) Less Uses

func (s ByStart) Less(i, j int) bool

func (ByStart) Swap Uses

func (s ByStart) Swap(i, j int)

type EndPoint Uses

type EndPoint struct {
    Element time.Time
    Type    EndPointType
}

EndPoint represents an extreme of an interval, and whether it is inclusive or exclusive (Closed or Open)

type EndPointType Uses

type EndPointType int

EndPointType represents whether the start or end of an interval is Closed or Open.

const (
    // Open means that the interval does not include a value
    Open EndPointType = iota
    // Closed means that the interval does include a value
    Closed
)

type IntersectionHandlerFunc Uses

type IntersectionHandlerFunc func(intersectingEvent1, intersectingEvent2, intersectionSpan Span) Span

IntersectionHandlerFunc is used by IntersectionWithHandler to allow for custom functionality when two spans intersect. It is passed the two spans that intersect, and span representing the intersection.

type Span Uses

type Span interface {
    Start() time.Time
    StartType() EndPointType
    End() time.Time
    EndType() EndPointType
}

Span represents a basic span, with a start and end time.

type Spans Uses

type Spans []Span

Spans represents a list of spans, on which other functions operate.

func (Spans) Intersection Uses

func (s Spans) Intersection() Spans

Intersection returns a list of Spans representing the overlaps between the contained spans. For example, given a list [A,B] where A and B overlap, a list [C] would be returned, with the span C covering the intersection of A and B.

Code:

intersection := input.Intersection()

for i := range intersection {
    fmt.Println(intersection[i].Start(), "->", intersection[i].End(), ": ", intersection[i].End().Sub(intersection[i].Start()))
}

Output:

2018-01-30 00:30:00 +0000 UTC -> 2018-01-30 01:00:00 +0000 UTC :  30m0s
2018-01-30 01:33:00 +0000 UTC -> 2018-01-30 01:34:00 +0000 UTC :  1m0s

func (Spans) IntersectionBetween Uses

func (s Spans) IntersectionBetween(b Spans) Spans

IntersectionBetween returns the slice of spans representing the overlaps between the contained spans and a given set of spans.

func (Spans) IntersectionBetweenWithHandler Uses

func (s Spans) IntersectionBetweenWithHandler(candidates Spans, intersectHandlerFunc IntersectionHandlerFunc) Spans

IntersectionBetweenWithHandler returns a list of pointers to Spans representing the overlaps between the contained spans and a given set of spans. It calls intersectHandlerFunc for each pair of spans that are intersected.

func (Spans) IntersectionWithHandler Uses

func (s Spans) IntersectionWithHandler(intersectHandlerFunc IntersectionHandlerFunc) Spans

IntersectionWithHandler returns a list of Spans representing the overlaps between the contained spans. For example, given a list [A,B] where A and B overlap, a list [C] would be returned, with the span C covering the intersection of the A and B. The provided handler function is notified of the two spans that have been found to overlap, and the span representing the overlap.

func (Spans) Union Uses

func (s Spans) Union() Spans

Union returns a list of Spans representing the union of all of the spans. For example, given a list [A,B] where A and B overlap, a list [C] would be returned, with the span C spanning both A and B.

Code:

union := input.Union()

for u := range union {
    fmt.Println(union[u].Start(), "->", union[u].End(), ": ", union[u].End().Sub(union[u].Start()))
}

Output:

2018-01-30 00:00:00 +0000 UTC -> 2018-01-30 01:30:00 +0000 UTC :  1h30m0s
2018-01-30 01:31:00 +0000 UTC -> 2018-01-30 01:35:00 +0000 UTC :  4m0s

func (Spans) UnionWithHandler Uses

func (s Spans) UnionWithHandler(unionHandlerFunc UnionHandlerFunc) Spans

UnionWithHandler returns a list of Spans representing the union of all of the spans. For example, given a list [A,B] where A and B overlap, a list [C] would be returned, with the span C spanning both A and B. The provided handler is passed the source and destination spans, and the currently merged empty span.

type TimeSpan Uses

type TimeSpan struct {
    // contains filtered or unexported fields
}

TimeSpan represents a simple span of time, with no additional properties. It should be constructed with NewEmpty.

Code:

start, _ := time.Parse("2006-01-02 15:04:05", "2018-01-01 00:00:00")
timespan := spaniel.New(start, time.Unix(1514768400, 0).UTC())

fmt.Printf("Start: %v (%v)\nEnd: %v (%v)\n", timespan.Start(), timespan.StartType(), timespan.End(), timespan.EndType())

Output:

Start: 2018-01-01 00:00:00 +0000 UTC (1)
End: 2018-01-01 01:00:00 +0000 UTC (0)

func New Uses

func New(start time.Time, end time.Time) *TimeSpan

New creates a span with a start and end time, with the types set to [] for instants and [) for spans.

func NewInstant Uses

func NewInstant(time time.Time) *TimeSpan

NewInstant creates a span with just a single time.

func NewWithTypes Uses

func NewWithTypes(start, end time.Time, startType, endType EndPointType) *TimeSpan

NewWithTypes creates a span with just a start and end time, and associated types, and is used when no handlers are provided to Union or Intersection.

func (TimeSpan) End Uses

func (ts TimeSpan) End() time.Time

End returns the end time of a span

func (TimeSpan) EndType Uses

func (ts TimeSpan) EndType() EndPointType

EndType returns the type of the end of the interval (Closed in this case)

func (TimeSpan) MarshalJSON Uses

func (ts TimeSpan) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshal

func (TimeSpan) Start Uses

func (ts TimeSpan) Start() time.Time

Start returns the start time of a span

func (TimeSpan) StartType Uses

func (ts TimeSpan) StartType() EndPointType

StartType returns the type of the start of the interval (Open in this case)

func (TimeSpan) String Uses

func (ts TimeSpan) String() string

String returns a string representation of a timespan

func (*TimeSpan) UnmarshalJSON Uses

func (ts *TimeSpan) UnmarshalJSON(b []byte) (err error)

UnmarshalJSON implements json.Unmarshal

type UnionHandlerFunc Uses

type UnionHandlerFunc func(mergeInto, mergeFrom, mergeSpan Span) Span

UnionHandlerFunc is used by UnionWithHandler to allow for custom functionality when two spans are merged. It is passed the two spans to be merged, and span which will result from the union.

Package spaniel imports 3 packages (graph). Updated 2019-08-19. Refresh now. Tools for package owners.