jwu323 commited on
Commit
d1ac3f2
·
verified ·
1 Parent(s): bd5cad6

Remove stale FlowBench v3 tool alias

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