Log execution times.

This commit is contained in:
Casper 2019-04-06 17:56:13 +02:00
parent e94199b7fd
commit d4bb45b84d
No known key found for this signature in database
GPG Key ID: 289CA03790535054
2 changed files with 8 additions and 2 deletions

View File

@ -1,7 +1,9 @@
import inspect import inspect
import statistics import statistics
import timeit
from dataclasses import asdict from dataclasses import asdict
from datetime import timedelta from datetime import timedelta
from logging import DEBUG
from typing import List from typing import List
import requests_cache import requests_cache
@ -12,6 +14,7 @@ from .util import Context
app = Flask(__name__) app = Flask(__name__)
logger = logging.create_logger(app) logger = logging.create_logger(app)
logger.setLevel(DEBUG)
requests_cache.install_cache("requests_cache", expire_after=timedelta(minutes=10)) requests_cache.install_cache("requests_cache", expire_after=timedelta(minutes=10))
@ -36,7 +39,10 @@ def probabilities():
predictions: List[dict] = [] predictions: List[dict] = []
for name, strategy in strategies.items(): for name, strategy in strategies.items():
try: try:
start = timeit.default_timer()
prediction = strategy(context) prediction = strategy(context)
stop = timeit.default_timer()
logger.debug("Execution time for %s: %ss", name, stop - start)
except Exception as e: except Exception as e:
logger.warning("Strategy '%s' failed:", name) logger.warning("Strategy '%s' failed:", name)
logger.exception(e) logger.exception(e)
@ -79,7 +85,7 @@ def probabilities():
def main(): def main():
app.run(host='0.0.0.0') app.run(host='0.0.0.0', debug=True)
if __name__ == '__main__': if __name__ == '__main__':

View File

@ -6,7 +6,7 @@ from ..util import Prediction, Context
def update(): 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: def check_games(context: Context) -> Prediction: