import random def fault_1(inputs): """A tiled map refresh renumbered nodes independently on either side of a tile boundary, breaking walking connections across the seam.""" ways = inputs["ways"] centres = [ sum(point[0] for point in way["coords"]) / len(way["coords"]) for way in ways if way["coords"] ] if not centres: return inputs boundary = sorted(centres)[len(centres) // 2] next_id = max( (node for way in ways for node in way["nodes"]), default=0 ) + 1 replacements = {} for way in ways: if not way["coords"]: continue centre = sum(point[0] for point in way["coords"]) / len(way["coords"]) if centre >= boundary: updated = [] for node in way["nodes"]: if node not in replacements: replacements[node] = next_id next_id += 1 updated.append(replacements[node]) way["nodes"] = updated return inputs def fault_2(inputs): """An access-tag migration mistakenly marked a subset of public walking paths as forbidden to pedestrians.""" rng = random.Random(2202) candidates = [ way for way in inputs["ways"] if way["tags"].get("highway") in {"footway", "path", "pedestrian", "steps"} and way["tags"].get("foot") not in {"no", "private"} and way["tags"].get("access") not in {"no", "private"} ] count = min(len(candidates), max(1, round(len(candidates) * 0.08))) for way in rng.sample(candidates, count): way["tags"] = dict(way["tags"], foot="no") return inputs def fault_3(inputs): """A stop-coordinate export applied an erroneous longitude offset, moving every stop roughly one city block east.""" inputs["stops"] = [ dict(stop, lon=stop["lon"] + 0.0012) for stop in inputs["stops"] ] return inputs def fault_4(inputs): """A stop-table cleanup deduplicated by display name, discarding distinct boarding locations on opposite sides of streets.""" seen = set() retained = [] for stop in inputs["stops"]: key = " ".join(stop["stop_name"].casefold().split()) if key not in seen: seen.add(key) retained.append(stop) inputs["stops"] = retained return inputs def fault_5(inputs): """A census spreadsheet sort shifted the population column by one row while leaving dissemination-area identifiers in place.""" areas = inputs["areas"] if len(areas) < 2: return inputs order = sorted(range(len(areas)), key=lambda index: areas[index]["da_uid"]) populations = [areas[index]["population"] for index in order] inputs["areas"] = [dict(area) for area in areas] for position, index in enumerate(order): inputs["areas"][index]["population"] = populations[position - 1] return inputs def fault_6(inputs): """The autumn refresh reused an expired summer feed and its stop subset, omitting boarding locations introduced for autumn service.""" rng = random.Random(6606) stops = inputs["stops"] count = min(len(stops), max(1, round(len(stops) * 0.06))) omitted = set(rng.sample(range(len(stops)), count)) inputs["stops"] = [ stop for index, stop in enumerate(stops) if index not in omitted ] inputs["service"] = dict( inputs["service"], feed_start="20260701", feed_end="20260930", ) return inputs def fault_7(inputs): """A distance-conversion refactor applied the feet-to-metres factor to edge lengths that were already in metres.""" inputs["length_scale"] *= 0.3048 return inputs def fault_8(inputs): """A census export introduced invisible nonbreaking spaces into some area identifiers, causing exact spatial population joins to miss those records.""" rng = random.Random(8808) areas = inputs["areas"] count = min(len(areas), max(1, round(len(areas) * 0.07))) affected = set(rng.sample(range(len(areas)), count)) inputs["areas"] = [ dict(area, da_uid=area["da_uid"] + "\u00a0") if index in affected else dict(area) for index, area in enumerate(areas) ] return inputs