gyrogpsc/core/trackings.go
2020-12-11 01:18:05 +01:00

107 lines
1.8 KiB
Go

package core
import (
"github.com/google/uuid"
"log"
"time"
)
type OpMode uint8
const (
STOPPED OpMode = iota
LIVE
REPLAY
)
type TrackingService struct {
Current *Tracking
config *Configuration
repo *repository
pipe *pipeline
opMode OpMode
collectors []Collector
//publish Publisher
}
type Tracking struct {
trackingMetadata
data []*sensorRecord
}
type trackingMetadata struct {
UUID uuid.UUID
TimeCreated time.Time
}
type sensorRecord struct {
RecordTime time.Time
Sensordata
}
func Service(c *Configuration) *TrackingService {
d := NewDispatcher()
r := &repository{}
return &TrackingService{
Current: nil,
opMode: STOPPED,
config: c,
repo: r,
pipe: NewPipeline(d, r, c),
collectors: nil,
}
}
func (t *TrackingService) NewTracking(cols ...CollectorType) {
t.opMode = LIVE
for _, col := range cols {
t.collectors = append(t.collectors, NewCollector(col, t.pipe, t.config))
}
t.Current = emptyTracking()
}
func (t *TrackingService) StartRecord() {
if t.opMode != LIVE {
log.Println("trackingservice: wrong mode of operation")
}
t.pipe.Run()
for _, e := range t.collectors {
e.Collect()
}
}
func (t *TrackingService) StopRecord() {
if t.opMode != LIVE {
log.Println("trackingservice: wrong mode of operation")
}
t.pipe.Stop()
for _, e := range t.collectors {
e.Stop()
}
err := t.repo.SaveTracking(t.Current)
if err != nil {
log.Println(err)
}
t.Current = emptyTracking()
}
func (t *TrackingService) Reset() {
}
func (t *TrackingService) LoadTrackings() {
}
func (t *TrackingService) LoadTracking(trackingId uuid.UUID) {
}
func emptyTracking() *Tracking {
return &Tracking{
trackingMetadata: trackingMetadata{
UUID: uuid.New(),
},
data: []*sensorRecord{},
}
}