Skip to content

Conversation

ronjalh
Copy link
Member

@ronjalh ronjalh commented Oct 17, 2026 •

Summary

The calculator works: calculateDScore(itemIds) returns the D-score of a list of elements or vaults for anyone, and saves nothing. Closes #72.

Stacked on #65 (the server). The base is 28-graphql-server-catalog. Change the base to dev when #65 is merged. It does not need the login: the calculator is open to everyone.

What's in it

  • backend/src/dscore.ts: the D-score function from constraint 13: the sum of the eight highest values, each code once, or the D-value of the single vault. It works in tenths (whole numbers), so there are no rounding errors (0.1 + 0.2 is 0.3). An empty list gives 0. Routine.dScore will use the same function.
  • calculateDScore resolver: loads the elements and vaults with one query for each table, whatever the number of ids. The same id twice counts once.
  • Errors: new INVALID_ITEMS (InvalidItemsError) for items from more than one apparatus, a vault with elements, more than one vault, and a removed item. BAD_USER_INPUT for more than 50 ids, an unknown id and an id with odd characters.
  • The schema.graphql description of calculateDScore now says that a removed item is refused. This is the same text as in feat: add the missing fields to the GraphQL schema #49, so the two should merge without a conflict.
  • Docs: docs/API.md and docs/AI_USAGE.md.

Testing

  • Lint, tsc --noEmit and 122 tests pass against a database (0 skipped); 17 are new: the function (fewer than, exactly and more than eight elements, the same code twice, a vault, empty list, rounding, errors) and the query (no login needed, same score as the function for catalog items, every error, 50 ids is fine and 51 is not, SQL in an id, fixed query count).
  • The removed-item case uses a fake database, because the seeded catalog has no removed items.

🤖 Generated with Claude Code

The D-score is the sum of the eight highest values with each code counted
once, or the D-value of the single vault. The sum is made in tenths to
avoid rounding errors. INVALID_ITEMS is thrown for items that do not fit
together and for removed items. The same function will give Routine.dScore.
@ronjalh ronjalh force-pushed the 72-calculate-dscore branch from c139cd2 to aea1ed0 Compare October 17, 2026 09:23
@ronjalh ronjalh changed the base branch from 70-login-and-session to 28-graphql-server-catalog October 17, 2026 09:23
@ronjalh ronjalh marked this pull request as ready for review October 17, 2026 09:37
Sign in to join this conversation on GitHub.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant