Finding a bottleneck using root cause algorithm


Hey guys,
imagine this scenario:
I have a production line with multiple stations in series.
One of these stations is the bottleneck of the line. It is in the middle of the line.
Each station has 5 possible status: working (W), idle (I), error (E), starving (S) and blocked (B):
starving means that the station is stopped because it doesn’t have material to work from the station before. In other words, when the station before is E, I or S.
blocked means that the station is stopped because it cant deliver more material to the next station. In other words, when the next station is B, E or I

The main goal is an algorithm that detects which station is the root cause of a status B or S in the bottleneck station.

Today this identification is made manually using a color table where the rows are the time, the columns are the station and each cell value is the status (W,E I, S or B) of each station in that time. Each status has a color and I can see visually the starving/blocked propagation wave until reaches the bottleneck station.

I have tried looking for the first E or I station backwards but somehow is not working.

Does anyone have an ideia?