UrbanFlow / backend /pcu.py
Subh775's picture
privacy modals; minor improvement
f69350e
"""
Passenger Car Unit (PCU) conversion using IRC:106-1990 guidelines.
PCU normalizes heterogeneous Indian traffic into a single unit of measurement
used by transport authorities for capacity analysis and road design.
"""
MODEL_CLASSES = {
0: "Hatchback", 1: "Sedan", 2: "SUV", 3: "MUV", 4: "Bus", 5: "Truck",
6: "Three-wheeler", 7: "Two-wheeler", 8: "LCV", 9: "Mini-bus",
10: "Tempo-traveller", 11: "Bicycle", 12: "Van", 13: "Others"
}
# IRC:106-1990 PCU equivalency factors
_PCU_TABLE = {
0: 1.0, # Hatchback
1: 1.0, # Sedan
2: 1.0, # SUV
3: 1.0, # MUV
4: 3.0, # Bus
5: 3.0, # Truck
6: 1.2, # Three-wheeler (Auto-rickshaw)
7: 0.5, # Two-wheeler
8: 3.0, # LCV
9: 3.0, # Mini-bus
10: 3.0, # Tempo-traveller
11: 0.5, # Bicycle
12: 1.0, # Van
13: 1.0, # Others
}
def get_pcu_factor(class_id):
return _PCU_TABLE.get(class_id, 1.0)
def compute_pcu(class_in, class_out):
"""Convert raw vehicle counts to PCU values.
Args:
class_in: dict {class_id_str: count}
class_out: dict {class_id_str: count}
Returns:
dict with total_pcu, pcu_in, pcu_out, per_class breakdown
"""
pcu_in = 0.0
pcu_out = 0.0
per_class = {}
all_ids = set(list(class_in.keys()) + list(class_out.keys()))
for cid_str in all_ids:
cid = int(cid_str)
factor = get_pcu_factor(cid)
in_count = class_in.get(cid_str, 0)
out_count = class_out.get(cid_str, 0)
cls_pcu_in = round(in_count * factor, 1)
cls_pcu_out = round(out_count * factor, 1)
pcu_in += cls_pcu_in
pcu_out += cls_pcu_out
per_class[MODEL_CLASSES.get(cid, f"cls_{cid}")] = {
"count": in_count + out_count,
"factor": factor,
"pcu": round(cls_pcu_in + cls_pcu_out, 1),
}
return {
"total_pcu": round(pcu_in + pcu_out, 1),
"pcu_in": round(pcu_in, 1),
"pcu_out": round(pcu_out, 1),
"per_class": per_class,
}