Merge pull request #149 from mikebryant/rework-115

Chance by category and row
master
Mike Bryant 5 years ago committed by GitHub
commit e9ac7e3676
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -212,7 +212,7 @@
<thead>
<tr>
<th valign="bottom" data-i18n="patterns.pattern"></th>
<th valign="bottom" data-i18n="output.chance"></th>
<th colspan="2" valign="bottom" data-i18n="output.chance"></th>
<th valign="bottom" data-i18n="weekdays.sunday"></th>
<th colspan="2">
<div data-i18n="weekdays.monday"></div>

@ -846,14 +846,20 @@ function analyze_possibilities(sell_prices, first_buy, previous_pattern) {
poss.weekMax = Math.max(...weekMaxes);
}
category_totals = {}
for (let i of [0, 1, 2, 3]) {
category_totals[i] = generated_possibilities
.filter(value => value.pattern_number == i)
.map(value => value.probability)
.reduce((previous, current) => previous + current, 0);
}
for (let pos of generated_possibilities) {
pos.category_total_probability = category_totals[pos.pattern_number];
}
generated_possibilities.sort((a, b) => {
if (a.weekMax < b.weekMax) {
return 1;
} else if (a.weekMax > b.weekMax) {
return -1;
} else {
return 0;
}
return b.category_total_probability - a.category_total_probability || b.probability - a.probability;
});
global_min_max = [];

@ -256,9 +256,18 @@ const calculateOutput = function (data, first_buy, previous_pattern) {
}
let output_possibilities = "";
let analyzed_possibilities = analyze_possibilities(data, first_buy, previous_pattern);
previous_pattern_number = ""
for (let poss of analyzed_possibilities) {
var out_line = "<tr><td class='table-pattern'>" + poss.pattern_description + "</td>"
out_line += `<td>${Number.isFinite(poss.probability) ? ((poss.probability * 100).toPrecision(3) + '%') : '—'}</td>`;
if (previous_pattern_number != poss.pattern_number) {
previous_pattern_number = poss.pattern_number
pattern_count = analyzed_possibilities
.filter(val => val.pattern_number == poss.pattern_number)
.length
percentage_display = percent => Number.isFinite(percent) ? ((percent * 100).toPrecision(3) + '%') : '—'
out_line += `<td rowspan=${pattern_count}>${percentage_display(poss.category_total_probability)}</td>`;
}
out_line += `<td>${percentage_display(poss.probability)}</td>`;
for (let day of poss.prices.slice(1)) {
if (day.min !== day.max) {
out_line += `<td>${day.min} ${i18next.t("output.to")} ${day.max}</td>`;

Loading…
Cancel
Save