og-tools 0.0.6 → 0.0.8

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/index.js +62 -17
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "og-tools",
3
- "version": "0.0.6",
3
+ "version": "0.0.8",
4
4
  "description": "",
5
5
  "main": "./src/index.js",
6
6
  "scripts": {
package/src/index.js CHANGED
@@ -60,33 +60,78 @@ async function correlateTournaments(teamA, teamB) {
60
60
 
61
61
  async function singleTournamentCorrelate(data) {
62
62
 
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
- }));
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
72
  function scoreRatio(calificacion) {
73
- const n = Math.round(Number(calificacion) * 100);
73
+ const n = Math.round(Number(calificacion) * 100);
74
74
 
75
- if (Number.isNaN(n)) return '?';
75
+ if (Number.isNaN(n)) return '?';
76
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 "🔵";
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
83
 
84
- return null;
84
+ return null;
85
85
  }
86
86
 
87
+ function DaysBetween(ts1, ts2) {
88
+ if (ts1 == null || ts2 == null) return 0;
89
+
90
+ const n1 = Number(ts1);
91
+ const n2 = Number(ts2);
92
+
93
+ if (isNaN(n1) || isNaN(n2)) return 0;
94
+ if (n1 === 0 || n2 === 0) return 0;
95
+
96
+ const diferencia = Math.abs(n2 - n1);
97
+ return Math.floor(diferencia / (60 * 60 * 24));
98
+ }
99
+
100
+ function Distance(location1, location2, unit = 'km') {
101
+ try {
102
+ const RADIO_TIERRA = { km: 6371, mi: 3958.8, m: 6371000 };
103
+
104
+ if (!RADIO_TIERRA[unit]) {
105
+ throw new Error(`Unidad no válida: "${unit}". Usa 'km', 'mi' o 'm'.`);
106
+ }
107
+
108
+ const toRad = (deg) => (deg * Math.PI) / 180;
109
+
110
+ const dLat = toRad(location2.lat - location1.lat);
111
+ const dLon = toRad(location2.lon - location1.lon);
112
+
113
+ const a =
114
+ Math.sin(dLat / 2) ** 2 +
115
+ Math.cos(toRad(location1.lat)) *
116
+ Math.cos(toRad(location2.lat)) *
117
+ Math.sin(dLon / 2) ** 2;
118
+
119
+ const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
120
+
121
+ // return parseFloat((RADIO_TIERRA[unit] * c).toFixed(4));
122
+ return Math.round(RADIO_TIERRA[unit] * c);
123
+
124
+ } catch (e) {
125
+ return { ok: false, error: { code: e.message, message: e.stack } };
126
+ }
127
+ }
128
+
129
+
87
130
  module.exports = {
88
- comillas,
131
+ comillas, // Reemplaza ' por spaces en string
89
132
  correlateTournaments,
90
133
  singleTournamentCorrelate,
91
- scoreRatio
134
+ scoreRatio, // Recibe una calificacion (6.62) y lo convierte en patrón emoji 🟡
135
+ Distance, // Calcula la distancia entre dos ubicaciones
136
+ DaysBetween, // Calcula el numero de días entre dos fechas
92
137
  };