const h2hMatchCount = {}; const h2hSelectedCount = {}; const h2hHalf = {}; const h2hLeague = {}; const h2hHome = {}; const h2hAway = {}; const h2hFixture = {}; function renderH2h(fixtures, type, divId, label, hClass) { if (!fixtures.length) { return; } const maxLength = Math.min(20, fixtures.length); const selectedCount = Math.min(10, fixtures.length); const sumData = { 'win': 0, 'lose': 0, 'draw': 0, 'odds': 0, 'odds_win': 0, 'o': 0, 'o_win': 0 }; for (let i = 0; i < selectedCount; i++) { const f = fixtures[i]; sumData['win'] += f.odds?.[0].result_open == 'W' ? 1 : 0; sumData['lose'] += f.odds?.[0].result_open == 'L' ? 1 : 0; sumData['draw'] += f.odds?.[0].result_open == 'D' ? 1 : 0; sumData['odds'] += f.odds?.[1].result_open != '' ? 1 : 0; sumData['odds_win'] += f.odds?.[1].result_open == 'W' ? 1 : 0; sumData['o'] += f.odds?.[2].result_open != '' ? 1 : 0; sumData['o_win'] += f.odds?.[2].result_open == 'O' ? 1 : 0; } sumData['all'] = Math.max(1, selectedCount); sumData['odds'] = Math.max(1, sumData['odds']); sumData['o'] = Math.max(1, sumData['o']); //init h2hMatchCount[divId] = Math.min(10, maxLength); h2hSelectedCount[divId] = selectedCount; h2hHalf[divId] = 0; h2hLeague[divId] = 0; h2hHome[divId] = 0; h2hAway[divId] = 0; h2hFixture[divId] = fixtures; html = ``; html += `
`; if (label) { html += `

${label}

`; } html += `
`; html += ``; html += ``; html += ``; html += ``; html += ``; html += ``; html += ``; html += ``; html += ``; html += ``; html += ``; html += ``; html += ``; html += ``; html += ``; html += ``; html += ``; html += ``; html += ``; html += ``; html += ``; html += ``; html += ``; html += ``; html += ``; html += `
`; if (type === 'home') { html += `
`; html += ``; html += ``; html += `
`; } else { html += `
`; html += ``; html += ``; html += `
`; } html += `
`; html += ``; html += ``; html += `
`; html += `
`; html += ``; html += ``; html += `
`; html += `
`; html += ``; html += `
`; html += `
ลีก / ถ้วยเวลาทีมเหย้าสกอร์ทีมเยือนเตะมุมเหย้าชนะเสมอเยือนชนะชนะ / แพ้เหย้าAHเยือนAHO / U
`; $('#' + divId).html(html); renderH2hContent(divId); } function renderH2hContent(divId) { const getTeamClass = (n) => n == homeTeam ? 'text-team-home' : (n == awayTeam ? 'text-team-away' : ''); let len = Math.min(h2hMatchCount[divId], h2hFixture[divId].length); const s = h2hHalf[divId] === 1 ? 3 : 0; const fixtures_ = []; // console.log(h2hFixture[divId]); for (let i = 0; i < h2hFixture[divId].length; i++) { const f = h2hFixture[divId][i]; if (h2hLeague[divId] === 1 && f['league'] !== leagueName) { continue; } if (h2hHome[divId] === 1 && f['team_home'] !== homeTeam) { continue; } if (h2hAway[divId] === 1 && f['team_away'] !== awayTeam) { continue; } fixtures_.push(f); } let html = ``; let sum = { 'win': 0, 'lose': 0, 'draw': 0, 'odds': 0, 'odds_win': 0, 'o': 0, 'o_win': 0 } for (let i = 0; i < fixtures_.length; i++) { const f = fixtures_[i]; if (i > len - 1) { continue; } if (!f['odds'] || !f['odds'][s]) { continue; } if (!f['odds'][s + 1]) { continue; } html += ``; html += `${f['league_code']}` html += `${dateShort(f['time'])}` html += `${f['team_home']}` html += `${f['score_half']} (${f['score']})` html += `${f['team_away']}` html += `${f['corner_half']} (${f['corner']})` html += `${f['odds'][s]['home_open']}` html += `${f['odds'][s]['draw_open']}` html += `${f['odds'][s]['away_open']}` html += `${f['odds'][s]['result_open']}` html += `${f['odds'][s + 1]['home_open']}` html += `${f['odds'][s + 1]['draw_open']}` html += `${f['odds'][s + 1]['away_open']}` html += `${f['odds'][s + 1]['result_open']}` html += `${f['odds'][s + 2]['result_open']}` html += ``; sum['win'] += f['odds'][s]['result_open'] == 'W' ? 1 : 0; sum['lose'] += f['odds'][s]['result_open'] == 'L' ? 1 : 0; sum['draw'] += f['odds'][s]['result_open'] == 'D' ? 1 : 0; sum['odds'] += f['odds'][s + 1]['result_open'] != '' ? 1 : 0; sum['odds_win'] += f['odds'][s + 1]['result_open'] == 'W' ? 1 : 0; sum['o'] += f['odds'][s + 2]['result_open'] != '' ? 1 : 0; sum['o_win'] += f['odds'][s + 2]['result_open'] == 'O' ? 1 : 0; } len = Math.max(1, len); sum['o'] = Math.max(1, sum['o']); sum['odds'] = Math.max(1, sum['odds']); html += ``; html += ``; html += `${len} นัดหลังสุด,`; html += `ชนะ ${sum['win']},`; html += `เสมอ ${sum['draw']},`; html += `แพ้ ${sum['lose']},`; html += `อัตราชนะ: ${(sum['win'] / len * 100).toFixed(1)}%,`; html += `อัตราชนะต่อรอง: ${(sum['odds_win'] / sum['odds'] * 100).toFixed(1)}% ,`; html += `อัตราเกมสูง: ${(sum['o_win'] / sum['o'] * 100).toFixed(1)}%`; html += ``; html += ``; $('#' + divId + 'Tbody').html(html); html = ``; if (h2hMatchCount[divId] > fixtures_.length) { h2hSelectedCount[divId] = fixtures_.length; } else { h2hSelectedCount[divId] = h2hMatchCount[divId]; } for (let i = 0; i < fixtures_.length; i++) { html += ``; } $('#' + divId + 'SelectMatch').html(html); } function h2hHomeChange(event, divId) { h2hHome[divId] = event.target.checked ? 1 : 0; renderH2hContent(divId); } function h2hAwayChange(event, divId) { h2hAway[divId] = event.target.checked ? 1 : 0; renderH2hContent(divId); } function h2hLeagueChange(event, divId) { h2hLeague[divId] = event.target.checked ? 1 : 0; renderH2hContent(divId); } function h2hHalfChange(event, divId) { h2hHalf[divId] = event.target.checked ? 1 : 0; renderH2hContent(divId); } function h2hMatchCountChange(event, divId) { h2hMatchCount[divId] = event.target.value; renderH2hContent(divId); } function getH2h(fixtureId) { getData('fixtures/' + fixtureId + '/analysis/h2h', null, (data) => { // console.log(data); renderH2h(data['h2h'], 'home', 'h2hSection', 'ผลงานการพบกัน', 'bg-primary'); renderH2h(data['home'], 'home', 'h2hHomeSection', 'ผลการแข่งย้อนหลัง '+homeTeam+'', 'bg-team-home'); renderH2h(data['away'], 'away', 'h2hAwaySection', 'ผลการแข่งย้อนหลัง '+awayTeam+'', 'bg-team-away'); renderHistoryCompare('tableLastFixtureCompare', 'เปรียบเทียบผลบอล', homeTeam, awayTeam, 'bg-primary', data); }, (error) => { console.log(error); }); }