|
|
@ -1,6 +1,7 @@ |
|
|
|
from flask import Flask, redirect, flash, render_template, session, g, request, get_flashed_messages |
|
|
|
import werkzeug.exceptions |
|
|
|
import json |
|
|
|
from datetime import datetime |
|
|
|
|
|
|
|
import hra.config as config |
|
|
|
import hra.db as db |
|
|
@ -37,21 +38,27 @@ def api_state(): |
|
|
|
game = team.game |
|
|
|
team_id = team.team_id |
|
|
|
min_round = args_get("min_round", int, True) |
|
|
|
if min_round is not None and min_round > game.current_round: |
|
|
|
return json.dumps({ |
|
|
|
"status": "too_early", |
|
|
|
"wait": 5.0, |
|
|
|
}) |
|
|
|
t = datetime.now() |
|
|
|
state = game.current_state() |
|
|
|
if state is None: |
|
|
|
return json.dumps({ |
|
|
|
"status": "working", |
|
|
|
"wait": 1.0, |
|
|
|
}) |
|
|
|
if game.step_mode == db.StepMode.automatic: |
|
|
|
time_to_end = max(1, game.step_every_s - (t - state.create_time).total_seconds()) |
|
|
|
else: |
|
|
|
time_to_end = None |
|
|
|
if min_round is not None and min_round > game.current_round: |
|
|
|
return json.dumps({ |
|
|
|
"status": "too_early", |
|
|
|
"wait": time_to_end + 1.0 if time_to_end is not None else 3.0, |
|
|
|
}) |
|
|
|
return json.dumps({ |
|
|
|
"status": "ok", |
|
|
|
"round": state.round, |
|
|
|
"team_id": team_id, |
|
|
|
"time_to_response": time_to_end, |
|
|
|
"state": game.get_logic().personalize_state(state.get_state(), team_id, state.round), |
|
|
|
}) |
|
|
|
|
|
|
|