Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions backend/src/db/functions/noteworthy_matches.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,14 @@ def callback(session: SessionType):
matches.add_columns(
func.greatest(red_score_col, blue_score_col).label("max_score")
)
.order_by(desc("max_score"), asc(MatchORM.time)) # type: ignore
.order_by(desc("max_score").nullslast(), asc(MatchORM.time)) # type: ignore
.limit(30)
.all()
)

combined_score_matches = (
matches.add_columns((red_score_col + blue_score_col).label("sum_score")) # type: ignore
.order_by(desc("sum_score"), asc(MatchORM.time)) # type: ignore
.order_by(desc("sum_score").nullslast(), asc(MatchORM.time)) # type: ignore
.limit(30)
.all()
)
Expand All @@ -73,7 +73,7 @@ def callback(session: SessionType):
"losing_score"
),
)
.order_by(desc("losing_score"), asc(MatchORM.time)) # type: ignore
.order_by(desc("losing_score").nullslast(), asc(MatchORM.time)) # type: ignore
.limit(30)
.all()
)
Expand All @@ -86,7 +86,7 @@ def callback(session: SessionType):
"max_auto_score"
)
)
.order_by(desc("max_auto_score"), asc("time")) # type: ignore
.order_by(desc("max_auto_score").nullslast(), asc("time")) # type: ignore
.limit(30)
.all()
)
Expand All @@ -97,7 +97,7 @@ def callback(session: SessionType):
"max_teleop_score"
)
)
.order_by(desc("max_teleop_score"), asc("time")) # type: ignore
.order_by(desc("max_teleop_score").nullslast(), asc("time")) # type: ignore
.limit(30)
.all()
)
Expand All @@ -108,7 +108,7 @@ def callback(session: SessionType):
"max_endgame_score"
)
)
.order_by(desc("max_endgame_score"), asc("time")) # type: ignore
.order_by(desc("max_endgame_score").nullslast(), asc("time")) # type: ignore
.limit(30)
.all()
)
Expand Down
33 changes: 25 additions & 8 deletions frontend/src/api/storage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,14 @@ export function decompress(buffer: any) {
return data;
}

async function query(
const inFlight: { [storageKey: string]: Promise<any> } = {};

async function fetchAndStore(
storageKey: string,
apiPath: string,
checkBucket: boolean,
minLength: number,
expiry: number
) {
const cacheData = await getWithExpiry(storageKey);
if (cacheData && (minLength === 0 || cacheData?.length > minLength)) {
log(`Used Local Storage: ${storageKey}`);
return cacheData;
}

const start = performance.now();

let buffer = null;
Expand Down Expand Up @@ -85,4 +80,26 @@ async function query(
}
}

async function query(
storageKey: string,
apiPath: string,
checkBucket: boolean,
minLength: number,
expiry: number
) {
const cacheData = await getWithExpiry(storageKey);
if (cacheData && (minLength === 0 || cacheData?.length > minLength)) {
log(`Used Local Storage: ${storageKey}`);
return cacheData;
}

if (!inFlight[storageKey]) {
inFlight[storageKey] = fetchAndStore(storageKey, apiPath, checkBucket, expiry).finally(() => {
delete inFlight[storageKey];
});
}

return inFlight[storageKey];
}

export default query;
2 changes: 1 addition & 1 deletion frontend/src/pages/match/[match_id].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const InnerPage = () => {

useEffect(() => {
const fetchMatchData = async () => {
if (!match_id || data) return;
if (!match_id || data?.match?.key == match_id) return;

try {
const matchData = await getMatch(match_id as string);
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/pagesContent/event/[event_id]/simulation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ const SimulationSection = ({ eventId, data }: { eventId: string; data: EventData
rank: i + 1,
num: teamEvent.team,
team: teamEvent?.team_name,
epa: round(teamEvent?.epa?.total_points?.mean ?? 0, 1),
epa: round(teamEvent?.epa?.breakdown?.total_points ?? 0, 1),
rankMean: rankMean[teamEvent.team] ? round(rankMean[teamEvent.team], 2) : "",
rank5: rank5[teamEvent.team] ? round(rank5[teamEvent.team], 2) : "",
rank50: rank50[teamEvent.team] ? round(rank50[teamEvent.team], 2) : "",
Expand All @@ -158,7 +158,7 @@ const SimulationSection = ({ eventId, data }: { eventId: string; data: EventData
return {
num: teamEvent.team,
team: teamEvent?.team_name,
epa: round(teamEvent?.epa?.total_points?.mean ?? 0, 1),
epa: round(teamEvent?.epa?.breakdown?.total_points ?? 0, 1),
rankMean: rankMean[teamEvent.team] ? round(rankMean[teamEvent.team], 2) : "",
RPMean: RPMean[teamEvent.team] ? round(RPMean[teamEvent.team], 2) : "",
...probsObj,
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/pagesContent/event/[event_id]/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ async function _strengthOfSchedule(data: EventData, simCount: number, postEvent:
currTeamOpponents.length;

const deltaEPA = epaAvg + 2 * avgPartnerEPA - 3 * avgOpponentEPA;
const distrib = Gaussian(0, (epaSd * epaSd * 5) / N);
const distrib = Gaussian(0, (epaSd * epaSd * 5) / N || 1e-9);
const epaPercentile = 1 - distrib.cdf(deltaEPA);

const overallPercentile = (rankPercentile + rpPercentile + epaPercentile) / 3;
Expand Down
8 changes: 5 additions & 3 deletions frontend/src/pagesContent/match/[match_id]/imageRow.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use client";

import React, { useEffect, useState } from "react";
import React, { useEffect, useMemo, useState } from "react";

import Image from "next/image";

Expand All @@ -10,8 +10,10 @@ import { getMediaUrls } from "../../../utils";
const ImageRow = ({ data }: { data: MatchData }) => {
const [media, setMedia] = useState<string[] | null>(null);

const reverseBlue = [...data?.match?.alliances?.blue?.team_keys].reverse();
const teams = data?.match?.alliances?.red?.team_keys?.concat(reverseBlue);
const teams = useMemo(() => {
const reverseBlue = [...data?.match?.alliances?.blue?.team_keys].reverse();
return data?.match?.alliances?.red?.team_keys?.concat(reverseBlue);
}, [data]);
const year = data.year.year;

useEffect(() => {
Expand Down