I would not suggest you attempt to implement it yourself. We do something more sophisticated than a simple algorithm.
You can "(a)
dd the Play Estimated Wait Time action to an in-queue flow's task sequence to make educated estimates on wait time based on historical data, and play the wait time back to the caller." (https://help.mypurecloud.com/articles/play-estimated-wait-time-action/)
We also expose EWT via API.
For more information on how EWT is calculated you can see the following Developer Center article:
https://developer.genesys.cloud/api/rest/v2/routing/estimatedwaittime-v2------------------------------
Jay Langsford
VP, R&D
------------------------------