Skip to content
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
35 changes: 15 additions & 20 deletions docs/planning/EVENT-AWARE-CHANNELS-DESIGN-NOTE.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,29 +45,24 @@ Per channel, from data the build already holds: the channel name, the provider g

### Signals, strong and weak

Points are a first guess [UNVERIFIED]. They must be tuned in the report-only step on the user's real lineup, and never trusted after tuning on one lineup.

| Signal | Where | Strength | Points |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------- | -------- | ----------------------------------------------- |
| Guide time mostly fillers: at least half of the window is titles like "No Event", "No Events", "No Live Event", "TBA", "TBD", "To Be Announced", "Coming Soon", "Event Offline" | provider guide | Strong | 3 |
| Name has PPV or "Pay Per View" as a whole word | channel name | Strong | 3 |
| Numbered family: two or more channels in one group share a name stem and differ by a trailing number ("PPV 1", "PPV 2") | names and groups | Medium | 2 |
| Provider group has PPV, "Pay Per View", "Event" or "Events" | group title | Medium | 2 |
| Name has "Event" or "Special Event" as a whole word with a slot number ("Event 3") | channel name | Medium | 2 |
| Name has "Event" as a whole word, no number | channel name | Weak | 1 |
| Few, long programmes: median programme length at least 2 hours | provider guide | Weak | 1 |
| One distinct title per local day, no title repeated | provider guide | Weak | 1 |
| Titles carry event words ("vs", "Main Card", "Prelims", "Live", a sports name token) | provider guide | Weak | 1 |
| Category is wrestling, mma, boxing or other sports | category decision | Weak | 1, only if other signals already gave 2 or more |
| Only filler "Off Air" or "Stand By" titles (no event wording) | provider guide | Weak | 1 |
| Normal TV pattern: 10 or more non-filler programmes in the window with median length 60 minutes or less | provider guide | Against | minus 2 |
Slice 1 measured two real guides (28,239 and 6,100 channels). Filler share alone flagged 129 and 57 normal channels (off-air and blacked-out feeds) and missed event channels whose placeholder is the channel name or one generic word. Average block length, distinct titles per day and venue text did not separate event channels from normal ones, so they are not used. The rules below replace the first guess of points and scores.

Placeholder time is programme time whose title is a filler ("Next Event Coming Soon", "SIGN OFF", "Channel No Longer Available", "To Be Announced", "No Event", "TBA", "Event Not Started", "Coming Soon"), equals the channel name (ignoring case and punctuation), or is one generic word such as "Pay-Per-View". The filler list is one small data list in `Get-ChannelForgeEventChannelCandidate.ps1`.

| Signal | Where | Result |
| ----------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------ | -------------------------------------------------------------------------------------------------------- |
| Name has PPV, Pay Per View or Pay-Per-View | channel name | `high`, always; `medium` only with 3 or more different real programmes and placeholder time at most half |
| Name has an event word (PPV, Pay Per View, Event, Events, UFC, WWE, AEW, Boxing, Fight, Wrestling, Live Event) and placeholder time over half of guide time | name and guide | `high` |
| Name has an event word and real programmes | name and guide | `medium` |
| Name has an event word and no programmes at all | channel name | `medium`, reason "no guide data" |
| No event word, category is a sports category, and most guide time is in single blocks of 6 hours or more | category and guide | `low` |

Rules for the result:

- Score 6 or more is `high`, 4 to 5 `medium`, 2 to 3 `low`, under 2 is not reported.
- Without any guide signal, confidence stops at `medium`. A name and a group are only words; guide behavior is evidence.
- Each fired signal adds one plain reason, for example `name has "PPV"; 3 sibling channels PPV 2 to PPV 4; 78% of guide time is "No Event"`.
- The category never counts by itself. It tells which events matter, not whether the channel is an event channel.
- A channel that matches none of the rows is not reported. A normal channel with filler and no event word is not flagged.
- Each rule adds one plain reason, for example `name has "ppv"; 78% of guide time is placeholder titles`.
- Only `high` will act (slice 3). `medium` and `low` keep their normal guide and are only listed.
- The 6 hour block limit for `low` is a first guess [UNVERIFIED]; it was not tuned on the measured guides.

### False-positive and false-negative risk (plain)

