Use this skill when a user wants weekly loyalty card points totalled per card holder from a list of purchases (member name and amount paid in cents), e.g. 'work out this week's points', 'how many points did each member earn', or 'write loyalty-points.csv from input.json'. Not for redeeming points or general sales reports.
Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
SSkills DirectorySkills Directory
Is that skill safe to install?
Are you the author of Loyalty Points?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/gabrielmoreira-loyalty-points-d14cd7ce)
---
name: loyalty-points
description: "Use this skill when a user wants weekly loyalty card points totalled per card holder from a list of purchases (member name and amount paid in cents), e.g. 'work out this week's points', 'how many points did each member earn', or 'write loyalty-points.csv from input.json'. Not for redeeming points or general sales reports."
---
# Loyalty points
Turn this week's purchases into a per-member points table, by reading and writing files only.
## Input
`input.json` in the working folder:
`{"purchases": [{"member": "Ana", "cents": 1299}, ...]}`
One entry per purchase; `cents` is the amount paid in whole cents.
## Rules (exact)
For each purchase:
- `base = floor(cents / 100)` (whole dollars, dropping the remainder; never round up)
- `points = base * 2` if `cents >= 5000`, else `points = base`
- If `cents <= 0` (or base is 0), the purchase earns 0 points. Never subtract points.
Apply this to each purchase separately, never to a member's combined total. Then a member's points = sum of their purchases' points.
## Steps
1. Read `input.json`.
2. Compute points for every purchase using the rules above.
3. Group by `member` (exact string match, trimmed of surrounding whitespace; do not change case) and sum.
4. Keep every member who appears, including those with 0 points.
5. Sort by points descending; ties by member name ascending (plain character order).
6. Write `loyalty-points.csv` next to `input.json`:
- first line `member,points`
- one line per member `name,points`, integers, no spaces, newline after each line
- if a name contains a comma, quote or newline, wrap it in double quotes and double any inner quotes
7. Re-check: the sum of the CSV points equals the sum of the per-purchase points, and each member appears once.
## Edge cases
- Empty `purchases`: write only the header line.
- Missing file or malformed entries: say so; skip nothing silently. If an entry lacks `member` or has a non-numeric `cents`, stop and report it rather than guessing.
- Overwrite an existing `loyalty-points.csv`.
## Worked example
Purchases: Ana 1299, Ben 5000, Ana 4250, Cal 899, Ben 349.
- Ana: 12 + 42 = 54
- Ben: 5000 is >= 5000, so 50*2 = 100, plus 3 = 103
- Cal: 8
```csv
member,points
Ben,103
Ana,54
Cal,8
```
Tie example: Dee 20 and Eve 20 are listed Dee first; 4999 cents earns 49 (below the 5000 threshold, no doubling).