Update data urls
This commit is contained in:
@@ -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() {
|
async function getStats() {
|
||||||
try {
|
try {
|
||||||
const stats = await Promise.all(
|
const stats = await fetch(
|
||||||
urls.map((url) => fetch(url).then((resp) => resp.json()))
|
"https://stats.grid.tf/api/stats-summary"
|
||||||
);
|
).then((res) => res.json());
|
||||||
return mergeStatsData(stats);
|
return formatStatsData(stats);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`Failed to retrieve data from network statistics: ${error}`
|
`Failed to retrieve data from network statistics: ${error}`
|
||||||
@@ -186,62 +177,13 @@ async function getStats() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function mergeStatsData(stats) {
|
function formatStatsData(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);
|
|
||||||
let items = document.querySelector(".items");
|
let items = document.querySelector(".items");
|
||||||
items.classList.remove('animate-pulse');
|
items.classList.remove("animate-pulse");
|
||||||
document.getElementById("capacity").innerHTML = capacity;
|
document.getElementById("capacity").innerHTML = stats.capacity;
|
||||||
document.getElementById("nodes").innerHTML = res.nodes;
|
document.getElementById("nodes").innerHTML = stats.nodes;
|
||||||
document.getElementById("countries").innerHTML = res.countries;
|
document.getElementById("countries").innerHTML = stats.countries;
|
||||||
document.getElementById("cores").innerHTML = res.totalCru
|
document.getElementById("cores").innerHTML = stats.cores;
|
||||||
.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`;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
readingTime();
|
readingTime();
|
||||||
|
|||||||
Reference in New Issue
Block a user