fix(mining): stamp hashrate history and label the chart by real time
The hashrate sparkline guessed the age of its oldest sample from the sample count, labelling the left edge "5m ago", "1m ago" or "start" regardless of how fast samples actually arrived. Solo and pool samples come in at different intervals, and a slow or stalled poll made those labels wrong. - Each hashrate sample now carries a wall-clock timestamp, kept in lockstep with the value as the history fills and rolls over, for both the solo and pool histories. - The chart's left-edge label is derived from the oldest sample's actual timestamp, falling back to "start" only when no stamp is available. Tests: a mining refresh records a timestamp per sample, and the timestamp history stays the same length as the value history once the history is capped. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
#include "../../config/settings.h"
|
||||
#include "../../util/i18n.h"
|
||||
#include "../../util/pool_registry.h"
|
||||
#include "../../util/text_format.h"
|
||||
#include "../schema/ui_schema.h"
|
||||
#include "../material/type.h"
|
||||
#include "../material/draw_helpers.h"
|
||||
@@ -40,6 +41,7 @@ static bool s_show_solo_log = false;
|
||||
// ---------------------------------------------------------------------------
|
||||
static void DrawHashrateSparkline(ImDrawList* dl, ImVec2 regionMin, ImVec2 regionMax,
|
||||
const std::vector<double>& chartHistory,
|
||||
std::time_t oldestSampleT, // 0 when unknown
|
||||
ImFont* capFont, float dp)
|
||||
{
|
||||
if (chartHistory.size() < 2) return;
|
||||
@@ -116,10 +118,11 @@ static void DrawHashrateSparkline(ImDrawList* dl, ImVec2 regionMin, ImVec2 regio
|
||||
dl->AddText(capFont, capFont->LegacySize, ImVec2(plotLeft + 2 * dp, plotBottom + 4 * dp), OnSurfaceDisabled(), yMinStr.c_str());
|
||||
|
||||
// X-axis labels
|
||||
std::string agoLbl = (oldestSampleT > 0) ? dragonx::util::formatTimeAgoShort(oldestSampleT)
|
||||
: std::string(TR("mining_chart_start"));
|
||||
dl->AddText(capFont, capFont->LegacySize,
|
||||
ImVec2(plotLeft, chartBot - capFont->LegacySize - 2 * dp), OnSurfaceDisabled(),
|
||||
chartHistory.size() >= 300 ? TR("mining_chart_5m_ago") :
|
||||
chartHistory.size() >= 60 ? TR("mining_chart_1m_ago") : TR("mining_chart_start"));
|
||||
agoLbl.c_str());
|
||||
std::string nowLbl = TR("mining_chart_now");
|
||||
ImVec2 nowSz = capFont->CalcTextSizeA(capFont->LegacySize, 10000, 0, nowLbl.c_str());
|
||||
dl->AddText(capFont, capFont->LegacySize,
|
||||
@@ -374,6 +377,11 @@ void RenderMiningStats(const WalletState& state, const MiningInfo& mining,
|
||||
const std::vector<double>& chartHistory = s_pool_mode
|
||||
? state.pool_mining.hashrate_history
|
||||
: mining.hashrate_history;
|
||||
const std::vector<std::time_t>& chartHistoryT = s_pool_mode
|
||||
? state.pool_mining.hashrate_history_t
|
||||
: mining.hashrate_history_t;
|
||||
const std::time_t oldestT = (chartHistoryT.size() == chartHistory.size() && !chartHistoryT.empty())
|
||||
? chartHistoryT.front() : 0;
|
||||
bool hasChartContent = chartHistory.size() >= 2;
|
||||
|
||||
float statRowH = ovFont->LegacySize + Layout::spacingXs() + sub1->LegacySize + Layout::spacingSm();
|
||||
@@ -432,7 +440,7 @@ void RenderMiningStats(const WalletState& state, const MiningInfo& mining,
|
||||
DrawHashrateSparkline(dl,
|
||||
ImVec2(chartBandX, rightMin.y + statRowH * 0.5f),
|
||||
ImVec2(chartBandX + chartBandW, rightMax.y),
|
||||
chartHistory, capFont, dp);
|
||||
chartHistory, oldestT, capFont, dp);
|
||||
} else {
|
||||
const char* hint = TR("mining_chart_start");
|
||||
ImVec2 hs = capFont->CalcTextSizeA(capFont->LegacySize, FLT_MAX, 0, hint);
|
||||
@@ -542,7 +550,7 @@ void RenderMiningStats(const WalletState& state, const MiningInfo& mining,
|
||||
DrawHashrateSparkline(dl,
|
||||
ImVec2(cardMin.x + pad, cardMin.y + statRowH),
|
||||
ImVec2(cardMax.x - pad, cardMax.y),
|
||||
chartHistory, capFont, dp);
|
||||
chartHistory, oldestT, capFont, dp);
|
||||
}
|
||||
ImGui::Dummy(ImVec2(availWidth, totalCardH));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user