TBA - Pulling in match schedule using TBA API

Is it possible to pull in the practice/qualification schedule using The Blue Alliance API? I am using the tabpy package.

tba.event_matches could give the list of matches/teams in a match and time (actual_time) but I am unsure if this will be available before the start of practice/qualifying.

Thanks in advance.

1 Like

I use the FIRST FRC API to get the schedule for the quals into our scouting app. For regular season events, it gets updated when the match schedule is released the morning of the first day of competition.

You can test by downloading schedules from last year’s events. The format shouldn’t be different this year.

The API documentation for schedules says that you can fetch practice, qualifier, or playoff match schedules, but last year I couldn’t get practice match schedules to work.

2 Likes

I filed a bug for this over a year ago but no luck on a response yet

2 Likes

I have used TBA to get the qualifier match schedule. It is usually posted there soon after First Event API has been updated. Once I see the match loading on the TBA website, I know I can retrieve the data. If I am only interested in the teams involved in the match, I just make the call to match simple.

…/api/v3/event/“eventkey”/matches/simple

1 Like

Below is the node.js script I wrote using the FRC (not TBA) schedule API specifically so that I could get the practice matches. The output is tab-delimited and looks like this:

Re-using schedule information stored in 2023OKTU_matches.json;
delete that file to force getting latest from FRC.
I found 127 matches for 2023 OKTU:
OKTU	Prep 1	Red	2333
OKTU	Prep 1	Red	3931
OKTU	Prep 1	Red	2972
OKTU	Prep 1	Blue	3465
OKTU	Prep 1	Blue	4613
OKTU	Prep 1	Blue	935
OKTU	Prep 2	Red	4646
OKTU	Prep 2	Red	1209
OKTU	Prep 2	Red	4005
...
const year = 2023
const event = 'OKTU'

const user = 'phrogz'
const authToken = 'your-auth-token-goes-here'

const fileToCacheResults = `${year}${event}_matches.json`
const apiKey = Buffer.from(`${user}:${authToken}`).toString('base64')
const base = 'https://frc-api.firstinspires.org/v3.0'
const opts = {method:'GET', headers: {'Authorization':`Basic ${apiKey}`}, redirect: 'follow'}

// If you don't want practice or playoff matches, remove them
const levels = ['Practice', 'Qualification', 'Playoff']

// Shorter names to show in the output
const aliases = {'Practice':'Prep', 'Qualification':'Qual', 'Playoff':'Match'}

const fs = require('fs')
const fetch = require('node-fetch')

async function findMyMatches() {
	let eventMatches
	if (fs.existsSync(fileToCacheResults)) {
		console.log(`Re-using schedule information stored in ${fileToCacheResults};\ndelete that file to force getting latest from FRC.`)
		eventMatches = JSON.parse(fs.readFileSync(fileToCacheResults, {encoding:'utf8'}))
	} else {
		console.log(`Fetching schedule information from FRC and storing in ${fileToCacheResults}.`)
		let promises = levels.map(level => scheduleForLevel(level))
		const schedules = await Promise.all(promises)
		eventMatches = schedules.flat()
		fs.writeFileSync(fileToCacheResults, JSON.stringify(eventMatches))
	}
	console.log(`I found ${eventMatches.length} matches for ${year} ${event}:`)
	eventMatches.forEach(match => {
		const prefix = [event, `${aliases[match.tournamentLevel]} ${match.matchNumber}`]
		match.teams.forEach(team => {
			console.log([...prefix, team.station.replace(/\d+/,''), team.teamNumber].join('\t'))
		})
	})
}

async function scheduleForLevel(level) {
	const response = await fetch(`${base}/${year}/schedule/${event}?tournamentLevel=${level}`, opts)
	const data = await response.json()
	return data.Schedule
}

findMyMatches()

I assume you couldn’t actually get the practice matches from the API either? The only source for practice match schedules is the FIRST FRC Events website as far as I can tell.

My workaround is to parse the HTML source code from a page on their site. Because I don’t want to be seen as automatically scraping it, I required somebody view the source in their browser, and copy it in.

I assume you couldn’t actually get the practice matches from the API either?

I was unable to see a way to get practice matches from The Blue Alliance API (or from their web page). However, the FRC API does allow fetching the schedule for practice matches. Worked for me to query the 2023 schedule; the schedule for our 2024 Week 1 event has not yet been published on FRC (or TBA).

For example, querying
https://frc-api.firstinspires.org/v3.0/2024/schedule/OKTU?tournamentLevel=Practice
yields (processed) results that start with:

OKTU	Prep 1	Red	2333
OKTU	Prep 1	Red	3931
OKTU	Prep 1	Red	2972
OKTU	Prep 1	Blue	3465
OKTU	Prep 1	Blue	4613
OKTU	Prep 1	Blue	935

which matches the data seen here:

This was fixed as of a few weeks ago- thanks FIRST!

2 Likes

This is huge for scouting apps! I know what I’m going to be working on tonight. Fetching practice match data from the API!

So, TBA does not store practice information or matches. If you really want to use that for scouting you’ll need to query the official API.

Also a word of caution - to use the TBA API you need to request an API Key - a Read API Key. There have been a number of requests for Write API keys which, obviously, won’t be approved.

You can get free Read API keys here: https://www.thebluealliance.com/account

Here are a few things I was told about this that might be useful for anyone planning on consuming this data:

  • Unlike Quals, team lists for practice matches can change when filler teams are added into FMS. The response will include filler teams, not scheduled teams, after they are entered.
  • I haven’t verified this, but I was told the API still rejects requests for match results/score data for practice matches. This is because many practice matches are run without referees at all so the scores will frequently be wrong. If this is something you would like anyway, I recommend filing a separate bug for this
1 Like

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.