Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: make universal rate computation #13

Merged
merged 1 commit into from
Sep 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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