-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathloteria.html
223 lines (204 loc) · 6.59 KB
/
loteria.html
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
<!DOCTYPE html>
<html lang="en" data-theme="dark">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="description" content="JPS chances" />
<title>Chances y Lotería Nacional</title>
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/@picocss/pico@2/css/pico.classless.min.css"
/>
<script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/jstat@latest/dist/jstat.min.js"></script>
<script src="./minified-web.js"></script>
<script src="./applyTo.js"></script>
<script src="./sw-test.js"></script>
</head>
<body>
<main>
<article>
<h4>Series</h4>
<details>
<summary role="button">Histogram</summary>
<div id="his-ser"></div>
</details>
</article>
<article>
<h4>Numbers</h4>
<details>
<summary role="button">Histogram</summary>
<div id="his-num"></div>
</details>
<details>
<summary role="button">
Counts <span id="count"></span>
<span style="float: right">
<code>
<small
id="num-his"
title="Numbers distribution is normal if p-value > 0.05"
>
</small>
</code>
</span>
</summary>
<div id="cou-num"></div>
</details>
<table class="striped">
<thead>
<tr>
<th scope="col">Number</th>
<th scope="col">Count</th>
<th scope="col">Skip Chances</th>
<th scope="col">Skip Lotería</th>
<th scope="col">Skips Sum</th>
</tr>
</thead>
<tbody id="nums"></tbody>
</table>
</article>
<script defer>
const LEGEND = {
orientation: "h",
x: 0,
y: 1.2,
};
const formatNumber = (num) => (num < 10 ? `0${num}` : `${num}`);
(async () => {
let response = await fetch("./chances.json");
let json = await response.json();
let values = Object.keys(json)
.map(Number)
.sort((a, b) => b - a)
.map((key) => json[key]);
const chances = values.map(({ n }) => n).flat();
let sers = values.map(({ s }) => s).flat();
response = await fetch("./loterianacional.json");
json = await response.json();
values = Object.keys(json)
.map(Number)
.sort((a, b) => b - a)
.map((key) => json[key]);
const loteria = values.map(({ n }) => n).flat();
const nums = chances.concat(loteria);
sers = sers.concat(values.map(({ s }) => s).flat());
sers = sers.filter((ser) => ser > 0);
Plotly.newPlot(document.getElementById("his-num"), [
{ x: nums, type: "histogram", histnorm: "probability" },
{ legend: LEGEND },
]);
Plotly.newPlot(document.getElementById("his-ser"), [
{ x: sers, type: "histogram", histnorm: "probability" },
{ legend: LEGEND },
]);
const counts = {
nums: {},
sers: {},
};
const skips = {
cha: {},
lot: {},
};
for (let num = 0; num < 100; ++num) {
counts.nums[num] = 0;
skips.cha[num] = chances.findIndex((n) => n === num);
skips.lot[num] = loteria.findIndex((n) => n === num);
}
for (let ser = 0; ser < 1000; ++ser) {
counts.sers[ser] = 0;
}
nums.forEach((num) => counts.nums[num]++);
sers.forEach((ser) => counts.sers[ser]++);
const orderNums = Object.entries(counts.nums).sort(
(a, b) => b[1] - a[1]
);
const x = orderNums.map((num) => formatNumber(Number(num[0])));
const y = orderNums.map((num) => num[1]);
const layout = {
legend: LEGEND,
xaxis: {
title: "Numbers",
type: "category",
tickmode: "array",
tickvals: x,
},
yaxis: {
title: "Count Numbers",
},
shapes: [
{
type: "line",
x0: -1,
x1: 100,
y0: 100,
y1: 100,
line: {
color: "green",
width: 1.5,
},
},
],
};
Plotly.newPlot(
document.getElementById("cou-num"),
[
{ x, y, name: "Counts", mode: "markers", type: "scatter" },
{
x,
y: x.map((n) => skips.cha[n]),
name: "Skips (chances)",
mode: "markers",
type: "scatter",
},
{
x,
y: x.map((n) => skips.lot[n]),
name: "Skips (lotería)",
mode: "markers",
type: "scatter",
},
],
layout
);
const count = Object.values(counts.nums).reduce((a, b) => a + b, 0);
window.applyTo("#count", "fill", EE("small", `(${count})`));
const sw = window.swTest(y, 0.05);
window.applyTo(
"#num-his",
"fill",
`p-value ~ ${Math.round(sw.pvalue * 100000) / 100000}`
);
const [q1, median, q3] = jStat.quartiles(y);
console.info(`[Q1: ${q1}, Median: ${median}, Q3: ${q3}]`);
const options = orderNums.filter((numCount) => {
return numCount[1] > q3;
});
options.forEach(([n, count]) => {
const num = Number(n);
const skipChs = skips.cha[n];
const skipLtr = skips.lot[n];
const skipsSum = skipChs + skipLtr;
if (skipChs > 100 && skipLtr > 100) {
window.applyTo(
"#nums",
"add",
EE("tr", [
EE("td", EE("mark", num)),
EE("td", count),
EE("td", skipChs),
EE("td", skipLtr),
EE("td", skipsSum),
])
);
}
});
// console.info([q1, median, q3]);
console.info(counts);
console.info(skips);
console.info(options);
})();
</script>
</main>
</body>
</html>