feat(dashboard): price earnings history from the platform's own figure - #127
Merged
Conversation
Earnings over time was computed locally: this node's token counts multiplied by published per-million rates. That cannot be right. The rates are not the whole of how the platform decides what a provider is owed, so the chart was an arithmetic exercise that happened to be denominated in dollars, sitting next to the platform's actual total and inviting the two to be compared. The platform exposes no earnings time series — /provider/me/stats returns lifetime totals and ignores period, from/to, granularity and days, and the history, payouts and settlements paths do not exist. But its lifetime total is cumulative and monotonic, so sampling it with each metrics snapshot and differencing consecutive samples gives what the platform says was earned in between, with no local rate arithmetic at all. It also sidesteps the restart problem the local counters have, since the platform's figure never resets. Intervals with no recorded figure — stored before this, or sampled while the API was unreachable — keep the local estimate. Each point reports which it is and the footer states the provenance, because a bar read off the ledger and a bar priced locally are different claims and only one reconciles with what is paid. The split by model stays local: the platform reports no per-model breakdown, so the share is rescaled onto the authoritative total to fill the bar. The bar's height is the platform's number; its division is this node's estimate, and the UI says so. A decrease in the lifetime total is a correction or a payout on the platform side, so it contributes zero rather than subtracting from the window.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Earnings over time was computed locally — this node's token counts times published per-million rates. Those rates are not the whole of how a provider's earnings are determined, so the chart was an arithmetic exercise denominated in dollars, sitting next to the platform's actual total and inviting the two to be compared.
What the platform actually offers
I probed it before designing anything. There is no earnings time series:
/provider/me/earnings,/earnings/history,/stats/history,/stats/daily,/history,/payouts,/settlements,/rewards→ all 404/provider/me/statsreturns lifetime totals and ignores?period=,?from=/to=,?granularity=,?days=— every variant returns the identical totalThe approach
That lifetime total is cumulative and monotonic. Recording it with each metrics snapshot and differencing consecutive samples gives what the platform says was earned in between — no local rate arithmetic at all. It also sidesteps the restart problem the local counters have, because the platform's figure never resets.
Costs one upstream call every couple of minutes at most; the stats client already caches.
Honest about what is still an estimate
authoritative, the series carriesauthoritative_points, and the footer states the provenance instead of presenting both as the same number.Verified
9 tests, including: the ledger delta is used even when a deliberately absurd local rate would give a wildly different answer; a bucket with no platform figure does not claim to be authoritative; the rescaled model segments sum to the bar and preserve the local 3:1 ratio; a decreasing total yields zero.
8/8 packages,
go vetandgofmtclean,tscclean, rebuilt bundle, config documented.Worth flagging
If the platform updates that figure on a settlement cycle rather than continuously, differencing will show flat stretches then jumps. That is truthful, but it changes the chart's shape — and a real time-series endpoint on the platform side would be the better long-term answer than sampling a running total.