GenerateMockShow takes scenes/avgCuesPerScene/avgBlocksPerCue instead of fixed cue/block counts

This commit is contained in:
Ian Gulliver
2026-02-20 22:39:29 -07:00
parent 7d3a23dfc1
commit b527b94b16
3 changed files with 7 additions and 32 deletions

View File

@@ -28,7 +28,7 @@ func main() {
runAndExit = strings.Fields(*runAndExitStr) runAndExit = strings.Fields(*runAndExitStr)
} }
show := GenerateMockShow(5, 10, 30) show := GenerateMockShow(5, 3, 3, 5)
if err := show.Validate(); err != nil { if err := show.Validate(); err != nil {
fmt.Fprintf(os.Stderr, "Error validating show: %v\n", err) fmt.Fprintf(os.Stderr, "Error validating show: %v\n", err)
os.Exit(1) os.Exit(1)

View File

@@ -25,7 +25,7 @@ var delayNamePool = []string{
"1s Delay", "2s Delay", "3s Delay", "5s Delay", "Hold", "1s Delay", "2s Delay", "3s Delay", "5s Delay", "Hold",
} }
func GenerateMockShow(numTracks, numCues, numBlocks int) *Show { func GenerateMockShow(numTracks, numScenes, avgCuesPerScene, avgBlocksPerCue int) *Show {
rng := rand.New(rand.NewPCG(42, 0)) rng := rand.New(rand.NewPCG(42, 0))
show := &Show{} show := &Show{}
@@ -78,9 +78,6 @@ func GenerateMockShow(numTracks, numCues, numBlocks int) *Show {
} }
} }
placed := 0
cueIdx := 0
scene := 0
chainFromByTrack := make(map[int]*Block) chainFromByTrack := make(map[int]*Block)
needsEnd := make(map[string]*Block) needsEnd := make(map[string]*Block)
allowedTracks := make(map[int]bool, numTracks) allowedTracks := make(map[int]bool, numTracks)
@@ -88,14 +85,10 @@ func GenerateMockShow(numTracks, numCues, numBlocks int) *Show {
allowedTracks[i] = true allowedTracks[i] = true
} }
for placed < numBlocks && cueIdx < numCues { for scene := 1; scene <= numScenes; scene++ {
scene++ cuesInScene := 1 + rng.IntN(avgCuesPerScene*2)
cuesInScene := 2 + rng.IntN(3)
for intra := 1; intra <= cuesInScene; intra++ { for intra := 1; intra <= cuesInScene; intra++ {
if placed >= numBlocks || cueIdx >= numCues {
break
}
for trackIdx, blk := range chainFromByTrack { for trackIdx, blk := range chainFromByTrack {
if needsEnd[blk.ID] == nil { if needsEnd[blk.ID] == nil {
delete(chainFromByTrack, trackIdx) delete(chainFromByTrack, trackIdx)
@@ -109,9 +102,8 @@ func GenerateMockShow(numTracks, numCues, numBlocks int) *Show {
Name: curCueName, Name: curCueName,
} }
show.Blocks = append(show.Blocks, cue) show.Blocks = append(show.Blocks, cue)
cueIdx++
blocksThisCue := 1 + rng.IntN(numTracks*2) blocksThisCue := 1 + rng.IntN(avgBlocksPerCue*2)
cueTargets := []TriggerTarget{} cueTargets := []TriggerTarget{}
for id, blk := range needsEnd { for id, blk := range needsEnd {
cueTargets = append(cueTargets, TriggerTarget{Block: blk.ID, Hook: "END"}) cueTargets = append(cueTargets, TriggerTarget{Block: blk.ID, Hook: "END"})
@@ -123,16 +115,12 @@ func GenerateMockShow(numTracks, numCues, numBlocks int) *Show {
} }
} }
for range blocksThisCue { for range blocksThisCue {
if placed >= numBlocks {
break
}
trackIdx := rng.IntN(numTracks) trackIdx := rng.IntN(numTracks)
if !allowedTracks[trackIdx] { if !allowedTracks[trackIdx] {
continue continue
} }
block := randBlock(trackIdx) block := randBlock(trackIdx)
show.Blocks = append(show.Blocks, block) show.Blocks = append(show.Blocks, block)
placed++
if prev := chainFromByTrack[trackIdx]; prev != nil { if prev := chainFromByTrack[trackIdx]; prev != nil {
show.Triggers = append(show.Triggers, &Trigger{ show.Triggers = append(show.Triggers, &Trigger{
Source: TriggerSource{Block: prev.ID, Signal: "END"}, Source: TriggerSource{Block: prev.ID, Signal: "END"},
@@ -175,7 +163,6 @@ func GenerateMockShow(numTracks, numCues, numBlocks int) *Show {
Name: endCueName, Name: endCueName,
} }
show.Blocks = append(show.Blocks, endCue) show.Blocks = append(show.Blocks, endCue)
cueIdx++
show.Triggers = append(show.Triggers, &Trigger{ show.Triggers = append(show.Triggers, &Trigger{
Source: TriggerSource{Block: endCue.ID, Signal: "GO"}, Source: TriggerSource{Block: endCue.ID, Signal: "GO"},
Targets: endTargets, Targets: endTargets,
@@ -183,17 +170,5 @@ func GenerateMockShow(numTracks, numCues, numBlocks int) *Show {
} }
} }
for cueIdx < numCues {
scene++
emptyCueName := fmt.Sprintf("S%d Q1", scene)
cue := &Block{
ID: emptyCueName,
Type: "cue",
Name: emptyCueName,
}
show.Blocks = append(show.Blocks, cue)
cueIdx++
}
return show return show
} }

View File

@@ -7,7 +7,7 @@ import (
func TestBuildTimelineFromMockShow(t *testing.T) { func TestBuildTimelineFromMockShow(t *testing.T) {
t0 := time.Now() t0 := time.Now()
show := GenerateMockShow(5, 100, 1000) show := GenerateMockShow(5, 20, 4, 5)
t.Logf("GenerateMockShow: %v (%d blocks, %d triggers)", time.Since(t0), len(show.Blocks), len(show.Triggers)) t.Logf("GenerateMockShow: %v (%d blocks, %d triggers)", time.Since(t0), len(show.Blocks), len(show.Triggers))
t1 := time.Now() t1 := time.Now()
@@ -26,7 +26,7 @@ func TestBuildTimelineFromMockShow(t *testing.T) {
} }
func BenchmarkBuildTimeline(b *testing.B) { func BenchmarkBuildTimeline(b *testing.B) {
show := GenerateMockShow(5, 100, 1000) show := GenerateMockShow(5, 20, 4, 5)
if err := show.Validate(); err != nil { if err := show.Validate(); err != nil {
b.Fatal(err) b.Fatal(err)
} }