Custom lists ranking

This commit is contained in:
relikd
2020-09-27 00:35:43 +02:00
parent 56087d5b21
commit b3ed43f5ec
5 changed files with 81 additions and 30 deletions

View File

@@ -30,6 +30,7 @@ header h1 {
margin-top: 0; margin-top: 0;
} }
header h1 span { font-size: .7em; color: silver; } header h1 span { font-size: .7em; color: silver; }
header ul { padding: 0; }
main { main {
padding: .1em 2em 1.5em; padding: .1em 2em 1.5em;
background: #fff; background: #fff;

View File

@@ -2,61 +2,109 @@
import lib_common as mylib import lib_common as mylib
import lib_html as HTML import lib_html as HTML
import index_rank # fname_ranking_category, fname_ranking_all import index_rank # fname_rank_list, fname_ranking_all
def html_base(*pathlist): def html_h2_path(pathlist, title='Ranking'):
return '<h2>{}</h2>'.format(HTML.a_path(pathlist, title))
def html_default_description():
return ''' return '''
<h2>{}</h2>
<p> <p>
This ranking shows only 500 of the most recently updated applications.<br> This ranking shows only 500 of the most recently updated applications.<br>
If you're missing an app, feel free to contribute a new app recording. If you're missing an app, feel free to contribute a new app recording.
</p> </p>'''
def html_table():
return '''
<div class="xscroll yscroll"> <div class="xscroll yscroll">
<table id="rank-list" class="alternate"><tr><td>Loading …</td></tr></table> <table id="rank-list" class="alternate"><tr><td>Loading …</td></tr></table>
</div> </div>'''
'''.format(HTML.a_path(pathlist, 'Ranking'))
def html_script_chunk(fname): def html_script_chunk(fname, sort_col, sort_order):
return ''' return '''
<script type="text/javascript" src="/static/ranking.js"></script> <script type="text/javascript" src="/static/ranking.js"></script>
<script type="text/javascript" src="/static/lozad.js"></script> <script type="text/javascript" src="/static/lozad.js"></script>
<script type="text/javascript"> <script type="text/javascript">
rank_js('{}', 12, -1); rank_js('{}', {}, {});
</script>'''.format(fname) </script>'''.format(fname, sort_col, sort_order)
def write_ranking_category(cid, category_name):
base = mylib.path_out('category', cid, 'ranking')
# full urls since categories can have page 2, 3, etc.
src = html_base(('All Categories', '/category/'),
(category_name, '/category/{}/'.format(cid)))
src += HTML.p_download_json('data.json',
'raw-category-{}.json'.format(cid))
src += html_script_chunk('data.json')
HTML.write(base, src, title='Category Ranking: ' + category_name)
mylib.symlink(index_rank.fname_rank_list('category', cid),
mylib.path_add(base, 'data.json'))
def write_ranking_all(title, base_dir): def write_ranking_all(title, base_dir):
# full urls since app index can have page 2, 3, etc. # full urls since app index can have page 2, 3, etc.
src = html_base(('Results', '/results/'), src = html_h2_path([('Results', '/results/'),
('Apps (AZ)', '/index/apps/')) ('Apps (AZ)', '/index/apps/')])
src += html_default_description()
src += html_table()
src += HTML.p_download_json('data.json', 'raw-apps.json') src += HTML.p_download_json('data.json', 'raw-apps.json')
src += html_script_chunk('data.json') src += html_script_chunk('data.json', 12, -1) # last update desc
HTML.write(base_dir, src, title=title) HTML.write(base_dir, src, title=title)
mylib.symlink(index_rank.fname_ranking_all(), mylib.symlink(index_rank.fname_ranking_all(),
mylib.path_add(base_dir, 'data.json')) mylib.path_add(base_dir, 'data.json'))
def write_ranking_category(cid, category_name):
base = mylib.path_out('category', cid, 'ranking')
# full urls since categories can have page 2, 3, etc.
src = html_h2_path([('All Categories', '/category/'),
(category_name, '/category/{}/'.format(cid))])
src += html_default_description()
src += html_table()
src += HTML.p_download_json('data.json',
'raw-category-{}.json'.format(cid))
src += html_script_chunk('data.json', 12, -1) # last update desc
HTML.write(base, src, title='Category Ranking: ' + category_name)
mylib.symlink(index_rank.fname_rank_list('category', cid),
mylib.path_add(base, 'data.json'))
def write_ranking_custom_lists(base_dir, list_id, list_name, parent_title):
base = mylib.path_add(base_dir, list_id)
src = html_h2_path([('Results', '/results/'),
(parent_title, '/lists/')], list_name)
src += html_table()
src += HTML.p_download_json('data.json',
'raw-list-{}.json'.format(list_id))
src += html_script_chunk('data.json', 9, 1) # tracker percent asc
HTML.write(base, src, title='Compare: ' + list_name)
mylib.symlink(index_rank.fname_rank_list('custom', list_id),
mylib.path_add(base, 'data.json'))
def process(): def process():
print('generating html: ranking ...') print('generating html: ranking ...')
print(' overall ranking')
write_ranking_all('Ranking', mylib.path_out('index', 'apps', 'ranking')) write_ranking_all('Ranking', mylib.path_out('index', 'apps', 'ranking'))
print(' category ranking')
for _, json in mylib.enum_categories(): for _, json in mylib.enum_categories():
cid, name = json['meta'] cid, name = json['meta']
write_ranking_category(cid, name) write_ranking_category(cid, name)
print(' custom lists')
base_custom = mylib.path_out('lists')
title_custom = 'Lists'
arr = []
for list_id, json in mylib.enum_custom_lists():
list_name = json['name']
arr.append((list_id, list_name, len(json['apps'])))
write_ranking_custom_lists(base_custom, list_id, list_name,
parent_title=title_custom)
print(' index page')
mylib.sort_by_name(arr, 1)
src = html_h2_path([('Results', '/results/')], title_custom)
src += '''
<p class="squeeze">
We present selected lists of apps that have been added to AppCheck.
</p>
<div class="found-in">'''
for x in arr:
src += '<p><a href="{}/">{}</a> <span>contains {} apps</span></p>\n'.format(*x)
HTML.write(base_custom, src + '</div>', title=title_custom)
print('') print('')

View File

@@ -93,6 +93,7 @@ def gen_results(base_dir, c_apps, c_domains, title):
<li>List of <a href="/index/domains/all/">Requested Domains</a></li> <li>List of <a href="/index/domains/all/">Requested Domains</a></li>
<li>List of <a href="/index/domains/tracker/">Trackers</a></li> <li>List of <a href="/index/domains/tracker/">Trackers</a></li>
</ul> </ul>
<p>Or compare similar application via custom comparison <a href="/lists/">Lists</a>.</p>
'''.format(title, c_apps, c_domains, c_recs, c_logs), title=title) '''.format(title, c_apps, c_domains, c_recs, c_logs), title=title)
mylib.symlink(index_rank.fname_app_rank(), mylib.symlink(index_rank.fname_app_rank(),
mylib.path_add(base_dir, 'rank.json')) # after HTML.write mylib.path_add(base_dir, 'rank.json')) # after HTML.write
@@ -116,4 +117,4 @@ def process(app_count, dom_count, inclStatic=False):
if __name__ == '__main__': if __name__ == '__main__':
process() process(-1, -1)

View File

@@ -112,11 +112,12 @@ def write_ranking_list(index, affected_ids):
del(values[8:]) # prepare for write_rank_index del(values[8:]) # prepare for write_rank_index
print(' write custom lists') print(' write custom lists')
# sort by %-tracker asc, #-pardom asc, avg-req-per-min asc
ret.sort(key=lambda x: (x[2 + 7], x[2 + 5], x[2 + 3]))
write_ranking_custom_lists(ret, affected_ids) write_ranking_custom_lists(ret, affected_ids)
ret.sort(key=lambda x: -x[2 + 10]) # sort by last update
print(' write category lists') print(' write category lists')
ret.sort(key=lambda x: -x[2 + 10]) # sort by last update desc
write_ranking_category_list(ret, affected_ids) write_ranking_category_list(ret, affected_ids)
if len(ret) > MAX_RANKING_LIMIT: # limit to most recent X entries if len(ret) > MAX_RANKING_LIMIT: # limit to most recent X entries
ret = ret[:MAX_RANKING_LIMIT] ret = ret[:MAX_RANKING_LIMIT]

View File

@@ -248,9 +248,9 @@ def enum_newly_added():
def enum_custom_lists(): def enum_custom_lists():
for fname in glob.glob(path_data('_lists', 'id_*.json')): for fname in glob.glob(path_data('_lists', 'list_*.json')):
with open(fname, 'r') as fp: with open(fname, 'r') as fp:
yield os.path.basename(fname)[3:-5], json.load(fp) yield os.path.basename(fname)[5:-5], json.load(fp)
def enum_jsons(bundle_id): def enum_jsons(bundle_id):