Please could someone help me with the LOGIC.(Programming part)
That is trivial. Note when the transition from green off to green on happens. Note when the transition from yellow off to yellow on happens. Note when the transition from red off to red on occurs.
Note when the transition from yellow on to yellow off occurs. When that happens, also increment the total yellow time and reset/clear the yellow on time.
Do the same for the red transition to off.
Periodically, see what time it is. If the green light is on, and has been on for more than 180 seconds, reset the green on time to now, and increment the part count.