feat: add calculateDScore for the calculator #77
+456
−14
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.
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 todevwhen #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.2is0.3). An empty list gives0.Routine.dScorewill use the same function.calculateDScoreresolver: loads the elements and vaults with one query for each table, whatever the number of ids. The same id twice counts once.INVALID_ITEMS(InvalidItemsError) for items from more than one apparatus, a vault with elements, more than one vault, and a removed item.BAD_USER_INPUTfor more than 50 ids, an unknown id and an id with odd characters.schema.graphqldescription ofcalculateDScorenow 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/API.mdanddocs/AI_USAGE.md.Testing
tsc --noEmitand 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).🤖 Generated with Claude Code