예제 #1
0
def captainsPop() -> Tuple[BallChaser, BallChaser]:
    if (not queueAlreadyPopped()):

        sorted_MMRList = sorted(currQueue.all(),
                                key=lambda x: (x[BallChaserKey.MMR]),
                                reverse=True)
        top2 = sorted_MMRList[0:2]
        random.shuffle(top2)

        orangeCapDoc = top2[0]
        orangeCap = BallChaser.fromDocument(orangeCapDoc)
        currQueue.update(
            {
                BallChaserKey.IS_CAP: True,
                BallChaserKey.TEAM: Team.ORANGE
            },
            doc_ids=[orangeCapDoc.doc_id])
        blueCapDoc = top2[1]
        blueCap = BallChaser.fromDocument(blueCapDoc)
        currQueue.update(
            {
                BallChaserKey.IS_CAP: True,
                BallChaserKey.TEAM: Team.BLUE
            },
            doc_ids=[blueCapDoc.doc_id])
    else:
        orangeCap = BallChaser.fromDocument(
            currQueue.get((where(BallChaserKey.TEAM) == Team.ORANGE)
                          & (where(BallChaserKey.IS_CAP) == True)))
        blueCap = BallChaser.fromDocument(
            currQueue.get((where(BallChaserKey.TEAM) == Team.BLUE)
                          & (where(BallChaserKey.IS_CAP) == True)))
    return blueCap, orangeCap
예제 #2
0
def addToQueue(player: Member, mins_to_queue_for: int = 60) -> None:
    new_player = BallChaser(id=player.id,
                            name=str(player),
                            mmr=Leaderboard.getPlayerMMR(player),
                            queueTime=(datetime.now() +
                                       timedelta(minutes=mins_to_queue_for)))
    currQueue.insert(Document(new_player.toJSON(), doc_id=new_player.id))
예제 #3
0
def getCaptains() -> Union[Tuple[BallChaser, BallChaser], Tuple[None, None]]:
    if (queueAlreadyPopped()):
        orangeCap = BallChaser.fromDocument(
            currQueue.get((where(BallChaserKey.TEAM) == Team.ORANGE)
                          & (where(BallChaserKey.IS_CAP) == True)))
        blueCap = BallChaser.fromDocument(
            currQueue.get((where(BallChaserKey.TEAM) == Team.BLUE)
                          & (where(BallChaserKey.IS_CAP) == True)))
        return blueCap, orangeCap
    else:
        return None, None
예제 #4
0
def getQueueList(mentionPlayers: bool = False,
                 includeTimes: bool = True,
                 separator: str = "\n",
                 includeLetters=False) -> str:  # noqa
    playerList = []
    letters = [
        "1️⃣",
        "2️⃣",
        "3️⃣",
        "4️⃣",
    ]
    i = 0

    for player in currQueue.search(where(BallChaserKey.TEAM) == None):
        player = BallChaser.fromDocument(player)
        if (mentionPlayers):
            playerList.append(player.mention)
        else:
            player_name = player.name.split("#")[0]
            if (includeTimes):
                minutes_diff = getQueueTimeRemaining(player)
                player_name += " (" + str(minutes_diff) + " mins)"
            if (includeLetters):
                player_name = letters[i] + " (" + str(
                    Leaderboard.getPlayerMMR(player)) + ") " + player_name
            playerList.append(player_name)
        i += 1

    return separator.join(playerList)
예제 #5
0
def checkQueueTimes() -> Tuple[List[BallChaser], List[BallChaser]]:
    warn_players = []
    remove_players = []

    for player in currQueue.all():
        player = BallChaser.fromDocument(player)
        minutes_diff = getQueueTimeRemaining(player)
        if (minutes_diff == 5):  # 5 minute warning
            warn_players.append(player)
        elif (minutes_diff >
              60):  # There is no negative time, it just overflows to like 1430
            removeFromQueue(player)
            remove_players.append(player)

    return warn_players, remove_players
예제 #6
0
def randomPop() -> Tuple[List[BallChaser], List[BallChaser]]:
    players = [BallChaser.fromDocument(p) for p in currQueue.all()]
    orangeTeam = random.sample(players, 3)

    for player in orangeTeam:
        player.team = Team.ORANGE
        players.remove(player)

    blueTeam = players[:]
    currQueue.truncate()

    for player in blueTeam:
        player.team = Team.BLUE

    return blueTeam, orangeTeam
