forked from rashikacodes/MAARG
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfix_next_array2.py
More file actions
32 lines (24 loc) · 1.22 KB
/
Copy pathfix_next_array2.py
File metadata and controls
32 lines (24 loc) · 1.22 KB
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
with open("app/app/api/routes/route.ts", "r", encoding="utf-8") as f:
code = f.read()
old_logic = """ const indexed = rawRoutes.map((r, i) => ({
r,
scored: scored[i] ?? { route_id: `route_${i + 1}`, disruption_risk: 50, risk_band: "MODERATE" },
i,
}));
indexed.sort((a, b) => a.scored.disruption_risk - b.scored.disruption_risk);
const routes = indexed.map(({ r, scored: s }, rankIdx) => {"""
new_logic = """ // Iterate over scored since ML might have added detour routes!
const indexed = scored.map((s, i) => {
// Find the original rawRoute that this route is based on
const originalRouteIdMatch = s.route_id.match(/route_(\\d+)/);
const originalIndex = originalRouteIdMatch ? parseInt(originalRouteIdMatch[1]) - 1 : 0;
const r = rawRoutes[originalIndex] || rawRoutes[0];
return { r, scored: s, i };
});
indexed.sort((a, b) => a.scored.disruption_risk - b.scored.disruption_risk);
const routes = indexed.map(({ r, scored: s }, rankIdx) => {"""
# Replace exact string
code = code.replace(old_logic, new_logic)
with open("app/app/api/routes/route.ts", "w", encoding="utf-8") as f:
f.write(code)
print("Updated Next.js to map over scored routes.")