File size: 12,273 Bytes
d251e1d | 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 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 | """Deterministic FlowBench v3 tools. This file contains no task answers."""
REGIONS = ["NA", "EU", "APAC", "LATAM"]
CATEGORIES = ["A", "B", "C", "D"]
CURRENCIES = {"NA": "USD", "EU": "EUR", "APAC": "JPY", "LATAM": "BRL"}
FX_TO_USD_BP = {"USD": 10000, "EUR": 10900, "JPY": 67, "BRL": 1850}
TIERS = ["std", "gold", "plat"]
DISCOUNT_PCT = {"std": 0, "gold": 10, "plat": 20}
CHANNELS = ["web", "store", "partner"]
MONTHS = [202601, 202602, 202603, 202604, 202605, 202606]
N_CUSTOMERS = 72
N_PRODUCTS = 48
N_ORDERS = 720
N_TICKETS = 260
N_RETURNS = 180
def _h(*xs):
import hashlib
s = "|".join(str(x) for x in xs).encode()
return int.from_bytes(hashlib.sha256(s).digest()[:8], "big") & 0x7FFFFFFF
def build_data():
customers = []
for cid in range(N_CUSTOMERS):
region = REGIONS[_h("region", cid) % len(REGIONS)]
customers.append({
"customer_id": cid,
"region": region,
"tier": TIERS[_h("tier", cid) % len(TIERS)],
"segment": ["consumer", "smb", "enterprise"][_h("segment", cid) % 3],
})
products = []
for pid in range(N_PRODUCTS):
cat = CATEGORIES[_h("cat", pid) % len(CATEGORIES)]
unit_price = 12 + _h("price", pid) % 240
cogs = unit_price * (45 + _h("margin", pid) % 35) // 100
products.append({
"product_id": pid,
"category": cat,
"unit_price_usd": unit_price,
"unit_cogs_usd": cogs,
"lead_time_days": 3 + _h("lead", pid) % 18,
})
inventory = []
for pid in range(N_PRODUCTS):
for region in REGIONS:
inventory.append({
"product_id": pid,
"region": region,
"on_hand": 10 + _h("onhand", pid, region) % 140,
"reserved": _h("reserved", pid, region) % 28,
"inbound": _h("inbound", pid, region) % 85,
})
orders = []
for oid in range(N_ORDERS):
customer_id = _h("ocust", oid) % N_CUSTOMERS
product_id = _h("oprod", oid) % N_PRODUCTS
month = MONTHS[_h("month", oid) % len(MONTHS)]
qty = 1 + _h("qty", oid) % 9
ship_days = 1 + _h("shipdays", oid) % 16
promised_days = 3 + _h("promise", oid) % 9
status = ["paid", "paid", "paid", "paid", "cancelled", "refunded"][
_h("status", oid) % 6]
orders.append({
"order_id": oid,
"customer_id": customer_id,
"product_id": product_id,
"month": month,
"qty": qty,
"status": status,
"channel": CHANNELS[_h("channel", oid) % len(CHANNELS)],
"ship_days": ship_days,
"promised_days": promised_days,
})
returns = []
for rid in range(N_RETURNS):
oid = _h("roid", rid) % N_ORDERS
order = orders[oid]
if order["status"] == "cancelled":
continue
returned_qty = 1 + _h("rqty", rid) % max(1, order["qty"])
reason = ["defect", "late", "changed_mind", "wrong_item"][_h("reason", rid) % 4]
returns.append({
"return_id": rid,
"order_id": oid,
"month": MONTHS[_h("rmonth", rid) % len(MONTHS)],
"returned_qty": returned_qty,
"reason": reason,
})
tickets = []
for tid in range(N_TICKETS):
oid = _h("toid", tid) % N_ORDERS
severity = ["low", "medium", "high", "critical"][_h("sev", tid) % 4]
opened = MONTHS[_h("tmonth", tid) % len(MONTHS)]
first_response_hours = 1 + _h("resp", tid) % 96
resolution_hours = first_response_hours + _h("res", tid) % 240
tickets.append({
"ticket_id": tid,
"order_id": oid,
"opened_month": opened,
"severity": severity,
"first_response_hours": first_response_hours,
"resolution_hours": resolution_hours,
})
return {
"customers": customers,
"products": products,
"inventory": inventory,
"orders": orders,
"returns": returns,
"tickets": tickets,
"fx_to_usd_bp": FX_TO_USD_BP,
}
DATA = build_data()
CUSTOMERS = {c["customer_id"]: c for c in DATA["customers"]}
PRODUCTS = {p["product_id"]: p for p in DATA["products"]}
ORDERS = {o["order_id"]: o for o in DATA["orders"]}
def region_currency(region: str) -> str:
return CURRENCIES[region]
def get_orders(region: str, category: str, month_start: int, month_end: int) -> list:
"""Paid/refunded order ids in a region/category/month window."""
out = []
for o in DATA["orders"]:
if o["status"] not in ("paid", "refunded"):
continue
c = CUSTOMERS[o["customer_id"]]
p = PRODUCTS[o["product_id"]]
if c["region"] == region and p["category"] == category and month_start <= o["month"] <= month_end:
out.append(o["order_id"])
return sorted(out)
def order_gross_usd(order_id: int) -> int:
o = ORDERS[order_id]
p = PRODUCTS[o["product_id"]]
return o["qty"] * p["unit_price_usd"]
def order_margin_usd(order_id: int) -> int:
o = ORDERS[order_id]
p = PRODUCTS[o["product_id"]]
return o["qty"] * (p["unit_price_usd"] - p["unit_cogs_usd"])
def refund_usd(order_id: int) -> int:
o = ORDERS[order_id]
p = PRODUCTS[o["product_id"]]
qty = sum(r["returned_qty"] for r in DATA["returns"] if r["order_id"] == order_id)
qty = min(qty, o["qty"])
return qty * p["unit_price_usd"]
def customer_tier(order_id: int) -> str:
o = ORDERS[order_id]
return CUSTOMERS[o["customer_id"]]["tier"]
def apply_discount(amount_usd: int, tier: str) -> int:
return amount_usd * (100 - DISCOUNT_PCT[tier]) // 100
def net_revenue_usd(order_id: int) -> int:
gross = apply_discount(order_gross_usd(order_id), customer_tier(order_id))
return max(0, gross - refund_usd(order_id))
def to_local(amount_usd: int, currency: str) -> int:
return amount_usd * 10000 // FX_TO_USD_BP[currency]
def inventory_position(product_id: int, region: str) -> int:
row = next(x for x in DATA["inventory"]
if x["product_id"] == product_id and x["region"] == region)
return row["on_hand"] - row["reserved"] + row["inbound"]
def product_lead_time(product_id: int) -> int:
return PRODUCTS[product_id]["lead_time_days"]
def product_id_for_top_seller(region: str, category: str, month_start: int, month_end: int) -> int:
totals = {}
for oid in get_orders(region, category, month_start, month_end):
o = ORDERS[oid]
totals[o["product_id"]] = totals.get(o["product_id"], 0) + o["qty"]
if not totals:
return -1
return min((-qty, pid) for pid, qty in totals.items())[1]
def units_sold(product_id: int, region: str, month_start: int, month_end: int) -> int:
total = 0
for o in DATA["orders"]:
if o["product_id"] != product_id or o["status"] not in ("paid", "refunded"):
continue
c = CUSTOMERS[o["customer_id"]]
if c["region"] == region and month_start <= o["month"] <= month_end:
total += o["qty"]
return total
def tickets_for_orders(order_ids: list, severity: str) -> list:
s = set(order_ids)
return sorted(t["ticket_id"] for t in DATA["tickets"]
if t["order_id"] in s and t["severity"] == severity)
def ticket_order_id(ticket_id: int) -> int:
return next(t["order_id"] for t in DATA["tickets"] if t["ticket_id"] == ticket_id)
def sla_breached(ticket_id: int, first_response_limit_hours: int,
resolution_limit_hours: int) -> bool:
t = next(x for x in DATA["tickets"] if x["ticket_id"] == ticket_id)
return (t["first_response_hours"] > first_response_limit_hours or
t["resolution_hours"] > resolution_limit_hours)
def delayed_orders(order_ids: list) -> list:
s = set(order_ids)
return sorted(o["order_id"] for o in DATA["orders"]
if o["order_id"] in s and o["ship_days"] > o["promised_days"])
def unique_customers(order_ids: list) -> list:
return sorted({ORDERS[oid]["customer_id"] for oid in order_ids})
def count_items(values: list) -> int:
return len(values)
def sum_values(values: list) -> int:
return sum(values)
def count_true(values: list) -> int:
return sum(1 for v in values if bool(v))
def count_below(values: list, threshold: int) -> int:
return sum(1 for v in values if v < threshold)
TOOLS = {
"region_currency": ("region_currency(region: str) -> str",
"ISO currency code for a region.", region_currency),
"get_orders": ("get_orders(region: str, category: str, month_start: int, month_end: int) -> list[int]",
"Paid/refunded order ids for a region, product category, and inclusive month window.",
get_orders),
"order_gross_usd": ("order_gross_usd(order_id: int) -> int",
"Gross order revenue in USD before discounts/refunds.", order_gross_usd),
"order_margin_usd": ("order_margin_usd(order_id: int) -> int",
"Gross order margin in USD before discounts/refunds.", order_margin_usd),
"refund_usd": ("refund_usd(order_id: int) -> int",
"Refund amount in USD for returned quantity on an order.", refund_usd),
"customer_tier": ("customer_tier(order_id: int) -> str",
"Customer loyalty tier for an order.", customer_tier),
"apply_discount": ("apply_discount(amount_usd: int, tier: str) -> int",
"Apply the order customer's loyalty discount to a USD amount.", apply_discount),
"net_revenue_usd": ("net_revenue_usd(order_id: int) -> int",
"Net USD revenue after loyalty discount and refunds.", net_revenue_usd),
"to_local": ("to_local(amount_usd: int, currency: str) -> int",
"Convert a USD integer amount to a local-currency integer.", to_local),
"inventory_position": ("inventory_position(product_id: int, region: str) -> int",
"Available inventory position: on_hand - reserved + inbound.",
inventory_position),
"product_lead_time": ("product_lead_time(product_id: int) -> int",
"Supplier lead time in days for a product.", product_lead_time),
"product_id_for_top_seller": (
"product_id_for_top_seller(region: str, category: str, month_start: int, month_end: int) -> int",
"Product id with the highest units sold in a region/category/month window.",
product_id_for_top_seller),
"units_sold": ("units_sold(product_id: int, region: str, month_start: int, month_end: int) -> int",
"Units sold for one product in a region and month window.", units_sold),
"tickets_for_orders": ("tickets_for_orders(order_ids: list[int], severity: str) -> list[int]",
"Support ticket ids for given orders and severity.", tickets_for_orders),
"ticket_order_id": ("ticket_order_id(ticket_id: int) -> int",
"Order id associated with a support ticket.", ticket_order_id),
"sla_breached": (
"sla_breached(ticket_id: int, first_response_limit_hours: int, resolution_limit_hours: int) -> bool",
"Whether a support ticket breaches first-response or resolution SLA.",
sla_breached),
"delayed_orders": ("delayed_orders(order_ids: list[int]) -> list[int]",
"Subset of order ids whose ship_days exceeded promised_days.", delayed_orders),
"unique_customers": ("unique_customers(order_ids: list[int]) -> list[int]",
"Unique customer ids among the given orders.", unique_customers),
"count_items": ("count_items(values: list) -> int", "Length of a list.", count_items),
"sum_values": ("sum_values(values: list[int]) -> int", "Sum a list of integers.", sum_values),
"count_true": ("count_true(values: list[bool]) -> int", "Count true values.", count_true),
"count_below": ("count_below(values: list[int], threshold: int) -> int",
"Count values below a threshold.", count_below),
}
__all__ = [name for name in TOOLS.keys()] + ['TOOLS']
|