og-tools 0.0.5 → 0.0.7
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 +69 -7
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -60,18 +60,80 @@ async function correlateTournaments(teamA, teamB) {
|
|
|
60
60
|
|
|
61
61
|
async function singleTournamentCorrelate(data) {
|
|
62
62
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
63
|
+
return data.map(t => ({
|
|
64
|
+
name: t.uniqueTournament.name,
|
|
65
|
+
slug: t.uniqueTournament.slug,
|
|
66
|
+
id: t.uniqueTournament.id,
|
|
67
|
+
seasons: t.seasons
|
|
68
|
+
}));
|
|
69
69
|
|
|
70
70
|
}
|
|
71
71
|
|
|
72
|
+
function scoreRatio(calificacion) {
|
|
73
|
+
const n = Math.round(Number(calificacion) * 100);
|
|
74
|
+
|
|
75
|
+
if (Number.isNaN(n)) return '?';
|
|
76
|
+
|
|
77
|
+
if (n < 600) return "🔴";
|
|
78
|
+
if (n < 650) return "🟠";
|
|
79
|
+
if (n < 700) return "🟡";
|
|
80
|
+
if (n < 800) return "🟢";
|
|
81
|
+
if (n < 900) return "💠";
|
|
82
|
+
if (n <= 1000) return "🔵";
|
|
83
|
+
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function DaysBetween(timestamp1, timestamp2) {
|
|
88
|
+
try {
|
|
89
|
+
if(parseInt(timestamp1) === 0 || parseInt(timestamp1) === 0) return 0;
|
|
90
|
+
const ms1 = parseInt(timestamp1) * 1000;
|
|
91
|
+
const ms2 = parseInt(timestamp2) * 1000;
|
|
92
|
+
|
|
93
|
+
const diferencia = Math.abs(ms2 - ms1);
|
|
94
|
+
const dias = Math.floor(diferencia / (1000 * 60 * 60 * 24));
|
|
95
|
+
|
|
96
|
+
return dias;
|
|
97
|
+
} catch (e) {
|
|
98
|
+
return { ok: false, error: { code: e.message, message: e.stack } };
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function Distance(location1, location2, unit = 'km') {
|
|
103
|
+
try {
|
|
104
|
+
const RADIO_TIERRA = { km: 6371, mi: 3958.8, m: 6371000 };
|
|
105
|
+
|
|
106
|
+
if (!RADIO_TIERRA[unit]) {
|
|
107
|
+
throw new Error(`Unidad no válida: "${unit}". Usa 'km', 'mi' o 'm'.`);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const toRad = (deg) => (deg * Math.PI) / 180;
|
|
111
|
+
|
|
112
|
+
const dLat = toRad(location2.lat - location1.lat);
|
|
113
|
+
const dLon = toRad(location2.lon - location1.lon);
|
|
114
|
+
|
|
115
|
+
const a =
|
|
116
|
+
Math.sin(dLat / 2) ** 2 +
|
|
117
|
+
Math.cos(toRad(location1.lat)) *
|
|
118
|
+
Math.cos(toRad(location2.lat)) *
|
|
119
|
+
Math.sin(dLon / 2) ** 2;
|
|
120
|
+
|
|
121
|
+
const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
|
|
122
|
+
|
|
123
|
+
// return parseFloat((RADIO_TIERRA[unit] * c).toFixed(4));
|
|
124
|
+
return Math.round(RADIO_TIERRA[unit] * c);
|
|
125
|
+
|
|
126
|
+
} catch (e) {
|
|
127
|
+
return { ok: false, error: { code: e.message, message: e.stack } };
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
72
131
|
|
|
73
132
|
module.exports = {
|
|
74
133
|
comillas,
|
|
75
134
|
correlateTournaments,
|
|
76
|
-
singleTournamentCorrelate
|
|
135
|
+
singleTournamentCorrelate,
|
|
136
|
+
scoreRatio,
|
|
137
|
+
Distance, // Calcula la distancia entre dos ubicaciones
|
|
138
|
+
DaysBetween, // Calcula el numero de días entre dos fechas
|
|
77
139
|
};
|