Skip to content

Commit

Permalink
fix findBestRun
Browse files Browse the repository at this point in the history
  • Loading branch information
roman-vorobiov committed Jan 10, 2025
1 parent d97036c commit fc1a031
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion evolve_analytics.meta.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// ==UserScript==
// @name Evolve Analytics
// @namespace http://tampermonkey.net/
// @version 0.10.6
// @version 0.10.7
// @description Track and see detailed information about your runs
// @author Sneed
// @match https://pmotschmann.github.io/Evolve/
Expand Down
12 changes: 8 additions & 4 deletions src/exports/historyFiltering.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,14 @@ export function applyFilters(history: HistoryManager, view: ViewConfig): History
return runs.reverse();
}

function findBestRunImpl(runs: HistoryEntry[]): HistoryEntry | undefined {
function findBestRunImpl(history: HistoryManager, view: ViewConfig): HistoryEntry | undefined {
let best: HistoryEntry | undefined = undefined;

for (const run of runs) {
for (const run of history.runs) {
if (!shouldIncludeRun(run, view, history)) {
continue;
}

if (best === undefined || runTime(run) < runTime(best)) {
best = run;
}
Expand All @@ -64,14 +68,14 @@ function findBestRunImpl(runs: HistoryEntry[]): HistoryEntry | undefined {

const bestRunCache: Record<string, HistoryEntry> = {};

export function findBestRun(runs: HistoryEntry[], view: ViewConfig): HistoryEntry | undefined {
export function findBestRun(history: HistoryManager, view: ViewConfig): HistoryEntry | undefined {
const cacheKey = `${view.resetType}.${view.universe ?? "*"}`;
const cacheEntry = bestRunCache[cacheKey];
if (cacheEntry !== undefined) {
return cacheEntry;
}

const best = findBestRunImpl(runs);
const best = findBestRunImpl(history, view);
if (best !== undefined) {
bestRunCache[cacheKey] = best;
}
Expand Down
2 changes: 1 addition & 1 deletion src/ui/graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ function* rectPointerMarks(plotPoints: PlotPoint[], history: HistoryEntry[], seg

export function makeGraph(history: HistoryManager, view: View, currentRun: LatestRun, onSelect: (run: HistoryEntry | null) => void) {
const filteredRuns = applyFilters(history, view);
const bestRun = findBestRun(filteredRuns, view);
const bestRun = findBestRun(history, view);

const milestones: string[] = Object.keys(view.milestones);

Expand Down

0 comments on commit fc1a031

Please sign in to comment.