MCPcopy Create free account
hub / github.com/codecombat/codecombat / refreshMatches

Method refreshMatches

app/views/ladder/MyMatchesTabView.js:54–120  ·  view source on GitHub ↗
(refreshDelay)

Source from the content-addressed store, hash-verified

52 }
53
54 refreshMatches (refreshDelay) {
55 let match
56 this.refreshDelay = refreshDelay
57 this.teams = teamDataFromLevel(this.level)
58
59 const convertMatch = (match, submitDate) => {
60 const opponent = match.opponents[0]
61 let state = 'win'
62 if (match.metrics.rank > opponent.metrics.rank) { state = 'loss' }
63 if (match.metrics.rank === opponent.metrics.rank) { state = 'tie' }
64 const fresh = match.date > (new Date(new Date() - (this.refreshDelay * 1000))).toISOString()
65 if (fresh) {
66 this.playSound('chat_received')
67 }
68 return {
69 state,
70 opponentName: this.nameMap[opponent.userID],
71 opponentID: opponent.userID,
72 when: moment(match.date).fromNow(),
73 sessionID: opponent.sessionID,
74 stale: match.date < submitDate,
75 fresh,
76 opTeam: opponent.team,
77 codeLanguage: match.codeLanguage,
78 simulator: match.simulator ? JSON.stringify(match.simulator) + ' | seed ' + match.randomSeed : ''
79 }
80 }
81
82 for (const team of Array.from(this.teams)) {
83 team.session = ((() => {
84 const result = []
85 for (const s of Array.from(this.sessions.models)) {
86 if (s.get('team') === team.id) {
87 result.push(s)
88 }
89 }
90 return result
91 })())[0]
92 const stats = this.statsFromSession(team.session)
93 team.readyToRank = team.session != null ? team.session.readyToRank() : undefined
94 team.isRanking = team.session != null ? team.session.get('isRanking') : undefined
95 team.matches = ((() => {
96 const result1 = []
97 for (match of Array.from(((stats != null ? stats.matches : undefined) || []))) {
98 result1.push(convertMatch(match, team.session.get('submitDate')))
99 }
100 return result1
101 })())
102 team.matches.reverse()
103 team.matches = team.matches.slice(0, this.matchesLimit)
104 team.score = ((stats != null ? stats.totalScore : undefined) != null ? (stats != null ? stats.totalScore : undefined) : 10).toFixed(2)
105 team.wins = _.filter(team.matches, { state: 'win', stale: false }).length
106 team.ties = _.filter(team.matches, { state: 'tie', stale: false }).length
107 team.losses = _.filter(team.matches, { state: 'loss', stale: false }).length
108 const scoreHistory = stats != null ? stats.scoreHistory : undefined
109 if ((scoreHistory != null ? scoreHistory.length : undefined) > 1) {
110 team.scoreHistory = scoreHistory
111 }

Callers 3

constructorMethod · 0.95
onLoadMoreMatchesMethod · 0.95
refreshViewsMethod · 0.80

Calls 5

statsFromSessionMethod · 0.95
loadNamesMethod · 0.95
readyToRankMethod · 0.80
filterMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected