Skip to content

Commit def54d7

Browse files
committed
Fix suboptimality chart
1 parent 588bffe commit def54d7

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

client/src/components/charts/SuboptimalityByAgentCountChart.tsx

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
} from "recharts";
1515
import { paper } from "theme";
1616
import { formatPercentage } from "utils/format";
17-
import _, { max, range } from "lodash";
17+
import _, { isNil, max, range } from "lodash";
1818
import { accentColors, colors, tone } from "utils/colors";
1919

2020
export function SuboptimalityByAgentCountChart({
@@ -58,13 +58,20 @@ export function SuboptimalityByAgentCountChart({
5858

5959
return {
6060
isLoading: minQuery.isLoading || maxQuery.isLoading,
61-
data: range(agents).map((agent) => ({
62-
agentCount: agent,
63-
range: [
64-
minData[agent]?.result ?? 1, // default to 1 if missing
65-
maxData[agent]?.result ?? 1,
66-
],
67-
})),
61+
data: range(agents).flatMap((agent) => {
62+
if (
63+
!isNil(minData[agent]?.result) &&
64+
!isNil(maxData[agent]?.result)
65+
) {
66+
return [
67+
{
68+
agentCount: agent,
69+
range: [minData[agent]?.result, maxData[agent]?.result],
70+
},
71+
];
72+
}
73+
return [];
74+
}),
6875
};
6976
},
7077
});

server/src/query/queries.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,12 @@ const createAggregateBase =
103103
result: operations[o](
104104
filters[f]("$solution_cost", "$lower_cost"),
105105
v === "suboptimality"
106-
? { $divide: ["$solution_cost", { $max: ["$lower_cost", 1] }] }
106+
? {
107+
$divide: [
108+
{ $subtract: ["$solution_cost", "$lower_cost"] },
109+
{ $max: ["$lower_cost", 1] },
110+
],
111+
}
107112
: `$${v}`,
108113
),
109114
});

0 commit comments

Comments
 (0)