From 4f4ec44bb373a6aff0c723943544f44907519dca Mon Sep 17 00:00:00 2001 From: asciimoo Date: Sun, 27 Oct 2013 02:50:24 +0200 Subject: [PATCH] [enh] stat updates --- searx/engines/__init__.py | 22 +++++++++++++++++----- searx/templates/stats.html | 18 ++++++++++++------ 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/searx/engines/__init__.py b/searx/engines/__init__.py index a5bbfdeeb..016f06b08 100644 --- a/searx/engines/__init__.py +++ b/searx/engines/__init__.py @@ -159,15 +159,27 @@ def search(query, request, selected_categories): return sorted(results, key=itemgetter('score'), reverse=True) def get_engines_stats(): - stats = {} + pageloads = [] + results = [] + max_pageload = max_results = 0 for engine in engines.values(): if engine.stats['search_count'] == 0: continue results_num = engine.stats['result_count']/float(engine.stats['search_count']) load_times = engine.stats['page_load_time']/float(engine.stats['search_count']) - stats[engine.name] = {'Average number of results': results_num - ,'Average page load time': load_times - } + max_results = max(results_num, max_results) + max_pageload = max(load_times, max_pageload) + pageloads.append({'avg': load_times, 'name': engine.name}) + results.append({'avg': results_num, 'name': engine.name}) - return stats + for engine in pageloads: + engine['percentage'] = int(engine['avg']/max_pageload*100) + + for engine in results: + engine['percentage'] = int(engine['avg']/max_results*100) + + + return [('Page loads', sorted(pageloads, key=itemgetter('avg'), reverse=True)) + ,('Number of results', sorted(results, key=itemgetter('avg'), reverse=True)) + ] diff --git a/searx/templates/stats.html b/searx/templates/stats.html index 3b5ad844b..66623629c 100644 --- a/searx/templates/stats.html +++ b/searx/templates/stats.html @@ -3,14 +3,20 @@ {% block content %}

Engine stats

-{% for engine,engine_stats in stats.items() %} +{% for stat_name,stat_category in stats %}
-

{{ engine }}

-
{% endfor %} {% endblock %}