mirror of
https://github.com/FAUSheppy/open-web-leaderboard.git
synced 2025-12-05 22:51:36 +01:00
add experimental live game support
This commit is contained in:
27
database.py
27
database.py
@@ -130,6 +130,33 @@ class DatabaseConnection:
|
||||
rank = cursor.fetchone()[0]
|
||||
return rank
|
||||
|
||||
def getLiveGames(self):
|
||||
'''Get current live games'''
|
||||
|
||||
cursor = self.connPlayers.cursor()
|
||||
cursor.execute('''SELECT * FROM live WHERE time > ? LIMIT 2''',
|
||||
(datetime.datetime.now().timestamp(),))
|
||||
|
||||
liveRounds = []
|
||||
for row in cursor:
|
||||
trackingID, time, duration, players = row
|
||||
insurgent = [] #2
|
||||
security = [] #3
|
||||
|
||||
for p in json.loads(players):
|
||||
if p["team"] == 2:
|
||||
insurgent += [p]
|
||||
elif p["team"] == 3:
|
||||
security += [p]
|
||||
p.update({"active_time":-1})
|
||||
|
||||
dbRow = [time, json.dumps(insurgent), json.loads(security), "N/A", 0, 0 ,0]
|
||||
r = Round.Round(row)
|
||||
r.id = trackingID
|
||||
liveRounds += [r]
|
||||
|
||||
return liveRounds
|
||||
|
||||
def roundsBetweenDates(self, start, end):
|
||||
'''Get rounds played between two times'''
|
||||
|
||||
|
||||
@@ -52,6 +52,14 @@ def singleRound():
|
||||
|
||||
return flask.render_template("single_round.html", r=r)
|
||||
|
||||
@app.route("/livegames")
|
||||
def liveGames():
|
||||
'''Display info about a single round itdentified by it's timestamp'''
|
||||
|
||||
db = DatabaseConnection(app.config["DB_PATH"])
|
||||
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'''
|
||||
|
||||
@@ -43,7 +43,7 @@
|
||||
$('.dataTables_length').addClass('bs-select');
|
||||
});
|
||||
</script>
|
||||
{% endif }
|
||||
{% endif %}
|
||||
{% include 'footer.html' %}
|
||||
</body>
|
||||
</html>
|
||||
|
||||
91
templates/livegames.html
Normal file
91
templates/livegames.html
Normal file
@@ -0,0 +1,91 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<title>Live Round</title>
|
||||
<meta name="Description" content="Insurgency games played on the AtlantisHQ">
|
||||
<meta name="robots" content="noarchive">
|
||||
{% include 'default_head_content.html' %}
|
||||
</head>
|
||||
<body class="bg-special">
|
||||
{% include 'navbar.html' %}
|
||||
{% if noRounds %}
|
||||
<h1 class="m-5 alert alert-warning text-center">
|
||||
No game currently detected as in progress :(
|
||||
</h1>
|
||||
{% endif %}
|
||||
|
||||
{% for r in liveGameRounds %}
|
||||
<div class="container mt-3 mb-3" role="main">
|
||||
|
||||
<div class="row">
|
||||
<div class="col-sm">
|
||||
<h1>Tracking ID {{ r.id }}</h1>
|
||||
<h4>{{ r.startTime }}</h4>
|
||||
<h4>Map: {{ r.mapName }}</h4>
|
||||
<h4>Duration: {{ r.duration }}</h4>
|
||||
|
||||
{% if r.invalid %}
|
||||
<div>
|
||||
<h5 style="color: red;">{{ r.invalid | safe }}</h5>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<hr>
|
||||
<div class="row">
|
||||
<div class="col-sm">
|
||||
<h5>Insurgency</h5>
|
||||
</div>
|
||||
<div class="col-sm">
|
||||
<h5>Security</h5>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-sm">
|
||||
{# WINNERS == INSURGENT for livegames #}
|
||||
{% for p in r["winners"] %}
|
||||
<div class="row">
|
||||
<div class="col-sm" style="overflow: hidden;">
|
||||
<a href="/player?id={{ p.playerId }}">{{ p.name }}</a>
|
||||
</div>
|
||||
<div class="col-sm">
|
||||
{% if not r.invalid %}
|
||||
<small style="color: green;">
|
||||
{{ p.ratingChangeString | safe }}
|
||||
</small>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
<div class="col-sm">
|
||||
{# LOSER == SECURITY for livegames #}
|
||||
{% for p in r["losers"] %}
|
||||
<div class="row">
|
||||
<div class="col-sm" style="overflow: hidden;">
|
||||
<a href="/player?id={{ p.playerId }}">{{ p.name }}</a>
|
||||
</div>
|
||||
<div class="col-sm">
|
||||
{{ p.participation }}%
|
||||
</div>
|
||||
<div class="col-sm">
|
||||
{% if not r.invalid %}
|
||||
<small style="color: red;">
|
||||
{{ p.ratingChangeString | safe }}
|
||||
</small>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<hr>
|
||||
<div class="mt-5">
|
||||
</div>
|
||||
{% endfor %}
|
||||
{% include 'footer.html' %}
|
||||
</body>
|
||||
</html>
|
||||
@@ -28,10 +28,10 @@
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="navbar-brand hover-to-75 patreon" style="position: unset !important;" href="https://www.patreon.com/erlangen_sheppy">Support me
|
||||
<!--<img style="max-height: 1.5rem;" src='/static/patreon.jpg'></img>-->
|
||||
</a>
|
||||
</li>
|
||||
<ul>
|
||||
<!--<img style="max-height: 1.5rem;" src='/static/patreon.jpg'></img>-->
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</nav>
|
||||
<nav class="navbar" style="visibility: hidden;">
|
||||
|
||||
@@ -18,6 +18,11 @@
|
||||
<li class="nav-item">
|
||||
<a id="button-forward" class="nav-link" href="/?page={{ nextPageNumber }}">Forward</a>
|
||||
</li>
|
||||
<li class="nav-item" {% if not gameInProgress %} style="opacity: 0.5" {% endif %}>
|
||||
<a id="button-forward" class="nav-link" href="/livegames">Livegames
|
||||
<div style="font-size: small; color: red; opacity: 1; float: right; margin-left: 10px;">(experimental)</div>
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
<ul class="navbar-nav">
|
||||
<li class="nav-item">
|
||||
|
||||
Reference in New Issue
Block a user