From aa69cfb07c9f5780713f1a8e08a644b3e0581586 Mon Sep 17 00:00:00 2001 From: Supremicus Date: Mon, 21 Jul 2014 15:38:50 +1000 Subject: [PATCH] Change SQL in templates. Split downloaded and snatched Use > instead of != in sql statement (speed improvement) Today's Next Episode removes correctly if today's date is snatched or downloaded (fix) Progressbar percentage calculated in python (speed improvement) Episode totals corrected (fix) --- gui/slick/interfaces/default/home.tmpl | 134 ++++++++++++++----- gui/slick/interfaces/default/inc_bottom.tmpl | 58 +++++--- 2 files changed, 137 insertions(+), 55 deletions(-) diff --git a/gui/slick/interfaces/default/home.tmpl b/gui/slick/interfaces/default/home.tmpl index 40370402..7e4ac658 100644 --- a/gui/slick/interfaces/default/home.tmpl +++ b/gui/slick/interfaces/default/home.tmpl @@ -14,10 +14,37 @@ #set $myDB = $db.DBConnection() #set $today = str($datetime.date.today().toordinal()) -#set $downloadedEps = $myDB.select("SELECT showid, COUNT(*) FROM tv_episodes WHERE (status IN ("+",".join([str(x) for x in $Quality.DOWNLOADED + [$ARCHIVED]])+") OR (status IN ("+",".join([str(x) for x in $Quality.SNATCHED + $Quality.SNATCHED_PROPER])+") AND location != '')) AND season != 0 and episode != 0 AND airdate <= "+$today+" GROUP BY showid") -#set $allEps = $myDB.select("SELECT showid, COUNT(*) FROM tv_episodes WHERE season != 0 and episode != 0 AND (airdate != 1 OR status IN ("+",".join([str(x) for x in ($Quality.DOWNLOADED + $Quality.SNATCHED + $Quality.SNATCHED_PROPER) + [$ARCHIVED]])+")) AND airdate <= "+$today+" AND status != "+str($IGNORED)+" GROUP BY showid") #set $layout = $sickbeard.HOME_LAYOUT +#set status_quality = '(' + ','.join([str(x) for x in $Quality.SNATCHED + $Quality.SNATCHED_PROPER]) + ')' +#set status_download = '(' + ','.join([str(x) for x in $Quality.DOWNLOADED + [$ARCHIVED]]) + ')' + +#set $sql_statement = 'SELECT showid, ' + +#set $sql_statement += '(SELECT COUNT(*) FROM tv_episodes WHERE showid=tv_eps.showid AND season > 0 AND episode > 0 AND airdate > 1 AND status IN ' + $status_quality + ') AS ep_snatched, ' +#set $sql_statement += '(SELECT COUNT(*) FROM tv_episodes WHERE showid=tv_eps.showid AND season > 0 AND episode > 0 AND airdate > 1 AND status IN ' + $status_download + ') AS ep_downloaded, ' + +#set $sql_statement += '(SELECT COUNT(*) FROM tv_episodes WHERE showid=tv_eps.showid AND season > 0 AND episode > 0 AND airdate > 1 ' +#set $sql_statement += ' AND ((airdate <= ' + $today + ' AND (status = ' + str($SKIPPED) + ' OR status = ' + str($WANTED) + ')) ' +#set $sql_statement += ' OR (status IN ' + status_quality + ') OR (status IN ' + status_download + '))) AS ep_total, ' + +#set $sql_statement += ' (SELECT airdate FROM tv_episodes WHERE showid=tv_eps.showid AND airdate >= ' + $today + ' AND (status = ' + str($UNAIRED) + ' OR status = ' + str($WANTED) + ') ORDER BY airdate ASC LIMIT 1) AS ep_airs_next ' +#set $sql_statement += ' FROM tv_episodes tv_eps GROUP BY showid' + +#set $sql_result = $myDB.select($sql_statement) + +#set $show_stat = {} +#set $max_download_count = 1000 + +#for $cur_result in $sql_result: + #set $show_stat[$cur_result['showid']] = $cur_result + #if $cur_result['ep_total'] > $max_download_count: + #set $max_download_count = $cur_result['ep_total'] + #end if +#end for + +#set $max_download_count = $max_download_count * 100 + @@ -75,16 +102,23 @@ match = s.match(/^(.*)/); if (match == null || match[1] == "?") - return -10; + return -10; var nums = match[1].split(" / "); + if (nums[0].indexOf("+") != -1) { + var num_parts = nums[0].split("+"); + nums[0] = num_parts[0]; + } - if (parseInt(nums[0]) === 0) - return parseInt(nums[1]); + nums[0] = parseInt(nums[0]) + nums[1] = parseInt(nums[1]) - var finalNum = parseInt((nums[0]/nums[1])*1000)*100; + if (nums[0] === 0) + return nums[1]; + + var finalNum = parseInt($max_download_count*nums[0]/nums[1]); if (finalNum > 0) - finalNum += parseInt(nums[0]); + finalNum += nums[0]; return finalNum; }, @@ -215,29 +249,58 @@ $myShowList.sort(lambda x, y: cmp(x.name, y.name)) #for $curShow in $myShowList: -#set $curShowDownloads = [x[1] for x in $downloadedEps if int(x[0]) == $curShow.indexerid] -#set $curShowAll = [x[1] for x in $allEps if int(x[0]) == $curShow.indexerid] -#if len($curShowAll) != 0: - #if len($curShowDownloads) != 0: - #set $dlStat = str($curShowDownloads[0])+" / "+str($curShowAll[0]) - #set $nom = $curShowDownloads[0] - #set $den = $curShowAll[0] - #else - #set $dlStat = "0 / "+str($curShowAll[0]) - #set $nom = 0 - #set $den = $curShowAll[0] - #end if -#else - #set $dlStat = "0 / 0" - #set $nom = 0 - #set $den = 1 -#end if + #set $cur_airs_next = '' + #set $cur_snatched = 0 + #set $cur_downloaded = 0 + #set $cur_total = 0 + #set $download_stat_tip = '' + + #if $curShow.indexerid in $show_stat: + #set $cur_airs_next = $show_stat[$curShow.indexerid]['ep_airs_next'] + + #set $cur_snatched = $show_stat[$curShow.indexerid]['ep_snatched'] + #if not $cur_snatched: + #set $cur_snatched = 0 + #end if + + #set $cur_downloaded = $show_stat[$curShow.indexerid]['ep_downloaded'] + #if not $cur_downloaded: + #set $cur_downloaded = 0 + #end if + + #set $cur_total = $show_stat[$curShow.indexerid]['ep_total'] + #if not $cur_total: + #set $cur_total = 0 + #end if + #end if + + #if $cur_total != 0: + #set $download_stat = str($cur_downloaded) + #set $download_stat_tip = "Downloaded: " + str($cur_downloaded) + #if $cur_snatched > 0: + #set $download_stat = download_stat + "+" + str($cur_snatched) + #set $download_stat_tip = download_stat_tip + " " + "Snatched: " + str($cur_snatched) + #end if + #set $download_stat = download_stat + " / " + str($cur_total) + #set $download_stat_tip = download_stat_tip + " " + "Total: " + str($cur_total) + #else + #set $download_stat = '?' + #set $download_stat_tip = "no data" + #end if + + #set $nom = $cur_downloaded + #set $den = $cur_total + #if $den == 0: + #set $den = 1 + #end if + +#set $progressbar_percent = $nom * 100 / $den #set $which_thumb = $layout+"_thumb" - #if $curShow.nextaired: - #set $ldatetime = $network_timezones.parse_date_time($curShow.nextaired,$curShow.airs,$curShow.network) + #if $cur_airs_next: + #set $ldatetime = $network_timezones.parse_date_time($cur_airs_next,$curShow.airs,$curShow.network)
$sbdatetime.sbdatetime.sbfdate($ldatetime)
$time.mktime($ldatetime.timetuple()) #else: @@ -282,17 +345,16 @@ $myShowList.sort(lambda x, y: cmp(x.name, y.name)) #else: Custom #end if - $dlStat
+ $download_stat
\"Y\"" diff --git a/gui/slick/interfaces/default/inc_bottom.tmpl b/gui/slick/interfaces/default/inc_bottom.tmpl index 9e77c115..ca8a8dc9 100644 --- a/gui/slick/interfaces/default/inc_bottom.tmpl +++ b/gui/slick/interfaces/default/inc_bottom.tmpl @@ -2,33 +2,53 @@ #import datetime #from sickbeard import db, sbdatetime #from sickbeard.common import * + + + - + \ No newline at end of file