diff options
author | Alexandre Flament <alex@al-f.net> | 2021-04-14 17:23:15 +0200 |
---|---|---|
committer | Alexandre Flament <alex@al-f.net> | 2021-04-21 16:24:46 +0200 |
commit | 7acd7ffc02d14d175ec2a99ba984e47d8cb65d7d (patch) | |
tree | 000b6e4b0038ed627bb114f8a2de83681bbf7ad4 /searx/engines | |
parent | aae7830d14242ac1f98232f428654c5d2c9c5eb2 (diff) | |
download | searxng-7acd7ffc02d14d175ec2a99ba984e47d8cb65d7d.tar.gz searxng-7acd7ffc02d14d175ec2a99ba984e47d8cb65d7d.zip |
[enh] rewrite and enhance metrics
Diffstat (limited to 'searx/engines')
-rw-r--r-- | searx/engines/__init__.py | 114 |
1 files changed, 0 insertions, 114 deletions
diff --git a/searx/engines/__init__.py b/searx/engines/__init__.py index 730f8b837..6c3ac7a42 100644 --- a/searx/engines/__init__.py +++ b/searx/engines/__init__.py @@ -21,7 +21,6 @@ import threading from os.path import realpath, dirname from babel.localedata import locale_identifiers from urllib.parse import urlparse -from flask_babel import gettext from operator import itemgetter from searx import settings from searx import logger @@ -136,22 +135,6 @@ def load_engine(engine_data): setattr(engine, 'fetch_supported_languages', lambda: engine._fetch_supported_languages(get(engine.supported_languages_url, headers=headers))) - engine.stats = { - 'sent_search_count': 0, # sent search - 'search_count': 0, # succesful search - 'result_count': 0, - 'engine_time': 0, - 'engine_time_count': 0, - 'score_count': 0, - 'errors': 0 - } - - engine_type = getattr(engine, 'engine_type', 'online') - - if engine_type != 'offline': - engine.stats['page_load_time'] = 0 - engine.stats['page_load_count'] = 0 - # tor related settings if settings['outgoing'].get('using_tor_proxy'): # use onion url if using tor. @@ -175,103 +158,6 @@ def load_engine(engine_data): return engine -def to_percentage(stats, maxvalue): - for engine_stat in stats: - if maxvalue: - engine_stat['percentage'] = int(engine_stat['avg'] / maxvalue * 100) - else: - engine_stat['percentage'] = 0 - return stats - - -def get_engines_stats(preferences): - # TODO refactor - pageloads = [] - engine_times = [] - results = [] - scores = [] - errors = [] - scores_per_result = [] - - max_pageload = max_engine_times = max_results = max_score = max_errors = max_score_per_result = 0 # noqa - for engine in engines.values(): - if not preferences.validate_token(engine): - continue - - if engine.stats['search_count'] == 0: - continue - - results_num = \ - engine.stats['result_count'] / float(engine.stats['search_count']) - - if engine.stats['engine_time_count'] != 0: - this_engine_time = engine.stats['engine_time'] / float(engine.stats['engine_time_count']) # noqa - else: - this_engine_time = 0 - - if results_num: - score = engine.stats['score_count'] / float(engine.stats['search_count']) # noqa - score_per_result = score / results_num - else: - score = score_per_result = 0.0 - - if engine.engine_type != 'offline': - load_times = 0 - if engine.stats['page_load_count'] != 0: - load_times = engine.stats['page_load_time'] / float(engine.stats['page_load_count']) # noqa - max_pageload = max(load_times, max_pageload) - pageloads.append({'avg': load_times, 'name': engine.name}) - - max_engine_times = max(this_engine_time, max_engine_times) - max_results = max(results_num, max_results) - max_score = max(score, max_score) - max_score_per_result = max(score_per_result, max_score_per_result) - max_errors = max(max_errors, engine.stats['errors']) - - engine_times.append({'avg': this_engine_time, 'name': engine.name}) - results.append({'avg': results_num, 'name': engine.name}) - scores.append({'avg': score, 'name': engine.name}) - errors.append({'avg': engine.stats['errors'], 'name': engine.name}) - scores_per_result.append({ - 'avg': score_per_result, - 'name': engine.name - }) - - pageloads = to_percentage(pageloads, max_pageload) - engine_times = to_percentage(engine_times, max_engine_times) - results = to_percentage(results, max_results) - scores = to_percentage(scores, max_score) - scores_per_result = to_percentage(scores_per_result, max_score_per_result) - errors = to_percentage(errors, max_errors) - - return [ - ( - gettext('Engine time (sec)'), - sorted(engine_times, key=itemgetter('avg')) - ), - ( - gettext('Page loads (sec)'), - sorted(pageloads, key=itemgetter('avg')) - ), - ( - gettext('Number of results'), - sorted(results, key=itemgetter('avg'), reverse=True) - ), - ( - gettext('Scores'), - sorted(scores, key=itemgetter('avg'), reverse=True) - ), - ( - gettext('Scores per result'), - sorted(scores_per_result, key=itemgetter('avg'), reverse=True) - ), - ( - gettext('Errors'), - sorted(errors, key=itemgetter('avg'), reverse=True) - ), - ] - - def load_engines(engine_list): global engines, engine_shortcuts engines.clear() |