logo

searx

Unnamed repository; edit this file 'description' to name the repository.
commit: 4f4ec44bb373a6aff0c723943544f44907519dca
parent: 43ac547bc1e4d7c10a56d70e42c542cbae6896d9
Author: asciimoo <asciimoo@gmail.com>
Date:   Sun, 27 Oct 2013 02:50:24 +0200

[enh] stat updates

Diffstat:

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 @@ -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}) + + 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 stats + 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 @@ -3,14 +3,20 @@ {% block content %} <h2>Engine stats</h2> -{% for engine,engine_stats in stats.items() %} +{% for stat_name,stat_category in stats %} <div> - <h3>{{ engine }}</h3> - <ul> - {% for statname,value in engine_stats.items() %} - <li>{{ statname }}: {{ value }}</li> + <table> + <tr colspan="3"> + <th>{{ stat_name }}</th> + </tr> + {% for engine in stat_category %} + <tr> + <td>{{ engine.name }}</td> + <td>{{ engine.percentage }}</td> + <td>{{ engine.avg }}</td> + </tr> {% endfor %} - </ul> + </table> </div> {% endfor %} {% endblock %}