Пример #1
0
def inprogress_game(id):
	## inpgrogress type
	if not backend.request(id):
		abort(404)
	if not backend.request(id)["action"] == "start":
		logger.warning("Invalid gameid!")
		abort(404)
	game = Game_inprogress(id, backend.request(id))

	stream = url_for("api.game_inprogress_log", id=game.id)
	return render_template(game.type.viz, game=game, inprogress=True, ai0=game.ais[0], ai1=game.ais[1], stream=stream)
Пример #2
0
def game_list_sse():
    yield ("connected", "connected")
    q = backend.subscribe_game_update()
    while True:
        try:
            update = q.get(timeout=15)
            d = backend.request(update["requestid"])

            if "status" in update:
                if update["status"] == "processed":
                    render_inprogress_game = get_template_attribute("game_list.html", "render_inprogress_game")
                    r = backend.request(update["requestid"])
                    html = render_inprogress_game(
                        dict(
                            id=r["requestid"],
                            ai0=r["ai0"],
                            ai1=r["ai1"],
                            status="angefangen...",
                            inqueue=r["status"] == "processed",
                        )
                    )
                    yield (html, "new_game")
            if "update" in update:
                if not "display" in update:
                    update["display"] = "Schritt " + str(update["update"])
                yield (
                    json.dumps(
                        {
                            "id": update["requestid"],
                            "status": update["display"],
                            "points": list(update["points"].values()),
                        }
                    ),
                    "update",
                )

            if "finished_game_obj" in d:
                yield (
                    json.dumps(
                        {
                            "url": url_for("anonymous.game", id=d["finished_game_obj"].id),
                            "id": d["requestid"],
                            "scores": [assoc.score for assoc in d["finished_game_obj"].ai_assocs],
                        }
                    ),
                    "finished_game",
                )
        except Empty:
            # falls es keine Verbindung mehr gibt wird der Generator hier beendet.
            yield None
Пример #3
0
def ai_qualify_blocking(id):
    ai = AI.query.get(id)
    if not ai:
        return (CommonErrors.INVALID_ID[0]["error"], "error")
    if not current_user.can_access(ai):
        return (CommonErrors.NO_ACCESS[0]["error"], "error")

    if not ai.latest_version().compiled:
        return {"error": "AI_Version isnt compiled."}, 400
    if ai.latest_version().frozen:
        return {"error": "AI_Version is frozen."}, 400

    reqid = backend.request_qualify(ai)
    for data, event in backend.inprogress_log(reqid):
        if event == "success":
            d = backend.request(reqid)
            if "position" in d:
                if d["position"][str(ai.id) + "v" + str(ai.latest_version(
                ).version_id)] > d["position"][str(-ai.type.id) + "v1"]:
                    yield "", "qualified"
                    ai.latest_version().compiled = True
                    ai.latest_version().qualified = True
                else:
                    logger.info("AI " + str(ai.id) + " '" + str(ai.name) +
                                "' failed its qualification")
                    yield "", "failed"
                    ai.latest_version().qualified = False
            else:
                logger.warning("no position in finished ai_qualify_blocking")
            db.session.commit()
        elif event == "crash":
            return False
Пример #4
0
def inprogress_game(id):
    ## inpgrogress type
    if not backend.request(id):
        abort(404)
    if not backend.request(id)["action"] == "start":
        logger.warning("Invalid gameid!")
        abort(404)
    game = Game_inprogress(id, backend.request(id))

    stream = url_for("api.game_inprogress_log", id=game.id)
    return render_template(game.type.viz,
                           game=game,
                           inprogress=True,
                           ai0=game.ais[0],
                           ai1=game.ais[1],
                           stream=stream)
Пример #5
0
def ai_qualify_blocking(id):
	ai = AI.query.get(id)
	if not ai:
		return (CommonErrors.INVALID_ID[0]["error"], "error")
	if not current_user.can_access(ai):
		return (CommonErrors.NO_ACCESS[0]["error"], "error")


	if not ai.latest_version().compiled:
		return ("AI_Version isnt compiled.", "error")
	if ai.latest_version().frozen:
		return ("AI_Version is frozen.", "error")

	reqid = backend.request_qualify(ai)
	for data, event in backend.inprogress_log(reqid):
		if event == "success":
			d = backend.request(reqid)
			if "position" in d:
				if d["position"][str(ai.id) + "v" + str(ai.latest_version().version_id)] > d["position"][str(-ai.type.id) + "v1"]:
					yield "", "qualified"
					ai.latest_version().compiled = True
					ai.latest_version().qualified = True
				else:
					logger.info("AI " + str(ai.id) + " '" + str(ai.name) + "' failed its qualification")
					yield "", "failed"
					ai.latest_version().qualified = False
			else:
				logger.warning("no position in finished ai_qualify_blocking")
			db.session.commit()
		elif event == "crash":
			return ("ai crashed", "error")
Пример #6
0
def game_list_sse():
    yield ("connected", "connected")
    q = backend.subscribe_game_update()
    while True:
        try:
            update = q.get(timeout=15)
            d = backend.request(update["requestid"])

            if "status" in update:
                if update["status"] == "processed":
                    render_inprogress_game = get_template_attribute(
                        "game_list.html", "render_inprogress_game")
                    r = backend.request(update["requestid"])
                    html = render_inprogress_game(
                        dict(id=r["requestid"],
                             ai0=r["ai0"],
                             ai1=r["ai1"],
                             status="angefangen...",
                             inqueue=r["status"] == "processed"))
                    yield (html, "new_game")
            if "update" in update:
                if not "display" in update:
                    update["display"] = "Schritt " + str(update["update"])
                yield (json.dumps({
                    "id": update["requestid"],
                    "status": update["display"],
                    "points": list(update["points"].values())
                }), "update")

            if "finished_game_obj" in d:
                yield (json.dumps({
                    "url":
                    url_for("anonymous.game", id=d["finished_game_obj"].id),
                    "id":
                    d["requestid"],
                    "scores": [
                        assoc.score
                        for assoc in d["finished_game_obj"].ai_assocs
                    ]
                }), "finished_game")
        except Empty:
            # falls es keine Verbindung mehr gibt wird der Generator hier beendet.
            yield None