Log execution times.

This commit is contained in:
Casper V. Kristensen 2019-04-06 17:56:13 +02:00
parent e94199b7fd
commit d4bb45b84d
Signed by: caspervk
GPG key ID: 289CA03790535054
2 changed files with 8 additions and 2 deletions

View file

@ -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__':

View file

@ -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: