Skip to content
Merged
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ node_modules
dist
.DS_Store
.rdb
.vscode/
.vscode/
scripts/
134 changes: 96 additions & 38 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
"description": "",
"type": "module",
"scripts": {
"dev": "NODE_ENV=development tsx watch src/index.ts",
"dev": "NODE_ENV=development tsx watch src/server.ts",
"build": "tsc",
"start": "node dist/index.js",
"start": "node dist/server.js",
"test": "tsc",
"lint": "eslint .",
"format": "prettier --write ."
Expand Down
24 changes: 24 additions & 0 deletions src/app.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import express from "express";
import bodyParser from "body-parser";
import cookieParser from "cookie-parser";
import "dotenv/config";

import { setupExpressErrorHandler } from "posthog-node";
import { posthog } from "./posthogClient.js";
import posthogReporter from "./lib/middleware/posthogMiddleware.js";

import routes from "./routes/index.js";

export const app = express();

setupExpressErrorHandler(posthog, app);
app.set("trust proxy", true);

app.use(bodyParser.json());
app.use(cookieParser());

// Logs requests using posthog
app.use(posthogReporter);

// API entry point
app.use("/v1", routes);
5 changes: 4 additions & 1 deletion src/handler/analysis/alliancePredictions/alliancePage.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import z from "zod";
import { runAnalysis } from "../analysisFunction.js";
import { FlippedRoleMap, Metric } from "../analysisConstants.js";
import {
FlippedRoleMap,
Metric,
} from "../analysisConstants.js";
import { arrayAndAverageTeams } from "../coreAnalysis/arrayAndAverageTeams.js";
import { autoPathsTeam } from "../autoPaths/autoPathsTeam.js";
import { robotRole } from "../coreAnalysis/robotRole.js";
Expand Down
4 changes: 2 additions & 2 deletions src/handler/analysis/analysisHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
calculateAnalysis: (
params: AnalysisHandlerParams<T, U, V>,
ctx: AnalysisContext,
) => Promise<any>;

Check warning on line 42 in src/handler/analysis/analysisHandler.ts

View workflow job for this annotation

GitHub Actions / build (22.x)

Unexpected any. Specify a different type
usesDataSource: boolean;
shouldCache: boolean;
};
Expand Down Expand Up @@ -120,7 +120,7 @@
context,
);

res.set('X-Lovat-Cache','miss');
res.set("X-Lovat-Cache", "miss");
res.status(200).send(calculatedAnalysis.error ?? calculatedAnalysis);

try {
Expand All @@ -143,7 +143,7 @@
return;
}
} else {
res.set('X-Lovat-Cache','hit');
res.set("X-Lovat-Cache", "hit");
res.status(200).send(JSON.parse(cacheRow.toString()));
}
} catch (error) {
Expand Down
5 changes: 4 additions & 1 deletion src/handler/analysis/coreAnalysis/arrayAndAverageTeams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@
dataSourceRuleToPrismaFilter,
} from "../dataSourceRule.js";
import z from "zod";
import { runAnalysis, AnalysisFunctionConfig } from "../analysisFunction.js";
import {
runAnalysis,
AnalysisFunctionConfig,
} from "../analysisFunction.js";

// Accurately aggregate an analog metric on multiple teams at once (weighs matches equally regardless of extra scout reports).
// Provides a timeline of metric value per match.
Expand Down Expand Up @@ -337,7 +340,7 @@
export const arrayAndAverageTeams = async (
user: import("@prisma/client").User,
args: z.infer<typeof argsSchema>,
) => runAnalysis(config, user, args);

Check warning on line 343 in src/handler/analysis/coreAnalysis/arrayAndAverageTeams.ts

View workflow job for this annotation

GitHub Actions / build (22.x)

Missing return type on function

// Most recent is last
export function weightedTourAvgLeft(values: number[]): number {
Expand Down
5 changes: 4 additions & 1 deletion src/handler/analysis/coreAnalysis/averageManyFast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@
dataSourceRuleToPrismaFilter,
dataSourceRuleSchema,
} from "../dataSourceRule.js";
import { runAnalysis, AnalysisFunctionConfig } from "../analysisFunction.js";
import {
runAnalysis,
AnalysisFunctionConfig,
} from "../analysisFunction.js";
import { User } from "@prisma/client";

export interface ArrayFilter<T> {
Expand Down Expand Up @@ -280,7 +283,7 @@
export const averageManyFast = async (
user: User,
args: z.infer<typeof argsSchema>,
) => runAnalysis(config, user, args);

Check warning on line 286 in src/handler/analysis/coreAnalysis/averageManyFast.ts

View workflow job for this annotation

GitHub Actions / build (22.x)

Missing return type on function

export const getSourceFilter = <T>(
sources: T[],
Expand Down
5 changes: 4 additions & 1 deletion src/handler/analysis/coreAnalysis/averageScoutReport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
} from "../analysisConstants.js";
import { EventAction, Position, User } from "@prisma/client";
import z from "zod";
import { runAnalysis, AnalysisFunctionConfig } from "../analysisFunction.js";
import {
runAnalysis,
AnalysisFunctionConfig,
} from "../analysisFunction.js";

export async function computeAverageScoutReport(
scoutReportUuid: string,
Expand Down Expand Up @@ -110,11 +113,11 @@
args.scoutReportUuid,
args.metrics,
);
return result as any;

Check warning on line 116 in src/handler/analysis/coreAnalysis/averageScoutReport.ts

View workflow job for this annotation

GitHub Actions / build (22.x)

Unexpected any. Specify a different type
},
};

export const averageScoutReport = async (
user: User,
args: z.infer<typeof argsSchema>,
) => runAnalysis(config, user, args);

Check warning on line 123 in src/handler/analysis/coreAnalysis/averageScoutReport.ts

View workflow job for this annotation

GitHub Actions / build (22.x)

Missing return type on function
10 changes: 8 additions & 2 deletions src/handler/analysis/coreAnalysis/robotRole.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import z from "zod";
import { MetricsBreakdown } from "../analysisConstants.js";
import { nonEventMetric, NonEventMetricResult } from "./nonEventMetric.js";
import { runAnalysis, AnalysisFunctionConfig } from "../analysisFunction.js";
import {
nonEventMetric,
NonEventMetricResult,
} from "./nonEventMetric.js";
import {
runAnalysis,
AnalysisFunctionConfig,
} from "../analysisFunction.js";
import { User } from "@prisma/client";

const argsSchema = z.object({ team: z.number() });
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Response } from "express";
import prismaClient from "../../prismaClient.js";
import { AuthenticatedRequest } from "../../lib/middleware/requireAuth.js";
import prismaClient from "../../../prismaClient.js";
import { AuthenticatedRequest } from "../../../lib/middleware/requireAuth.js";
import { stringify } from "csv-stringify/sync";
import {
UserRole,
Expand All @@ -16,12 +16,15 @@ import {
TeamMatchData,
Event,
} from "@prisma/client";
import { autoEnd, endgameToPoints } from "../analysis/analysisConstants.js";
import {
autoEnd,
endgameToPoints,
} from "../analysisConstants.js";
import { z } from "zod";
import {
dataSourceRuleToPrismaFilter,
dataSourceRuleSchema,
} from "../analysis/dataSourceRule.js";
} from "../dataSourceRule.js";

// Scouting report condensed into a single dimension that can be pushed to a row in the csv
export interface CondensedReport {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Response } from "express";
import prismaClient from "../../prismaClient.js";
import { AuthenticatedRequest } from "../../lib/middleware/requireAuth.js";
import prismaClient from "../../../prismaClient.js";
import { AuthenticatedRequest } from "../../../lib/middleware/requireAuth.js";
import { stringify } from "csv-stringify/sync";
import {
UserRole,
Expand All @@ -14,12 +14,15 @@ import {
UnderShallowCage,
Event,
} from "@prisma/client";
import { autoEnd, endgameToPoints } from "../analysis/analysisConstants.js";
import {
autoEnd,
endgameToPoints,
} from "../analysisConstants.js";
import { z } from "zod";
import {
dataSourceRuleToPrismaFilter,
dataSourceRuleSchema,
} from "../analysis/dataSourceRule.js";
} from "../dataSourceRule.js";

interface AggregatedTeamData {
teamNumber: number;
Expand Down
Loading
Loading