Skip to content

Commit

Permalink
Fix cropping of max damage on discrete probability graphs
Browse files Browse the repository at this point in the history
## Fixes

- Fix for the max damage of a profile was being forced to 0 when creating the discrete probability graphs
  • Loading branch information
damonhook authored May 22, 2020
1 parent f9da7f3 commit 79375c9
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 5 deletions.
4 changes: 3 additions & 1 deletion api/controllers/statsController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,17 @@ export default class StatsController {

private buildSimulationResult(data: TMappedResult): ISimulationResult {
const unitNames = Object.keys(data.results);
const metrics = this.buildSimulationMetrics(data);
const maxDamage = Math.max(...Object.keys(metrics.max).map((name) => metrics.max[name]));
const mappedProbabilities = Object.keys(data.results).reduce<TMappedProbabilities>((acc, name) => {
data.results[name].buckets.forEach(({ damage, probability }) => {
if (damage > maxDamage) return;
if (acc[damage] == null) acc[damage] = {};
acc[damage][name] = probability;
});
return acc;
}, {});

const metrics = this.buildSimulationMetrics(data);
const discrete = this.buildDiscreteProbabilities(mappedProbabilities);
const cumulative = this.buildCumulativeProbabilities(mappedProbabilities, unitNames, metrics);
return { save: data.save, discrete, cumulative, metrics };
Expand Down
5 changes: 4 additions & 1 deletion api/models/unit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,10 @@ class Unit {
[...range(sampleMax + 1, max, step)].forEach((i) => {
buckets.push({ damage: i, count: 0, probability: 0 });
});
buckets.push({ damage: max, count: 0, probability: 0 });
if (sampleMax < max) {
buckets.push({ damage: max, count: 0, probability: 0 });
}
buckets.push({ damage: max + 1, count: 0, probability: 0 });

return buckets;
}
Expand Down
2 changes: 1 addition & 1 deletion client/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "statshammer",
"version": "2.1.1",
"version": "2.1.2",
"private": true,
"proxy": "http://localhost:5000/",
"dependencies": {
Expand Down
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
"*",
"."
],
"version": "2.1.1",
"version": "2.1.2",
"npmClient": "yarn"
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "statshammer-express",
"private": true,
"version": "2.1.1",
"version": "2.1.2",
"engines": {
"node": "12.16.3",
"yarn": "1.22.4"
Expand Down

0 comments on commit 79375c9

Please sign in to comment.