File size: 3,139 Bytes
a61cfbe | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 | """Generate the synthetic CSVs in this dataset. Every value is invented.
Brands, model names, prices and dates are made up by a seeded random
generator; nothing is real, scraped or copied. Re-running this script
reproduces the files byte for byte:
python make_data.py
"""
import csv
import random
from datetime import date, timedelta
SEED = 20260927
BRANDS = ["Arvelo", "Brindlecore", "Corvane", "Duskmere", "Elmstead", "Fennix", "Glimmerly", "Halvorn"]
CATEGORIES = {
# category: (price range in USD, model-name stems)
"cpu": ((79, 899), ["Vex", "Torrent", "Kestrel"]),
"gpu": ((149, 1899), ["Auralis", "Nimbus", "Ember"]),
"ssd": ((39, 549), ["Drift", "Slate", "Quill"]),
"ram": ((29, 429), ["Pulse", "Lattice", "Ripple"]),
"motherboard": ((89, 699), ["Keystone", "Harbor", "Trellis"]),
"psu": ((49, 329), ["Volta", "Current", "Bastion"]),
"monitor": ((119, 1299), ["Vista", "Prism", "Horizon"]),
}
STORES = ["north-depot", "harbor-outlet", "ridge-market", "online"]
def hardware_prices(rng: random.Random) -> list[dict]:
rows = []
seen = set()
while len(rows) < 200:
brand = rng.choice(BRANDS)
category = rng.choice(sorted(CATEGORIES))
(lo, hi), stems = CATEGORIES[category]
model = f"{rng.choice(stems)} {rng.choice('ABCDEFGHJKLMNPRSTXZ')}{rng.randint(1, 9)}{rng.choice(['', '0', '00', '50'])}"
if (brand, model) in seen:
continue
seen.add((brand, model))
rows.append(
{
"id": len(rows) + 1,
"brand": brand,
"model": model,
"category": category,
"price_usd": f"{rng.uniform(lo, hi):.2f}",
"release_year": rng.randint(2019, 2026),
}
)
return rows
def price_observations(rng: random.Random, products: list[dict]) -> list[dict]:
"""A second, long-shaped table: price checks of some products over time."""
rows = []
start = date(2026, 1, 5)
for n in range(120):
p = rng.choice(products)
base = float(p["price_usd"])
observed = start + timedelta(days=rng.randint(0, 250))
in_stock = rng.random() > 0.2
rows.append(
{
"observation_id": f"obs-{n + 1:04d}",
"product_id": p["id"],
"store": rng.choice(STORES),
"observed_on": observed.isoformat(),
"price_usd": f"{base * rng.uniform(0.85, 1.12):.2f}" if in_stock else "",
"in_stock": "true" if in_stock else "false",
}
)
rows.sort(key=lambda r: (r["observed_on"], r["observation_id"]))
return rows
def write(path: str, rows: list[dict]) -> None:
with open(path, "w", newline="", encoding="utf-8") as f:
w = csv.DictWriter(f, fieldnames=list(rows[0]), lineterminator="\n")
w.writeheader()
w.writerows(rows)
if __name__ == "__main__":
rng = random.Random(SEED)
products = hardware_prices(rng)
write("hardware_prices.csv", products)
write("price_observations.csv", price_observations(rng, products))
|