Commit 08cb03c4 authored by echel0n's avatar echel0n
Browse files

Merged overall_stats and show_stat functions

Cut main show view load time down by 6s
parent edb99a07
# Changelog
- * 1e6a667 - 2018-07-31: Fixed CSS issue for quicksearch items
- * 8ca2dfb - 2018-07-31: Merged overall_stats and show_stat functions Cut main show view load time down by 6s
- * edb99a0 - 2018-07-31: Fixed CSS issue for quicksearch items
- * 3acc96b - 2018-07-31: Pre-Release v9.3.56.dev11
- * d60e09f - 2018-07-31: Added delay for quicksearch input
- * 8c90243 - 2018-07-31: Pre-Release v9.3.56.dev10
......
......@@ -47,7 +47,7 @@ import six
from bs4 import BeautifulSoup
import sickrage
from sickrage.core.common import Quality, SKIPPED, WANTED
from sickrage.core.common import Quality, SKIPPED, WANTED, FAILED, UNAIRED
from sickrage.core.exceptions import MultipleShowObjectsException
mediaExtensions = [
......@@ -1522,14 +1522,10 @@ def clean_url(url):
return cleaned_url
def overall_stats():
today = str(datetime.date.today().toordinal())
def app_statistics():
show_stat = {}
downloaded_status = Quality.DOWNLOADED + Quality.ARCHIVED
snatched_status = Quality.SNATCHED + Quality.SNATCHED_PROPER
total_status = [SKIPPED, WANTED]
stats = {
overall_stats = {
'episodes': {
'downloaded': 0,
'snatched': 0,
......@@ -1543,22 +1539,55 @@ def overall_stats():
'total_size': 0
}
for result in sickrage.app.main_db.all('tv_episodes'):
if not (result['season'] > 0 and result['episode'] > 0 and result['airdate'] > 1):
continue
if result['status'] in downloaded_status:
stats['episodes']['downloaded'] += 1
stats['episodes']['total'] += 1
elif result['status'] in snatched_status:
stats['episodes']['snatched'] += 1
stats['episodes']['total'] += 1
elif result['airdate'] <= today and result['status'] in total_status:
stats['episodes']['total'] += 1
stats['total_size'] += result['file_size']
return stats
today = datetime.date.today().toordinal()
status_quality = Quality.SNATCHED + Quality.SNATCHED_PROPER + Quality.SNATCHED_BEST
status_download = Quality.DOWNLOADED + Quality.ARCHIVED
max_download_count = 1000
for epData in sickrage.app.main_db.all('tv_episodes'):
showid = epData['showid']
if showid not in show_stat:
show_stat[showid] = {}
show_stat[showid]['ep_snatched'] = 0
show_stat[showid]['ep_downloaded'] = 0
show_stat[showid]['ep_total'] = 0
show_stat[showid]['ep_airs_next'] = None
show_stat[showid]['ep_airs_prev'] = None
season = epData['season']
episode = epData['episode']
airdate = epData['airdate']
status = epData['status']
if season > 0 and episode > 0 and airdate > 1:
if status in status_quality:
show_stat[showid]['ep_snatched'] += 1
overall_stats['episodes']['snatched'] += 1
overall_stats['episodes']['total'] += 1
if status in status_download:
show_stat[showid]['ep_downloaded'] += 1
overall_stats['episodes']['downloaded'] += 1
overall_stats['episodes']['total'] += 1
if (airdate <= today and status in [SKIPPED, WANTED, FAILED]) or (
status in status_quality + status_download):
show_stat[showid]['ep_total'] += 1
overall_stats['episodes']['total'] += 1
if show_stat[showid]['ep_total'] > max_download_count:
max_download_count = show_stat[showid]['ep_total']
if airdate >= today and status in [WANTED, UNAIRED] and not show_stat[showid]['ep_airs_next']:
show_stat[showid]['ep_airs_next'] = airdate
elif airdate < today > show_stat[showid]['ep_airs_prev'] and status != UNAIRED:
show_stat[showid]['ep_airs_prev'] = airdate
overall_stats['total_size'] += epData['file_size']
max_download_count *= 100
return show_stat, overall_stats, max_download_count
def launch_browser(protocol=None, host=None, startport=None):
......
......@@ -48,7 +48,7 @@ from sickrage.core.common import ARCHIVED, DOWNLOADED, IGNORED, \
timeFormat
from sickrage.core.exceptions import CantUpdateShowException, CantRemoveShowException, CantRefreshShowException
from sickrage.core.helpers import chmodAsParent, findCertainShow, makeDir, \
pretty_filesize, sanitizeFileName, srdatetime, try_int, readFileBuffered, overall_stats
pretty_filesize, sanitizeFileName, srdatetime, try_int, readFileBuffered, app_statistics
from sickrage.core.media.banner import Banner
from sickrage.core.media.fanart import FanArt
from sickrage.core.media.network import Network
......@@ -2727,12 +2727,12 @@ class CMD_ShowsStats(ApiCall):
def run(self):
""" Get the global shows and episodes statistics """
stats = overall_stats()
stats = app_statistics()
return _responds(RESULT_SUCCESS, {
'ep_downloaded': stats['episodes']['downloaded'],
'ep_snatched': stats['episodes']['snatched'],
'ep_total': stats['episodes']['total'],
'shows_active': stats['shows']['active'],
'shows_total': stats['shows']['total'],
'ep_downloaded': stats[2]['episodes']['downloaded'],
'ep_snatched': stats[2]['episodes']['snatched'],
'ep_total': stats[2]['episodes']['total'],
'shows_active': stats[2]['shows']['active'],
'shows_total': stats[2]['shows']['total'],
})
......@@ -60,7 +60,7 @@ from sickrage.core.helpers import argToBool, backupSR, chmodAsParent, findCertai
getDiskSpaceUsage, makeDir, readFileBuffered, \
remove_article, restoreConfigZip, \
sanitizeFileName, clean_url, try_int, torrent_webui_url, checkbox_to_value, clean_host, \
clean_hosts, overall_stats
clean_hosts, app_statistics
from sickrage.core.helpers.browser import foldersAtPath
from sickrage.core.helpers.compat import cmp
from sickrage.core.helpers.srdatetime import srDateTime
......@@ -601,64 +601,20 @@ class Home(WebHandler):
else:
showlists['Shows'] = sickrage.app.showlist
show_stats = self.show_statistics()
app_stats = app_statistics()
return self.render(
"/home/index.mako",
title="Home",
header="Show List",
topmenu="home",
showlists=showlists,
show_stat=show_stats[0],
max_download_count=show_stats[1],
overall_stats=overall_stats(),
show_stat=app_stats[0],
overall_stats=app_stats[1],
max_download_count=app_stats[2],
controller='home',
action='index'
)
@staticmethod
def show_statistics():
show_stat = {}
today = datetime.date.today().toordinal()
status_quality = Quality.SNATCHED + Quality.SNATCHED_PROPER + Quality.SNATCHED_BEST
status_download = Quality.DOWNLOADED + Quality.ARCHIVED
max_download_count = 1000
for epData in sickrage.app.main_db.all('tv_episodes'):
showid = epData['showid']
if showid not in show_stat:
show_stat[showid] = {}
show_stat[showid]['ep_snatched'] = 0
show_stat[showid]['ep_downloaded'] = 0
show_stat[showid]['ep_total'] = 0
show_stat[showid]['ep_airs_next'] = None
show_stat[showid]['ep_airs_prev'] = None
season = epData['season']
episode = epData['episode']
airdate = epData['airdate']
status = epData['status']
if season > 0 and episode > 0 and airdate > 1:
if status in status_quality: show_stat[showid]['ep_snatched'] += 1
if status in status_download: show_stat[showid]['ep_downloaded'] += 1
if (airdate <= today and status in [SKIPPED, WANTED, FAILED]
) or (status in status_quality + status_download): show_stat[showid]['ep_total'] += 1
if show_stat[showid]['ep_total'] > max_download_count:
max_download_count = show_stat[showid]['ep_total']
if airdate >= today and status in [WANTED, UNAIRED] and not show_stat[showid]['ep_airs_next']:
show_stat[showid]['ep_airs_next'] = airdate
elif airdate < today > show_stat[showid]['ep_airs_prev'] and status != UNAIRED:
show_stat[showid]['ep_airs_prev'] = airdate
max_download_count *= 100
return show_stat, max_download_count
def is_alive(self, *args, **kwargs):
self.set_header('Content-Type', 'text/javascript')
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment