From 18695795cb0c9e60278a5faee1c39e18bcaaf48c Mon Sep 17 00:00:00 2001 From: ellenyuX Date: Tue, 15 Oct 2024 08:45:05 +0200 Subject: [PATCH] trying to fix Vis informasjon so that it shows up --- src/admin/api.py | 18 ++++++++++-------- src/models.py | 2 +- src/storage.py | 7 ++++--- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/admin/api.py b/src/admin/api.py index b7d7fe0..9a744ff 100644 --- a/src/admin/api.py +++ b/src/admin/api.py @@ -126,14 +126,16 @@ def admin_page(action): return json.dumps(response), 200 elif action == "status": - new_blob_image_count = storage.image_count() - iteration = classifier.get_iteration() - current_app.logger.info(shared_models.get_games_played()) - data = { - "CV_iteration_name": iteration.name, - "CV_time_created": str(iteration.created), - "BLOB_image_count": new_blob_image_count, - } + try: + new_blob_image_count = storage.image_count() + iteration = classifier.get_iteration() + data = { + "CV_iteration_name": iteration.name, + "CV_time_created": str(iteration.created), + "BLOB_image_count": new_blob_image_count, + } + except Exception as e: + current_app.logger.error("Something in admin/status failed: " + e) return json.dumps(data), 200 elif action == "logging": diff --git a/src/models.py b/src/models.py index d4b2fcc..3937368 100644 --- a/src/models.py +++ b/src/models.py @@ -819,7 +819,7 @@ def get_scores_count_per_month(year): extract("month", Scores.date).label("month"), func.count(Scores.score).label("score_count"), ) - .filter(extract("year", Scores.date) == 2024) + .filter(extract("year", Scores.date) == year) .group_by(extract("month", Scores.date)) .all() ) diff --git a/src/storage.py b/src/storage.py index 20c8135..1da4a3e 100644 --- a/src/storage.py +++ b/src/storage.py @@ -96,13 +96,14 @@ def create_container(): def image_count(): """ - Returns number of images in 'newimgcontainer'. + Returns number of images in relevant container. """ - container_client = blob_connection() + container_client = blob_connection(Keys.get("CONTAINER_NAME")) + return container_client.get_container_properties().metadata["image_count"] -def blob_connection(container_name=setup.CONTAINER_NAME_NEW): +def blob_connection(container_name): """ Helper method for connection to blob service. """