File size: 2,044 Bytes
d9ebe88
 
 
 
 
 
f69350e
 
 
 
 
 
d9ebe88
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""
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,
    }