From 955d7d3e551bb57c02b4e170e0e9cc26c7490ae9 Mon Sep 17 00:00:00 2001 From: Aleksandr Tcitlionok <803797+terghalin@users.noreply.github.com> Date: Fri, 6 Dec 2024 03:51:48 +0000 Subject: [PATCH] update(k8s): add granularity --- app/routes/k8s.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/app/routes/k8s.py b/app/routes/k8s.py index 8f912f0..a912cce 100644 --- a/app/routes/k8s.py +++ b/app/routes/k8s.py @@ -68,15 +68,24 @@ def fetch_k8s_data_with_usage(): def calculate_time_on_duty(creation_timestamp): """ - Calculate the time on duty in hours or days from the creation timestamp. + Calculate the time on duty in hours, days, or minutes from the creation timestamp. """ now = datetime.now(timezone.utc) delta = now - creation_timestamp - # If less than a day, return hours; otherwise, return days + # If less than an hour, return minutes + if delta.days < 1 and delta.seconds < 3600: + minutes = delta.seconds // 60 + return f"{minutes} minutes" if minutes > 1 else "less than a minute" + + # If less than a day, return hours if delta.days < 1: - return f"{delta.seconds // 3600} hours" - return f"{delta.days} days" + hours = delta.seconds // 3600 + return f"{hours} hours" if hours > 1 else "1 hour" + + # Otherwise, return days + return f"{delta.days} days" if delta.days > 1 else "1 day" + def convert_memory_to_gb(memory): """