harishl199121/bottleneck_analyzer
0
1import pandas as pd2 3class BottleneckAnalyzer:4 def __init__(self, steps_df: pd.DataFrame):5 # expects columns: name, processing_time (min), capacity_per_hour6 self.df = steps_df.copy()7 self.df["processing_time"] = self.df["processing_time"].astype(float)8 self.df["capacity_per_hour"] = self.df["capacity_per_hour"].astype(float)9 10 def find_bottleneck_row(self):11 return self.df.sort_values(by="capacity_per_hour", ascending=True).iloc[0]12 13 def find_bottleneck_name(self):14 return self.find_bottleneck_row()["name"]15 16 def throughput_per_hour(self):17 return float(self.df["capacity_per_hour"].min())18 19 def total_cycle_time_minutes(self):20 return float(self.df["processing_time"].sum())21 22 def wip_units(self):23 # Little's Law: WIP = Throughput * Cycle Time (in hours)24 ct_hours = self.total_cycle_time_minutes() / 60.025 return round(self.throughput_per_hour() * ct_hours, 2)26 27 def analyze(self):28 return {29 "Bottleneck Step": self.find_bottleneck_name(),30 "Throughput (units/hr)": self.throughput_per_hour(),31 "Total Cycle Time (min)": self.total_cycle_time_minutes(),32 "WIP (units)": self.wip_units(),33 }34 