Use this skill when a garden centre (or similar shop) needs weekly points-card loyalty points worked out per card holder from a list of purchases (member, cents) in input.json, and written to loyalty-points.csv ranked by points.
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-5040cdbf)
---
name: loyalty-points
description: "Use this skill when a garden centre (or similar shop) needs weekly points-card loyalty points worked out per card holder from a list of purchases (member, cents) in input.json, and written to loyalty-points.csv ranked by points."
---
# Loyalty points
Turn this week's purchases into a ranked points table per card holder.
## When to use
- `input.json` in the working folder has `purchases`: an array of `{ "member": string, "cents": integer }`, and the user wants `loyalty-points.csv` beside it.
- Not for other reward schemes, other file formats, or inputs without this shape (tell the user instead of guessing).
## Rules (exact)
For each purchase:
- `base = floor(cents / 100)` (whole currency units paid; cents are dropped, never rounded up).
- `points = base * 2` if `cents >= 5000`, otherwise `points = base`.
- Rate is applied per purchase, never to a member's combined total.
- If `cents < 0` (refund) or `base` is 0, the purchase earns 0 points (never negative).
A member's points = sum of `points` over all their purchases. Members are matched by exact `member` string (case-sensitive; do not trim or merge variants).
## Steps
1. Read `input.json`.
2. For each purchase compute `points` with the rules above. Do the arithmetic carefully, writing each purchase's value down.
3. Sum per member. Every member who appears gets a row, even with 0 points.
4. Sort by points descending; ties by member name ascending (plain character order).
5. Write `loyalty-points.csv` beside `input.json` (overwrite if present):
- First line exactly `member,points`.
- One line per member: `name,points` (integer, no decimals), `\n` line endings, trailing newline.
- If a name contains a comma, quote or newline, wrap in double quotes and double inner quotes.
- If `purchases` is empty, write only the header line.
6. Re-read the file and re-check sums and ordering.
## Worked example
Purchases: Ana 1299, Ben 5000, Ana 4250, Cal 899, Ben 349.
- Ana: 12 + 42 = 54. Ben: 5000 → 50×2 = 100, 349 → 3, total 103. Cal: 8.
```csv
member,points
Ben,103
Ana,54
Cal,8
```
Edge: Hal 5099 and 450 → 50×2 + 4 = 104 (floor first, then double). Kai 4999 → 49 (below 5000, no doubling).
## Missing or odd input
- If `input.json` or `purchases` is missing, stop and report it; do not invent data.
- A non-integer `cents`: use `floor(cents / 100)` on the value as given and mention it in your reply.
- A purchase lacking `member` or `cents`: skip it and tell the user.