From f2a47588955a8f5d038abf0a49c59026c3ee7738 Mon Sep 17 00:00:00 2001 From: timurgordon Date: Tue, 12 Mar 2024 11:28:10 -0400 Subject: [PATCH 1/5] hide threefold community person card --- templates/partials/personCard.html | 3 ++- templates/partials/person_card.html | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/templates/partials/personCard.html b/templates/partials/personCard.html index 2204df7ee..024b06be7 100644 --- a/templates/partials/personCard.html +++ b/templates/partials/personCard.html @@ -1,3 +1,4 @@ +{% if page.title != 'ThreeFold Community' %}
{% set url = get_url(path='/' ~ page.relative_path | replace(from='_', to='-') | replace(from='index.md', to=page.extra.imgPath)) %} @@ -23,4 +24,4 @@
- +{% endif %} diff --git a/templates/partials/person_card.html b/templates/partials/person_card.html index f5e37ccc1..9286f9cf6 100644 --- a/templates/partials/person_card.html +++ b/templates/partials/person_card.html @@ -1,3 +1,4 @@ +{% if page.title != 'ThreeFold Community' %}
{% set url = get_url(path='/' ~ page.relative_path | replace(from='_', to='-') | replace(from='index.md', to=page.extra.imgPath)) %} @@ -23,4 +24,5 @@
+{%endif%} From 1e8346282e3c25284faf27e7d994f90dd65e018e Mon Sep 17 00:00:00 2001 From: samaradel Date: Tue, 12 Mar 2024 22:36:23 +0200 Subject: [PATCH 2/5] Fix broken link --- static/js/custom.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/static/js/custom.js b/static/js/custom.js index 7e5d053fe..f4b300c54 100644 --- a/static/js/custom.js +++ b/static/js/custom.js @@ -166,7 +166,7 @@ const urls = [ "https://gridproxy.grid.tf/stats?status=up", "https://gridproxy.dev.grid.tf/stats?status=up", "https://gridproxy.test.grid.tf/stats?status=up", - "https://gridproxy.bknd1.ninja.tf/stats?status=standby", // will change to mainnet when release + "https://gridproxy.grid.tf/stats?status=standby", "https://gridproxy.dev.grid.tf/stats?status=standby", "https://gridproxy.test.grid.tf/stats?status=standby", ]; From 0a25f36dd617251cd71ff1e0b8276aaede311751 Mon Sep 17 00:00:00 2001 From: samaradel Date: Tue, 12 Mar 2024 23:06:39 +0200 Subject: [PATCH 3/5] Add loading to stats cards --- static/js/custom.js | 8 ++++++-- templates/shortcodes/grid_stats.html | 10 +++++----- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/static/js/custom.js b/static/js/custom.js index f4b300c54..402f301ae 100644 --- a/static/js/custom.js +++ b/static/js/custom.js @@ -142,8 +142,10 @@ window.onload = function () { }); }); - document.getElementById("filter-btn").addEventListener('click', toggleFilter); - document.getElementById("mobile-learn-btn").addEventListener('click', toggleMenu); + document.getElementById("filter-btn").addEventListener("click", toggleFilter); + document + .getElementById("mobile-learn-btn") + .addEventListener("click", toggleMenu); }; function openInNewTab(url) { @@ -198,6 +200,8 @@ function mergeStatsData(stats) { res.countries = Object.keys(res.nodesDistribution).length; } let capacity = toTeraOrGiga(res.totalHru + res.totalSru); + let items = document.querySelector(".items"); + items.classList.remove('animate-pulse'); document.getElementById("capacity").innerHTML = capacity; document.getElementById("nodes").innerHTML = res.nodes; document.getElementById("countries").innerHTML = res.countries; diff --git a/templates/shortcodes/grid_stats.html b/templates/shortcodes/grid_stats.html index 539583cd9..ca8c25824 100644 --- a/templates/shortcodes/grid_stats.html +++ b/templates/shortcodes/grid_stats.html @@ -3,9 +3,9 @@
{{body | markdown | safe }} -
+
-
+
capacity
-
+
nodes
-
+
countries
-
+
Date: Tue, 12 Mar 2024 23:38:18 +0200 Subject: [PATCH 4/5] Update data urls --- static/js/custom.js | 78 ++++++--------------------------------------- 1 file changed, 10 insertions(+), 68 deletions(-) diff --git a/static/js/custom.js b/static/js/custom.js index 402f301ae..7c6130572 100644 --- a/static/js/custom.js +++ b/static/js/custom.js @@ -164,21 +164,12 @@ function readingTime() { } } -const urls = [ - "https://gridproxy.grid.tf/stats?status=up", - "https://gridproxy.dev.grid.tf/stats?status=up", - "https://gridproxy.test.grid.tf/stats?status=up", - "https://gridproxy.grid.tf/stats?status=standby", - "https://gridproxy.dev.grid.tf/stats?status=standby", - "https://gridproxy.test.grid.tf/stats?status=standby", -]; - async function getStats() { try { - const stats = await Promise.all( - urls.map((url) => fetch(url).then((resp) => resp.json())) - ); - return mergeStatsData(stats); + const stats = await fetch( + "https://stats.grid.tf/api/stats-summary" + ).then((res) => res.json()); + return formatStatsData(stats); } catch (error) { throw new Error( `Failed to retrieve data from network statistics: ${error}` @@ -186,62 +177,13 @@ async function getStats() { } } -function mergeStatsData(stats) { - const res = stats[0]; - for (let i = 1; i < stats.length; i++) { - res.nodes += stats[i].nodes; - res.totalCru += stats[i].totalCru; - res.totalHru += stats[i].totalHru; - res.totalSru += stats[i].totalSru; - res.nodesDistribution = mergeNodeDistribution([ - res.nodesDistribution, - stats[i].nodesDistribution, - ]); - res.countries = Object.keys(res.nodesDistribution).length; - } - let capacity = toTeraOrGiga(res.totalHru + res.totalSru); +function formatStatsData(stats) { let items = document.querySelector(".items"); - items.classList.remove('animate-pulse'); - document.getElementById("capacity").innerHTML = capacity; - document.getElementById("nodes").innerHTML = res.nodes; - document.getElementById("countries").innerHTML = res.countries; - document.getElementById("cores").innerHTML = res.totalCru - .toString() - .replace(/\B(?=(\d{3})+(?!\d))/g, ","); -} - -function mergeNodeDistribution(stats) { - const keys = new Set(stats.map((obj) => Object.keys(obj)).flat()); - - return Array.from(keys).reduce((res, key) => { - res[key] = 0; - stats.forEach((country) => { - res[key] += country[key] ?? 0; - }); - return res; - }, {}); -} - -function toTeraOrGiga(value) { - const giga = 1024 ** 3; - - if (!value) return "0"; - - const val = +value; - if (val === 0 || isNaN(val)) return "0"; - - if (val < giga) return val.toString(); - - let gb = val / giga; - - if (gb < 1024) return `${gb.toFixed(2)} GB`; - - gb = gb / 1024; - - if (gb < 1024) return `${gb.toFixed(2)} TB`; - - gb = gb / 1024; - return `${gb.toFixed(2)} PB`; + items.classList.remove("animate-pulse"); + document.getElementById("capacity").innerHTML = stats.capacity; + document.getElementById("nodes").innerHTML = stats.nodes; + document.getElementById("countries").innerHTML = stats.countries; + document.getElementById("cores").innerHTML = stats.cores; } readingTime(); From bfd27bc27d3bdcc9913f5a983a58b6b3da3285a5 Mon Sep 17 00:00:00 2001 From: samaradel Date: Wed, 13 Mar 2024 00:25:06 +0200 Subject: [PATCH 5/5] format core --- static/js/custom.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/static/js/custom.js b/static/js/custom.js index 7c6130572..793737311 100644 --- a/static/js/custom.js +++ b/static/js/custom.js @@ -183,7 +183,9 @@ function formatStatsData(stats) { document.getElementById("capacity").innerHTML = stats.capacity; document.getElementById("nodes").innerHTML = stats.nodes; document.getElementById("countries").innerHTML = stats.countries; - document.getElementById("cores").innerHTML = stats.cores; + document.getElementById("cores").innerHTML = stats.cores + .toString() + .replace(/\B(?=(\d{3})+(?!\d))/g, ","); } readingTime();