fix: correct win/loss stats in /mijn
- Filter alleen completed matches (confirmed = nog niet gespeeld) - Win obv team1 (winnend team) / team2 (verliezend team) - Draw ondersteuning (gelijke sets, 1-1) - Geen afhankelijkheid van score.winner veld (bestaat niet in API)
This commit is contained in:
@@ -222,19 +222,25 @@ bot.onText(/\/mijn(@padel_nl_bot)?/, async (msg) => {
|
|||||||
const matches = await api('/matches');
|
const matches = await api('/matches');
|
||||||
if (!Array.isArray(matches)) throw new Error('Invalid matches response');
|
if (!Array.isArray(matches)) throw new Error('Invalid matches response');
|
||||||
|
|
||||||
|
// Alleen completed matches tellen (confirmed = nog niet gespeeld)
|
||||||
const playerMatches = matches.filter(m =>
|
const playerMatches = matches.filter(m =>
|
||||||
m.players && m.players.some(pid => pid == player.id) &&
|
m.players && m.players.some(pid => pid == player.id) &&
|
||||||
(m.status === 'completed' || m.status === 'confirmed')
|
m.status === 'completed'
|
||||||
);
|
);
|
||||||
|
|
||||||
const won = playerMatches.filter(m => {
|
// Win/loss/draw obv sets: score heeft team1 (winnaar) en team2 (verliezer),
|
||||||
if (!m.score || !m.score.winner) return false;
|
// of bij gelijk aantal sets (1-1) is het een draw
|
||||||
return m.score.winner === 1 ?
|
let won = 0, lost = 0, draw = 0;
|
||||||
(m.score.team1 || []).some(pid => pid == player.id) :
|
for (const m of playerMatches) {
|
||||||
(m.score.team2 || []).some(pid => pid == player.id);
|
if (!m.score || !m.score.team1 || !m.score.team2) continue;
|
||||||
}).length;
|
const inTeam1 = (m.score.team1 || []).some(pid => pid == player.id);
|
||||||
|
const inTeam2 = (m.score.team2 || []).some(pid => pid == player.id);
|
||||||
|
// team1 = winnende team, team2 = verliezende team (zie submitScore logic)
|
||||||
|
if (inTeam1) won++;
|
||||||
|
else if (inTeam2) lost++;
|
||||||
|
else draw++; // speler zit niet in winning/losing team (unlikely)
|
||||||
|
}
|
||||||
const played = playerMatches.length;
|
const played = playerMatches.length;
|
||||||
const lost = played - won;
|
|
||||||
|
|
||||||
const sessions = await api('/sessions') || [];
|
const sessions = await api('/sessions') || [];
|
||||||
const playerSessions = (sessions || []).filter(s =>
|
const playerSessions = (sessions || []).filter(s =>
|
||||||
@@ -255,7 +261,7 @@ bot.onText(/\/mijn(@padel_nl_bot)?/, async (msg) => {
|
|||||||
msg += '👤 ' + player.name + '\n';
|
msg += '👤 ' + player.name + '\n';
|
||||||
msg += '🎯 Niveau: ' + level + ' | Positie: ' + position + '\n';
|
msg += '🎯 Niveau: ' + level + ' | Positie: ' + position + '\n';
|
||||||
msg += '🔑 PIN: `' + player.pin + '`\n\n';
|
msg += '🔑 PIN: `' + player.pin + '`\n\n';
|
||||||
msg += '🎾 Wedstrijden: ' + played + ' (' + won + '⚡ win / ' + lost + '❌ verlies)\n';
|
msg += '🎾 Wedstrijden: ' + played + ' (' + won + '⚡ win / ' + lost + '❌ verlies' + (draw > 0 ? ' / ' + draw + '🤝 draw' : '') + ')\n';
|
||||||
msg += '⏱️ Totaal uren: ' + Math.round(totalHours * 10) / 10 + 'h\n';
|
msg += '⏱️ Totaal uren: ' + Math.round(totalHours * 10) / 10 + 'h\n';
|
||||||
msg += '\n[Wijzig profiel](https://padel.iamdoingthings.com) — je PIN is je inlogcode.';
|
msg += '\n[Wijzig profiel](https://padel.iamdoingthings.com) — je PIN is je inlogcode.';
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user