Repository navigation
feat(prices): a price summary per day or per month for the app - #2183
Conversation
price.get serves slots and stops at eight days, and a year of quarters is
some 35 000 slots. The app's price history (week, month, year) needs one
point per day or per month and the lowest and highest quarter, against the
same period before.
price.summary.get {fromMs, toMs, per} answers price.summary with one row
per day or month in the box's own time zone, the one hello_ok names. The
box widens the window to whole rows. Each row carries its bounds
(startMs, endMs, so 23 and 25 hour days show), coveredMs, and for spot and
total the time-weighted mean, the lowest and highest slot and where each
starts. A row with no prices has no figures. The money is the stored rows
price.get serves, rounded once.
Coverage is time, not a slot count: the market moved from hours to
quarters in 2025 and a box keeps both, so a count has no fixed "expected".
The registry names the read (scope ftw.plan.read, as price.get), the
capability price.summary, and price_summary_per with max_rows: 62 days or
24 months. More is refused with E_RANGE_TOO_LARGE before any read. The
widest answer, with every figure a 9 byte integer, is 15 147 bytes and
fits the 16 KiB bulk bucket.
The store walks the rows one at a time (state.VisitPrices), so a two-year
read holds a row per day or month, not 70 000 slots.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 09a1a3a8e5
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| } | ||
|
|
||
| folds := make([]struct{ spot, total priceFold }, len(rows)) | ||
| err = h.cfg.Prices.Visit(ctx, rows[0].StartMs, rows[len(rows)-1].EndMs, func(p PricePoint) error { |
There was a problem hiding this comment.
Reject timestamp ranges that produce no calendar rows
A request with fromMs = -9223372036854775808, toMs = -9223372036854775807, and per = "day" passes the ordering check, but in Europe/Stockholm the containing midnight overflows when converted back to Unix milliseconds. Consequently, priceRows returns an empty slice with ok = true, and this indexing panics instead of refusing the request. An authenticated client or agent with price-read access can trigger this without any stored prices. Validate the representable calendar bounds and reject an empty result before indexing it.
Useful? React with 👍 / 👎.
Why
HannesB's Elpris design, approved for iPhone 1.2, has a Historik tab with week, month and year. Week and month draw one point per day (the day's mean). Year draws one point per month. Rings show the period's mean, lowest and highest against the same length of time before, for total price or spot.
Today the app has only
price.get, which serves quarter slots and stops at eight days. A year is some 35 000 quarters. This adds the smallest read that lets the app draw that view from what the box holds.What
price.summary.get {fromMs, toMs, per}withperdayormonth. The answer isprice.summary {zone, currency, tz, per, rows}, one row for each day or month in the box's own time zone (the onehello_oknames), oldest first:endMssays which.price.getserves, in the same minor units, each figure rounded once. Nothing here applies VAT or fees; the stored total already has them.minandmaxare single slots, and the earliest wins a tie.coveredMsis how much of the row has prices. BelowendMs - startMsmeans a partial row; 0 means none, and thenspotandtotalare absent. I used time and not a count of slots on purpose: the market moved from hours to quarters in 2025, and a box that ran before that holds both, so "expected slots" has no fixed value. Time also gives the app the weight it needs to sum rows into a period mean for the rings.E_RANGE_TOO_LARGE {per, maxRows}before the box reads anything, so a phone whose clock says 1970 costs a refusal, not a scan. The widest answer, with every money figure a 9-byte integer, is 15 147 bytes and fits the 16 KiB bulk bucket; a test holds it there.perortoMs <= fromMsgetsE_UNKNOWN_OP {field}. No price service or a failed read getsE_UNAVAILABLE {subsystem}.The registry gets:
price.summary.get(const: MsgPriceSummaryGet, scopeftw.plan.read, asprice.get), so agents can send it too;price.summary, sent withprice.spot, so the app can hide history on an older box;price_summary_per: {day: {max_rows: 62}, month: {max_rows: 24}}, which the generator turns intoPricePerconstants andPricePerMaxRows.The store walks the rows one at a time (
state.VisitPrices, whichLoadPricesnow uses), so a two-year read holds a row per day or month, not 70 000 slots. One path only: the handler sits besideprice.getinappproto. The on-box UI has no use for it, so there is no REST route.Tests
go/internal/appproto/price_summary_test.go: days across both DST changes (23 h and 25 h), a partial day, a day with no prices, negative prices, months with hours and quarters mixed and October's 745 hours, widening to whole rows, the row bounds (62/63 days, 24/25 months, from 1970), the widest answer fitting a bulk bucket, bad requests, no service and a failed read, and an agent with and withoutftw.plan.read.go/cmd/ftw/app_prices_test.go:appPrices.Visitagainst a real store, half-open and zone-bound, and a visitor error stops the walk.make verifypassed locally.Overlap
#2126 also touches
contract/registry.yaml,go/protocol/messages.goanddocs/agents.md, in other hunks. No conflict today; whichever lands second rebases.Clients
Not changed here. The registry snapshot needs copying byte for byte to
ftw-webapp/contract/andftw-app/protocol/, anddocs/protocol.mdto the web client's working copy.🤖 Generated with Claude Code