예제 #7
0
def reportConfirm(player: BallChaser, match: Document, whoWon: Team) -> bool:
    # If first responder or a winning team disagreement, we update the report
    if (
        match[MatchKey.REPORTED_WINNER][MatchKey.WINNING_TEAM] is None or
        match[MatchKey.REPORTED_WINNER][MatchKey.WINNING_TEAM] != whoWon
    ):

        activeMatches.update({
            MatchKey.REPORTED_WINNER: {
                MatchKey.WINNING_TEAM: whoWon,
                MatchKey.REPORTER: player.toJSON(short=True)
            }
        }, doc_ids=[match.doc_id])

        return False

    # Make sure second reported is on the other team
    if (player.team == match[MatchKey.REPORTED_WINNER][MatchKey.REPORTER][MatchKey.TEAM]):
        return False

    return True
예제 #8
0
def reportMatch(player: Union[Member, str], whoWon: Team, adminOverride: bool = False) -> bool:
    global sorted_lb
    match = getActiveMatch(player)

    if (not match):
        return False

    if (isinstance(player, Member)):
        foundPlayer = match[str(player.id)]
    elif (isinstance(player, str)):
        foundPlayer = match[player]

    player = BallChaser(
        name=foundPlayer[MatchKey.NAME],
        id=foundPlayer[MatchKey.ID],
        mmr=foundPlayer[MatchKey.MMR],
        team=foundPlayer[MatchKey.TEAM]
    )
    report_confirm_success = reportConfirm(player, match, whoWon)

    # report confirmed
    matchMMR = Points.calculateMMR(match)

    if (report_confirm_success or adminOverride == True):
        for key in match:
            if (key != MatchKey.REPORTED_WINNER):
                teamMember = match[key]
                if (
                    (whoWon == Team.BLUE and teamMember["team"] == Team.BLUE) or
                    (whoWon == Team.ORANGE and teamMember["team"] == Team.ORANGE)
                ):
                    win = 1
                    loss = 0
                    mmr = matchMMR
                else:
                    win = 0
                    loss = 1
                    mmr = -matchMMR

                player = leaderboard.get(doc_id=teamMember[MatchKey.ID])
                if (not player):
                    leaderboard.insert(Document({
                        LbKey.ID: teamMember[MatchKey.ID],
                        LbKey.NAME: teamMember[MatchKey.NAME],
                        LbKey.MMR: 100 + mmr,
                        LbKey.WINS: win,
                        LbKey.LOSSES: loss,
                        LbKey.MATCHES: 1,
                        LbKey.WIN_PERC: float(win),
                    }, doc_id=teamMember[MatchKey.ID]))
                else:
                    updated_player = {
                        LbKey.NAME: teamMember[MatchKey.NAME],
                        LbKey.MMR: max(player[LbKey.MMR] + mmr, 0),
                        LbKey.WINS: player[LbKey.WINS] + win,
                        LbKey.LOSSES: player[LbKey.LOSSES] + loss,
                        LbKey.MATCHES: player[LbKey.MATCHES] + 1,
                        LbKey.WIN_PERC: player[LbKey.WIN_PERC],
                    }

                    total_wins = int(updated_player[LbKey.WINS])
                    total_matches = int(updated_player[LbKey.MATCHES])
                    updated_player[LbKey.WIN_PERC] = float("{:.2f}".format(total_wins / total_matches))

                    leaderboard.update(updated_player, doc_ids=[player.doc_id])

    elif (not report_confirm_success):
        return report_confirm_success

    activeMatches.remove(doc_ids=[match.doc_id])
    sorted_lb = sorted(leaderboard.all(), key=lambda x: (x[LbKey.MMR], x[LbKey.WINS], x[LbKey.WIN_PERC]), reverse=True)

    with concurrent.futures.ThreadPoolExecutor() as executor:
        executor.submit(AWS.writeRemoteLeaderboard, dumps(sorted_lb))

    return True
예제 #9
0
def getTeamList() -> Tuple[List[BallChaser], List[BallChaser]]:
    orangeTeam = currQueue.search(where(BallChaserKey.TEAM) == Team.ORANGE)
    blueTeam = currQueue.search(where(BallChaserKey.TEAM) == Team.BLUE)
    return [BallChaser.fromDocument(p) for p in blueTeam
            ], [BallChaser.fromDocument(p) for p in orangeTeam]
예제 #10
0
def getAvailablePicks() -> List[BallChaser]:
    availablePicks = []
    for player in currQueue.search(where(BallChaserKey.TEAM) == None):
        availablePicks.append(BallChaser.fromDocument(player))
    return availablePicks