Merge pull request #1333 from nymkappa/feature/weekly-hashrate-indexing-monday

Index weekly hashrates using last Monday midnight - Fix charts tooltip
This commit is contained in:
softsimon 2022-03-10 12:39:31 +01:00 committed by GitHub
commit 192c61f9cb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 6 deletions

View File

@ -93,8 +93,11 @@ class Mining {
const indexedTimestamp = await HashratesRepository.$getWeeklyHashrateTimestamps(); const indexedTimestamp = await HashratesRepository.$getWeeklyHashrateTimestamps();
const hashrates: any[] = []; const hashrates: any[] = [];
const genesisTimestamp = 1231006505; // bitcoin-cli getblock 000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f const genesisTimestamp = 1231006505; // bitcoin-cli getblock 000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f
const lastMidnight = this.getDateMidnight(new Date());
let toTimestamp = Math.round((lastMidnight.getTime() - 604800) / 1000); const now = new Date();
const lastMonday = new Date(now.setDate(now.getDate() - (now.getDay() + 6) % 7));
const lastMondayMidnight = this.getDateMidnight(lastMonday);
let toTimestamp = Math.round((lastMondayMidnight.getTime() - 604800) / 1000);
const totalWeekIndexed = (await BlocksRepository.$blockCount(null, null)) / 1008; const totalWeekIndexed = (await BlocksRepository.$blockCount(null, null)) / 1008;
let indexedThisRun = 0; let indexedThisRun = 0;
@ -142,7 +145,7 @@ class Mining {
hashrates.length = 0; hashrates.length = 0;
const elapsedSeconds = Math.max(1, Math.round((new Date().getTime() / 1000) - startedAt)); const elapsedSeconds = Math.max(1, Math.round((new Date().getTime() / 1000) - startedAt));
if (elapsedSeconds > 5) { if (elapsedSeconds > 1) {
const weeksPerSeconds = (indexedThisRun / elapsedSeconds).toFixed(2); const weeksPerSeconds = (indexedThisRun / elapsedSeconds).toFixed(2);
const formattedDate = new Date(fromTimestamp * 1000).toUTCString(); const formattedDate = new Date(fromTimestamp * 1000).toUTCString();
const weeksLeft = Math.round(totalWeekIndexed - totalIndexed); const weeksLeft = Math.round(totalWeekIndexed - totalIndexed);
@ -228,7 +231,7 @@ class Mining {
} }
const elapsedSeconds = Math.max(1, Math.round((new Date().getTime() / 1000) - startedAt)); const elapsedSeconds = Math.max(1, Math.round((new Date().getTime() / 1000) - startedAt));
if (elapsedSeconds > 5) { if (elapsedSeconds > 1) {
const daysPerSeconds = (indexedThisRun / elapsedSeconds).toFixed(2); const daysPerSeconds = (indexedThisRun / elapsedSeconds).toFixed(2);
const formattedDate = new Date(fromTimestamp * 1000).toUTCString(); const formattedDate = new Date(fromTimestamp * 1000).toUTCString();
const daysLeft = Math.round(totalDayIndexed - totalIndexed); const daysLeft = Math.round(totalDayIndexed - totalIndexed);

View File

@ -182,8 +182,9 @@ export class HashrateChartComponent implements OnInit {
difficulty = Math.round(data[1].data[1] / difficultyPowerOfTen.divider); difficulty = Math.round(data[1].data[1] / difficultyPowerOfTen.divider);
} }
const date = new Date(data[0].data[0]).toLocaleDateString(this.locale, { year: 'numeric', month: 'short', day: 'numeric' });
return ` return `
<b style="color: white; margin-left: 18px">${data[0].axisValueLabel}</b><br> <b style="color: white; margin-left: 18px">${date}</b><br>
<span>${data[0].marker} ${data[0].seriesName}: ${formatNumber(hashrate, this.locale, '1.0-0')} ${hashratePowerOfTen.unit}H/s</span><br> <span>${data[0].marker} ${data[0].seriesName}: ${formatNumber(hashrate, this.locale, '1.0-0')} ${hashratePowerOfTen.unit}H/s</span><br>
<span>${data[1].marker} ${data[1].seriesName}: ${formatNumber(difficulty, this.locale, '1.2-2')} ${difficultyPowerOfTen.unit}</span> <span>${data[1].marker} ${data[1].seriesName}: ${formatNumber(difficulty, this.locale, '1.2-2')} ${difficultyPowerOfTen.unit}</span>
`; `;

View File

@ -160,7 +160,8 @@ export class HashrateChartPoolsComponent implements OnInit {
}, },
borderColor: '#000', borderColor: '#000',
formatter: function (data) { formatter: function (data) {
let tooltip = `<b style="color: white; margin-left: 18px">${data[0].axisValueLabel}</b><br>`; const date = new Date(data[0].data[0]).toLocaleDateString(this.locale, { year: 'numeric', month: 'short', day: 'numeric' });
let tooltip = `<b style="color: white; margin-left: 18px">${date}</b><br>`;
data.sort((a, b) => b.data[1] - a.data[1]); data.sort((a, b) => b.data[1] - a.data[1]);
for (const pool of data) { for (const pool of data) {
if (pool.data[1] > 0) { if (pool.data[1] > 0) {