mirror of
https://github.com/FAUSheppy/open-web-leaderboard.git
synced 2025-12-06 07:01:36 +01:00
implement simple rounds display
This commit is contained in:
22
Round.py
Normal file
22
Round.py
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
import json
|
||||||
|
import datetime
|
||||||
|
|
||||||
|
class Round:
|
||||||
|
def __init__(self, dbRow):
|
||||||
|
'''Create Round Object from cursor database row'''
|
||||||
|
|
||||||
|
timestamp, winners, losers, winnerSide, mapName, duration, prediction, confidence = dbRow
|
||||||
|
startTime = datetime.datetime.fromtimestamp(int(float(timestamp)))
|
||||||
|
winnersParsed = json.loads(winners)
|
||||||
|
losersParsed = json.loads(losers)
|
||||||
|
|
||||||
|
self.startTime = startTime
|
||||||
|
self.winners = winners
|
||||||
|
self.losers = losers
|
||||||
|
self.winnerSide = winnerSide
|
||||||
|
if winnerSide == 2:
|
||||||
|
self.winnerSideString = "Insurgent"
|
||||||
|
else:
|
||||||
|
self.winnerSideString = "Security"
|
||||||
|
self.mapName = mapName
|
||||||
|
self.duration = datetime.timedelta(seconds=int(duration))
|
||||||
16
database.py
16
database.py
@@ -3,6 +3,7 @@ import json
|
|||||||
import sqlite3
|
import sqlite3
|
||||||
import player
|
import player
|
||||||
import os
|
import os
|
||||||
|
import Round
|
||||||
|
|
||||||
DATABASE_PLAYERS = "players.sqlite"
|
DATABASE_PLAYERS = "players.sqlite"
|
||||||
DATABASE_ROUNDS = "rounds.sqlite"
|
DATABASE_ROUNDS = "rounds.sqlite"
|
||||||
@@ -120,3 +121,18 @@ class DatabaseConnection:
|
|||||||
(player.mu, player.sigma))
|
(player.mu, player.sigma))
|
||||||
rank = cursor.fetchone()[0]
|
rank = cursor.fetchone()[0]
|
||||||
return rank
|
return rank
|
||||||
|
|
||||||
|
def roundsBetweenDates(self, start, end):
|
||||||
|
'''Get rounds played between two times'''
|
||||||
|
|
||||||
|
cursor = self.connRounds.cursor()
|
||||||
|
cursor.execute('''SELECT * FROM rounds WHERE timestamp between ? and ?''',
|
||||||
|
(start.timestamp(), end.timestamp()))
|
||||||
|
|
||||||
|
print('''SELECT * FROM rounds WHERE timestamp between {} and {}'''.format(
|
||||||
|
start.timestamp(), end.timestamp()))
|
||||||
|
|
||||||
|
rounds = []
|
||||||
|
for row in cursor:
|
||||||
|
rounds += [Round.Round(row)]
|
||||||
|
return rounds
|
||||||
|
|||||||
26
server.py
26
server.py
@@ -28,6 +28,32 @@ def prettifyMinMaxY(computedMin, computedMax):
|
|||||||
else:
|
else:
|
||||||
return (computedMin - 100, 4000)
|
return (computedMin - 100, 4000)
|
||||||
|
|
||||||
|
@app.route("/rounds-by-timestamp")
|
||||||
|
def rounds():
|
||||||
|
'''Show rounds played on the server'''
|
||||||
|
|
||||||
|
start = flask.request.args.get("start")
|
||||||
|
end = flask.request.args.get("end")
|
||||||
|
|
||||||
|
if not start or not end:
|
||||||
|
start = datetime.datetime.now() - datetime.timedelta(days=4000)
|
||||||
|
end = datetime.datetime.now()
|
||||||
|
else:
|
||||||
|
start = datetime.datetime.fromtimestamp(start)
|
||||||
|
end = datetime.datetime.fromtimestamp(end)
|
||||||
|
|
||||||
|
db = DatabaseConnection(app.config["DB_PATH"])
|
||||||
|
rounds = db.roundsBetweenDates(start, end)
|
||||||
|
|
||||||
|
return flask.render_template("rounds.html", rounds=rounds)
|
||||||
|
|
||||||
|
|
||||||
|
# get timestamp
|
||||||
|
# display players
|
||||||
|
# display rating change
|
||||||
|
# display outcome
|
||||||
|
# display map
|
||||||
|
|
||||||
@app.route("/player")
|
@app.route("/player")
|
||||||
def player():
|
def player():
|
||||||
'''Show Info about Player'''
|
'''Show Info about Player'''
|
||||||
|
|||||||
52
templates/rounds.html
Normal file
52
templates/rounds.html
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<title>Rounds Played</title>
|
||||||
|
<meta name="Description" content="Insurgency games played on the AtlantisHQ">
|
||||||
|
<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">Winner</th>
|
||||||
|
<th class="th-sm">Duration</th>
|
||||||
|
<th class="th-sm">Start Time</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{% for r in rounds %}
|
||||||
|
<tr>
|
||||||
|
<td>{{ r.mapName }}</td>
|
||||||
|
<td>{{ r.winnerSideString }}</td>
|
||||||
|
<td>{{ r.duration }}</td>
|
||||||
|
<td>{{ r.startTime.strftime('%H:%M %d.%m.%Y') }}</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
{% include 'footer.html' %}
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
Reference in New Issue
Block a user