# Space used calculation
# Scott Presnell, srp@tworoads.net, Wed Nov 21 10:31:25 PST 2001
# Borrows heavliy from module ui.itcl procs nowshowing and showing
# $Id: spaceused.itcl,v 1.9 2002/06/21 21:02:38 srp Exp srp $
#
# Does not take into account variable bit rates, assumes standard
# bitrates.
#
# Does not take into account deleted (but still available) recordings
#
# "Actual Hrs" reflects disk space used translated into real world
# hours as calculated with the appropriate bitrate for the given quality
#
# "Capacity Hrs" reflects disk space used translated into basic quality
# capacity hours at the appropriate bitrate: should be comparable to
# your machine's stated basic quality capacity.
proc action_spaceused {chan path env} {
global db
global tzoffset
global selectiontypes
global presentationbehtypes
global expirationtypes
global qualitytypes
global qualityfactors
global mbperhr
set basicbyselection "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0"
set mediumbyselection "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0"
set highbyselection "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0"
set bestbyselection "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0"
set totalbyselection "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0"
set basicbyexpiration "0 0 0"
set mediumbyexpiration "0 0 0"
set highbyexpiration "0 0 0"
set bestbyexpiration "0 0 0"
set totalbyexpiration "0 0 0"
set basictotal 0
set mediumtotal 0
set hightotal 0
set besttotal 0
set basicetotal 0
set mediumetotal 0
set highetotal 0
set bestetotal 0
if {[string index $path 0] == "/"} {
set path [string range $path 1 end]
}
if { $path == ""} { set path 0 }
if {$::version3} {
set nowshowingdir "/Recording/NowShowingByTitle"
} else {
set nowshowingdir "/Recording/NowShowing"
}
ForeachMfsFileTrans fsid name type $nowshowingdir "" 15 {
set rec [db $db openid $fsid]
set showing [dbobj $rec get Showing]
set showingfsid [dbobj $rec gettarget Showing]
set program [dbobj $showing get Program]
set title [strim [dbobj $program get Title]]
if {$::version3} {
set recbeh [dbobj $rec get RecordingBehavior]
set seltype [dbobj $recbeh get PresentationBehavior]
if { $seltype == 10 || $seltype == 9 } {
if { $title == "" } {
set title "Manual Recording"
} else {
set title "Manual: $title"
}
}
} else {
set seltype [dbobj $rec get SelectionType]
if { $seltype == 10 || $seltype == 5 } {
if { $title == "" } {
set title "Manual Recording"
} else {
set title "Manual: $title"
}
}
}
set state [dbobj $rec get State]
if { [regexp {([0-9]*)/(.*)} $showingfsid junk fsid subobjid] } {
set showing [db $db openidconstruction $fsid $subobjid]
} else {
set showing [db $db openid $showingfsid]
}
set rec [dbobj $showing get IndexUsedBy]
set recfsid ""
if { $rec == "" } {
set recfsid [get_fsidbyprefix "/Recording/Active" "4:$day:$timestr:"]
}
set station [dbobj $showing get Station]
set stationid [dbobj $station fsid]
if { $rec == "" && $recfsid != "" } {
set rec [db $db openid $recfsid]
set showing2 [dbobj $rec get Showing]
set station2 [dbobj $showing2 get Station]
set stationfsid2 [dbobj $station2 fsid]
if { $stationid != $stationfsid2 } {
set rec ""
} else {
set showing $showing2
}
}
if { $rec != "" && $recfsid == "" } {
set recfsid [dbobj $rec fsid]
}
# if { $seltype != "" } {
# if {$::version3} {
# set seltypestr [lindex $presentationbehtypes [expr $seltype - 1]]
# } else {
# set seltypestr [lindex $selectiontypes [expr $seltype - 1]]
# }
# puts $chan "title: \"$title\" type: \"$seltypestr\"
"
# }
set recquality [dbobj $rec get RecordQuality]
# switch -exact $recquality {
# 0 { set recqualitystr "Basic" }
# 40 { set recqualitystr "Medium" }
# 75 { set recqualitystr "High" }
# default { set recqualitystr "Best" }
# }
# puts $chan "quality: \"$recqualitystr\"
"
if { $rec != "" } {
if { [catch {dbobj $rec get StreamFileSize} streamsize] } {
set streamsize 0
}
if { $streamsize == "" } {
set streamsize 0
}
set parts [dbobj $rec get Part]
if { ($streamsize == 0) && ($state == 3 || $parts == "") } {
switch -exact $recquality {
0 { set bitrate 1630000 }
40 { set bitrate 2760000 }
75 { set bitrate 3660000 }
default { set bitrate 5960000 }
}
set seconds [dbobj $showing get Duration]
# Estimate size of recording.
set size [expr ($seconds * ($bitrate / (8 * 1024))) / 1024]
} else {
set size 0
if { $streamsize == 0 } {
foreach part $parts {
set file [dbobj $part get File]
if { [catch {mfs streamsize $file} sizes] } {
} else {
incr size [expr ([lindex $sizes 0] / 1024) * [lindex $sizes 1] / 1024]
}
}
} else {
set size [expr $streamsize / 1024]
}
}
}
set nowtime [clock seconds]
set expirationdate [dbobj $rec get ExpirationDate]
if { $expirationdate == 0 || $expirationdate == "" || $expirationdate == 24855 } {
set eindex 2; # Save until delete
} else {
set expirationsecs [expr $expirationdate * 86400 + [dbobj $rec get ExpirationTime] + $tzoffset]
if { $nowtime > $expirationsecs } {
set eindex 1; # Expired
} else {
set eindex 0; # Active
}
}
if { $size != "" && $seltype != "" } {
set index [expr $seltype - 1]
if { $recquality == 0 } {
set current [lindex $basicbyselection $index]
set basicbyselection [lreplace $basicbyselection $index $index [expr $current + $size]]
set basictotal [expr $basictotal + $size]
set ecurrent [lindex $basicbyexpiration $eindex]
set basicbyexpiration [lreplace $basicbyexpiration $eindex $eindex [expr $ecurrent + $size]]
set basicetotal [expr $basicetotal + $size]
} elseif { $recquality == 40 } {
set current [lindex $mediumbyselection $index]
set mediumbyselection [lreplace $mediumbyselection $index $index [expr $current + $size]]
set mediumtotal [expr $mediumtotal + $size]
set ecurrent [lindex $mediumbyexpiration $eindex]
set mediumbyexpiration [lreplace $mediumbyexpiration $eindex $eindex [expr $ecurrent + $size]]
set mediumetotal [expr $mediumetotal + $size]
} elseif { $recquality == 75 } {
set current [lindex $highbyselection $index]
set highbyselection [lreplace $highbyselection $index $index [expr $current + $size]]
set hightotal [expr $hightotal + $size]
set ecurrent [lindex $highbyexpiration $eindex]
set highbyexpiration [lreplace $highbyexpiration $eindex $eindex [expr $ecurrent + $size]]
set highetotal [expr $highetotal + $size]
} else {
set current [lindex $bestbyselection $index]
set bestbyselection [lreplace $bestbyselection $index $index [expr $current + $size]]
set besttotal [expr $besttotal + $size]
set ecurrent [lindex $bestbyexpiration $eindex]
set bestbyexpiration [lreplace $bestbyexpiration $eindex $eindex [expr $ecurrent + $size]]
set bestetotal [expr $bestetotal + $size]
}
set current [lindex $totalbyselection $index]
set totalbyselection [lreplace $totalbyselection $index $index [expr $current + $size]]
set ecurrent [lindex $totalbyexpiration $eindex]
set totalbyexpiration [lreplace $totalbyexpiration $eindex $eindex [expr $ecurrent + $size]]
# puts $chan "index: $index current: $current
"
}
}
set thrs 0
puts $chan [html_start "Space Used"]
puts $chan [html_table_start "" "" "ALIGN=TOP"]
puts $chan "
Does not take into account variable bit rates, assumes standard bitrates.
" # # puts $chan "Does not take into account deleted (but still available) recordings.
" # # puts $chan "\"Actual Hrs\" reflects disk space used translated into real world" # puts $chan "hours as calculated with the appropriate bitrate for the given quality.
" # # puts $chan "\"Capacity Hrs\" reflects disk space used translated into basic quality" # puts $chan "capacity hours at the appropriate bitrate: should be comparable to" # puts $chan "your machine's stated basic quality capacity.
" puts $chan [html_end] } proc init_spaceused {} { global qualitytypes global qualityfactors global expirationtypes global mbperhr set qualitytypes "Basic Medium High Best" set qualityfactors "1 1.714 2.182 3.365" set expirationtypes "Current Expired {Save Until Delete}" set mbperhr 745.1 # set blksperhr 1525974. } if { $reload == 0 } { init_spaceused } register_module "spaceused" "Space Used" "Accounting of Space Used"