From fd8c19cdb75f7004d3579e359d36c3c7149eb759 Mon Sep 17 00:00:00 2001 From: Kirill K Date: Sun, 15 Sep 2024 11:03:19 +0300 Subject: [PATCH] fix: switch time scale (#58) * refactor(backend): save idea for future getFullData handler * fix(frontend): reactivity * chore(dev): disable s3 by default * chore(chart): bump version --- backend/main.py | 22 +++++++ charts/pagetron/Chart.yaml | 2 +- charts/pagetron/values.dev.yaml | 2 +- frontend/src/lib/Component.svelte | 85 ++++++++++++++++++-------- frontend/src/lib/ComponentsList.svelte | 25 ++++---- frontend/src/lib/Overview.svelte | 14 ++--- frontend/src/lib/Tick.svelte | 83 +++++++++++++++++-------- frontend/src/routes/+page.server.js | 4 +- frontend/src/routes/+page.svelte | 13 ++-- 9 files changed, 163 insertions(+), 87 deletions(-) diff --git a/backend/main.py b/backend/main.py index 38757b2..71d47ae 100644 --- a/backend/main.py +++ b/backend/main.py @@ -58,3 +58,25 @@ def get_components_or_details(name: str | None = None, view: str = "quarter"): component = db.get_component(name=name, view=view) return component + + +# @app.get("/full/") +# @ttl_cache(CACHE_TTL_DEFAULT) +# def get_full(): +# views = ("quarter", "hours", "year") +# +# data = {} +# +# data["overview"] = db.get_overview() +# data["components"] = db.list_components() +# +# data["data"] = {} +# +# for component in data["components"]: +# data["data"][component] = {} +# +# for component in data["components"]: +# for view in views: +# data["data"][component][view] = db.get_component(name=component, view=view) +# +# return data diff --git a/charts/pagetron/Chart.yaml b/charts/pagetron/Chart.yaml index 20d0447..0d58077 100644 --- a/charts/pagetron/Chart.yaml +++ b/charts/pagetron/Chart.yaml @@ -8,4 +8,4 @@ type: application version: 0.1.0 -appVersion: "0.2.1" +appVersion: "0.2.2" diff --git a/charts/pagetron/values.dev.yaml b/charts/pagetron/values.dev.yaml index 15e93f8..844a024 100644 --- a/charts/pagetron/values.dev.yaml +++ b/charts/pagetron/values.dev.yaml @@ -14,7 +14,7 @@ publicAccess: class: traefik s3: - enabled: true + enabled: false secretName: s3-publish-credentials bucketName: pagetron-status-page diff --git a/frontend/src/lib/Component.svelte b/frontend/src/lib/Component.svelte index 1da811f..aedadfa 100644 --- a/frontend/src/lib/Component.svelte +++ b/frontend/src/lib/Component.svelte @@ -1,6 +1,9 @@
diff --git a/frontend/src/lib/ComponentsList.svelte b/frontend/src/lib/ComponentsList.svelte index ac2e6cd..8d466fa 100644 --- a/frontend/src/lib/ComponentsList.svelte +++ b/frontend/src/lib/ComponentsList.svelte @@ -1,29 +1,26 @@
{#each components as c} - {#await c} - - {:then c} - - {:catch error} - - {/await} + {/each}
diff --git a/frontend/src/lib/Overview.svelte b/frontend/src/lib/Overview.svelte index 6de0008..828ffac 100644 --- a/frontend/src/lib/Overview.svelte +++ b/frontend/src/lib/Overview.svelte @@ -1,9 +1,9 @@ @@ -25,7 +25,7 @@

{statusText}

-

Last updated on {datetimeHuman} UTC

+

Last updated on {datetime_human} UTC

diff --git a/frontend/src/lib/Tick.svelte b/frontend/src/lib/Tick.svelte index 7fe798b..807fc1e 100644 --- a/frontend/src/lib/Tick.svelte +++ b/frontend/src/lib/Tick.svelte @@ -8,14 +8,20 @@ let units = []; - if (capacity <= 60 * 5) { - units = ['m', 's']; - } else if (capacity <= 60 * 60 * 24) { - units = ['d', 'h', 'm']; - } else if (capacity <= 60 * 60 * 24 * 7) { - units = ['w', 'd', 'h']; - } else { - units = ['w', 'd']; + function getUnits(capacity) { + let units = []; + + if (capacity <= 60 * 5) { + units = ['m', 's']; + } else if (capacity <= 60 * 60 * 24) { + units = ['d', 'h', 'm']; + } else if (capacity <= 60 * 60 * 24 * 7) { + units = ['w', 'd', 'h']; + } else { + units = ['w', 'd']; + } + + return units; } let tickStateClasses = ''; @@ -23,31 +29,54 @@ let downtime = 0.0; let downtimeHumanText = ''; - if (uptime == -1.0) { - downtime = 1.0 * capacity * 1000; // no data - } else { - downtime = Math.round((1.0 - uptime) * capacity) * 1000; + function getDowntime(uptime) { + if (uptime == -1.0) { + downtime = 1.0 * capacity * 1000; // no data + } else { + downtime = Math.round((1.0 - uptime) * capacity) * 1000; + } + + return downtime; } - if (uptime == -1.0) { - tickStateClasses = 'has-background-grey'; - } else if (uptime > thresholds[0]) { - tickStateClasses = 'has-background-success'; - if (downtime > 0) { - tickStateClasses += ' ' + 'has-minor-issue'; + function getTickStateClass(uptime) { + let tickStateClasses; + + if (uptime == -1.0) { + tickStateClasses = 'has-background-grey'; + } else if (uptime > thresholds[0]) { + tickStateClasses = 'has-background-success'; + if (downtime > 0) { + tickStateClasses += ' ' + 'has-minor-issue'; + } + } else if (uptime > thresholds[1]) { + tickStateClasses = 'has-background-warning'; + } else { + tickStateClasses = 'has-background-danger'; } - } else if (uptime > thresholds[1]) { - tickStateClasses = 'has-background-warning'; - } else { - tickStateClasses = 'has-background-danger'; + + return tickStateClasses; } - if (uptime == -1.0) { - downtimeHumanText = '\n' + 'no data'; - } else if (downtime > 0) { - let downtimeHuman = humanizeDuration(downtime, { maxDecimalPoints: 0, units: units }); - downtimeHumanText = '\n' + 'down for ' + downtimeHuman; + function getDowntimeText(uptime) { + let getDowntimeText; + + if (uptime == 1) { + downtimeHumanText = ''; + } else if (uptime == -1.0) { + downtimeHumanText = '\n' + 'no data'; + } else if (downtime > 0) { + let downtimeHuman = humanizeDuration(downtime, { maxDecimalPoints: 0, units: units }); + downtimeHumanText = '\n' + 'down for ' + downtimeHuman; + } + + return downtimeHumanText; } + + $: downtime = getDowntime(uptime); + $: units = getUnits(capacity); + $: downtimeHumanText = getDowntimeText(uptime); + $: tickStateClasses = getTickStateClass(uptime);
- import { apiUrl, getAllData } from '$lib/api.js'; + import { getAllData } from '$lib/api.js'; import { isBuildingSnapshot } from '$lib/utils.js'; + import { get } from 'svelte/store'; import { viewStore } from '$lib/stores.js'; import Header from '$lib/Header.svelte'; @@ -21,7 +22,7 @@ viewStore.subscribe((value) => (view = value)); - $: view; + $: view = get(viewStore);
@@ -29,13 +30,7 @@ {#await data} {:then data} - + {:catch error}