Skip to content

Commit

Permalink
site: player: Add separate teams page
Browse files Browse the repository at this point in the history
Add a page which shows all teams a player has been on, in addition to the short list on the
overview.

Signed-off-by: Sean Anderson <[email protected]>
  • Loading branch information
Forty-Bot committed Apr 26, 2023
1 parent fb16d5e commit 6ff791d
Show file tree
Hide file tree
Showing 5 changed files with 139 additions and 96 deletions.
117 changes: 66 additions & 51 deletions trends/site/player.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,60 @@ def get_logs(c, playerid, filters, duplicates=True, order_clause="logid DESC", l
})
return logs

def get_teams(c, filters, order_clause="upper(rostered)", limit=10, offset=0):
inner_clauses = get_filter_clauses(filters, 'league', date_range='rostered')
outer_clauses = get_filter_clauses(filters, 'formatid')

teams = c.cursor()
teams.execute(
"""SELECT
league,
format,
competition.name AS comp,
competition.compid,
division AS div,
team,
teamid,
lower(rostered) AS from,
upper(rostered) AS to
FROM (SELECT
tc.league,
tc.compid,
tc.teamid,
divid,
team_name AS team,
rostered,
rank() OVER (
PARTITION BY tc.league, tc.teamid
ORDER BY tc.league, tc.compid DESC
) AS r
FROM (SELECT
league,
teamid,
compid,
range_max(rostered) AS rostered
FROM team_player
WHERE playerid = %(playerid)s
{}
GROUP BY league, teamid, compid
) AS tp
JOIN team_comp AS tc ON (
tp.league = tc.league
AND tp.teamid = tc.teamid
AND (NOT league_team_per_comp(tc.league)
OR tp.compid = tc.compid)
)) AS teams
JOIN competition USING (league, compid)
JOIN format USING (formatid)
LEFT JOIN division USING (league, divid)
LEFT JOIN div_name USING (div_nameid)
WHERE r = 1
{}
ORDER BY {} NULLS FIRST, lower(rostered) ASC
LIMIT %(limit)s OFFSET %(offset)s;""".format(inner_clauses, outer_clauses, order_clause),
{ 'playerid': flask.g.playerid, 'limit': limit, 'offset': offset, **filters })
return teams.fetchall()

