add run timer and other minor tweaks

This commit is contained in:
Bob Buxton 2020-05-31 15:36:01 +01:00
parent b59cc9e687
commit 9b8b7f1f2a
3 changed files with 130 additions and 23 deletions

View File

@ -281,13 +281,14 @@ switch -- $::opt {
-h -
--help -
default { # Help
puts "fmtrsv = Check for recording schedule issues and attempt to fix them"
puts "fmtrsv = Formats schedule entries from the rsv.db"
puts " "
puts "fmtrsv -h = produce this help"
puts "fmtrsv -fmt = format the recording schedule"
puts "fmtrsv options "
puts "no options will list all reservations"
puts ""
puts "Options "
puts "-h produce this help"
#puts "-d 0 = produce detailed debug on Stdout (0, 1, 2) "
puts "-n,-name xxx = select recording name contains"
puts "-s,-slot n = select slot"

View File

@ -10,7 +10,8 @@ set optarray {
{{No Unscheduled} {noUnsched} n {Don't check for episodes missing from schedule}}
{{No sCRID change} {noSCRID} n {Don't check for series CRID changes}}
{{No one off} {no1off} n {Don't check for episodes scheduled as one off programmes}}
{{No not recorded} {noNotRec} n {Don't check for failures to record}}
{{No not recording} {noNotRec} n {Don't check for failures to record}}
{{Recording wait} {recWait} 300 {Don't assume recording failed until x seconds late starting}}
{{No missing epg} {noMissEPG} n {Don't resolve missing epg entries}}
{{No epg changes} {noEPGchg} n {Don't resolve epg time/ duration/ event crid changes}}
{{No split checks} {noSplit} n {Don't resolve repeated split recordings}}

View File

@ -3,7 +3,7 @@
# author MymsMan based on webif functions by af123
source /mod/webif/lib/setup
require rsv.class epg.class system.class
require rsv.class epg.class system.class ts.class
proc log {msg {level 1}} {
@ -18,14 +18,14 @@ proc log {msg {level 1}} {
}
}
# let's mess with the internals - needs to be moved to rsv.class
rsv method set {ivName val} {
set $ivName $val
}
rsv method issplit {} {
if {$ucRecKind == 2} { return 1 } else { return 0 }
}
## let's mess with the internals - needs to be moved to rsv.class
#rsv method set {ivName val} {
# set $ivName $val
#}
#
#rsv method issplit {} {
# if {$ucRecKind == 2} { return 1 } else { return 0 }
#}
# Parse command options and apply defaults
proc checkopts {argv} {
@ -182,7 +182,7 @@ proc rsvscan {} {
global svcmap conflicts svcdef now thresh slot name def
svcmap
conflict-list
set sttimer [clock seconds]
set resvs [rsv list]
@ -318,26 +318,117 @@ proc rsvscan {} {
if {[llength $conflicts] > 1} {
log "++++ [llength $conflicts] Unresolved conflicts remain +++" 1
}
log "===============================================" 2
epg cleanup
set endtimer [clock seconds]
log "=== All done - run time [clock format $($endtimer - $sttimer) -format {%H:%M:%S}] ===" 1
}
#
# Should be recording now, check if it is
#
proc chkActive {resv dresv rstatus} {
global now svcmap svcdef
log "Already started? Status = $rstatus - $dresv" 1
if {$::opts(nonotrec)} {
log "-noNotRec - Not checking for failed recording" 2
return
}
# need to check whether it has actually started and schedule alternate if not recording
if {$rstatus=="recording"} {
# Recording but is it actually growing
# How to associate recording with slot?22
puts [system nugget recordings]
if {$::opts(recwait)+[$resv start] > $now} {
log "-recWait - Still within wait interval" 2
return
}
set svc $svcmap([$resv get hsvc])
set event_id [$resv get usevtid]
# Retrieve epg record for the episode
set record [lindex [\
epg dbfetch dump -service $svc -event $event_id -sort ""] 0]
set epgname [$record get name]
set ok true
set file [find_file $resv $epgname]
# need to check whether it has actually started and schedule alternate if not recording
if {$file !=0} {
set ifsz [file size "$file.ts"]
set cfsz $ifsz
for {set i 0} {$i < 5} {incr i} {
sleep 1
set cfsz [file size "$file.ts"]
if {$cfsz > $ifsz} {break}
}
if {!($cfsz > $ifsz)} {
log "$file.ts size size $cfsz not growing - $dresv" 1
set ok false
} else {
log "Recording OK - $dresv" 1
return
}
}
set rstatus [$resv status]
switch -exact -- $rstatus {
"recording" {
set ok false
log "*** Status recording but Not recording *** - $dresv" 0
}
"ready" -
"unknown" -
"arwatch" {
set ok false
log "*** Recording not started *** - $dresv" 0
}
default {
log "*** Status $rstatus Unexpected *** - $dresv" 0
return
}
}
#Find Alternate
set epgcrid [$record get event_crid]
set def $svcdef([$record get channel_hsvc])
set start [$record get start]
set others [epg dbfetch dump -crid $epgcrid -sort "start" ]
set other [findAlternate $resv $others $start $def 1]
if {$other != ""} {
set ostart [$other get start]
set odur [$other get duration]
set oend $($ostart+$odur)
set oname [$other get name]
set ocname [$other get channel_name]
set dother "[clock format $ostart -format {%d/%m/%y %H:%M}] [clock format $odur -format {%H:%M}] === $oname === $ocname"
# attempt to schedule the alternate (always 1-off)
schedule $other $dother "Alternate for non-recording"
conflict-list
return
} else {
log "Unable to schedule alternate for non-recording programme -$dresv " 0
}
}
# Find file name matching recordings
# {There must be a better way of doing it than name matching)
proc find_file {resv name} {
set files [split [system nugget recordings] "\n"]
set nl [split $name {}]
foreach file $files {
set fl [split [file tail $file] {}]
lmap n $nl f $fl {
if {$n==$f} {continue}
if {$n == {}} {
#names matchs check channel and start times match
set ts [ts fetch "$file.ts"]
if {[$ts get channel_num] != [$resv get usLcn] } {break}
if {[$ts get schedstart] != [$resv start] } {break}
#puts "$name - $file match"
return $file
}
if {![string is alnum $n]} {continue}
break
}
}
return 0
}
#
# Split recording, check for repeats incorrectly scheduled
@ -461,6 +552,10 @@ proc chkEpisode {resv epsd ecrid} {
set dother "[clock format $ostart -format {%d/%m/%y %H:%M}] [clock format $odur -format {%H:%M}] === $oname === $ocname"
# attempt to schedule the alternate (inplace)
if {!$::opts(noinplace)} {
if {[$other scheduled]} {
log "Alternate already scheduled "$deps--->$dother" 1
set other {}
}
update_event $resv $other $epsd "$deps--->$dother" "Event Changed"
conflict-list
return
@ -562,6 +657,10 @@ proc chkEpisode {resv epsd ecrid} {
# attempt to schedule the alternate
if {!$::opts(noinplace)} {
if {[$other scheduled]} {
log "Alternate already scheduled "$deps--->$dother" 1
set other {}
}
update_event $resv $other $epsd "$deps--->$dother" "Confict resolution"
conflict-list
continue
@ -612,8 +711,9 @@ proc scanAlternates {resv others start definition sametime samedef} {
# should favour same definition
if {$odef != $definition && $samedef} {continue}
log "Alternate Episode $dother" 2
if {[$other scheduled]} {
log "Already scheduled - $dother" 2
set sched [$other scheduled]
if {$sched >2} {
log "Already skipped - $dother" 2
continue
}
set oconflicts [rsv checkconflict \
@ -792,6 +892,11 @@ proc miss_epsd {resv desc} {
log "Already skipped episode $desc-->$dother" 2
continue
}
if {[$other scheduled]} {
log "Already scheduled elsewhere $desc-->$dother"
continue
}
log "Found Unscheduled episode $ocrid $desc-->$dother" 1
update_event $resv $other {} "$desc-->$dother" "Unscheduled episode"
}
@ -1001,7 +1106,7 @@ switch -- $opt {
lassign $optl desc key default helptxt
puts [format "-%-11s %-4s = %s" $key $default $helptxt]
}
puts "/nNote: Options are not case sensitive"
puts "\n Note: Options are not case sensitive"
}
}