From f5af133cfda71fa0f7b9e8705030785d51d64718 Mon Sep 17 00:00:00 2001 From: Todd Zullinger Date: Sun, 20 Dec 2009 17:08:43 -0500 Subject: [PATCH] spins: Improve sorting by torrent downloads This changes 'spins' from a list to a dict which has the short name as its key and contains the torrent names and total downloads as items. --- spins.fedoraproject.org/data/content/index.html | 14 +++------ spins.fedoraproject.org/data/templates/master.html | 30 ++++++++++--------- .../data/templates/sidebar.html | 16 +++------- 3 files changed, 26 insertions(+), 34 deletions(-) diff --git a/spins.fedoraproject.org/data/content/index.html b/spins.fedoraproject.org/data/content/index.html index af23503..819151f 100644 --- a/spins.fedoraproject.org/data/content/index.html +++ b/spins.fedoraproject.org/data/content/index.html @@ -41,14 +41,11 @@ #${t+1} - ${name}
${num_download} ${_('downloads')} + ${name}
${num} ${_('downloads')} ${sdata[name.lower()]}
${_('Learn more & download! >')} @@ -61,9 +58,8 @@ #${t+1} ${name}
${num} downloads diff --git a/spins.fedoraproject.org/data/templates/master.html b/spins.fedoraproject.org/data/templates/master.html index 8ab2f56..3a1d0b3 100644 --- a/spins.fedoraproject.org/data/templates/master.html +++ b/spins.fedoraproject.org/data/templates/master.html @@ -139,21 +139,23 @@ def formatsize(n, format='%0.2f'): return format % (n / 1024.0**2) # this gets all the current spins torrents -spins = [] -for t_dict in torrents.torrents: - # Ugly hack, this should probably be be refactored. - if not t_dict['name'].startswith('Fedora-%s-i686' % release): - continue - if torrents.matches_a_spin(t_dict['name']): - if release in t_dict['name']: - spins.append(t_dict) - - -#sort by most downloaded -most_downloaded = sorted(spins,key=itemgetter('completed'), reverse=True) +spins = {} +for t in torrents.torrents: + if torrents.matches_a_spin(t['name']) and release in t['name']: + name = t['name'].split('-')[-1] + if name not in spins: + spins[name] = { + 'torrents': [t['name']], + 'downloads': t['completed'] + } + else: + spins[name]['torrents'].append(t['name']) + spins[name]['downloads'] += t['completed'] + +# sort by most downloaded +most_downloaded = sorted(spins.items(), key=lambda(k,v):spins[k]['downloads'], reverse=True) # sort by alphabetical -alphabetical = sorted(spins, key=itemgetter('name')) - +alphabetical = sorted(spins.items()) #data used on sidebar, for featured-spin section sdata_feature = { diff --git a/spins.fedoraproject.org/data/templates/sidebar.html b/spins.fedoraproject.org/data/templates/sidebar.html index f4e99a9..b9b64ff 100644 --- a/spins.fedoraproject.org/data/templates/sidebar.html +++ b/spins.fedoraproject.org/data/templates/sidebar.html @@ -17,25 +17,19 @@ - +
#${t+1} ${name}${num_download} downloads${num} downloads