Skip to content

feat(prices): a price summary per day or per month for the app - #2183

Merged
frahlg merged 1 commit into
masterfrom
price-summary
Dec 5, 2026
Merged

frahlg merged 1 commit into
masterfrom
price-summary

Conversation

@frahlg

@frahlg frahlg commented Dec 5, 2026

Copy link
Copy Markdown
Member

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} with per day or month. The answer is price.summary {zone, currency, tz, per, rows}, one row for each day or month in the box's own time zone (the one hello_ok names), oldest first:

{ startMs, endMs, coveredMs,
  spot?:  { meanMinor, minMinor, maxMinor, minStartMs, maxStartMs },
  total?: { same } }
  • The box widens the window to whole rows. A day runs from local midnight to local midnight, so it is 23, 24 or 25 hours, and endMs says which.
  • The money is the stored rows price.get serves, in the same minor units, each figure rounded once. Nothing here applies VAT or fees; the stored total already has them.
  • The mean counts each slot by its length. min and max are single slots, and the earliest wins a tie.
  • coveredMs is how much of the row has prices. Below endMs - startMs means a partial row; 0 means none, and then spot and total are 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.
  • Bounds: at most 62 day rows (a month and the month before) or 24 month rows (a year and the year before). More gets 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.
  • A bad per or toMs <= fromMs gets E_UNKNOWN_OP {field}. No price service or a failed read gets E_UNAVAILABLE {subsystem}.

The registry gets:

  • the read price.summary.get (const: MsgPriceSummaryGet, scope ftw.plan.read, as price.get), so agents can send it too;
  • the capability price.summary, sent with price.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 into PricePer constants and PricePerMaxRows.

The store walks the rows one at a time (state.VisitPrices, which LoadPrices now uses), so a two-year read holds a row per day or month, not 70 000 slots. One path only: the handler sits beside price.get in appproto. 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 without ftw.plan.read.
  • go/cmd/ftw/app_prices_test.go: appPrices.Visit against a real store, half-open and zone-bound, and a visitor error stops the walk.
  • make verify passed locally.

Overlap

#2126 also touches contract/registry.yaml, go/protocol/messages.go and docs/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/ and ftw-app/protocol/, and docs/protocol.md to the web client's working copy.

🤖 Generated with Claude Code

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>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Dec 5, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-12-05T13:57:08.037934Z 09a1a3a PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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 {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

@frahlg
frahlg merged commit 5269281 into master Dec 5, 2026
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant