From 12c001ac71883d81fa58403950126124e35f362c Mon Sep 17 00:00:00 2001 From: Yannik Schmidt Date: Mon, 20 Dec 2021 15:15:35 +0100 Subject: [PATCH] lol --- balance.py | 36 ++++++++++++++++++++++++++++++++++++ server.py | 22 ---------------------- 2 files changed, 36 insertions(+), 22 deletions(-) create mode 100644 balance.py diff --git a/balance.py b/balance.py new file mode 100644 index 0000000..a30673d --- /dev/null +++ b/balance.py @@ -0,0 +1,36 @@ +def swap(teams, teamIndex, pos1, pos2): + tmp = teams[teamIndex][pos1] + teams[teamIndex][pos1] = teams[teamIndex][pos2] + teams[teamIndex][pos2] = tmp + +def ratingDiff(team1, team2): + '''Positive if first > seconds, negative if second > first, 0 if equal''' + return sum([p.rating for p in team1]) - sum([p.rating for p in team2]) + +def balance(players): + + # initial teams # + playersByRating = sorted(players, key=lambda p: p.rating) + + teams = dict( { 0 : [] }, { 1 : [] } ) + for i in range(0, len(playersByRating)): + teams[i%2] = playersByRating[i] + + # optimize positions worst case ~8n^2 * 2log(n) # + for teamIndex in teamIndex.keys(): + changed = True + while changed: + changed = False + for curIndex in range(0, len(teams[teamIndex])) + for compareIndex in range(curIndex, len(teams[teamIndex])) + if curIndex == compareIndex: + continue + elif swapBasedOnPos(curIndex, teams[teamIndex]) + changed = True + swap(teams, teamIndex, curIndex, compareIndex) + + # optimize ratings simple # + changedRating = True + while changedRating: + for curIndex in range(0, len(teams[0])): + if rating diff diff --git a/server.py b/server.py index 01ce1e9..917f9e2 100755 --- a/server.py +++ b/server.py @@ -95,28 +95,6 @@ def liveGames(): rounds = db.getLiveGames() return flask.render_template("livegames.html", liveGameRounds=rounds, noRounds=not bool(rounds)) -@app.route("/maps") -def maps(): - '''Show an overview of maps''' - - db = DatabaseConnection(app.config["DB_PATH"]) - start = datetime.datetime.now() - datetime.timedelta(days=4000) - end = datetime.datetime.now() - rounds = db.roundsBetweenDates(start, end) - distinctMaps = db.distinctMaps() - maps = [] - for mapName in [ tupel[0] for tupel in distinctMaps]: - roundsWithMap = list(filter(lambda r: r.mapName == mapName , rounds)) - maps += [MapSummary.MapSummary(roundsWithMap)] - - allMaps = MapSummary.MapSummary(rounds) - allMaps.mapName = "All Maps*" - maps += [allMaps] - - - mapsFiltered = filter(lambda x: x.mapName, maps) - return flask.render_template("maps.html", maps=mapsFiltered) - @app.route("/rounds-by-timestamp") @app.route("/rounds") def rounds():