frMatchViewHelper.js
2.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
angular.module('fr.matchViewHelper', [])
.service('matchViewHelper', ['$interval', function ($interval) {
function startMinutesJob(match) {
var job;
if (match.statusType === 'inprogress' || match.statusType === 'notstarted') {
job = $interval(function () {
setMinutes(match);
}, 30000);
setMinutes(match);
}
return job;
}
function stopMinutesJob(job) {
if (job) {
$interval.cancel(job);
}
}
function setMinutes(match) {
if (match.timerStart) {
match.minute = Math.floor((new Date() - new Date(match.timerStart)) / 1000 / 60) + 1;
if (match.status == '1st' && match.minute > 45) {
match.minute = '45\'+';
} else if (match.status == '2nd' && (match.minute += 45) > 90) {
match.minute = '90\'+';
} else {
match.minute += '\'';
}
}
}
function setMainIncidents(match) {
match.mainIncidents = [];
match.homeRedCards = 0;
match.awayRedCards = 0;
_(match.incidents).each(function (incident) {
if (incident.code.category === 'g' || incident.code.id === 'r' || incident.code.id === 'y2') {
match.mainIncidents.push(incident);
if (incident.code.id == 'r' || incident.code.id == 'y2') {
if (incident.side == 'home') {
match.homeRedCards++;
} else {
match.awayRedCards++;
}
}
}
});
}
function arrangeIncidents(match) {
var output = {
homeGoals: [],
awayGoals: [],
homeCards: [],
awayCards: [],
};
_(match.incidents).each(function (incident) {
if (incident.code.id === 'ps' || incident.code.id === 'psm') {
incident.elapsed = 'PEN';
}
switch (incident.code.category) {
case 'g':
output[incident.side + 'Goals'].push(incident);
break;
case 'c':
output[incident.side + 'Cards'].push(incident);
break;
default:
break;
}
});
return output;
}
function setScore(match) {
if (match.homeScore === undefined) {
match.homeScore = 0;
}
if (match.awayScore === undefined) {
match.awayScore = 0;
}
}
return {
startMinutesJob: startMinutesJob,
stopMinutesJob: stopMinutesJob,
setMinutes: setMinutes,
setMainIncidents: setMainIncidents,
arrangeIncidents: arrangeIncidents,
setScore: setScore,
};
}]);