team4909 / 2018-Core

2018 Scouting Platform
MIT License
10 stars 3 forks source link

Implement Find Next Match #29

Closed roshanr10 closed 6 years ago

roshanr10 commented 6 years ago

Implement updateNextMatch() function https://github.com/FRCteam4909/The-Green-Alliance/blob/8afdb69669cb5c34387067e5265ead4cf23801b8/app/www/js/main.js#L92

Use templates.dashboard.config.team_number and TBA API calls. Just fetch all team matches and utilize a JS deep array sort.

roshanr10 commented 6 years ago

Use getTeamMatchesByYearSimple() from the TBA API client to get a list of all matches that the chosen team is at for the competition season.

Existing Match API Instance: https://github.com/FRCteam4909/The-Green-Alliance/blob/f849ce668c4971f8524d1ab83d73ace86e055cbb/app/www/js/main.js#L5

Following that, this call should give you data which contains an array of MatchSimple objects.

 matchApi.getTeamMatchesByYearSimple("frc"+4909, 2017,  {}, (err, data) => {});

Update this function to use templates.dashboard.config.team_number (team number) and config.season (year) instead of hardcoded values.


Delete this placeholder, should be taken care of err param from the API call. https://github.com/FRCteam4909/The-Green-Alliance/blob/f849ce668c4971f8524d1ab83d73ace86e055cbb/app/www/js/main.js#L93

Put lines 95-108 from the updateNextMatch() function into the callback from the API function, so it runs only after the response.

Once you have the data array, and verify !exists(err) (no error when trying to get data), iterate through the array and rewrite all the time properties on every object using the predictedTime, if available.

The predictedTime should be more accurate as those are recalculated(by TBA) based on delays as opposed to the official match schedule created at the start of the event.

Then, do an array.sort() based on time.

With the sorted array, choose the first one that's past the current time. Set templates.dashboard.config.metadata.event_match_key to the key of that match. If no match is past the current time, set templates.dashboard.config.api to false, so the system downgrades to allow manual team number entry.


Everything else should work with this once this is complete. You can test this by opening in a browser and typing any team number. Since we are using current date, you may not be getting any results. I'd suggest taking a random match from TBA, and creating a JS date object a few minutes prior to use instead of the current time for debugging. If all works well, you should see that match number, the teams in that match, the alliance station and what team you looked up.


Also config is set to 2017 for debugging right now, so you shouldn't have to worry about the year. https://github.com/FRCteam4909/The-Green-Alliance/blob/f849ce668c4971f8524d1ab83d73ace86e055cbb/app/www/config.js#L2