Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

6: Implement randomized scheduling #12

Merged
merged 1 commit into from
Jun 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions content/schedule.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"github.com/jmillerv/go-utilities/formatter"
log "github.com/sirupsen/logrus"
"github.com/spf13/viper"
"math/rand"
"time"
)

Expand All @@ -27,6 +28,8 @@ type Slot struct {
End string
}

var Shuffled bool

var TimeslotMap = map[Timeslot]*Slot{
Early: {"4:00 AM", "6:00 AM"},
Morning: {"6:00 AM", "8:00 AM"},
Expand All @@ -50,8 +53,11 @@ func (s *Scheduler) Run() error {
log.Info("Starting Daemon")
now := time.Now()
ts := getTimeSlot(&now)
// if randomized mode do x

for _, p := range s.Content.Programs {
log.Debugf("program %v", formatter.StructToIndentedString(p))
// Check Timeslots
if ts == p.Timeslot || ts == All {
log.Infof("getting media type: %v", p.Type)
content := p.GetMedia()
Expand All @@ -60,13 +66,33 @@ func (s *Scheduler) Run() error {
content.Play() // play will block until done
}
}
// if radio station start 30 minute counter.
// smartly allocate programs to timeslots based on length if known
// if time between TimeSlotMap
// play program from that slot.
// wait for program to finish
// get next
return nil
}

// Shuffle plays through the config content at random
func (s *Scheduler) Shuffle() error {
rand.Seed(time.Now().UnixNano())
rand.Shuffle(len(s.Content.Programs),
func(i, j int) {
s.Content.Programs[i], s.Content.Programs[j] = s.Content.Programs[j], s.Content.Programs[i]
})
for _, p := range s.Content.Programs {
log.Debugf("program %v", formatter.StructToIndentedString(p))
log.Infof("getting media type: %v", p.Type)
content := p.GetMedia()
log.Debugf("media struct: %v", content)
content.Get()
content.Play() // play will block until done
}
return nil
}

func getTimeSlot(t *time.Time) Timeslot {
// if t between certain times return Timeslot
return All
Expand Down
14 changes: 2 additions & 12 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,9 @@ module github.com/jmillerv/go-dj
go 1.16

require (
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6 // indirect
github.com/coreos/etcd v3.3.10+incompatible // indirect
github.com/coreos/go-etcd v2.0.0+incompatible // indirect
github.com/faiface/beep v1.1.0 // indirect
github.com/google/martian v2.1.0+incompatible
github.com/gopherjs/gopherwasm v1.0.0 // indirect
github.com/gordonklaus/portaudio v0.0.0-20200911161147-bb74aa485641 // indirect
github.com/faiface/beep v1.1.0
github.com/jmillerv/go-utilities v0.0.0-20211009175413-077cd5304cea
github.com/mmcdole/gofeed v1.1.3 // indirect
github.com/sirupsen/logrus v1.8.1
github.com/spf13/viper v1.8.1
github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8 // indirect
github.com/urfave/cli v1.22.3 // indirect
github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77 // indirect
gopkg.in/DATA-DOG/go-sqlmock.v1 v1.3.0 // indirect
github.com/urfave/cli v1.22.3
)
Loading