$extens("include.py") include("import os", []) def csv_report_sample(path: str = "~/extella-demo-data/orders.csv", rows: int = 4000) -> dict: # Writes a file of synthetic orders on the device this program runs on. The data depends on the # device's host name, so two devices hold two different files. import csv, hashlib, io, os, random, socket host = socket.gethostname() rnd = random.Random(int(hashlib.sha256(host.encode()).hexdigest()[:12], 16)) regions = ["North", "South", "East", "West", "Central"] products = ["Espresso beans", "Filter beans", "Decaf", "Cold brew", "Grinder", "Paper filters", "Gift box"] prices = [18, 16, 17, 6, 120, 4, 45] region_weights = [rnd.uniform(0.5, 2.0) for _ in regions] product_weights = [rnd.uniform(0.5, 2.0) for _ in products] out = io.StringIO() w = csv.writer(out) w.writerow(["date", "region", "product", "quantity", "amount"]) count = max(100, min(int(rows), 20000)) for _ in range(count): month = rnd.randint(1, 9) day = rnd.randint(1, 28) p = rnd.choices(range(len(products)), weights=product_weights)[0] quantity = rnd.randint(1, 6) w.writerow(["2026-%02d-%02d" % (month, day), rnd.choices(regions, weights=region_weights)[0], products[p], quantity, quantity * prices[p]]) data = out.getvalue().encode("utf-8") full = os.path.expanduser(path) os.makedirs(os.path.dirname(full), exist_ok=True) with open(full, "wb") as f: f.write(data) return {"status": "success", "file": path, "rows": count, "file_sha256": hashlib.sha256(data).hexdigest(), "host": host, "note": "synthetic data, generated from the host name"}