og-statistics 3.0.3 → 3.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/index.js +47 -8
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -109,22 +109,26 @@ function filterIncidents(incidents) {
|
|
|
109
109
|
const home_cards = filterCards(incidents.incidents, true);
|
|
110
110
|
const home_goals = filterGoals(incidents.incidents, true);
|
|
111
111
|
const home_subs = filterSubs(incidents.incidents, true);
|
|
112
|
+
const home_penalties = filterPenalties(incidents.incidents, true);
|
|
112
113
|
|
|
113
114
|
const away = incidents.incidents.filter(s => s.isHome === false);
|
|
114
115
|
const away_cards = filterCards(incidents.incidents, false);
|
|
115
116
|
const away_goals = filterGoals(incidents.incidents, false);
|
|
116
117
|
const away_subs = filterSubs(incidents.incidents, false);
|
|
118
|
+
const away_penalties = filterPenalties(incidents.incidents, false);
|
|
117
119
|
|
|
118
120
|
return {
|
|
119
121
|
home: {
|
|
120
122
|
cards: home_cards,
|
|
121
123
|
goals: home_goals,
|
|
122
|
-
subs: home_subs
|
|
124
|
+
subs: home_subs,
|
|
125
|
+
penalties: home_penalties
|
|
123
126
|
},
|
|
124
127
|
away: {
|
|
125
128
|
cards: away_cards,
|
|
126
129
|
goals: away_goals,
|
|
127
|
-
subs: away_subs
|
|
130
|
+
subs: away_subs,
|
|
131
|
+
penalties: away_penalties
|
|
128
132
|
},
|
|
129
133
|
full:{
|
|
130
134
|
home: home,
|
|
@@ -137,6 +141,20 @@ function filterIncidents(incidents) {
|
|
|
137
141
|
}
|
|
138
142
|
}
|
|
139
143
|
|
|
144
|
+
function filterPenalties(incidents, isHome) {
|
|
145
|
+
let scored = incidents.filter(s => s.isHome === isHome && s.incidentType === 'goal' && s.incidentClass === 'penalty');
|
|
146
|
+
let failed = incidents.filter(s => s.isHome === isHome && s.incidentType === 'inGamePenalty' && s.incidentClass === 'missed');
|
|
147
|
+
|
|
148
|
+
return {
|
|
149
|
+
all: scored.length + failed.length,
|
|
150
|
+
scored: scored.length,
|
|
151
|
+
failed: failed.length
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
//
|
|
140
158
|
const CARD_CLASSES = ['red', 'yellow', 'yellowRed'];
|
|
141
159
|
|
|
142
160
|
const filterCards = (incidents, isHome) => {
|
|
@@ -148,9 +166,9 @@ const filterCards = (incidents, isHome) => {
|
|
|
148
166
|
const st = all.filter(s => s.time > 45);
|
|
149
167
|
|
|
150
168
|
acc[cardClass] = {
|
|
151
|
-
all: all,
|
|
152
|
-
ft: ft,
|
|
153
|
-
st: st,
|
|
169
|
+
all: all.length,
|
|
170
|
+
ft: ft.length,
|
|
171
|
+
st: st.length,
|
|
154
172
|
};
|
|
155
173
|
|
|
156
174
|
return acc;
|
|
@@ -167,9 +185,9 @@ const filterGoals = (incidents, isHome) => {
|
|
|
167
185
|
const teamIncidents = incidents.filter(s => s.isHome === isHome && s.incidentType === 'goal');
|
|
168
186
|
|
|
169
187
|
const goles = GOAL_CLASSES.reduce((acc, cls) => {
|
|
170
|
-
const
|
|
188
|
+
const fulltime = teamIncidents.filter(s => s.incidentClass === cls);
|
|
171
189
|
|
|
172
|
-
acc[cls] =
|
|
190
|
+
acc[cls] = fulltime.length;
|
|
173
191
|
|
|
174
192
|
return acc
|
|
175
193
|
}, {});
|
|
@@ -437,4 +455,25 @@ function goalSummary(incidentsData, windowMinutes = 15) {
|
|
|
437
455
|
}
|
|
438
456
|
}
|
|
439
457
|
|
|
440
|
-
|
|
458
|
+
function pointAverage(jugadores) {
|
|
459
|
+
|
|
460
|
+
if (!Array.isArray(jugadores) || jugadores.length === 0) {
|
|
461
|
+
return '--';
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
let suma = 0;
|
|
465
|
+
let conteo = 0;
|
|
466
|
+
|
|
467
|
+
for (const j of jugadores) {
|
|
468
|
+
const s = j?.statistics;
|
|
469
|
+
|
|
470
|
+
if (s?.minutesPlayed > 0 && Number.isFinite(s.rating)) {
|
|
471
|
+
suma += s.rating;
|
|
472
|
+
conteo++;
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
return conteo ? Math.round((suma / conteo) * 100) / 100 : 0;
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
module.exports = { filterStats, filterIncidents, goalSummary, pointAverage };
|