# 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 "" puts $chan "Quality" if {$::version3} { set myselectiontypes $presentationbehtypes } else { set myselectiontypes $selectiontypes } foreach selection $myselectiontypes { set index [lsearch $myselectiontypes $selection] # If the total for the selection type is 0, don't print set samount [lindex $totalbyselection $index] if { $path == 0 && $samount == 0 } { continue; } puts $chan "$selection" } puts $chan "Total" puts $chan "Actual Hrs" puts $chan "Capacity Hrs" puts $chan "" foreach quality $qualitytypes { # Beginning of row print quality set qindex [lsearch $qualitytypes $quality] # Hack - which row are we in? if { $quality == "Basic" } { set rtotal $basictotal } elseif { $quality == "Medium" } { set rtotal $mediumtotal } elseif { $quality == "High" } { set rtotal $hightotal } elseif { $quality == "Best" } { set rtotal $besttotal } if { $path == 0 && $rtotal == 0 } { continue; } puts $chan "" puts $chan "$quality" # Now loop over seletion types... foreach selection $myselectiontypes { set index [lsearch $myselectiontypes $selection] # If the total for the selection type is 0, don't print set samount [lindex $totalbyselection $index] if { $path == 0 && $samount == 0 } { continue; } # Hack - which row are we in? if { $quality == "Basic" } { set amount [lindex $basicbyselection $index] } elseif { $quality == "Medium" } { set amount [lindex $mediumbyselection $index] } elseif { $quality == "High" } { set amount [lindex $highbyselection $index] } elseif { $quality == "Best" } { set amount [lindex $bestbyselection $index] } puts -nonewline $chan "$amount" # If there is an amount, translate into hours too. if { $amount != 0 } { set bhrs [expr $amount / $mbperhr] set ahrs [expr $bhrs / [lindex $qualityfactors $qindex]] puts -nonewline $chan [format " (%-4.1f hrs)" $ahrs] } puts $chan "" } # End of the row - put out the row total puts $chan "$rtotal" # If there is an amount, translate into hours too. if { $rtotal != 0 } { set bhrs [expr $rtotal / $mbperhr] set ahrs [expr $bhrs / [lindex $qualityfactors $qindex] ] set thrs [expr $thrs + $ahrs] puts $chan [format "%-4.1f" $ahrs] puts $chan [format "%-4.1f" $bhrs] } else { puts $chan "0" puts $chan "0" } puts $chan "" } # Totals row puts $chan "" puts $chan "Totals" set rtotal 0 foreach selection $myselectiontypes { set index [lsearch $myselectiontypes $selection] set samount [lindex $totalbyselection $index] if { $path == 0 && $samount == 0 } { continue; } incr rtotal $samount puts $chan "$samount" } puts $chan "$rtotal" if { $rtotal != 0 } { set bhrs [expr $rtotal / $mbperhr] puts $chan [format "%-4.1f" $thrs] puts $chan [format "%-4.1f" $bhrs] } else { puts $chan "0" puts $chan "0" } puts $chan "" puts $chan [html_table_end] puts $chan [html_table_start "" "" "ALIGN=TOP"] puts $chan "" puts $chan "Quality" foreach expiration $expirationtypes { set index [lsearch $expirationtypes $expiration] # If the total for the expiration type is 0, don't print set samount [lindex $totalbyexpiration $index] if { $path == 0 && $samount == 0 } { continue; } puts $chan "$expiration" } puts $chan "" foreach quality $qualitytypes { # Beginning of row print quality set qindex [lsearch $qualitytypes $quality] # Hack - which row are we in? if { $quality == "Basic" } { set rtotal $basicetotal } elseif { $quality == "Medium" } { set rtotal $mediumetotal } elseif { $quality == "High" } { set rtotal $highetotal } elseif { $quality == "Best" } { set rtotal $bestetotal } if { $path == 0 && $rtotal == 0 } { continue; } puts $chan "" puts $chan "$quality" # Now loop over expiration types... foreach expiration $expirationtypes { set index [lsearch $expirationtypes $expiration] # If the total for the expiration type is 0, don't print set samount [lindex $totalbyexpiration $index] if { $path == 0 && $samount == 0 } { continue; } # Hack - which row are we in? if { $quality == "Basic" } { set amount [lindex $basicbyexpiration $index] } elseif { $quality == "Medium" } { set amount [lindex $mediumbyexpiration $index] } elseif { $quality == "High" } { set amount [lindex $highbyexpiration $index] } elseif { $quality == "Best" } { set amount [lindex $bestbyexpiration $index] } puts -nonewline $chan "$amount" # If there is an amount, translate into hours too. if { $amount != 0 } { set bhrs [expr $amount / $mbperhr] set ahrs [expr $bhrs / [lindex $qualityfactors $qindex]] puts -nonewline $chan [format " (%-4.1f hrs)" $ahrs] } puts $chan "" } # # End of the row - put out the row total # puts $chan "$rtotal" # # If there is an amount, translate into hours too. # if { $rtotal != 0 } { # set bhrs [expr $rtotal / $mbperhr] # set ahrs [expr $bhrs / [lindex $qualityfactors $qindex] ] # set thrs [expr $thrs + $ahrs] # puts $chan [format "%-4.1f" $ahrs] # puts $chan [format "%-4.1f" $bhrs] # } else { # puts $chan "0" # puts $chan "0" # } puts $chan "" } # Totals row puts $chan "" puts $chan "Totals" set rtotal 0 foreach expiration $expirationtypes { set index [lsearch $expirationtypes $expiration] set samount [lindex $totalbyexpiration $index] if { $path == 0 && $samount == 0 } { continue; } incr rtotal $samount puts $chan "$samount" } # puts $chan "$rtotal" # if { $rtotal != 0 } { # set bhrs [expr $rtotal / $mbperhr] # puts $chan [format "%-4.1f" $thrs] # puts $chan [format "%-4.1f" $bhrs] # } else { # puts $chan "0" # puts $chan "0" # } puts $chan "" puts $chan [html_table_end] # 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"