Hi,
I checked the script and wanted to bring in your attension something.
I found that in "get reporting statistics" you are pulling the info for ready agents, however the variable says logged in agents.
If all the agents are talking or in not ready state the call will go to false which has a different call treatment.
I would suggest to change the field in get reporting statistics to "Logged-In Resources" from Ready Resources.
Screenshot attached:

Let me know if that fixes your issue !!
Please rate helpful replies.