Skip to content
Open
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 package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"start": "node dist/src/server.js --omit=dev",
"test": "tsc",
"lint": "eslint .",
"format": "prettier --write ."
"format": "prettier --write .",
"import-all-matches": "tsx src/runImportAllTournaments.ts"
},
"keywords": [],
"author": "",
Expand Down
113 changes: 104 additions & 9 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
generator client {
provider = "prisma-client-js"
engineType = "binary"
provider = "prisma-client-js"
engineType = "binary"
}

datasource db {
Expand All @@ -26,14 +26,99 @@ model FeatureToggle {
enabled Boolean @default(true)
}

model TeamMatchData {
key String @id
model Match {
key String @id
tournamentKey String
matchNumber Int @db.SmallInt
teamNumber Int
matchType MatchType
scoutReports ScoutReport[]
tournament Tournament @relation(fields: [tournamentKey], references: [key], onDelete: Cascade)
year Int
compLevel MatchType
setNumber Int
matchNumber Int
scheduledTime DateTime?
actualTime DateTime?
redScore Int?
blueScore Int?
rawTba String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt

tournament Tournament @relation(fields: [tournamentKey], references: [key], onDelete: Cascade)
participants MatchParticipant[]
breakdowns OfficialAllianceBreakdown[]
videos MatchVideo[]

@@index([tournamentKey, compLevel, matchNumber])
}

model MatchParticipant {
matchKey String
teamNumber Int
alliance AllianceColor
station Int
teamMatchKey String? @unique

match Match @relation(fields: [matchKey], references: [key], onDelete: Cascade)
teamMatchData TeamMatchData? @relation(fields: [teamMatchKey], references: [key])

@@id([matchKey, teamNumber])
@@index([teamNumber])
}

model OfficialAllianceBreakdown {
matchKey String
alliance AllianceColor

// autoCoralCount Int?
// autoCoralPoints Int?
// teleopCoralCount Int?
// teleopCoralPoints Int?

// autoL1 Int?
// autoL2 Int?
// autoL3 Int?
// autoL4 Int?

// teleopL1 Int?
// teleopL2 Int?
// teleopL3 Int?
// teleopL4 Int?

isConsistent Boolean?
raw Json
fetchedAt DateTime @default(now())
updatedAt DateTime @updatedAt

match Match @relation(fields: [matchKey], references: [key], onDelete: Cascade)

@@id([matchKey, alliance])
}

model MatchVideo {
uuid String @id @default(uuid())
matchKey String
type String
externalKey String
createdAt DateTime @default(now())

match Match @relation(fields: [matchKey], references: [key], onDelete: Cascade)

@@unique([matchKey, type, externalKey])
@@index([matchKey])
}

enum AllianceColor {
RED
BLUE
}

model TeamMatchData {
key String @id
tournamentKey String
matchNumber Int @db.SmallInt
teamNumber Int
matchType MatchType
scoutReports ScoutReport[]
matchParticipant MatchParticipant?
tournament Tournament @relation(fields: [tournamentKey], references: [key], onDelete: Cascade)

@@index([tournamentKey, teamNumber])
}
Expand Down Expand Up @@ -197,6 +282,7 @@ model Tournament {
location String?
date String?
mutablePicklists MutablePicklist[]
matches Match[]
scouterScheduleShifts ScouterScheduleShift[]
teamMatchData TeamMatchData[]
latestFetchETag String?
Expand Down Expand Up @@ -234,6 +320,15 @@ model CachedAnalysis {
tournamentDependencies String[] @default([])
}

model DataFetch {
key String @id
etag String?
createdAt DateTime @default(now())
lastTried DateTime?
lastFetched DateTime?
data String?
}

enum Position {
LEFT_TRENCH
LEFT_BUMP
Expand Down
2 changes: 1 addition & 1 deletion railway.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"restartPolicyType": "ON_FAILURE",
"restartPolicyMaxRetries": 20,
"healthcheckPath": "/status",
"healthcheckTimeout": 1000
"healthcheckTimeout": 30000
},

"environments": {
Expand Down
7 changes: 7 additions & 0 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import posthogReporter from "./lib/middleware/posthogMiddleware.js";

import routes from "./routes/index.js";
import path from "path";
import importAllTournaments from "./lib/importAllTournaments.js";
import { requireAuth } from "./lib/middleware/requireAuth.js";

export const app = express();

Expand Down Expand Up @@ -44,3 +46,8 @@ app.use("/v1", routes); //theo was here
app.get("/status", (req, res) => {
res.status(200).send("Server running");
});

app.get("/import", requireAuth, async (req, res) => {
await importAllTournaments();
res.status(200).send("Import complete");
});
4 changes: 2 additions & 2 deletions src/handler/analysis/picklist/picklistShell.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import prismaClient from "../../../prismaClient.js";
import z from "zod";
import { addTournamentMatches } from "../../manager/addTournamentMatches.js";
import { importTournamentMatches } from "../../../lib/importTournamentMatches.js";
import {
Metric,
metricsCategory,
Expand Down Expand Up @@ -122,7 +122,7 @@ export const picklistShell = createAnalysisHandler({
},
});
if (!matches) {
await addTournamentMatches(query.tournamentKey);
await importTournamentMatches(query.tournamentKey);
}

// Teams to look at
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { User } from "@prisma/client";
import { alliancePage } from "./alliancePage.js";
import z from "zod";
import { runAnalysis } from "../analysisFunction.js";
import { addTournamentMatches } from "../../manager/addTournamentMatches.js";
import { importTournamentMatches } from "../../../lib/importTournamentMatches.js";

type TeamRanking = {
teamNumber: number;
Expand Down Expand Up @@ -46,7 +46,7 @@ const config = {
let matchesResponse = null;
let teamsResponse = null;

await addTournamentMatches(args.tournamentKey);
await importTournamentMatches(args.tournamentKey);

const url = "https://www.thebluealliance.com/api/v3";
try {
Expand Down
Loading
Loading