コード例 #1
0
ファイル: scoreboards.py プロジェクト: MarechJ/hll_rcon_tool
def get_scoreboard_maps(request):
    data = _get_data(request)

    page_size = min(int(data.get("limit", 100)), 1000)
    page = max(1, int(data.get("page", 1)))
    server_number = data.get("server_number", os.getenv("SERVER_NUMBER"))

    with enter_session() as sess:
        query = (sess.query(Maps).filter(
            Maps.server_number == server_number).order_by(Maps.start.desc()))
        total = query.count()
        res = query.limit(page_size).offset((page - 1) * page_size).all()

        return api_response(
            result={
                "page":
                page,
                "page_size":
                page_size,
                "total":
                total,
                "maps": [
                    dict(
                        just_name=map_name(r.map_name),
                        long_name=LONG_HUMAN_MAP_NAMES.get(
                            r.map_name, r.map_name),
                        **r.to_dict(),
                    ) for r in res
                ],
            },
            failed=False,
            command="get_scoreboard_maps",
        )
コード例 #2
0
ファイル: views.py プロジェクト: MarechJ/hll_rcon_tool
def public_info(request):
    status = ctl.get_status()
    try:
        current_map = MapsHistory()[0]
    except IndexError:
        logger.error(
            "Can't get current map time, map_recorder is probably offline")
        current_map = {"name": status["map"], "start": None, "end": None}
    current_map = dict(
        just_name=map_name(current_map["name"]),
        human_name=LONG_HUMAN_MAP_NAMES.get(current_map["name"],
                                            current_map["name"]),
        **current_map,
    )
    vote_status = get_votes_status(none_on_fail=True)
    next_map = ctl.get_next_map()
    return api_response(
        result=dict(
            current_map=current_map,
            **status,
            vote_status=vote_status,
            next_map=next_map,
        ),
        failed=False,
        command="public_info",
    )
コード例 #3
0
def suggest_next_maps(
    maps_history,
    all_maps,
    selection_size=6,
    exclude_last_n=4,
    offsensive_ratio=0.5,
    consider_offensive_as_same_map=True,
    allow_consecutive_offensive=True,
    allow_consecutive_offensives_of_opposite_side=False,
    current_map=None,
):
    last_n_map = set(m["name"] for m in maps_history[:exclude_last_n])
    logger.info("Excluding last %s player maps: %s", exclude_last_n,
                last_n_map)
    remaining_maps = set(all_maps) - last_n_map
    logger.info("Remaining maps to suggest from: %s", remaining_maps)

    try:
        current_map = current_map or maps_history[0]["name"]
    except (IndexError, KeyError):
        logger.exception("Unable to get current map for generating selection")
        raise

    current_side = get_map_side(current_map)

    if consider_offensive_as_same_map:
        last_names = set(map_name(m) for m in last_n_map)
        logger.info("Considering offensive mode as same map, excluding %s",
                    last_names)
        remaining_maps = set(m for m in remaining_maps
                             if not map_name(m) in last_names)
        logger.info("Remaining maps to suggest from: %s", remaining_maps)

    if not allow_consecutive_offensives_of_opposite_side and current_side:
        opposite_side = "us" if current_side == "ger" else "ger"
        logger.info(
            "Not allowing consecutive offensive with opposite side: %s",
            opposite_side)
        remaining_maps = [
            m for m in remaining_maps if get_map_side(m) != opposite_side
        ]
        logger.info("Remaining maps to suggest from: %s", remaining_maps)

    # Handle case if all maps got excluded
    categorized_maps = categorize_maps(remaining_maps)
    if offsensive_ratio == 0:
        nb_offensive = 0
    else:
        nb_offensive = round(offsensive_ratio * selection_size)
    warfares = []

    offensives = _get_random_map_selection(categorized_maps["offensive"],
                                           nb_offensive)

    if not allow_consecutive_offensive and "offensive" in current_map:
        logger.info(
            "Current map %s is offensive. Excluding all offsensives from suggestions",
            current_map,
        )
        offensives = []

    warfares = _get_random_map_selection(categorized_maps["warfare"],
                                         selection_size - len(offensives))
    selection = offensives + warfares

    if not selection:
        logger.error("No maps can be suggested with the given parameters.")
        raise ValueError("Unable to suggest map")
    logger.info("Suggestion %s", selection)
    return selection