1.0.1-fix: Fixed 'winner-team' regarded as win.
This commit is contained in:
@@ -178,19 +178,29 @@ class StatsService:
|
||||
|
||||
@staticmethod
|
||||
def get_shared_matches(steam_ids):
|
||||
# Find matches where ALL steam_ids were present in the SAME team (or just present?)
|
||||
# "共同经历" usually means played together.
|
||||
# Query: Intersect match_ids for each player.
|
||||
# SQLite doesn't have INTERSECT ALL easily for dynamic list, but we can group by match_id.
|
||||
|
||||
if not steam_ids or len(steam_ids) < 2:
|
||||
# Find matches where ALL steam_ids were present
|
||||
if not steam_ids or len(steam_ids) < 1:
|
||||
return []
|
||||
|
||||
placeholders = ','.join('?' for _ in steam_ids)
|
||||
count = len(steam_ids)
|
||||
|
||||
# We need to know which team the players were on to determine win/loss
|
||||
# Assuming they were on the SAME team for "shared experience"
|
||||
# If count=1, it's just match history
|
||||
|
||||
# Query: Get matches where all steam_ids are present
|
||||
# Also join to get team_id to check if they were on the same team (optional but better)
|
||||
# For simplicity in v1: Just check presence in the match.
|
||||
# AND check if the player won.
|
||||
|
||||
# We need to return: match_id, map_name, score, result (Win/Loss)
|
||||
# "Result" is relative to the lineup.
|
||||
# If they were on the winning team, it's a Win.
|
||||
|
||||
sql = f"""
|
||||
SELECT m.match_id, m.start_time, m.map_name, m.score_team1, m.score_team2, m.winner_team
|
||||
SELECT m.match_id, m.start_time, m.map_name, m.score_team1, m.score_team2, m.winner_team,
|
||||
MAX(mp.team_id) as player_team_id -- Just take one team_id (assuming same)
|
||||
FROM fact_matches m
|
||||
JOIN fact_match_players mp ON m.match_id = mp.match_id
|
||||
WHERE mp.steam_id_64 IN ({placeholders})
|
||||
@@ -203,7 +213,33 @@ class StatsService:
|
||||
args = list(steam_ids)
|
||||
args.append(count)
|
||||
|
||||
return query_db('l2', sql, args)
|
||||
rows = query_db('l2', sql, args)
|
||||
|
||||
results = []
|
||||
for r in rows:
|
||||
# Determine if Win
|
||||
# winner_team in DB is 'Team 1' or 'Team 2' usually, or the team name.
|
||||
# fact_matches.winner_team stores the NAME of the winner? Or 'team1'/'team2'?
|
||||
# Let's check how L2_Builder stores it. Usually it stores the name.
|
||||
# But fact_match_players.team_id stores the name too.
|
||||
|
||||
# Logic: If m.winner_team == mp.team_id, then Win.
|
||||
is_win = (r['winner_team'] == r['player_team_id'])
|
||||
|
||||
# If winner_team is NULL or empty, it's a draw?
|
||||
if not r['winner_team']:
|
||||
result_str = 'Draw'
|
||||
elif is_win:
|
||||
result_str = 'Win'
|
||||
else:
|
||||
result_str = 'Loss'
|
||||
|
||||
res = dict(r)
|
||||
res['is_win'] = is_win # Boolean for styling
|
||||
res['result_str'] = result_str # Text for display
|
||||
results.append(res)
|
||||
|
||||
return results
|
||||
|
||||
@staticmethod
|
||||
def get_player_trend(steam_id, limit=20):
|
||||
|
||||
Reference in New Issue
Block a user