UNPKG

iplr

Version:

Node package for IPLR.

54 lines (43 loc) 1.22 kB
import BaseClass from './BaseClass'; import PointsTable from './PointsTable'; export default class Ground extends BaseClass { constructor (tournament, jo) { super(); this.tournament = tournament; this.jo = jo; this.id = jo.id; this.fn = jo.fn; this.sn = jo.sn; this.city = jo.city; this.path = jo.path; } postBundleSetup () { this.setHometeam(); this.pointsTable = new PointsTable(this.tournament, this.matches); } getLink = () => `/grounds/${this.path}`; setHometeam () { let teamIds = []; for (let match of this.matches) { teamIds.push(match.team_a.id); teamIds.push(match.team_b.id); } let counter = {}; for (let teamId of teamIds) { counter[teamId] = counter[teamId] ? counter[teamId] + 1 : 1; } this.teams = []; for (let k in counter) { this.teams.push({ team: this.tournament.teams[k], count: counter[k] }) } this.teams.sort((a, b) => (b.count - a.count)); // default value is used when only one season is initialized this.hometeam = this.teams[0] ? this.teams[0].team : this.tournament.teamsArray[0]; this.bdStyle = this.hometeam.bdStyle; this.bgStyle = this.hometeam.bgStyle; this.fgStyle = this.hometeam.fgStyle; } }