Datasets:
Download source/tests/solvers/cmp_fifo.py from Syndicate604/skills-desk: direct link, hf CLI and curl.
- Browser
- Download file 521 Bytes
-
https://huggingface.co/datasets/Syndicate604/skills-desk/resolve/main/source/tests/solvers/cmp_fifo.py
- Command line
-
hf download hf://datasets/Syndicate604/skills-desk/source/tests/solvers/cmp_fifo.py
-
curl -L -o cmp_fifo.py https://huggingface.co/datasets/Syndicate604/skills-desk/resolve/main/source/tests/solvers/cmp_fifo.py
521 Bytes
| import csv, json | |
| from decimal import Decimal | |
| lots, cogs = [], Decimal(0) | |
| for r in csv.DictReader(open("movements.csv")): | |
| q = int(r["qty"]) | |
| if r["type"] == "buy": lots.append([q, Decimal(r["unit_cost"])]); continue | |
| while q: | |
| t = min(q, lots[0][0]); cogs += t * lots[0][1]; lots[0][0] -= t; q -= t | |
| if not lots[0][0]: lots.pop(0) | |
| json.dump({"cogs": float(cogs), "units_on_hand": sum(l[0] for l in lots), "inventory_value": float(sum(l[0] * l[1] for l in lots))}, | |
| open("fifo.json", "w")) | |