How to calculate a player's remaining time via the API?


After a disgraceful number of timeouts, and no mobile app on the horizon, I sat down this afternoon to code a simple python notifier that would tell me the number of active games I had on OGS. (I’d offer it to the world, but it’s implemented as a status plugin to py3bar under the i3 window manager, and I don’t think that it’s sufficiently useful to other people to justify supporting it.)

It took me about an hour of digging, altogether, to get something functional. I currently have a nice ‘OGS: 4’ line in my status bar that will pop up Chromium when I click on it. (I still have to log in manually every time, but that’s another issue…)

What I’d like now is for my notifier to turn a frightening shade of red if any game drops below a given minimum time left to play, as I still don’t receive email warnings of this. From looking at the API, though, I’m confused as to how to calculate the time remaining for the current active player in a given game.

The relevant fields in the ‘games’ section of the API seem to be: “last_move”, “expiration”, and “thinking_time” (which can be negative). I could probably work it out, but I found another thread here that implied it was confusing.

As a simple question, then, how do I calculate the time remaining for the current play to make a move using the available fields in the API? (This is aimed at correspondence games, so no need to worry about the specifics of live games.)

(All I’m really looking for is something like: “It’s (expiration - now).”)


Hi tealeaf,

You’re in luck, that’s actually something we’ve actually gotten around to documenting for our up n’ coming 4.2 release

Excellent! Thank you!

Wow. On looking over the description, that’s quite a significant chunk of calculation to do. (I think the time calculation code will be longer than the rest of my module!)

I don’t know what your constraints are, but could that pseudocode not be wrapped up to produce a simple time_remaining field itself? I can understand the need to prevent frequent polling for live games, but that’s a pretty extreme solution!

EDIT: Much as I complain, I’ve now got this implemented and it seems to be working fine. Thanks for the link!