Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #111: Match scouting errors for secondary robots #171

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
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});
}
Comment on lines +84 to +91
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like it should work, but I think this could potentially cause other errors to happen in stats pages- maybe we should abstract this code to a general getTeam function that can compensate for letter team keys.


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