Skip to content

Commit

Permalink
#111: Match scouting errors for secondary robots
Browse files Browse the repository at this point in the history
  • Loading branch information
JL102 committed Nov 13, 2023
1 parent 54cfca8 commit a1f295d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 10 deletions.
34 changes: 26 additions & 8 deletions primary/src/routes/scouting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ router.get('/match*', wrap(async (req, res) => {
return;
}

let matchKey = match_team_key.split('_').slice(0, 2).join('_');

// Retrieve match information & verify it exists
let match = await utilities.findOne('matches', {key: matchKey}, {}, {allowCache: true});
if (!match) throw new e.NotFoundError(res.msg('errors.noMatchFound', {matchKey}));

//check if there is already data for this match
// 2020-02-11, M.O'C: Renaming "scoringdata" to "matchscouting", adding "org_key": org_key,
let scoringdata: MatchScouting[] = await utilities.find('matchscouting', {'org_key': org_key, 'year' : eventYear, 'match_team_key': match_team_key}, {sort: {'order': 1}});
Expand Down Expand Up @@ -70,25 +76,37 @@ router.get('/match*', wrap(async (req, res) => {
{allowCache: true}
);


const images = await uploadHelper.findTeamImages(org_key, eventYear, teamKey);
const team: Team = await utilities.findOne('teams', {key: teamKey}, {}, {allowCache: true});

let team: Team;

// Check if team has a letter at the end, e.g. frc102B
let letterTeamMatch = /(frc\d+)[a-zA-Z]$/g.exec(teamKey);
// if so, just find the info for the team without the letter on the end (found w/ a capturing group1)
if (letterTeamMatch) {
team = await utilities.findOne('teams', {key: letterTeamMatch[1]}, {}, {allowCache: true});
}
else {
team = await utilities.findOne('teams', {key: teamKey}, {}, {allowCache: true});
}

if (!team) throw new e.UserError(req.msg('scouting.invalidTeam', {team: teamKey}));

let allianceLocale = (alliance.toLowerCase().startsWith('b')) ? req.msg('alliance.blueShort') : req.msg('alliance.redShort');
let title = `#${scoringdata[0]?.match_number} - ${teamKey.substring(3)} ${allianceLocale} | ${req.msg('scouting.match')}`;

let title = `#${match.match_number} - ${teamKey.substring(3)} ${allianceLocale} | ${req.msg('scouting.match')}`;
let heading = res.msg('scouting.matchHeading', {match: match.match_number, team: teamKey.substring(3)});

//render page
res.render('./scouting/match', {
title: title,
layout: layout,
key: match_team_key,
alliance: alliance,
answers: answers,
teamKey: teamKey,
images: images,
team: team,
heading,
answers,
teamKey,
images,
team,
});
}));

Expand Down
3 changes: 1 addition & 2 deletions primary/views/scouting/match.pug
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ block content
}
*/
script(src=`${fileRoot}/js/script-matchscouting.js?v=${functionVersion}`)
- var titleParts = key.split('_').map(key => key.replace(/\D/g, '')); // 2022mrcmp_qm77_frc102 to ['2022', '77', '102']
- var btnColor = alliance ? ((alliance.toLowerCase().startsWith('r')) ? "alliance-red" : "alliance-blue") : '';
p
if images && images.main
Expand All @@ -37,7 +36,7 @@ block content
br
h3
div(class=`${btnColor} w3-btn`)
span!=msg('scouting.matchHeading', {match: titleParts[1], team: titleParts[2]})
span!=heading
h5!=msgMarked('scouting.subheading', {team: team.nickname, city: team.city, state: team.state_prov})
p
form#matchform(name="matchform" class="w3-centered")
Expand Down

0 comments on commit a1f295d

Please sign in to comment.