49 lines
1.8 KiB
Python
49 lines
1.8 KiB
Python
|
|
from flask import Blueprint, render_template, request, Response
|
||
|
|
from web.services.stats_service import StatsService
|
||
|
|
from web.config import Config
|
||
|
|
import json
|
||
|
|
|
||
|
|
bp = Blueprint('matches', __name__, url_prefix='/matches')
|
||
|
|
|
||
|
|
@bp.route('/')
|
||
|
|
def index():
|
||
|
|
page = request.args.get('page', 1, type=int)
|
||
|
|
map_name = request.args.get('map')
|
||
|
|
date_from = request.args.get('date_from')
|
||
|
|
|
||
|
|
matches, total = StatsService.get_matches(page, Config.ITEMS_PER_PAGE, map_name, date_from)
|
||
|
|
total_pages = (total + Config.ITEMS_PER_PAGE - 1) // Config.ITEMS_PER_PAGE
|
||
|
|
|
||
|
|
return render_template('matches/list.html', matches=matches, total=total, page=page, total_pages=total_pages)
|
||
|
|
|
||
|
|
@bp.route('/<match_id>')
|
||
|
|
def detail(match_id):
|
||
|
|
match = StatsService.get_match_detail(match_id)
|
||
|
|
if not match:
|
||
|
|
return "Match not found", 404
|
||
|
|
|
||
|
|
players = StatsService.get_match_players(match_id)
|
||
|
|
rounds = StatsService.get_match_rounds(match_id)
|
||
|
|
|
||
|
|
# Organize players by team
|
||
|
|
team1_players = [p for p in players if p['team_id'] == 1]
|
||
|
|
team2_players = [p for p in players if p['team_id'] == 2]
|
||
|
|
|
||
|
|
return render_template('matches/detail.html', match=match,
|
||
|
|
team1_players=team1_players, team2_players=team2_players,
|
||
|
|
rounds=rounds)
|
||
|
|
|
||
|
|
@bp.route('/<match_id>/raw')
|
||
|
|
def raw_json(match_id):
|
||
|
|
match = StatsService.get_match_detail(match_id)
|
||
|
|
if not match:
|
||
|
|
return "Match not found", 404
|
||
|
|
|
||
|
|
# Construct a raw object from available raw fields
|
||
|
|
data = {
|
||
|
|
'round_list': json.loads(match['round_list_raw']) if match['round_list_raw'] else None,
|
||
|
|
'leetify_data': json.loads(match['leetify_data_raw']) if match['leetify_data_raw'] else None
|
||
|
|
}
|
||
|
|
|
||
|
|
return Response(json.dumps(data, indent=2, ensure_ascii=False), mimetype='application/json')
|