From d4bb45b84d0573fe231121d7dad4872240bdfa75 Mon Sep 17 00:00:00 2001 From: "Casper V. Kristensen" Date: Sat, 6 Apr 2019 17:56:13 +0200 Subject: [PATCH] Log execution times. --- server/nightr/app.py | 8 +++++++- server/nightr/strategies/upstairs_neighbour.py | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/server/nightr/app.py b/server/nightr/app.py index 00c41ef..3f8b923 100644 --- a/server/nightr/app.py +++ b/server/nightr/app.py @@ -1,7 +1,9 @@ import inspect import statistics +import timeit from dataclasses import asdict from datetime import timedelta +from logging import DEBUG from typing import List import requests_cache @@ -12,6 +14,7 @@ from .util import Context app = Flask(__name__) logger = logging.create_logger(app) +logger.setLevel(DEBUG) requests_cache.install_cache("requests_cache", expire_after=timedelta(minutes=10)) @@ -36,7 +39,10 @@ def probabilities(): predictions: List[dict] = [] for name, strategy in strategies.items(): try: + start = timeit.default_timer() prediction = strategy(context) + stop = timeit.default_timer() + logger.debug("Execution time for %s: %ss", name, stop - start) except Exception as e: logger.warning("Strategy '%s' failed:", name) logger.exception(e) @@ -79,7 +85,7 @@ def probabilities(): def main(): - app.run(host='0.0.0.0') + app.run(host='0.0.0.0', debug=True) if __name__ == '__main__': diff --git a/server/nightr/strategies/upstairs_neighbour.py b/server/nightr/strategies/upstairs_neighbour.py index 4b528b6..63ff206 100644 --- a/server/nightr/strategies/upstairs_neighbour.py +++ b/server/nightr/strategies/upstairs_neighbour.py @@ -6,7 +6,7 @@ from ..util import Prediction, Context def update(): - requests.post('https://euw.op.gg/summoner/ajax/renew.json/', data = {'summonerId': 34009256}) + requests.post('https://euw.op.gg/summoner/ajax/renew.json/', data={'summonerId': 34009256}) def check_games(context: Context) -> Prediction: