og-tools 0.0.1 → 0.0.3
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 +2 -2
- package/src/index.js +74 -7
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -1,11 +1,78 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
function comillas(d){
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
3
|
+
function comillas(d) {
|
|
4
|
+
try {
|
|
5
|
+
return d.replace(/'/g, " ").replace(/\s+/g, " ").trim();
|
|
6
|
+
} catch (error) {
|
|
7
|
+
return null;
|
|
8
|
+
}
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
function correlateTournaments(teamA, teamB) {
|
|
12
|
+
try {
|
|
13
|
+
const mapB = new Map();
|
|
14
|
+
|
|
15
|
+
// indexar torneos del equipo B
|
|
16
|
+
for (const t of teamB) {
|
|
17
|
+
mapB.set(t.uniqueTournament.id, t);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const result = [];
|
|
21
|
+
|
|
22
|
+
for (const tournamentA of teamA) {
|
|
23
|
+
const id = tournamentA.uniqueTournament.id;
|
|
24
|
+
|
|
25
|
+
if (!mapB.has(id)) continue;
|
|
26
|
+
|
|
27
|
+
const tournamentB = mapB.get(id);
|
|
28
|
+
|
|
29
|
+
// crear mapa de seasons del B por year
|
|
30
|
+
const seasonsB = new Map(
|
|
31
|
+
tournamentB.seasons.map(s => [s.year, s])
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
const sharedSeasons = [];
|
|
35
|
+
|
|
36
|
+
for (const seasonA of tournamentA.seasons) {
|
|
37
|
+
if (seasonsB.has(seasonA.year)) {
|
|
38
|
+
sharedSeasons.push({
|
|
39
|
+
year: seasonA.year,
|
|
40
|
+
seasonAId: seasonA.id,
|
|
41
|
+
seasonBId: seasonsB.get(seasonA.year).id
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (sharedSeasons.length > 0) {
|
|
47
|
+
result.push({
|
|
48
|
+
tournamentId: id,
|
|
49
|
+
tournamentName: tournamentA.uniqueTournament.name,
|
|
50
|
+
slug: tournamentA.uniqueTournament.slug,
|
|
51
|
+
seasons: sharedSeasons
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return result;
|
|
57
|
+
} catch (error) {
|
|
58
|
+
return { ok: false, error: { code: error.message, message: error.stack } };
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function singleTournamentCorrelate(data) {
|
|
63
|
+
|
|
64
|
+
return data.map(t => ({
|
|
65
|
+
name: t.uniqueTournament.name,
|
|
66
|
+
slug: t.uniqueTournament.slug,
|
|
67
|
+
id: t.uniqueTournament.id,
|
|
68
|
+
seasons: t.seasons
|
|
69
|
+
}));
|
|
70
|
+
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
module.exports = {
|
|
75
|
+
comillas,
|
|
76
|
+
correlateTournaments,
|
|
77
|
+
singleTournamentCorrelate
|
|
78
|
+
};
|