mirror of
https://github.com/FAUSheppy/open-web-leaderboard.git
synced 2025-12-05 22:51:36 +01:00
implement map overview
This commit is contained in:
45
MapSummary.py
Normal file
45
MapSummary.py
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
import json
|
||||||
|
import datetime
|
||||||
|
import player
|
||||||
|
import datetime
|
||||||
|
|
||||||
|
class MapSummary:
|
||||||
|
def __init__(self, rounds):
|
||||||
|
'''Create a map MapSummary from a Round-Array'''
|
||||||
|
|
||||||
|
self.securityWins = 0
|
||||||
|
self.insurgentWins = 0
|
||||||
|
self.times = []
|
||||||
|
self.predictions = []
|
||||||
|
self.totalGames = 0
|
||||||
|
self.confidence = []
|
||||||
|
self.mapName = None
|
||||||
|
|
||||||
|
for r in rounds:
|
||||||
|
self.mapName = r.mapName
|
||||||
|
self.totalGames += 1
|
||||||
|
if r.winnerSideString == "Insurgent":
|
||||||
|
self.insurgentWins += 1
|
||||||
|
else:
|
||||||
|
self.securityWins += 1
|
||||||
|
|
||||||
|
self.predictions += [r.numericPrediction]
|
||||||
|
self.confidence += [r.confidence]
|
||||||
|
self.times += [r.duration]
|
||||||
|
|
||||||
|
self.insurgentWinPercent = ""
|
||||||
|
self.securityWinPercent = ""
|
||||||
|
self.ratingSystemDeviation = "-"
|
||||||
|
self.averageTime = ""
|
||||||
|
|
||||||
|
try:
|
||||||
|
self.insurgentWinPercent = self.insurgentWins / self.totalGames*100
|
||||||
|
self.securityWinPercent = self.securityWins / self.totalGames*100
|
||||||
|
predictionPercision = 1 - sum(self.predictions)/len(self.predictions)
|
||||||
|
confidenceAverage = sum(self.confidence) / len(self.confidence)
|
||||||
|
averageSeconds = sum([t.total_seconds() for t in self.times]) / len(self.times)
|
||||||
|
self.averageTime = datetime.timedelta(seconds=int(averageSeconds))
|
||||||
|
self.ratingSystemDeviation = predictionPercision*100 - confidenceAverage
|
||||||
|
except ZeroDivisionError:
|
||||||
|
pass
|
||||||
|
|
||||||
1
Round.py
1
Round.py
@@ -29,6 +29,7 @@ class Round:
|
|||||||
self.mapName = "unavailiable"
|
self.mapName = "unavailiable"
|
||||||
|
|
||||||
self.confidence = int(confidence * 100)
|
self.confidence = int(confidence * 100)
|
||||||
|
self.numericPrediction = prediction
|
||||||
if prediction == 0:
|
if prediction == 0:
|
||||||
self.prediction = self.winnerSideString
|
self.prediction = self.winnerSideString
|
||||||
elif prediction == 1:
|
elif prediction == 1:
|
||||||
|
|||||||
@@ -168,4 +168,8 @@ class DatabaseConnection:
|
|||||||
return None
|
return None
|
||||||
return Round.Round(row)
|
return Round.Round(row)
|
||||||
|
|
||||||
|
def distinctMaps(self):
|
||||||
|
'''Get all distinct maps from rounds database'''
|
||||||
|
cursorRounds = self.connRounds.cursor()
|
||||||
|
return cursorRounds.execute('''SELECT DISTINCT map from rounds''')
|
||||||
|
|
||||||
|
|||||||
BIN
rounds.sqlite
Normal file
BIN
rounds.sqlite
Normal file
Binary file not shown.
18
server.py
18
server.py
@@ -6,6 +6,7 @@ import datetime
|
|||||||
import flask_caching as fcache
|
import flask_caching as fcache
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
|
import MapSummary
|
||||||
|
|
||||||
from database import DatabaseConnection
|
from database import DatabaseConnection
|
||||||
|
|
||||||
@@ -44,6 +45,23 @@ def singleRound():
|
|||||||
|
|
||||||
return flask.render_template("single_round.html", r=r)
|
return flask.render_template("single_round.html", r=r)
|
||||||
|
|
||||||
|
@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)]
|
||||||
|
|
||||||
|
mapsFiltered = filter(lambda x: x.mapName, maps)
|
||||||
|
return flask.render_template("maps.html", maps=mapsFiltered)
|
||||||
|
|
||||||
@app.route("/rounds-by-timestamp")
|
@app.route("/rounds-by-timestamp")
|
||||||
@app.route("/rounds")
|
@app.route("/rounds")
|
||||||
def rounds():
|
def rounds():
|
||||||
|
|||||||
60
templates/maps.html
Normal file
60
templates/maps.html
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<title>Maps</title>
|
||||||
|
<meta name="Description" content="Insurgency Map Overview">
|
||||||
|
<link rel="stylesheet" type="text/css" href="/static/site.css">
|
||||||
|
<link rel="shortcut icon" href="/static/defaultFavicon.ico">
|
||||||
|
|
||||||
|
<!-- needed for @media-css mofiers -->
|
||||||
|
<meta content="width=device-width, initial-scale=1" name="viewport" />
|
||||||
|
|
||||||
|
<!-- Font Awesome -->
|
||||||
|
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.8.2/css/all.css">
|
||||||
|
<!-- Bootstrap core CSS -->
|
||||||
|
<link href="static/bootstrap/css/bootstrap.min.css" rel="stylesheet">
|
||||||
|
<!-- Material Design Bootstrap -->
|
||||||
|
<link href="static/bootstrap/css/mdb.min.css" rel="stylesheet">
|
||||||
|
|
||||||
|
<script src="static/bootstrap/js/jquery.js"></script>
|
||||||
|
<script src="static/bootstrap/js/popper.js"></script>
|
||||||
|
<script src="static/bootstrap/js/bootstrap.js"></script>
|
||||||
|
<script src="static/bootstrap/js/mdb.min.js"></script>
|
||||||
|
|
||||||
|
</head>
|
||||||
|
<body class="bg-special">
|
||||||
|
{% include 'navbar.html' %}
|
||||||
|
<div class="container mt-3 mb-3" role="main">
|
||||||
|
<table id="tableMain" class="table table-striped table-bordered table-sm"
|
||||||
|
cellspacing="0" width="100%">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th class="th-sm">Map</th>
|
||||||
|
<th class="th-sm">Insurgent Win</th>
|
||||||
|
<th class="th-sm">Security Win</th>
|
||||||
|
<th class="th-sm">Average Time</th>
|
||||||
|
<th class="th-sm">Rating System Deviation</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{% for m in maps %}
|
||||||
|
<tr>
|
||||||
|
<td>{{ m.mapName }}</td>
|
||||||
|
<td>{{ '%0.2f' | format(m.insurgentWinPercent) }}%</td>
|
||||||
|
<td>{{ '%0.2f' | format(m.securityWinPercent) }}%</td>
|
||||||
|
<td>{{ m.averageTime }}</td>
|
||||||
|
{% if m.ratingSystemDeviation >= 0 %}
|
||||||
|
<td style="color: green;">+{{ '%0.2f' | format(m.ratingSystemDeviation) }}%
|
||||||
|
</td>
|
||||||
|
{% else %}
|
||||||
|
<td style="color: red;">+{{ '%0.2f' | format(m.ratingSystemDeviation) }}%
|
||||||
|
</td>
|
||||||
|
{% endif %}
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
{% include 'footer.html' %}
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
Reference in New Issue
Block a user