@player.route('/')
def overview(steamid):
c = get_db()
Expand Down Expand Up @@ -227,58 +281,8 @@ def overview(steamid):
) AS names
JOIN name USING (nameid)""", (flask.g.playerid,))

teams = c.cursor()
teams.execute(
"""SELECT
league,
format,
competition.name AS comp,
competition.compid,
division AS div,
team,
teamid,
lower(rostered) AS from,
upper(rostered) AS to
FROM (SELECT
tc.league,
tc.compid,
tc.teamid,
divid,
team_name AS team,
rostered,
rank() OVER (
PARTITION BY tc.league, tc.teamid
ORDER BY tc.league, tc.compid DESC
) AS r
FROM (SELECT
league,
teamid,
compid,
range_max(rostered) AS rostered
FROM team_player
WHERE playerid = %(playerid)s
{}
GROUP BY league, teamid, compid
) AS tp
JOIN team_comp AS tc ON (
tp.league = tc.league
AND tp.teamid = tc.teamid
AND (NOT league_team_per_comp(tc.league)
OR tp.compid = tc.compid)
)) AS teams
JOIN competition USING (league, compid)
JOIN format USING (formatid)
LEFT JOIN division USING (league, divid)
LEFT JOIN div_name USING (div_nameid)
WHERE r = 1
{}
ORDER BY upper(rostered) DESC NULLS FIRST, lower(rostered) ASC
LIMIT 10;""".format(get_filter_clauses(filters, 'league', date_range='rostered'),
get_filter_clauses(filters, 'formatid')),
{ 'playerid': flask.g.playerid, **filters })
teams = teams.fetchall()

logs = get_logs(c, flask.g.playerid, filters, limit=25, duplicates=False)
teams = get_teams(c, filters)
return flask.render_template("player/overview.html", logs=logs, classes=classes,
formats=formats, aliases=aliases, teams=teams)

Expand All @@ -305,6 +309,17 @@ def logs(steamid):
logs = get_logs(get_db(), flask.g.playerid, filters, order_clause=order_clause, limit=limit, offset=offset)
return flask.render_template("player/logs.html", logs=logs.fetchall())

@player.route('/teams')
def teams(steamid):
limit, offset = get_pagination()
filters = get_filter_params()
order, order_clause = get_order({
'to': "upper(rostered)",
'from': "lower(rostered)",
}, 'to')
teams = get_teams(get_db(), get_filter_params(), order_clause, limit=limit, offset=offset)
return flask.render_template("player/teams.html", teams=teams)

@player.route('/peers')
def peers(steamid):
limit, offset = get_pagination()
Expand Down
47 changes: 47 additions & 0 deletions trends/site/templates/macros/teams.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{# SPDX-License-Identifier: AGPL-3.0-only #}
{# Copyright (C) 2023 Sean Anderson <seanga2@gmail.com> #}
{% from "macros/format.html" import date_col, optformat, optint %}
{% from "macros/pretty.html" import format_map, league_map %}
{% macro team_table(teams) %}
<table>
<thead>
<tr>
<th>League</th>
<th>Team</th>
<th>Most-recent Competition</th>
<th><abbr title="Division of most-recent competition">
Division
</abbr></th>
<th><abbr title="Format of most-recent competition">
Format
</abbr></th>
<th><abbr title="Most-recent join date">Rostered From</abbr></th>
<th><abbr title="Most-recent leave date">Rostered To</abbr></th>
</tr>
</thead>
<tbody>
{% for team in teams %}
<tr>
<td class="left"><a href="{{ url_for('league.comps',
league=team['league']) }}">
{{ league_map[team['league']] }}
</a></td>
<td class="left">
<a href="{{ url_for('league.team.overview', league=team['league'],
teamid=team['teamid']) }}">
{{ team['team'] }}
</a></td>
<td class="left">
<a href="{{ url_for('league.comp.overview', league=team['league'],
compid=team['compid']) }}">
{{ team['comp'] }}
</a></td>
<td class="left">{{ team['div'] if team['div'] != None }}</td>
<td class="left">{{ format_map[team['format']] }}</td>
{{ date_col(team['from']) }}
{{ date_col(team['to']) }}
</tr>
{% endfor %}
</tbody>
</table>
{% endmacro %}
6 changes: 3 additions & 3 deletions trends/site/templates/player/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ <h1><a href="https://steamcommunity.com/profiles/{{ g.player['steamid64'] }}">
</div>


{{ navbar(('.overview', "Overview"), ('.logs', "Logs"), ('.peers', "Peers"),
('.totals', "Totals"), ('.weapons', "Weapons"), ('.trends', "Trends"),
('.maps', "Maps"), steamid=g.player.steamid64) }}
{{ navbar(('.overview', "Overview"), ('.logs', "Logs"), ('.teams', "Teams"),
('.peers', "Peers"), ('.totals', "Totals"), ('.weapons', "Weapons"),
('.trends', "Trends"), ('.maps', "Maps"), steamid=g.player.steamid64) }}
{% endblock %}
45 changes: 3 additions & 42 deletions trends/site/templates/player/overview.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
{# SPDX-License-Identifier: AGPL-3.0-only #}
{# Copyright (C) 2020 Sean Anderson <seanga2@gmail.com> #}
{% from "macros/filter.html" import filter %}
{% from "macros/format.html" import date_col, optformat, optint %}
{% from "macros/format.html" import optformat, optint %}
{% from "macros/logs.html" import log_table %}
{% from "macros/pretty.html" import class_map, format_map, league_map %}
{% from "macros/teams.html" import team_table %}
{% from "macros/wlt.html" import wlt %}
{% extends "player/base.html" %}
{% block title %}Overview - {{ super() }}{% endblock %}
Expand Down Expand Up @@ -98,47 +99,7 @@ <h3>Aliases</h3>
{% if teams | length %}
<div class="float">
<h3>Recent Teams</h3>
<table>
<thead>
<tr>
<th>League</th>
<th>Team</th>
<th>Most-recent Competition</th>
<th><abbr title="Division of most-recent competition">
Division
</abbr></th>
<th><abbr title="Format of most-recent competition">
Format
</abbr></th>
<th><abbr title="Most-recent join date">Rostered From</abbr></th>
<th><abbr title="Most-recent leave date">Rostered To</abbr></th>
</tr>
</thead>
<tbody>
{% for team in teams %}
<tr>
<td class="left"><a href="{{ url_for('league.comps',
league=team['league']) }}">
{{ league_map[team['league']] }}
</a></td>
<td class="left">
<a href="{{ url_for('league.team.overview', league=team['league'],
teamid=team['teamid']) }}">
{{ team['team'] }}
</a></td>
<td class="left">
<a href="{{ url_for('league.comp.overview', league=team['league'],
compid=team['compid']) }}">
{{ team['comp'] }}
</a></td>
<td class="left">{{ team['div'] if team['div'] != None }}</td>
<td class="left">{{ format_map[team['format']] }}</td>
{{ date_col(team['from']) }}
{{ date_col(team['to']) }}
</tr>
{% endfor %}
</tbody>
</table>
{{ team_table(teams) }}
</div>
{% endif %}
</div>
Expand Down
20 changes: 20 additions & 0 deletions trends/site/templates/player/teams.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{# SPDX-License-Identifier: AGPL-3.0-only #}
{# Copyright (C) 2020, 23 Sean Anderson <seanga2@gmail.com> #}
{% from "macros/filter.html" import filter %}
{% from "macros/pagination.html" import navigation %}
{% from "macros/sort.html" import sort %}
{% from "macros/teams.html" import team_table %}
{% extends "player/base.html" %}
{% block title %}Teams - {{ super() }}{% endblock %}
{% block content %}
{{ super() }}
<h2>Teams</h2>
{{ filter('league', 'date', 'format') }}
{{ sort({
'to': "Rostered to",
'from': "Rostered from",
}) }}
{{ navigation(teams) }}
{{ team_table(teams) }}
{{ navigation(teams) }}
{% endblock %}

0 comments on commit 6ff791d

Please sign in to comment.