Skip to content

Commit

Permalink
fix: make universal rate computation
Browse files Browse the repository at this point in the history
  • Loading branch information
Cifko committed Sep 5, 2023
1 parent 121a862 commit 95cf91b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 27 deletions.
17 changes: 2 additions & 15 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 19 additions & 12 deletions routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ router.get("/", async function (req, res) {
let limit = parseInt(req.query.limit || "20");

let version_result = await client.getVersion({});
let version = version_result.value.slice(0,25);
let version = version_result.value.slice(0, 25);

let tipInfo = await client.getTipInfo({});

Expand Down Expand Up @@ -86,15 +86,17 @@ router.get("/", async function (req, res) {

// estimated hash rates
let lastDifficulties = await client.getNetworkDifficulty({ from_tip: 100 });
let totalHashRates = getHashRates(lastDifficulties, "estimated_hash_rate");
let moneroHashRates = getHashRates(
lastDifficulties,
"monero_estimated_hash_rate"
);
let shaHashRates = getHashRates(
lastDifficulties,
"sha3_estimated_hash_rate"
);
let totalHashRates = getHashRates(lastDifficulties, [
"estimated_hash_rate",
]);
let moneroHashRates = getHashRates(lastDifficulties, [
"monero_estimated_hash_rate",
"randomx_estimated_hash_rate",
]);
let shaHashRates = getHashRates(lastDifficulties, [
"sha3_estimated_hash_rate",
"sha3x_estimated_hash_rate",
]);

// list of active validator nodes
let tipHeight = tipInfo.metadata.height_of_longest_chain;
Expand Down Expand Up @@ -142,12 +144,17 @@ router.get("/", async function (req, res) {
}
});

function getHashRates(difficulties, property) {
function getHashRates(difficulties, properties) {
const end_idx = difficulties.length - 1;
const start_idx = end_idx - 60;

return difficulties
.map((d) => parseInt(d[property]))
.map((d) =>
properties.reduce(
(sum, property) => sum + (parseInt(d[property]) || 0),
0
)
)
.slice(start_idx, end_idx);
}

Expand Down

0 comments on commit 95cf91b

Please sign in to comment.