1.0.0 : Web Implemented.
This commit is contained in:
73
web/routes/tactics.py
Normal file
73
web/routes/tactics.py
Normal file
@@ -0,0 +1,73 @@
|
||||
from flask import Blueprint, render_template, request, jsonify
|
||||
from web.services.web_service import WebService
|
||||
from web.services.stats_service import StatsService
|
||||
from web.services.feature_service import FeatureService
|
||||
import json
|
||||
|
||||
bp = Blueprint('tactics', __name__, url_prefix='/tactics')
|
||||
|
||||
@bp.route('/')
|
||||
def index():
|
||||
return render_template('tactics/index.html')
|
||||
|
||||
# API: Analyze Lineup
|
||||
@bp.route('/api/analyze', methods=['POST'])
|
||||
def api_analyze():
|
||||
data = request.json
|
||||
steam_ids = data.get('steam_ids', [])
|
||||
|
||||
if not steam_ids:
|
||||
return jsonify({'error': 'No players selected'}), 400
|
||||
|
||||
# 1. Get Basic Info & Stats
|
||||
players = StatsService.get_players_by_ids(steam_ids)
|
||||
player_data = []
|
||||
|
||||
total_rating = 0
|
||||
total_kd = 0
|
||||
total_adr = 0
|
||||
count = 0
|
||||
|
||||
for p in players:
|
||||
p_dict = dict(p)
|
||||
# Fetch L3 features
|
||||
f = FeatureService.get_player_features(p_dict['steam_id_64'])
|
||||
stats = dict(f) if f else {}
|
||||
p_dict['stats'] = stats
|
||||
player_data.append(p_dict)
|
||||
|
||||
if stats:
|
||||
total_rating += stats.get('basic_avg_rating', 0) or 0
|
||||
total_kd += stats.get('basic_avg_kd', 0) or 0
|
||||
total_adr += stats.get('basic_avg_adr', 0) or 0
|
||||
count += 1
|
||||
|
||||
# 2. Shared Matches
|
||||
shared_matches = StatsService.get_shared_matches(steam_ids)
|
||||
|
||||
# 3. Aggregates
|
||||
avg_stats = {
|
||||
'rating': total_rating / count if count else 0,
|
||||
'kd': total_kd / count if count else 0,
|
||||
'adr': total_adr / count if count else 0
|
||||
}
|
||||
|
||||
return jsonify({
|
||||
'players': player_data,
|
||||
'shared_matches': [dict(m) for m in shared_matches],
|
||||
'avg_stats': avg_stats
|
||||
})
|
||||
|
||||
# API: Save Board
|
||||
@bp.route('/save_board', methods=['POST'])
|
||||
def save_board():
|
||||
data = request.json
|
||||
title = data.get('title', 'Untitled Strategy')
|
||||
map_name = data.get('map_name', 'de_mirage')
|
||||
markers = data.get('markers')
|
||||
|
||||
if not markers:
|
||||
return jsonify({'success': False, 'message': 'No markers to save'})
|
||||
|
||||
WebService.save_strategy_board(title, map_name, json.dumps(markers), 'Anonymous')
|
||||
return jsonify({'success': True, 'message': 'Board saved successfully'})
|
||||
Reference in New Issue
Block a user