示例#1
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
示例#2
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")
示例#3
0
def game_inprogress_log(id):
	gen = backend.inprogress_log(id)
	try:
		d, s = next(gen)
		yield json.dumps(d), s
	except StopIteration:
		return ("Invalid ID", "error")

	for data, data_type in gen:
		if data_type == "state":
			Game.filter_output(data)
			yield json.dumps(data), data_type
		elif data_type == "finished_game_obj":
			yield url_for("anonymous.game", id=data.id), "game_finished"
		elif data_type == "crash":
			can_access, data = Game.filter_crash(data)
			if can_access:
				yield json.dumps(data), "crash"
		elif data_type == "success":
			pass
		else:
			logger.error("invalid log_sse type: " + str(data_type) + " " + str(data))
示例#4
0
def game_inprogress_log(id):
    gen = backend.inprogress_log(id)
    try:
        d, s = next(gen)
        yield json.dumps(d), s
    except StopIteration:
        return CommonErrors.INVALID_ID

    for data, data_type in gen:
        if data_type == "state":
            Game.filter_output(data)
            yield json.dumps(data), data_type
        elif data_type == "finished_game_obj":
            yield url_for("anonymous.game", id=data.id), "game_finished"
        elif data_type == "crash":
            can_access, data = Game.filter_crash(data)
            if can_access:
                yield json.dumps(data), "crash"
        elif data_type == "success":
            pass
        else:
            logger.error("invalid log_sse type: " + str(data_type) + " " +
                         str(data))