Expand Down
13 changes: 13 additions & 0 deletions scripts/Build-Lineup.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -1138,6 +1138,19 @@ if ($candidatePublished) {
}
}

# Event channels (event-channel/v2, slice 1): report only. A failure is one warning line.
if ($candidatePublished) {
try {
$eventInput = @(Invoke-ChannelForgePrivateCandidateFunction -Name 'Get-ChannelForgeEventChannelInput' -Arguments @{ CandidateDirectory = $candidateNamespacePath; CategoryReport = (Get-ChannelForgeCategoryReport -CandidateDirectory $candidateNamespacePath -RepositoryRoot $Root); Programme = @($allProgrammes) })
$eventFound = @(Invoke-ChannelForgePrivateCandidateFunction -Name 'Get-ChannelForgeEventChannelCandidate' -Arguments @{ Channel = $eventInput })
$eventLines = Invoke-ChannelForgePrivateCandidateFunction -Name 'Get-ChannelForgeEventChannelSummaryLines' -Arguments @{ Candidate = $eventFound }
foreach ($eventLine in $eventLines) { $md += (Get-SafeReportText $eventLine) }
}
catch {
Write-Warning 'The event channel check could not run, so the event channel section is left out of the summary.'
}
}

# Guide comparison (xguide-compare/v1): report only. A failure is one warning line.
if (@($allProgrammes).Count -gt 0) {
try {
Expand Down
94 changes: 94 additions & 0 deletions src/ChannelForge/Private/Get-ChannelForgeEventChannelCandidate.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
function Get-ChannelForgeEventChannelCandidate {
# event-channel/v2, slice 1: report only. One record per channel that looks like an event
# channel (PPV 1 and similar), with a confidence and plain reasons. Pure: no file access,
# nothing stored, nothing hashed. Rules and measured counts are in
# docs\planning\EVENT-AWARE-CHANNELS-DESIGN-NOTE.md (part A).
# Each Channel needs Key, DisplayName, GroupTitle, Category and Programmes (Title, Start, Stop).
[CmdletBinding()]
param([Parameter(Mandatory)][AllowEmptyCollection()][object[]]$Channel)

# Placeholder titles, compared after lowercasing and dropping punctuation. Extend here.
$fillers = @('next event coming soon', 'sign off', 'channel no longer available', 'to be announced', 'tba', 'tbd',
'no event', 'no events', 'no live event', 'event not started', 'coming soon', 'event offline',
'pay per view', 'ppv', 'event', 'events')
$ppvWords = @([pscustomobject]@{ Key = 'ppv'; Aliases = @('ppv', 'pay per view') })
$eventWords = @([pscustomobject]@{ Key = 'event'; Aliases = @('ppv', 'pay per view', 'event', 'events', 'ufc', 'wwe', 'aew', 'boxing', 'fight', 'wrestling', 'live event') })
$sportsKeys = @(Get-ChannelForgeOneGuideCategoryRegistry | Where-Object { $_.Group -ceq 'sports' } | ForEach-Object { [string]$_.Key })
$normalize = { param([string]$Text) ((($Text.ToLowerInvariant() -replace '[^\p{L}\p{N}]+', ' ')).Trim()) }

foreach ($item in $Channel) {
$name = & $normalize ([string]$item.DisplayName)
$ppvHit = @(Find-ChannelForgeCategoryWord -Text $name -Registry $ppvWords -Property Aliases)
$eventHit = @(Find-ChannelForgeCategoryWord -Text $name -Registry $eventWords -Property Aliases)
$programmes = @($item.Programmes)

$total = 0.0; $placeholder = 0.0; $long = 0.0; $realTitles = @{}
foreach ($programme in $programmes) {
$hours = ([datetimeoffset]$programme.Stop - [datetimeoffset]$programme.Start).TotalHours
if ($hours -le 0) { continue }
$title = & $normalize ([string]$programme.Title)
$total += $hours
if ($fillers -contains $title -or $title -ceq $name) { $placeholder += $hours }
else { $realTitles[$title] = $true; if ($hours -ge 6) { $long += $hours } }
}
$share = if ($total -gt 0) { $placeholder / $total } else { 0.0 }
$percent = [int][math]::Round($share * 100)
$reasons = [System.Collections.Generic.List[string]]::new()
$confidence = $null

if ($ppvHit.Count -gt 0) {
$reasons.Add("name has `"$($ppvHit[0].Word)`"")
# Always high, unless the guide shows several different real programmes.
if ($realTitles.Count -ge 3 -and $share -le 0.5) { $confidence = 'medium'; $reasons.Add("$($realTitles.Count) different real programmes, so the normal guide is likely fine") }
else { $confidence = 'high'; if ($total -gt 0) { $reasons.Add("$percent% of guide time is placeholder titles") } }
}
elseif ($eventHit.Count -gt 0) {
$reasons.Add("name has `"$($eventHit[0].Word)`"")
if ($total -eq 0) { $confidence = 'medium'; $reasons.Add('no guide data') }
elseif ($share -gt 0.5) { $confidence = 'high'; $reasons.Add("$percent% of guide time is placeholder titles") }
else { $confidence = 'medium'; $reasons.Add('real programmes in the guide') }
}
elseif ($sportsKeys -contains [string]$item.Category -and $total -gt 0 -and $long / $total -gt 0.5) {
$confidence = 'low'
$reasons.Add("category $($item.Category); most guide time is in blocks of 6 hours or more")
}
if ($null -eq $confidence) { continue }

[pscustomobject][ordered]@{
Key = [string]$item.Key
DisplayName = [string]$item.DisplayName
GroupTitle = [string]$item.GroupTitle
Confidence = $confidence
Reasons = @($reasons)
}
}
}

function Get-ChannelForgeEventChannelInput {
# Joins the candidate channels, their category and their provider programmes into the
# shape Get-ChannelForgeEventChannelCandidate reads. Programmes join on the exact tvg-id.
[CmdletBinding()]
param(
[Parameter(Mandatory)][string]$CandidateDirectory,
[Parameter(Mandatory)][object]$CategoryReport,
[AllowEmptyCollection()][object[]]$Programme = @()
)

$categoryOf = @{}
foreach ($row in $CategoryReport.Rows) { if ($null -ne $row.Category) { $categoryOf[[string]$row.ChannelKey] = [string]$row.Category } }
$byGuideId = [System.Collections.Generic.Dictionary[string, object]]::new([System.StringComparer]::Ordinal)
foreach ($entry in $Programme) {
$guideId = [string]$entry.RawChannelId
if (-not $byGuideId.ContainsKey($guideId)) { $byGuideId[$guideId] = [System.Collections.Generic.List[object]]::new() }
$byGuideId[$guideId].Add([pscustomobject]@{ Title = [string]$entry.Title; Start = $entry.Start; Stop = $entry.End })
}
foreach ($channel in @(Read-ChannelForgeCandidateChannels -Directory $CandidateDirectory)) {
$key = Get-ChannelForgeChannelKey -Url ([string]$channel.Url)
$guideId = [string]$channel.TvgId
[pscustomobject]@{
Key = $key; DisplayName = [string]$channel.DisplayName; GroupTitle = [string]$channel.Group
Category = $categoryOf[$key]
Programmes = $(if ($guideId -and $byGuideId.ContainsKey($guideId)) { @($byGuideId[$guideId]) } else { @() })
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
function Get-ChannelForgeEventChannelSummaryLines {
<#
.SYNOPSIS
Turns event channel candidates into the few lines shown in the build summary (event-channel/v2, report only).
#>
[CmdletBinding()]
param([AllowEmptyCollection()][object[]]$Candidate = @(), [int]$Cap = 5)

$found = @($Candidate)
if ($found.Count -eq 0) { return @() }
$high = @($found | Where-Object { $_.Confidence -ceq 'high' })
$medium = @($found | Where-Object { $_.Confidence -ceq 'medium' })
$low = @($found | Where-Object { $_.Confidence -ceq 'low' })
$lines = @('', '## Event Channels',
"$($found.Count) channels look like event channels: $($high.Count) high, $($medium.Count) medium, $($low.Count) low. Nothing was changed.")
foreach ($row in @($high | Select-Object -First $Cap)) {
$lines += "- $($row.DisplayName) (group '$($row.GroupTitle)', high): $(@($row.Reasons) -join '; ')"
}
if ($high.Count -gt $Cap) { $lines += "- and $($high.Count - $Cap) more" }
return $lines
}
Loading
Loading