Skip to content

Commit fd3c4a5

Browse files
committed
Fix issue of 0-length solutions being counted as 1
1 parent f77561d commit fd3c4a5

File tree

7 files changed

+24
-15
lines changed

7 files changed

+24
-15
lines changed

client/src/pages/visualiser/Visualisation.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ export function Visualisation({
269269
}
270270
}, [viewport, getAgentPositions, step, setSelection]);
271271

272-
const noVisualisation = !isLoading && (disablePlayback ? false : !timespan);
272+
const noVisualisation = !isLoading && (disablePlayback ? false : false);
273273

274274
// ─── Toggle Fullscreen ───────────────────────────────────────────────
275275

@@ -655,7 +655,7 @@ export function Visualisation({
655655
name: "Moving",
656656
value: proportionOf(
657657
getAgentPath(selection.agent),
658-
(p) => p.action !== "w",
658+
(p) => ["u", "d", "l", "r"].includes(p.action),
659659
),
660660
},
661661
{
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
export function proportionOf<T>(xs: T[], f: (x: T) => boolean): number {
2-
return xs.filter(f).length / xs.length;
2+
console.log(xs)
3+
return xs.length ? xs.filter(f).length / xs.length : 0;
34
}

client/src/pages/visualiser/useSolution.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ function createAgentPositionGetter(
103103
}
104104
);
105105

106-
const bs = paths.map((c) => processAgentSimple(c || "w"));
106+
const bs = paths.map((c) => processAgentSimple(c ?? ""));
107107
const getAgentPosition = memoize(
108108
(n: number): { action?: string; x: number; y: number }[] => {
109109
let t = 0;
@@ -113,8 +113,9 @@ function createAgentPositionGetter(
113113
[pick(last(path), "x", "y")],
114114
createOffsetMap(createActionMap(t, [bs[n]]), defaultOffsetMap)
115115
);
116-
if (!offset.x && !offset.y) continue;
117-
path.push({ ...offset, action: bs[n].seek(t) });
116+
if (offset.x || offset.y) {
117+
path.push({ ...offset, action: bs[n].seek(t) });
118+
}
118119
t++;
119120
}
120121
return path;

client/src/queries/useOngoingSubmissionQuery.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import {
1818
import { del, post } from "queries/mutation";
1919
import { json } from "queries/query";
2020

21-
const REFETCH_MS = 1000;
21+
const REFETCH_MS = 2500;
2222

2323
function mergeArray<T>(
2424
xs: T[],
@@ -145,6 +145,9 @@ const summaryPageCountQuery = (key?: string | number) => ({
145145
enabled: !!key,
146146
refetchInterval: REFETCH_MS,
147147
staleTime: 0,
148+
refetchOnReconnect: false,
149+
refetchOnMount: false,
150+
refetchOnWindowFocus: false,
148151
});
149152

150153
const MAX_TASKS = 4;
@@ -164,6 +167,8 @@ const summaryQuery = (key: string | number, i: number = 0) => ({
164167
-now(),
165168
),
166169
enabled: !!key,
170+
staleTime: 0,
171+
refetchInterval: REFETCH_MS,
167172
refetchOnReconnect: false,
168173
refetchOnMount: false,
169174
refetchOnWindowFocus: false,

server/src/controllers/solutionPath.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { RequestHandler } from "express";
2-
import { chunk, map, split, zipWith } from "lodash";
3-
import { OngoingSubmissionSolution, SolutionPath, Submission } from "models";
2+
import { chunk, map, split } from "lodash";
3+
import { OngoingSubmissionSolution, SolutionPath } from "models";
44
import { Types } from "mongoose";
5+
import { isDefined } from "utils/isDefined";
56
import { encode } from "validator";
67
import { z } from "zod";
78

@@ -14,7 +15,7 @@ export const getSolutionPath = async (
1415
) => {
1516
if (source === "ongoing") {
1617
const data = await OngoingSubmissionSolution.findOne({ _id: id });
17-
if (data?.solutions) {
18+
if (isDefined(data?.solutions)) {
1819
return split(data.solutions, "\n");
1920
}
2021
} else {

server/src/utils/isDefined.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export const isDefined = <T>(value: T | undefined | null): value is T => {
2+
return value !== undefined && value !== null;
3+
};

server/src/validation/submissionValidatorWorker.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ async function validateGroup({
162162
const timeStart = now();
163163
validate({
164164
domain: { cells, width, height },
165-
paths: solutions.map((s) => s || "w"),
165+
paths: solutions.map((s) => s ?? ""),
166166
sources: sources.slice(0, count),
167167
checks: [
168168
checkImmediateCollision,
@@ -240,8 +240,7 @@ function logOutcome(
240240
.value();
241241
if (mode === "comprehensive" && isInteger(a) && a > 0)
242242
log.warn(
243-
`Errors began on agent ${a}, it's possible that ${
244-
a - 1
243+
`Errors began on agent ${a}, it's possible that ${a - 1
245244
} agents constitutes a valid solution.`
246245
);
247246
return;
@@ -304,8 +303,7 @@ export async function run(data: SubmissionValidatorData[number]): Promise<{
304303
(await OngoingSubmissionSolution.findById(submission._id)) ?? {};
305304

306305
log.info(
307-
`Validating for ${mapMeta.map_name}-${scenarioMeta.scen_type}-${
308-
scenarioMeta.type_id
306+
`Validating for ${mapMeta.map_name}-${scenarioMeta.scen_type}-${scenarioMeta.type_id
309307
}, agent count ${solutions?.length ?? 0}.`
310308
);
311309

0 commit comments

Comments
 (0)