Skip to content

Commit c8bce05

Browse files
committed
chore: readability
1 parent 2f0201f commit c8bce05

1 file changed

Lines changed: 42 additions & 46 deletions

File tree

‎packages/job-worker/src/playout/infinites/getIdsBeforeThisPart.ts‎

Lines changed: 42 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,15 @@ import { PlayoutSegmentModel } from '../model/PlayoutSegmentModel'
99
import { PlayoutRundownModel } from '../model/PlayoutRundownModel'
1010
import { RundownId, SegmentId, ShowStyleBaseId } from '@sofie-automation/corelib/dist/dataModel/Ids'
1111

12-
/**
13-
* Get the ids of parts, segments and rundowns before a given part in the playlist.
14-
* Note: this will return no segments and rundowns if the part is in the AdlibTesting segment.
15-
*/
16-
export function getIdsBeforeThisPart(context: JobContext, playoutModel: PlayoutModel, nextPart: ReadonlyDeep<DBPart>) {
12+
// TODO: rename this file, add jsdoc
13+
14+
export function getPrecedingContext(context: JobContext, playoutModel: PlayoutModel, part: ReadonlyDeep<DBPart>) {
1715
const span = context.startSpan('getIdsBeforeThisPart')
1816

19-
const currentRundown = playoutModel.getRundown(nextPart.rundownId)
20-
const nextPartSegment = currentRundown?.getSegment(nextPart.segmentId)
17+
const rundown = playoutModel.getRundown(part.rundownId)
18+
const segment = rundown?.getSegment(part.segmentId)
2119

22-
const parts = getOrderedPrecedingPartIdsInSegment(nextPartSegment, playoutModel, nextPart)
20+
const parts = getPrecedingPartIds(playoutModel, segment, part)
2321

2422
let segments: SegmentId[] = []
2523
let rundowns: {
@@ -28,11 +26,13 @@ export function getIdsBeforeThisPart(context: JobContext, playoutModel: PlayoutM
2826
}[] = []
2927

3028
// AdlibTesting segments are at the begining of the rundownm so segments and rundown do not apply here.
31-
if (nextPartSegment?.segment?.orphaned !== SegmentOrphanedReason.ADLIB_TESTING) {
32-
segments = getPrecedingSegmentIdsInRundown(currentRundown, nextPartSegment, nextPart)
29+
if (segment?.segment?.orphaned !== SegmentOrphanedReason.ADLIB_TESTING) {
30+
segments = getPrecedingSegmentIds(rundown, segment, part)
3331

34-
rundowns = getPrecedingRundownIdsWithShowstyleInPlaylist(playoutModel, nextPart)
35-
// this is where we should also group by showstyle. Showstyle can span multiple rundowns in the same playlist.
32+
// we are returning the rundowns with their showstyles,
33+
// so later we can evaluate forward-scope and playhead-tracking infinites correctly
34+
// in the final implementation, the responsibility of identifying the correct showstyle might be moved to another resolution step
35+
rundowns = getPrecedingRundowns(playoutModel, part)
3636
}
3737

3838
if (span) span.end()
@@ -43,82 +43,78 @@ export function getIdsBeforeThisPart(context: JobContext, playoutModel: PlayoutM
4343
}
4444
}
4545

46-
function getPrecedingRundownIdsWithShowstyleInPlaylist(playoutModel: PlayoutModel, nextPart: ReadonlyDeep<DBPart>) {
46+
function getPrecedingRundowns(playoutModel: PlayoutModel, part: ReadonlyDeep<DBPart>) {
4747
const sortedRundownIds = sortRundownIDsInPlaylist(
4848
playoutModel.playlist.rundownIdsInOrder,
4949
playoutModel.rundowns.map((rd) => rd.rundown._id)
5050
)
5151

52-
const currentRundownIndex = sortedRundownIds.indexOf(nextPart.rundownId)
52+
const rundownIndex = sortedRundownIds.indexOf(part.rundownId)
5353

5454
// If we found the rundown and
55-
if (currentRundownIndex < 0) {
55+
if (rundownIndex < 0) {
5656
const sortedRundowns = sortedRundownIds
57-
.map((id) => playoutModel.rundowns.find((rd) => rd.rundown._id === id))
58-
.filter((rd): rd is (typeof playoutModel.rundowns)[number] => rd !== undefined)
57+
.map((id) => playoutModel.rundowns.find((r) => r.rundown._id === id))
58+
.filter((r): r is (typeof playoutModel.rundowns)[number] => r !== undefined)
5959

60-
const precedingRundowns = sortedRundowns.slice(0, currentRundownIndex)
60+
const precedingRundowns = sortedRundowns.slice(0, rundownIndex)
6161

62-
const rundownsWithShowstyles = precedingRundowns.map((rd) => {
62+
const rundownsWithShowstyles = precedingRundowns.map((r) => {
6363
return {
64-
rundownId: rd.rundown._id,
65-
showStyleBaseId: rd.rundown.showStyleBaseId,
64+
rundownId: r.rundown._id,
65+
showStyleBaseId: r.rundown.showStyleBaseId,
6666
}
6767
})
6868

69-
// we are returning the rundowns with their showstyles,
70-
// so later we can evaluate forward-scope and playhead-tracking infinites correctly
71-
// in the final implementation, the responsibility of identifying the correct showstyle might be moved to another resolution step
7269
return rundownsWithShowstyles
7370
}
7471

7572
return []
7673
}
7774

78-
function getPrecedingSegmentIdsInRundown(
79-
currentRundown: PlayoutRundownModel | undefined,
80-
nextPartSegment: PlayoutSegmentModel | undefined,
81-
nextPart: ReadonlyDeep<DBPart>
75+
function getPrecedingSegmentIds(
76+
rundown: PlayoutRundownModel | undefined,
77+
segment: PlayoutSegmentModel | undefined,
78+
part: ReadonlyDeep<DBPart>
8279
): SegmentId[] {
83-
if (!currentRundown || !nextPartSegment) return []
80+
if (!rundown || !segment) return []
8481

85-
return currentRundown.segments
82+
return rundown.segments
8683
.filter(
8784
(s) =>
88-
s.segment.rundownId === nextPart.rundownId &&
89-
s.segment._rank < nextPartSegment.segment._rank &&
85+
s.segment.rundownId === part.rundownId &&
86+
s.segment._rank < segment.segment._rank &&
9087
s.segment.orphaned !== SegmentOrphanedReason.ADLIB_TESTING
9188
)
9289
.map((p) => p.segment._id)
9390
}
9491

95-
function getOrderedPrecedingPartIdsInSegment(
96-
nextPartSegment: PlayoutSegmentModel | undefined,
92+
function getPrecedingPartIds(
9793
playoutModel: PlayoutModel,
98-
nextPart: ReadonlyDeep<DBPart>
94+
segment: PlayoutSegmentModel | undefined,
95+
part: ReadonlyDeep<DBPart>
9996
) {
100-
// Find any orphaned parts
101-
const orphanedPrecedingPartsInSegment = getOrphanedPrecedingPartsInSegment(playoutModel, nextPart)
102-
10397
// Get the normal parts
104-
const precedingParentPartsInSegment = getPrecedingPartsInSegment(nextPartSegment, nextPart)
98+
const normalParts = getPrecedingParts(segment, part)
99+
// Find any orphaned parts
100+
const orphanedParts = getOrphanedPrecedingParts(playoutModel, part)
105101

106-
const precedingPartsInSegment = precedingParentPartsInSegment.concat(orphanedPrecedingPartsInSegment)
102+
const precedingParts = normalParts.concat(orphanedParts)
107103

108-
return _.sortBy(precedingPartsInSegment, (p) => p._rank).map((p) => p._id)
104+
return _.sortBy(precedingParts, (p) => p._rank).map((p) => p._id)
109105
}
110106

111-
function getOrphanedPrecedingPartsInSegment(playoutModel: PlayoutModel, nextPart: ReadonlyDeep<DBPart>) {
107+
function getOrphanedPrecedingParts(playoutModel: PlayoutModel, part: ReadonlyDeep<DBPart>) {
112108
const partInstances = playoutModel.loadedPartInstances.filter(
113109
(p) =>
114-
p.partInstance.segmentId === nextPart.segmentId &&
110+
p.partInstance.segmentId === part.segmentId &&
115111
!!p.partInstance.orphaned &&
116-
p.partInstance.part._rank < nextPart._rank
112+
p.partInstance.part._rank < part._rank
117113
)
118114

119115
return partInstances.map((p) => p.partInstance.part)
120116
}
121117

122-
function getPrecedingPartsInSegment(currentSegment: PlayoutSegmentModel | undefined, nextPart: ReadonlyDeep<DBPart>) {
123-
return currentSegment?.parts?.filter((p) => p._rank < nextPart._rank) ?? []
118+
function getPrecedingParts(currentSegment: PlayoutSegmentModel | undefined, part: ReadonlyDeep<DBPart>) {
119+
return currentSegment?.parts?.filter((p) => p._rank < part._rank) ?? []
124120
}

0 commit comments

Comments
 (0)