")`. Create a ```TBA``` object for usage with no constructors (better if parameters
35 | will be changed frequently) and a ```CTBA``` object for usage with constructors (better if parameters won't be changed frequently).
36 | For more information, visit the wiki at https://www.github.com/wdavies973/TBA-API-V3/wiki.
37 |
38 | # Android troubleshooting
39 | Make sure you have internet permissions declared in the manifest:
40 | ```java
41 |
42 |
43 | ```
44 |
45 | Make sure you run this line of code before calling any API commands:
46 | ```java
47 | StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitNetwork().build(); StrictMode.setThreadPolicy(policy);
48 | ```
49 |
50 | Make sure you make API calls in an ```AsyncTask```
51 |
52 | # Tutorial and Examples
53 | Find them at https://www.github.com/wdavies973/TBA-API-V3/wiki.
54 |
55 | # Future
56 | I plan on supporting this project continually since it's used extensively in my scouting app over at https://www.roblu.net.
57 | Any contributions are welcome, including bug reports, feature requests, or code contributions.
58 |
59 | # Other
60 | Report any bugs or suggestions to wdavies973@gmail.com
61 | If you'd like any more functionality as far as ways you can pull data, and what you can pull, let me know and I'll add it right away.
62 |
63 | # Roblu
64 | This API is used by my scouting app Roblu. It's an all-in-one solution for scouting.
65 | Check it out at: https://www.roblu.net
66 |
67 |
68 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | plugins {
2 | id 'java'
3 | id 'maven'
4 | }
5 | version '1.0.2'
6 | group "com.github.wdavies973"
7 |
8 | sourceCompatibility = 1.8
9 |
10 | // for JitPack
11 | task sourcesJar(type: Jar, dependsOn: classes) {
12 | classifier = 'sources'
13 | from sourceSets.main.allSource
14 | }
15 |
16 | task javadocJar(type: Jar, dependsOn: javadoc) {
17 | classifier = 'javadoc'
18 | from javadoc.destinationDir
19 | }
20 |
21 | artifacts {
22 | archives sourcesJar
23 | archives javadocJar
24 | }
25 |
26 | repositories {
27 | mavenCentral()
28 | maven { url 'https://jitpack.io' }
29 | }
30 |
31 | dependencies {
32 | testCompile group: 'junit', name: 'junit', version: '4.12'
33 | implementation fileTree(include: ['*.jar'], dir: 'libs')
34 | }
35 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/widavies/TBA-API-V3/4cea315d16811adfe8088e88d9553d52da97098b/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Wed Jul 05 20:22:15 CDT 2017
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.8-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn ( ) {
37 | echo "$*"
38 | }
39 |
40 | die ( ) {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Escape application args
158 | save ( ) {
159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160 | echo " "
161 | }
162 | APP_ARGS=$(save "$@")
163 |
164 | # Collect all arguments for the java command, following the shell quoting and substitution rules
165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166 |
167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169 | cd "$(dirname "$0")"
170 | fi
171 |
172 | exec "$JAVACMD" "$@"
173 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/libs/json-simple-1.1.1.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/widavies/TBA-API-V3/4cea315d16811adfe8088e88d9553d52da97098b/libs/json-simple-1.1.1.jar
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | rootProject.name = 'TBA-API-V3'
2 |
3 |
--------------------------------------------------------------------------------
/src/main/java/com/cpjd/main/CTBA.java:
--------------------------------------------------------------------------------
1 | package com.cpjd.main;
2 |
3 | import com.cpjd.models.APIStatus;
4 | import com.cpjd.models.districts.District;
5 | import com.cpjd.models.events.*;
6 | import com.cpjd.models.teams.Robot;
7 | import com.cpjd.models.matches.SMatch;
8 | import com.cpjd.models.teams.STeam;
9 | import com.cpjd.models.matches.Match;
10 | import com.cpjd.models.teams.Team;
11 | import com.cpjd.requests.*;
12 |
13 | /**
14 | * This is an alternative to the TBA class. It allows you to use constructors/getters/setters. For more information on this,
15 | * read the javadoc header for the TBA class.
16 | *
17 | * @since 1.0.0
18 | * @author Will Davies
19 | */
20 | @SuppressWarnings("unused")
21 | public class CTBA {
22 |
23 | /**
24 | * TBA District Key, eg 2016fim
25 | */
26 | private String districtKey;
27 | /**
28 | * TBA Team Key, eg frc254
29 | */
30 | private int number;
31 | /**
32 | * Page number of results to return, zero-indexed
33 | */
34 | private int pageNum;
35 | /**
36 | * TBA Event Key, eg 2016nytr
37 | */
38 | private String eventKey;
39 | /**
40 | * TBA Match Key, eg 2016nytr_qm1
41 | */
42 | private String matchKey;
43 | /**
44 | * Competition Year (or Season). Must be 4 digits.
45 | */
46 | private int year;
47 |
48 | private DistrictRequest dr;
49 | private EventRequest er;
50 | private MatchRequest mr;
51 | private OtherRequest or;
52 | private TeamRequest tr;
53 |
54 | public CTBA() {
55 | dr = new DistrictRequest();
56 | er = new EventRequest();
57 | mr = new MatchRequest();
58 | or = new OtherRequest();
59 | tr = new TeamRequest();
60 | }
61 |
62 | /**
63 | * Mirror of: /district/{district_key}/teams
64 | *
65 | * @return Team[] including a Team object for every team in the specified district
66 | */
67 | public Team[] getDistrictTeams() {
68 | return dr.getDistrictTeams(districtKey);
69 | }
70 |
71 | /**
72 | * Mirror of: /district/{district_key}/teams/simple
73 | *
74 | * @return STeam[] including a STeam object for every team in the specified district (simple model)
75 | */
76 | public STeam[] getDistrictSTeams() {
77 | return dr.getDistrictSTeams(districtKey);
78 | }
79 |
80 | /**
81 | * Mirror of: /district/{district_key}/teams/keys
82 | *
83 | * Gets a list of Team objects that competed in events in the given district.
84 | *
85 | * @return String[] containing all the team keys in this district
86 | */
87 | public String[] getDistrictTeamKeys() {
88 | return dr.getDistrictTeamKeys(districtKey);
89 | }
90 |
91 | /**
92 | * Mirror of: /district/{district_key}/events
93 | *
94 | * @return Event[] including an Event object for every event in the specified district
95 | */
96 | public Event[] getDistrictEvents() {
97 | return dr.getDistrictEvents(districtKey);
98 | }
99 |
100 | /**
101 | * Mirror of: /district/{district_key}/events/simple
102 | *
103 | * @return SEvent[] including an SEvent object for every event in the specified district (simple model)
104 | */
105 | public SEvent[] getDistrictSEvents() {
106 | return dr.getDistrictSEvents(districtKey);
107 | }
108 |
109 | /**
110 | * Mirror of: /district/{district_key}/events/keys
111 | *
112 | * Gets a list of Team objects that competed in events in the given district.
113 | *
114 | * @return String[] containing all the team keys in this district
115 | */
116 | public String[] getDistrictEventKeys() {
117 | return dr.getDistrictEventKeys(districtKey);
118 | }
119 |
120 | /**
121 | * Mirror of: /districts/{year}
122 | *
123 | * Gets a list of districts and their corresponding district key, for the given year.
124 | *
125 | * @return District[] containing a District for each active district in the specified year
126 | */
127 | public District[] getDistricts() {
128 | return dr.getDistricts(year);
129 | }
130 |
131 | /**
132 | * Mirror of: /event/{event_key}/teams
133 | *
134 | * Gets a list of Team objects that competed in the given event.
135 | *
136 | * @param eventKey TBA Event Key, eg 2016nytr
137 | * @return the Team[] array that this event includes
138 | */
139 | public Team[] getEventTeams(String eventKey) {
140 | return er.getEventTeams(eventKey);
141 | }
142 |
143 | /**
144 | * Mirror of: /event/{event_key}/teams/simple
145 | *
146 | * Gets a list of Team objects that competed in the given event.
147 | *
148 | * @param eventKey TBA Event Key, eg 2016nytr
149 | * @return the STeam[] array that this event includes (simple model)
150 | */
151 | public STeam[] getSEventTeams(String eventKey) {
152 | return er.getSEventTeams(eventKey);
153 | }
154 |
155 | /**
156 | * Mirror of: /event/{event_key}/teams/keys
157 | *
158 | * Gets a list of Team keys that competed in the given event.
159 | *
160 | * @param eventKey TBA Event Key, eg 2016nytr
161 | * @return String[] containing all the team keys in this event
162 | */
163 | public String[] getEventTeamKeys(String eventKey) {
164 | return er.getTeamKeys(eventKey);
165 | }
166 |
167 | /**
168 | * Mirror of: /events/{year}
169 | *
170 | * Gets a list of events in the given year.
171 | *
172 | * @return Event[] containing all the events in the specified year
173 | */
174 | public Event[] getEvents() {
175 | return er.getEvents(year);
176 | }
177 |
178 | /**
179 | * Mirror of: /event/{event_key}/rankings
180 | *
181 | * @return EventRanking[] containing rankings of teams in this event
182 | */
183 | public EventRanking[] getEventRankings() { return er.getEventRankings(eventKey); }
184 |
185 | /**
186 | * Mirror of: /events/{year}/simple
187 | *
188 | * Gets a list of events in the given year.
189 | *
190 | * @return SEvent[] containing all the events in the specified year
191 | */
192 | public SEvent[] getSEvents() {
193 | return er.getSEvents(year);
194 | }
195 |
196 | /**
197 | * Mirror of: /events/{year}/keys
198 | *
199 | * Gets a list of event keys in the given year.
200 | *
201 | * @return String[] containing event keys for the specified year
202 | */
203 | public String[] getEventKeys() {
204 | return er.getEventKeys(year);
205 | }
206 |
207 | /**
208 | * Mirror of: /event/{event_key}
209 | *
210 | * Gets an Event.
211 | *
212 | * @return Event model representing the event associated with the event key
213 | */
214 | public Event getEvent() {
215 | return er.getEvent(eventKey);
216 | }
217 |
218 | /**
219 | * Mirror of: /event/{event_key}/simple
220 | *
221 | * Gets an Event.
222 | *
223 | * @return Event model representing the event associated with the event key
224 | */
225 | public SEvent getSEvent() {
226 | return er.getSEvent(eventKey);
227 | }
228 |
229 | /**
230 | * Mirror of: /event/{event_key}/oprs
231 | *
232 | * Gets a set of Event OPRs (including OPR, DPR, and CCWM) for the given Event.
233 | * @return EventOPR[] containing an EventOPR for each team
234 | */
235 | public EventOPR[] getOprs() {
236 | return er.getOprs(eventKey);
237 | }
238 |
239 | /**
240 | * Mirror of: /event/{event_key}/predictions
241 | *
242 | * Gets information on TBA-generated predictions for the given Event. Contains year-specific information. WARNING This endpoint is currently under development and may change at any time.
243 | *
244 | * Not stable! No official model for this yet.
245 | * @return JSON String containing prediction information
246 | */
247 | public String getPredictions() {
248 | return er.getPredictions(eventKey);
249 | }
250 |
251 | /**
252 | * Mirror of: /event/{event_key}/matches
253 | *
254 | * Gets a list of matches for the given event.
255 | * @return Match[] containing a Match object for each match in the specified event
256 | */
257 | public Match[] getMatches() {
258 | return er.getMatches(eventKey);
259 | }
260 |
261 | /**
262 | * Mirror of: /event/{event_key}/matches/simple
263 | *
264 | * Gets a list of matches for the given event.
265 | * @return Match[] containing a Match object for each match in the specified event
266 | */
267 | public SMatch[] getSMatches() {
268 | return er.getSMatches(eventKey);
269 | }
270 |
271 |
272 | /**
273 | * Mirror of: /event/{event_key}/matches/keys
274 | *
275 | * GGets a list of match keys for the given event.
276 | * @return String[] containing matches keys for the specified event
277 | */
278 | public String[] getMatchKeys() {
279 | return er.getMatchKeys(eventKey);
280 | }
281 |
282 | /**
283 | * Mirror of: /event/{event_key}/awards
284 | *
285 | * Gets a list of awards from the given event.
286 | * @return Award[] containing all the awards won in this event
287 | */
288 | public Award[] getEventAwards() {
289 | return er.getEventAwards(eventKey);
290 | }
291 |
292 | /**
293 | * Mirror of: /match/{match_key}
294 | *
295 | * Gets a Match object for the given match key.
296 | * @return Match object represented by the match key
297 | */
298 | public Match getMatch() {
299 | return mr.getMatch(matchKey);
300 | }
301 |
302 | /**
303 | * Mirror of: /match/{match_key}/simple
304 | *
305 | * Gets a Match object for the given match key.
306 | * @return SMatch object represented by the match key (simple model)
307 | */
308 | public SMatch getSMatch() {
309 | return mr.getSMatch(matchKey);
310 | }
311 |
312 | /**
313 | * Returns API status, and TBA status information.
314 | * @return APIStatus representing the state of the TBA API interface
315 | */
316 | public APIStatus getStatus() {
317 | return or.getStatus();
318 | }
319 |
320 | /**
321 | * Makes a custom call to the URL
322 | * @param URL the URL suffix to make a call to, this API automatically fills in Constants.URL for you, so an example parameter here might be 'teams/{page_num}'
323 | * @return an Object (json formatted), representing the data received from the server
324 | */
325 | public Object customCall(String URL) {
326 | return or.customCall(URL);
327 | }
328 |
329 | /**
330 | * Mirror of: /teams/{page_num}
331 | *
332 | * Gets a list of Team objects, paginated in groups of 500.
333 | * @return list of Team objects (full team models)
334 | */
335 | public Team[] getTeams() {
336 | return tr.getTeams(pageNum);
337 | }
338 |
339 | /**
340 | * Mirror of: /teams/{page_num}/simple
341 | *
342 | * Gets a list of STeam objects, paginated in groups of 500.
343 | * @return list of STeam objects (simple team models)
344 | */
345 | public STeam[] getSTeams() {
346 | return tr.getSTeams(pageNum);
347 | }
348 |
349 | /**
350 | * Mirror of: /teams/{page_num}/keys
351 | *
352 | * Gets a list of Team keys, paginated in groups of 500. (Note, each page will not have 500 teams, but will include the teams within that range of 500.)
353 | * @return String[] of team keys in the format 'frc254'
354 | */
355 | public String[] getTeamKeys() {
356 | return tr.getTeamKeys(pageNum);
357 | }
358 |
359 | /**
360 | * Mirror of: /teams/{year}/{page_num}
361 | *
362 | * Gets a list of Team objects that competed in the given year, paginated in groups of 500.
363 | * @return list of Team objects (full models)
364 | */
365 | public Team[] getTeamsByPage() {
366 | return tr.getTeams(pageNum);
367 | }
368 |
369 | /**
370 | * Mirror of: /teams/{year}/{page_num}/simple
371 | *
372 | * Gets a list of Team objects that competed in the given year, paginated in groups of 500.
373 | * @return list of Team objects (simple models)
374 | */
375 | public STeam[] getSTeamsByPage() {
376 | return tr.getSTeams(year, pageNum);
377 | }
378 |
379 | /**
380 | * Mirror of: /team/{year}/{page_num}/keys
381 | *
382 | * Gets a list Team Keys that competed in the given year, paginated in groups of 500.
383 | * @return String[] of team keys in format 'frc254'
384 | */
385 | public String[] getTeamKeysByPage() {
386 | return tr.getTeamKeys(year, pageNum);
387 | }
388 |
389 | /**
390 | * Mirror of: /team/{team_key}
391 | *
392 | * Gets the specified team (full team model)
393 | * @return Team object (full model)
394 | */
395 | public Team getTeam() {
396 | return tr.getTeam(number);
397 | }
398 |
399 | /**
400 | * Mirror of: /team{team_key}/simple
401 | *
402 | * Gets the specified team (simple team model)
403 | * @return STeam object (simple model)
404 | */
405 | public STeam getSTeam() {
406 | return tr.getSTeam(number);
407 | }
408 |
409 | /**
410 | * Mirror of: /team/{team_key}/years_participated
411 | *
412 | * Returns an array containing the years that a particular team participated in FRC events
413 | * @return long[] containing years participated
414 | */
415 | public long[] getYearsParticipated() {
416 | return tr.getYearsParticipated(number);
417 | }
418 |
419 | /**
420 | * Mirror of: /team/{team_key}/districts
421 | *
422 | * Gets the districts this team was in, empty array if none
423 | * @return District[] containing a District object for each district this team was in
424 | */
425 | public String[] getTeamDistricts() {
426 | return tr.getTeamDistricts(number);
427 | }
428 |
429 | /**
430 | * Mirror of: /team{team_key}/robots
431 | *
432 | * Gets the robots that this team has had
433 | * @return Robot[] containing a Robot object for each robot this team has built
434 | */
435 | public Robot[] getRobots() {
436 | return tr.getRobots(number);
437 | }
438 |
439 | /**
440 | * Mirror of: /team/{team_key}/events
441 | *
442 | * Gets a list of all events this team has competed at.
443 | * @return Event[] containing an Event object for each event this team was in
444 | */
445 | public Event[] getTeamEvents() {
446 | return tr.getTeamEvents(number);
447 | }
448 |
449 | /**
450 | * Mirror of: /team/{team_key}/events/simple
451 | *
452 | * Gets a list of all events this team has competed at.
453 | * @return SEvent[] containing an Event object for each event this team was in (simple model)
454 | */
455 | public SEvent[] getTeamSEvents() {
456 | return tr.getTeamSEvents(number);
457 | }
458 |
459 | /**
460 | * Mirror of: /team/{team_key}/events_keys
461 | *
462 | * Gets a list of the event keys for all events this team has competed at.
463 | * @return String[] containg all the event keys for events this team is in
464 | */
465 | public String[] getTeamEventKeys() {
466 | return tr.getTeamEventKeys(number);
467 | }
468 |
469 | /**
470 | * Mirror of: /team/{team_key}/events/{year}
471 | *
472 | * Gets a list of events this team has competed at in the given year.
473 | * @return Event[] containing an Event object for each event this team was in the specified year (full model)
474 | */
475 | public Event[] getTeamEventsByYear() {
476 | return tr.getEvents(number, year);
477 | }
478 |
479 | /**
480 | * Mirror of: /team/{team_key}/events/{year}/simple
481 | *
482 | * Gets a short-form list of events this team has competed at in the given year.
483 | * @return Event[] containing an Event object for each event this team was in the specified year (simple model)
484 | */
485 | public SEvent[] getTeamSEventsByYear() {
486 | return tr.getSEvents(number, year);
487 | }
488 |
489 | /**
490 | * Mirror of: /team/{team_key}/events/{year}/keys
491 | *
492 | * Gets a list of the event keys for events this team has competed at in the given year.
493 | * @return String[] containing an event key for each event this team has participated in
494 | */
495 | public String[] getTeamEventKeysByYear() {
496 | return tr.getEventKeys(number, year);
497 | }
498 |
499 | /**
500 | * Mirror of: /team/{team_key}/event/{event_key}/matches
501 | *
502 | * Gets a list of matches for the given team and event.
503 | * @return Match[] containing a match for each match this team was in in the specified event
504 | */
505 | public Match[] getTeamEventMatches() {
506 | return tr.getTeamEventMatches(number, eventKey);
507 | }
508 |
509 | /**
510 | * Mirror of: /team/{team_key}/event/{event_key}/matches/simple
511 | *
512 | * Gets a short-form list of matches for the given team and event.
513 | * @return SMatch[] containing a match for each match this team was in in the specified event (simple model)
514 | */
515 | public SMatch[] getTeamEventSMatches() {
516 | return tr.getTeamEventSMatches(number, eventKey);
517 | }
518 |
519 | /**
520 | * Mirror of: /team/{team_key}/event/{event_key}/matches/keys
521 | *
522 | * Gets a list of the event keys for events this team has competed at in the given year.
523 | * @return String[] containing an event key for each event this team has participated in
524 | */
525 | public String[] getTeamMatchKeysByEvent() {
526 | return tr.getMatchKeys(number, eventKey);
527 | }
528 |
529 | /**
530 | * Mirror of: /team/{team_key}/event/{event_key}/awards
531 | *
532 | * Gets a list of awards the given team won at the given event.
533 | * @return Award[] containing n award object for each award this team won in the specified event
534 | */
535 | public Award[] getTeamEventAwards() {
536 | return tr.getTeamEventAwards(number, eventKey);
537 | }
538 |
539 | /**
540 | * Mirror of: /team/{team_key}/awards
541 | *
542 | * Gets a list of awards the given team has won.
543 | * @return Award[] containing all the awards this team has won
544 | */
545 | public Award[] getTeamAwardsByNumber() {
546 | return tr.getTeamAwards(number);
547 | }
548 |
549 | /**
550 | * Mirror of: /team/{team_key}/awards/{year}
551 | *
552 | * Gets a list of awards the given team has won.
553 | * @return Award[] containing all the awards this team has won
554 | */
555 | public Award[] getTeamAwards() {
556 | return tr.getTeamAwards(number, year);
557 | }
558 |
559 | /**
560 | * Mirror of: /team/{team_key}/matches/{year}
561 | *
562 | * Gets a list of matches for the given team and year.
563 | * @return Match[] containing all the matches the specified team was in for the specified year
564 | */
565 | public Match[] getTeamMatches() {
566 | return tr.getTeamMatches(number, year);
567 | }
568 |
569 | /**
570 | * Mirror of: /team/{team_key}/matches/{year}/simple
571 | *
572 | * Gets a list of matches for the given team and year.
573 | * @return SMatch[] containing all the matches the specified team was in for the specified year (simple models)
574 | */
575 | public SMatch[] getTeamSMatches() {
576 | return tr.getTeamSMatches(number, year);
577 | }
578 |
579 | /**
580 | * Mirror of: /team/{team_key}/matches/{year}/keys
581 | *
582 | * Gets a list of match keys for matches for the given team and year.
583 | * @return String[] containing match string keys for each match
584 | */
585 | public String[] getTeamMatchKeys() {
586 | return tr.getTeamMatchKeys(number, year);
587 | }
588 |
589 | /**
590 | * Mirror of: /team/{team_key}/media/{year}
591 | *
592 | * Gets a list of Media (videos / pictures) for the given team and year.
593 | * @return Media[] containing all the media associated with this team for the specified year
594 | */
595 | public Media[] getTeamMedia() {
596 | return tr.getTeamMedia(number, year);
597 | }
598 |
599 | /**
600 | * Mirror of: /team/{team_key}/social_media
601 | *
602 | * Gets a list of Media (social media) for the given team.
603 | * @return Media[] containing all social media associated with this team
604 | */
605 | public Media[] getTeamSocialMedia() {
606 | return tr.getTeamSocialMedia(number);
607 | }
608 |
609 | /**
610 | * Mirror of: /event/{event_key}/alliances
611 | *
612 | * @return List of all alliances in this event
613 | */
614 | public Alliance[] getEventAlliances() {
615 | return er.getEventAlliances(eventKey);
616 | }
617 |
618 | /**
619 | * Mirror of: /event/{event_key}/insights
620 | *
621 | * @return Insights for this event
622 | */
623 | public Insight getEventInsights() {
624 | return er.getEventInsights(eventKey);
625 | }
626 |
627 | public void setDistrictKey(String districtKey) {
628 | this.districtKey = districtKey;
629 | }
630 |
631 | public void setNumber(int number) {
632 | this.number = number;
633 | }
634 |
635 | public void setPageNum(int pageNum) {
636 | this.pageNum = pageNum;
637 | }
638 |
639 | public void setEventKey(String eventKey) {
640 | this.eventKey = eventKey;
641 | }
642 |
643 | public void setMatchKey(String matchKey) {
644 | this.matchKey = matchKey;
645 | }
646 |
647 | public void setYear(int year) {
648 | this.year = year;
649 | }
650 |
651 | public void setDr(DistrictRequest dr) {
652 | this.dr = dr;
653 | }
654 |
655 | public void setEr(EventRequest er) {
656 | this.er = er;
657 | }
658 |
659 | public void setMr(MatchRequest mr) {
660 | this.mr = mr;
661 | }
662 |
663 | public void setOr(OtherRequest or) {
664 | this.or = or;
665 | }
666 |
667 | public void setTr(TeamRequest tr) {
668 | this.tr = tr;
669 | }
670 |
671 | public String getDistrictKey() {
672 | return districtKey;
673 | }
674 |
675 | public int getNumber() {
676 | return number;
677 | }
678 |
679 | public int getPageNum() {
680 | return pageNum;
681 | }
682 |
683 | public String getEventKey() {
684 | return eventKey;
685 | }
686 |
687 | public String getMatchKey() {
688 | return matchKey;
689 | }
690 |
691 | public int getYear() {
692 | return year;
693 | }
694 |
695 | public DistrictRequest getDr() {
696 | return dr;
697 | }
698 |
699 | public EventRequest getEr() {
700 | return er;
701 | }
702 |
703 | public MatchRequest getMr() {
704 | return mr;
705 | }
706 |
707 | public OtherRequest getOr() {
708 | return or;
709 | }
710 |
711 | public TeamRequest getTr() {
712 | return tr;
713 | }
714 | }
715 |
--------------------------------------------------------------------------------
/src/main/java/com/cpjd/main/Constants.java:
--------------------------------------------------------------------------------
1 | package com.cpjd.main;
2 |
3 | /**
4 | * @since 1.0.0
5 | * @author Will Davies
6 | */
7 | public class Constants {
8 |
9 | /**
10 | * The base URL for all com.cpjd.requests
11 | */
12 | public static String URL = "https://www.thebluealliance.com/api/v3/";
13 |
14 | /**
15 | * This is your TBA authentication token obtained from the accounts section on the website.
16 | * This is needed for all read API com.cpjd.requests
17 | */
18 | public static String AUTH_TOKEN;
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/src/main/java/com/cpjd/main/TBA.java:
--------------------------------------------------------------------------------
1 | package com.cpjd.main;
2 |
3 | import com.cpjd.models.APIStatus;
4 | import com.cpjd.models.districts.District;
5 | import com.cpjd.models.events.*;
6 | import com.cpjd.models.teams.Robot;
7 |
8 | import com.cpjd.models.matches.SMatch;
9 | import com.cpjd.models.teams.STeam;
10 | import com.cpjd.models.matches.Match;
11 | import com.cpjd.models.teams.Team;
12 | import com.cpjd.requests.*;
13 | import com.cpjd.sorting.Sortable;
14 | import com.cpjd.sorting.SortingType;
15 | import com.cpjd.utils.IO;
16 | import com.cpjd.utils.exceptions.DataNotFoundException;
17 | import org.json.simple.JSONArray;
18 | import org.json.simple.JSONObject;
19 |
20 | import java.util.Arrays;
21 |
22 | /**
23 | * This is the com.cpjd.main interface for the API, let's talk about that.
24 | *
25 | * The actual API calls are organized by the type of request (district, event, match, team, other), which can be found
26 | * in the com.cpjd.requests package. Essentially, TBA is a single class that allows you to call every single method without having
27 | * to worry about what type it is. However, for debugging, it's nice to keep the actual API code organized by type.
28 | * You'll notice that TBA doesn't have any getters/setters/constructors for parameters, even though only a couple parameters are
29 | * shared across the entire API. There are several reasons for this, 1) to keep the Java implementation more consistent with the
30 | * online API 2) if you need to change parameters or input different ones for each method calls, it's nice to avoid having to
31 | * manually setting them with setters and the like. However, if you'd like a constructor/setter/getter implementation, check out the CTBA class.
32 | *
33 | * @since 1.0.0
34 | * @author Will Davies
35 | */
36 | @SuppressWarnings("unused")
37 | public class TBA {
38 |
39 | private DistrictRequest dr;
40 | private EventRequest er;
41 | private MatchRequest mr;
42 | private OtherRequest or;
43 | private TeamRequest tr;
44 |
45 | public TBA() {
46 | dr = new DistrictRequest();
47 | er = new EventRequest();
48 | mr = new MatchRequest();
49 | or = new OtherRequest();
50 | tr = new TeamRequest();
51 | }
52 |
53 | /**
54 | * Sets the authentication token for the API, required for all calls!
55 | * Obtain an auth token from your account page on thebluealliance.com
56 | * @param authToken the auth token to set
57 | */
58 | public static void setAuthToken(String authToken) {
59 | Constants.AUTH_TOKEN = authToken;
60 | }
61 |
62 | /*
63 | * Sorting functions
64 | */
65 |
66 | public static void sort(T[] array, SortingType type, boolean ascending) {
67 | Arrays.sort(array, (o1, o2) -> ascending ? o1.sort(type, ascending, o2) : o2.sort(type, ascending, o1));
68 | }
69 |
70 | public static void sort(T[] array) {
71 | sort(array, SortingType.DEFAULT, true);
72 | }
73 |
74 | public static void sort(T[] array, SortingType type) {
75 | sort(array, type, true);
76 | }
77 |
78 | /**
79 | * Mirror of: /district/{district_key}/teams
80 | *
81 | * @param districtKey TBA District Key, eg 2016fim
82 | * @return Team[] including a Team object for every team in the specified district
83 | */
84 | public Team[] getDistrictTeams(String districtKey) {
85 | return dr.getDistrictTeams(districtKey);
86 | }
87 |
88 | /**
89 | * Mirror of: /district/{district_key}/teams/simple
90 | *
91 | * @param districtKey TBA District Key, eg 2016fim
92 | * @return STeam[] including a STeam object for every team in the specified district (simple model)
93 | */
94 | public STeam[] getDistrictSTeams(String districtKey) {
95 | return dr.getDistrictSTeams(districtKey);
96 | }
97 |
98 | /**
99 | * Mirror of: /district/{district_key}/teams/keys
100 | *
101 | * Gets a list of Team objects that competed in events in the given district.
102 | *
103 | * @param districtKey TBA District Key, eg 2016fim
104 | * @return String[] containing all the team keys in this district
105 | */
106 | public String[] getDistrictTeamKeys(String districtKey) {
107 | return dr.getDistrictTeamKeys(districtKey);
108 | }
109 |
110 | /**
111 | * Mirror of: /district/{district_key}/events
112 | *
113 | * @param districtKey TBA District Key, eg 2016fim
114 | * @return Event[] including an Event object for every event in the specified district
115 | */
116 | public Event[] getDistrictEvents(String districtKey) {
117 | return dr.getDistrictEvents(districtKey);
118 | }
119 |
120 | /**
121 | * Mirror of: /district/{district_key}/events/simple
122 | *
123 | * @param districtKey TBA District Key, eg 2016fim
124 | * @return SEvent[] including an SEvent object for every event in the specified district (simple model)
125 | */
126 | public SEvent[] getDistrictSEvents(String districtKey) {
127 | return dr.getDistrictSEvents(districtKey);
128 | }
129 |
130 | /**
131 | * Mirror of: /district/{district_key}/events/keys
132 | *
133 | * Gets a list of Team objects that competed in events in the given district.
134 | *
135 | * @param districtKey TBA District Key, eg 2016fim
136 | * @return String[] containing all the team keys in this district
137 | */
138 | public String[] getDistrictEventKeys(String districtKey) {
139 | return dr.getDistrictEventKeys(districtKey);
140 | }
141 |
142 | /**
143 | * Mirror of: /districts/{year}
144 | *
145 | * Gets a list of districts and their corresponding district key, for the given year.
146 | *
147 | * @param year Competition Year (or Season). Must be 4 digits.
148 | * @return District[] containing a District for each active district in the specified year
149 | */
150 | public District[] getDistricts(int year) {
151 | return dr.getDistricts(year);
152 | }
153 |
154 | /**
155 | * Mirror of: /event/{event_key}/teams
156 | *
157 | * Gets a list of Team objects that competed in the given event.
158 | *
159 | * @param eventKey TBA Event Key, eg 2016nytr
160 | * @return the Team[] array that this event includes
161 | */
162 | public Team[] getEventTeams(String eventKey) {
163 | return er.getEventTeams(eventKey);
164 | }
165 |
166 | /**
167 | * Mirror of: /event/{event_key}/teams/simple
168 | *
169 | * Gets a list of Team objects that competed in the given event.
170 | *
171 | * @param eventKey TBA Event Key, eg 2016nytr
172 | * @return the STeam[] array that this event includes (simple model)
173 | */
174 | public STeam[] getSEventTeams(String eventKey) {
175 | return er.getSEventTeams(eventKey);
176 | }
177 |
178 | /**
179 | * Mirror of: /event/{event_key}/teams/keys
180 | *
181 | * Gets a list of Team keys that competed in the given event.
182 | *
183 | * @param eventKey TBA Event Key, eg 2016nytr
184 | * @return String[] containing all the team keys in this event
185 | */
186 | public String[] getTeamKeys(String eventKey) {
187 | return er.getTeamKeys(eventKey);
188 | }
189 |
190 | /**
191 | * Mirror of: /events/{year}
192 | *
193 | * Gets a list of events in the given year.
194 | *
195 | * @param year Competition Year (or Season). Must be 4 digits.
196 | * @return Event[] containing all the events in the specified year
197 | */
198 | public Event[] getEvents(int year) {
199 | return er.getEvents(year);
200 | }
201 |
202 | /**
203 | * Mirror of: /events/{year}/simple
204 | *
205 | * Gets a list of events in the given year.
206 | *
207 | * @param year Competition Year (or Season). Must be 4 digits.
208 | * @return SEvent[] containing all the events in the specified year
209 | */
210 | public SEvent[] getSEvents(int year) {
211 | return er.getSEvents(year);
212 | }
213 |
214 | /**
215 | * Mirror of: /events/{year}/keys
216 | *
217 | * Gets a list of event keys in the given year.
218 | *
219 | * @param year Competition Year (or Season). Must be 4 digits.
220 | * @return String[] containing event keys for the specified year
221 | */
222 | public String[] getEventKeys(int year) {
223 | return er.getEventKeys(year);
224 | }
225 |
226 | /**
227 | * Mirror of: /event/{event_key}
228 | *
229 | * Gets an Event.
230 | *
231 | * @param eventKey TBA Event Key, eg 2016nytr
232 | * @return Event model representing the event associated with the event key
233 | */
234 | public Event getEvent(String eventKey) {
235 | return er.getEvent(eventKey);
236 | }
237 |
238 | /**
239 | * Mirror of: /event/{event_key}/simple
240 | *
241 | * Gets an Event.
242 | *
243 | * @param eventKey TBA Event Key, eg 2016nytr
244 | * @return Event model representing the event associated with the event key
245 | */
246 | public SEvent getSEvent(String eventKey) {
247 | return er.getSEvent(eventKey);
248 | }
249 |
250 | /**
251 | * Mirror of: /event/{event_key}/oprs
252 | *
253 | * Gets a set of Event OPRs (including OPR, DPR, and CCWM) for the given Event.
254 | * @param eventKey TBA Event Key, eg 2016nytr
255 | * @return EventOPR[] containing an EventOPR for each team
256 | */
257 | public EventOPR[] getOprs(String eventKey) {
258 | return er.getOprs(eventKey);
259 | }
260 |
261 | /**
262 | * Mirror of: /event/{event_key}/predictions
263 | *
264 | * Gets information on TBA-generated predictions for the given Event. Contains year-specific information. WARNING This endpoint is currently under development and may change at any time.
265 | *
266 | * Not stable! No official model for this yet.
267 | * @param eventKey TBA Event Key, eg 2016nytr
268 | * @return JSON String containing prediction information
269 | */
270 | public String getPredictions(String eventKey) {
271 | return er.getPredictions(eventKey);
272 | }
273 |
274 | /**
275 | * Mirror of: /event/{event_key}/matches
276 | *
277 | * Gets a list of matches for the given event.
278 | * @param eventKey TBA Event Key, eg 2016nytr
279 | * @return Match[] containing a Match object for each match in the specified event
280 | */
281 | public Match[] getMatches(String eventKey) {
282 | return er.getMatches(eventKey);
283 | }
284 |
285 | /**
286 | * Mirror of: /event/{event_key}/matches/simple
287 | *
288 | * Gets a list of matches for the given event.
289 | * @param eventKey TBA Event Key, eg 2016nytr
290 | * @return Match[] containing a Match object for each match in the specified event
291 | */
292 | public SMatch[] getSMatches(String eventKey) {
293 | return er.getSMatches(eventKey);
294 | }
295 |
296 |
297 | /**
298 | * Mirror of: /event/{event_key}/matches/keys
299 | *
300 | * GGets a list of match keys for the given event.
301 | * @param eventKey TBA Event Key, eg 2016nytr
302 | * @return String[] containing matches keys for the specified event
303 | */
304 | public String[] getMatchKeys(String eventKey) {
305 | return er.getMatchKeys(eventKey);
306 | }
307 |
308 | /**
309 | * Mirror of: /event/{event_key}/awards
310 | *
311 | * Gets a list of awards from the given event.
312 | * @param eventKey TBA Event Key, eg 2016nytr
313 | * @return Award[] containing all the awards won in this event
314 | */
315 | public Award[] getEventAwards(String eventKey) {
316 | return er.getEventAwards(eventKey);
317 | }
318 |
319 | /**
320 | * Mirror of: /match/{match_key}
321 | *
322 | * Gets a Match object for the given match key.
323 | * @param matchKey TBA Match Key, eg 2016nytr_qm1
324 | * @return Match object represented by the match key
325 | */
326 | public Match getMatch(String matchKey) {
327 | return mr.getMatch(matchKey);
328 | }
329 |
330 | /**
331 | * Mirror of: /match/{match_key}/simple
332 | *
333 | * Gets a Match object for the given match key.
334 | * @param matchKey TBA Match Key, eg 2016nytr_qm1
335 | * @return SMatch object represented by the match key (simple model)
336 | */
337 | public SMatch getSMatch(String matchKey) {
338 | return mr.getSMatch(matchKey);
339 | }
340 |
341 | /**
342 | * Returns API status, and TBA status information.
343 | * @return APIStatus representing the state of the TBA API interface
344 | */
345 | public APIStatus getStatus() {
346 | return or.getStatus();
347 | }
348 |
349 | /**
350 | * Makes a custom call to the URL
351 | * @param URL the URL suffix to make a call to, this API automatically fills in Constants.URL for you, so an example parameter here might be 'teams/{page_num}'
352 | * @return an Object (json formatted), representing the data received from the server
353 | */
354 | public Object customCall(String URL) {
355 | return or.customCall(URL);
356 | }
357 |
358 | /**
359 | * Mirror of: /teams/{page_num}
360 | *
361 | * Gets a list of Team objects, paginated in groups of 500.
362 | * @param pageNum the page number, eg: 0 for the first 500, 1 for the second 500, etc.
363 | * @return list of Team objects (full team models)
364 | */
365 | public Team[] getTeams(int pageNum) {
366 | return tr.getTeams(pageNum);
367 | }
368 |
369 | /**
370 | * Mirror of: /teams/{page_num}/simple
371 | *
372 | * Gets a list of STeam objects, paginated in groups of 500.
373 | * @param pageNum the page number, eg: 0 for the first 500, 1 for the second 500, etc.
374 | * @return list of STeam objects (simple team models)
375 | */
376 | public STeam[] getSTeams(int pageNum) {
377 | return tr.getSTeams(pageNum);
378 | }
379 |
380 | /**
381 | * Mirror of: /teams/{page_num}/keys
382 | *
383 | * Gets a list of Team keys, paginated in groups of 500. (Note, each page will not have 500 teams, but will include the teams within that range of 500.)
384 | * @param pageNum the page number, eg: 0 for the first 500, 1 for the second 500, etc.
385 | * @return String[] of team keys in the format 'frc254'
386 | */
387 | public String[] getTeamKeys(int pageNum) {
388 | return tr.getTeamKeys(pageNum);
389 | }
390 |
391 | /**
392 | * Mirror of: /teams/{year}/{page_num}
393 | *
394 | * Gets a list of Team objects that competed in the given year, paginated in groups of 500.
395 | * @param year the year to get teams from
396 | * @param pageNum the page number, eg: 0 for the first 500, 1 for the second 500, etc.
397 | * @return list of Team objects (full models)
398 | */
399 | public Team[] getTeams(int year, int pageNum) {
400 | return tr.getTeams(year, pageNum);
401 | }
402 |
403 | /**
404 | * Mirror of: /teams/{year}/{page_num}/simple
405 | *
406 | * Gets a list of Team objects that competed in the given year, paginated in groups of 500.
407 | * @param year the year to get teams from
408 | * @param pageNum the page number, eg: 0 for the first 500, 1 for the second 500, etc.
409 | * @return list of Team objects (simple models)
410 | */
411 | public STeam[] getSTeams(int year, int pageNum) {
412 | return tr.getSTeams(year, pageNum);
413 | }
414 |
415 | /**
416 | * Mirror of: /team/{year}/{page_num}/keys
417 | *
418 | * Gets a list Team Keys that competed in the given year, paginated in groups of 500.
419 | * @param year the year to get teams from
420 | * @return String[] of team keys in format 'frc254'
421 | */
422 | public String[] getTeamKeys(int year, int pageNum) {
423 | return tr.getTeamKeys(year, pageNum);
424 | }
425 |
426 | /**
427 | * Mirror of: /team/{team_key}
428 | *
429 | * Gets the specified team (full team model)
430 | * @param number the team's frc number
431 | * @return Team object (full model)
432 | */
433 | public Team getTeam(int number) {
434 | return tr.getTeam(number);
435 | }
436 |
437 | /**
438 | * Mirror of: /team{team_key}/simple
439 | *
440 | * Gets the specified team (simple team model)
441 | * @param number the team's frc number
442 | * @return STeam object (simple model)
443 | */
444 | public STeam getSTeam(int number) {
445 | return tr.getSTeam(number);
446 | }
447 |
448 | /**
449 | * Mirror of: /team/{team_key}/years_participated
450 | *
451 | * Returns an array containing the years that a particular team participated in FRC events
452 | * @param number the team's frc number
453 | * @return long[] containing years participated
454 | */
455 | public long[] getYearsParticipated(int number) {
456 | return tr.getYearsParticipated(number);
457 | }
458 |
459 | /**
460 | * Mirror of: /team/{team_key}/districts
461 | *
462 | * Gets the districts this team was in, empty array if none
463 | * @param number the team's frc number
464 | * @return District[] containing a District object for each district this team was in
465 | */
466 | public String[] getTeamDistricts(int number) {
467 | return tr.getTeamDistricts(number);
468 | }
469 |
470 | /**
471 | * Mirror of: /team{team_key}/robots
472 | *
473 | * Gets the robots that this team has had
474 | * @param number the team's frc number
475 | * @return Robot[] containing a Robot object for each robot this team has built
476 | *
477 | *
478 | */
479 | public Robot[] getRobots(int number) {
480 | return tr.getRobots(number);
481 | }
482 |
483 | /**
484 | * Mirror of: /team/{team_key}/events
485 | *
486 | * Gets a list of all events this team has competed at.
487 | * @param number the team's frc number
488 | * @return Event[] containing an Event object for each event this team was in
489 | */
490 | public Event[] getTeamEvents(int number) {
491 | return tr.getTeamEvents(number);
492 | }
493 |
494 | /**
495 | * Mirror of: /team/{team_key}/events/simple
496 | *
497 | * Gets a list of all events this team has competed at.
498 | * @param number the team's frc number
499 | * @return SEvent[] containing an Event object for each event this team was in (simple model)
500 | */
501 | public SEvent[] getTeamSEvents(int number) {
502 | return tr.getTeamSEvents(number);
503 | }
504 |
505 | /**
506 | * Mirror of: /team/{team_key}/events_keys
507 | *
508 | * Gets a list of the event keys for all events this team has competed at.
509 | * @param number the team's frc number
510 | * @return String[] containg all the event keys for events this team is in
511 | */
512 | public String[] getTeamEventKeys(int number) {
513 | return tr.getTeamEventKeys(number);
514 | }
515 |
516 | /**
517 | * Mirror of: /team/{team_key}/events/{year}
518 | *
519 | * Gets a list of events this team has competed at in the given year.
520 | * @param number the team's frc number
521 | * @param year the year to get events from
522 | * @return Event[] containing an Event object for each event this team was in the specified year (full model)
523 | */
524 | public Event[] getEvents(int number, int year) {
525 | return tr.getEvents(number, year);
526 | }
527 |
528 | /**
529 | * Mirror of: /team/{team_key}/events/{year}/simple
530 | *
531 | * Gets a short-form list of events this team has competed at in the given year.
532 | * @param number the team's frc number
533 | * @param year the year to get events from
534 | * @return Event[] containing an Event object for each event this team was in the specified year (simple model)
535 | */
536 | public SEvent[] getSEvents(int number, int year) {
537 | return tr.getSEvents(number, year);
538 | }
539 |
540 | /**
541 | * Mirror of: /team/{team_key}/events/{year}/keys
542 | *
543 | * Gets a list of the event keys for events this team has competed at in the given year.
544 | * @param number the team's frc number
545 | * @param year the year to get events from
546 | * @return String[] containing an event key for each event this team has participated in
547 | */
548 | public String[] getEventKeys(int number, int year) {
549 | return tr.getEventKeys(number, year);
550 | }
551 |
552 | /**
553 | * Mirror of: /team/{team_key}/event/{event_key}/matches
554 | *
555 | * Gets a list of matches for the given team and event.
556 | * @param number the team's frc number
557 | * @param eventKey the event's key code (example: '2016nytr')
558 | * @return Match[] containing a match for each match this team was in in the specified event
559 | */
560 | public Match[] getTeamEventMatches(int number, String eventKey) {
561 | return tr.getTeamEventMatches(number, eventKey);
562 | }
563 |
564 | /**
565 | * Mirror of: /event/{event_key}/rankings
566 | * @param eventKey the event's key code (example: '2016nytr')
567 | * @return EventRanking[] containing rankings of teams in this event
568 | */
569 | public EventRanking[] getEventRankings(String eventKey) {return er.getEventRankings(eventKey); }
570 |
571 | /**
572 | * Mirror of: /team/{team_key}/event/{event_key}/matches/simple
573 | *
574 | * Gets a short-form list of matches for the given team and event.
575 | * @param number the team's frc number
576 | * @param eventKey the event's key code (example: '2016nytr')
577 | * @return SMatch[] containing a match for each match this team was in in the specified event (simple model)
578 | */
579 | public SMatch[] getTeamEventSMatches(int number, String eventKey) {
580 | return tr.getTeamEventSMatches(number, eventKey);
581 | }
582 |
583 | /**
584 | * Mirror of: /team/{team_key}/event/{event_key}/matches/keys
585 | *
586 | * Gets a list of the event keys for events this team has competed at in the given year.
587 | * @param number the team's frc number
588 | * @param eventKey the event's key code (example: '2016nytr')
589 | * @return String[] containing an event key for each event this team has participated in
590 | */
591 | public String[] getMatchKeys(int number, String eventKey) {
592 | return tr.getMatchKeys(number, eventKey);
593 | }
594 |
595 | /**
596 | * Mirror of: /team/{team_key}/event/{event_key}/awards
597 | *
598 | * Gets a list of awards the given team won at the given event.
599 | * @param number the team's frc number
600 | * @param eventKey the event's key code (example: '2016nytr')
601 | * @return Award[] containing n award object for each award this team won in the specified event
602 | */
603 | public Award[] getTeamEventAwards(int number, String eventKey) {
604 | return tr.getTeamEventAwards(number, eventKey);
605 | }
606 |
607 | /**
608 | * Mirror of: /team/{team_key}/awards
609 | *
610 | * Gets a list of awards the given team has won.
611 | * @param number the team's frc number
612 | * @return Award[] containing all the awards this team has won
613 | */
614 | public Award[] getTeamAwards(int number) {
615 | return tr.getTeamAwards(number);
616 | }
617 |
618 | /**
619 | * Mirror of: /team/{team_key}/awards/{year}
620 | *
621 | * Gets a list of awards the given team has won.
622 | * @param number the team's frc number
623 | * @param year the year
624 | * @return Award[] containing all the awards this team has won
625 | */
626 | public Award[] getTeamAwards(int number, int year) {
627 | return tr.getTeamAwards(number, year);
628 | }
629 |
630 | /**
631 | * Mirror of: /team/{team_key}/matches/{year}
632 | *
633 | * Gets a list of matches for the given team and year.
634 | * @param number the team's frc number
635 | * @param year the year
636 | * @return Match[] containing all the matches the specified team was in for the specified year
637 | */
638 | public Match[] getTeamMatches(int number, int year) {
639 | return tr.getTeamMatches(number, year);
640 | }
641 |
642 | /**
643 | * Mirror of: /team/{team_key}/matches/{year}/simple
644 | *
645 | * Gets a list of matches for the given team and year.
646 | * @param number the team's frc number
647 | * @param year the year
648 | * @return SMatch[] containing all the matches the specified team was in for the specified year (simple models)
649 | */
650 | public SMatch[] getTeamSMatches(int number, int year) {
651 | return tr.getTeamSMatches(number, year);
652 | }
653 |
654 | /**
655 | * Mirror of: /team/{team_key}/matches/{year}/keys
656 | *
657 | * Gets a list of match keys for matches for the given team and year.
658 | * @param number the team's frc number
659 | * @param year the year to get match keys from
660 | * @return String[] containing match string keys for each match
661 | */
662 | public String[] getTeamMatchKeys(int number, int year) {
663 | return tr.getTeamMatchKeys(number, year);
664 | }
665 |
666 | /**
667 | * Mirror of: /team/{team_key}/media/{year}
668 | *
669 | * Gets a list of Media (videos / pictures) for the given team and year.
670 | * @param number the team's frc number
671 | * @param year the year
672 | * @return Media[] containing all the media associated with this team for the specified year
673 | */
674 | public Media[] getTeamMedia(int number, int year) {
675 | return tr.getTeamMedia(number, year);
676 | }
677 |
678 | /**
679 | * Mirror of: /team/{team_key}/social_media
680 | *
681 | * Gets a list of Media (social media) for the given team.
682 | * @param number the team's frc number
683 | * @return Media[] containing all social media associated with this team
684 | */
685 | public Media[] getTeamSocialMedia(int number) {
686 | return tr.getTeamSocialMedia(number);
687 | }
688 |
689 | /**
690 | * Mirror of: /event/{event_key}/alliances
691 | *
692 | * @param eventKey TBA Event Key, eg 2016nytr
693 | * @return List of all alliances in this event
694 | */
695 | public Alliance[] getEventAlliances(String eventKey) {
696 | return er.getEventAlliances(eventKey);
697 | }
698 |
699 | /**
700 | * Mirror of: /event/{event_key}/insights
701 | *
702 | * @param eventKey TBA Event Key, eg 2016nytr
703 | * @return Insights for this event
704 | */
705 | public Insight getEventInsights(String eventKey) {
706 | return er.getEventInsights(eventKey);
707 | }
708 | }
--------------------------------------------------------------------------------
/src/main/java/com/cpjd/models/APIStatus.java:
--------------------------------------------------------------------------------
1 | package com.cpjd.models;
2 |
3 | import java.io.Serializable;
4 | import java.util.Arrays;
5 |
6 | /**
7 | *
8 | * @since 1.0.0
9 | * @author Will Davies
10 | */
11 | public class APIStatus implements Serializable {
12 | /**
13 | * Year of the current FRC season.
14 | */
15 | private long currentSeason;
16 | /**
17 | * Maximum FRC season year for valid queries.
18 | */
19 | private long maxSeason;
20 | /**
21 | * True if the entire FMS API provided by FIRST is down.
22 | */
23 | private boolean isDatafeedDown;
24 | /**
25 | * An array of strings containing event keys of any active events that are no longer updating.
26 | */
27 | private String[] downEvents;
28 | private long iosMinAppVersion;
29 | private long iosLatestAppVersion;
30 | private long androidMinAppVersion;
31 | private long androidLatestAppVersion;
32 |
33 | public long getCurrentSeason() {
34 | return currentSeason;
35 | }
36 |
37 | public void setCurrentSeason(long currentSeason) {
38 | this.currentSeason = currentSeason;
39 | }
40 |
41 | public long getMaxSeason() {
42 | return maxSeason;
43 | }
44 |
45 | public void setMaxSeason(long maxSeason) {
46 | this.maxSeason = maxSeason;
47 | }
48 |
49 | public boolean isDatafeedDown() {
50 | return isDatafeedDown;
51 | }
52 |
53 | public void setDatafeedDown(boolean datafeedDown) {
54 | isDatafeedDown = datafeedDown;
55 | }
56 |
57 | public String[] getDownEvents() {
58 | return downEvents;
59 | }
60 |
61 | public void setDownEvents(String[] downEvents) {
62 | this.downEvents = downEvents;
63 | }
64 |
65 | public long getIosMinAppVersion() {
66 | return iosMinAppVersion;
67 | }
68 |
69 | public void setIosMinAppVersion(long iosMinAppVersion) {
70 | this.iosMinAppVersion = iosMinAppVersion;
71 | }
72 |
73 | public long getIosLatestAppVersion() {
74 | return iosLatestAppVersion;
75 | }
76 |
77 | public void setIosLatestAppVersion(long iosLatestAppVersion) {
78 | this.iosLatestAppVersion = iosLatestAppVersion;
79 | }
80 |
81 | public long getAndroidMinAppVersion() {
82 | return androidMinAppVersion;
83 | }
84 |
85 | public void setAndroidMinAppVersion(long androidMinAppVersion) {
86 | this.androidMinAppVersion = androidMinAppVersion;
87 | }
88 |
89 | public long getAndroidLatestAppVersion() {
90 | return androidLatestAppVersion;
91 | }
92 |
93 | public void setAndroidLatestAppVersion(long androidLatestAppVersion) {
94 | this.androidLatestAppVersion = androidLatestAppVersion;
95 | }
96 |
97 | @Override
98 | public String toString() {
99 | return "APIStatus{" +
100 | "currentSeason=" + currentSeason +
101 | ", maxSeason=" + maxSeason +
102 | ", isDatafeedDown=" + isDatafeedDown +
103 | ", downEvents=" + Arrays.toString(downEvents) +
104 | ", iosMinAppVersion=" + iosMinAppVersion +
105 | ", iosLatestAppVersion=" + iosLatestAppVersion +
106 | ", androidMinAppVersion=" + androidMinAppVersion +
107 | ", androidLatestAppVersion=" + androidLatestAppVersion +
108 | '}';
109 | }
110 | }
111 |
--------------------------------------------------------------------------------
/src/main/java/com/cpjd/models/districts/District.java:
--------------------------------------------------------------------------------
1 | package com.cpjd.models.districts;
2 |
3 | import com.cpjd.sorting.Sortable;
4 | import com.cpjd.sorting.SortingType;
5 |
6 | import java.io.Serializable;
7 |
8 | /**
9 | * @since 1.0.0
10 | * @author Will Davies
11 | */
12 | public class District extends Sortable implements Serializable {
13 | /**
14 | * The short identifier for the district.
15 | */
16 | private String abbreviation;
17 | /**
18 | * The long name for the district.
19 | */
20 | private String displayName;
21 | /**
22 | * Key for this district, e.g. 2016ne.
23 | */
24 | private String key;
25 | /**
26 | * Year this district participated.
27 | */
28 | private long year;
29 |
30 | @Override
31 | public int sort(SortingType type, boolean ascending, District t2) {
32 | if(type == SortingType.DEFAULT || type == SortingType.DATE) {
33 | return Long.compare(year, t2.getYear());
34 | } else if(type == SortingType.NAME) {
35 | return displayName.compareTo(t2.getDisplayName());
36 | }
37 |
38 | throw new RuntimeException("Unsupported sort type for model District.");
39 | }
40 |
41 | public String getAbbreviation() {
42 | return abbreviation;
43 | }
44 |
45 | public void setAbbreviation(String abbreviation) {
46 | this.abbreviation = abbreviation;
47 | }
48 |
49 | public String getDisplayName() {
50 | return displayName;
51 | }
52 |
53 | public void setDisplayName(String displayName) {
54 | this.displayName = displayName;
55 | }
56 |
57 | public String getKey() {
58 | return key;
59 | }
60 |
61 | public void setKey(String key) {
62 | this.key = key;
63 | }
64 |
65 | public long getYear() {
66 | return year;
67 | }
68 |
69 | public void setYear(long year) {
70 | this.year = year;
71 | }
72 |
73 |
74 | @Override
75 | public String toString() {
76 | return "District{" +
77 | "abbreviation='" + abbreviation + '\'' +
78 | ", displayName='" + displayName + '\'' +
79 | ", key='" + key + '\'' +
80 | ", year=" + year +
81 | '}';
82 | }
83 | }
84 |
--------------------------------------------------------------------------------
/src/main/java/com/cpjd/models/events/Alliance.java:
--------------------------------------------------------------------------------
1 | package com.cpjd.models.events;
2 |
3 | import com.cpjd.sorting.Sortable;
4 | import com.cpjd.sorting.SortingType;
5 |
6 | import java.util.Arrays;
7 |
8 | public class Alliance extends Sortable {
9 |
10 | private String name;
11 | private String backupOut;
12 | private String backupIn;
13 | private String[] declines;
14 | private String[] picks;
15 |
16 | /*
17 | * Status
18 | */
19 | private String status;
20 | private long currentLevelRecord_Losses;
21 | private long currentLevelRecord_Wins;
22 | private long currentLevelRecord_Ties;
23 | private String level;
24 | private double playoffAverage;
25 | private long recordLosses;
26 | private long recordWins;
27 | private long recordTies;
28 |
29 | @Override
30 | public int sort(SortingType type, boolean ascending, Alliance t2) {
31 | if(type == SortingType.DEFAULT || type == SortingType.NAME) {
32 | return name.compareTo(t2.getName());
33 | }
34 |
35 | throw new RuntimeException("Unsupported sort type for model Alliance");
36 | }
37 |
38 | public String getName() {
39 | return name;
40 | }
41 |
42 | public void setName(String name) {
43 | this.name = name;
44 | }
45 |
46 | public String getBackupOut() {
47 | return backupOut;
48 | }
49 |
50 | public void setBackupOut(String backupOut) {
51 | this.backupOut = backupOut;
52 | }
53 |
54 | public String getBackupIn() {
55 | return backupIn;
56 | }
57 |
58 | public void setBackupIn(String backupIn) {
59 | this.backupIn = backupIn;
60 | }
61 |
62 | public String[] getDeclines() {
63 | return declines;
64 | }
65 |
66 | public void setDeclines(String[] declines) {
67 | this.declines = declines;
68 | }
69 |
70 | public String[] getPicks() {
71 | return picks;
72 | }
73 |
74 | public void setPicks(String[] picks) {
75 | this.picks = picks;
76 | }
77 |
78 | public String getStatus() {
79 | return status;
80 | }
81 |
82 | public void setStatus(String status) {
83 | this.status = status;
84 | }
85 |
86 | public long getCurrentLevelRecord_Losses() {
87 | return currentLevelRecord_Losses;
88 | }
89 |
90 | public void setCurrentLevelRecord_Losses(long currentLevelRecord_Losses) {
91 | this.currentLevelRecord_Losses = currentLevelRecord_Losses;
92 | }
93 |
94 | public long getCurrentLevelRecord_Wins() {
95 | return currentLevelRecord_Wins;
96 | }
97 |
98 | public void setCurrentLevelRecord_Wins(long currentLevelRecord_Wins) {
99 | this.currentLevelRecord_Wins = currentLevelRecord_Wins;
100 | }
101 |
102 | public long getCurrentLevelRecord_Ties() {
103 | return currentLevelRecord_Ties;
104 | }
105 |
106 | public void setCurrentLevelRecord_Ties(long currentLevelRecord_Ties) {
107 | this.currentLevelRecord_Ties = currentLevelRecord_Ties;
108 | }
109 |
110 | public String getLevel() {
111 | return level;
112 | }
113 |
114 | public void setLevel(String level) {
115 | this.level = level;
116 | }
117 |
118 | public double getPlayoffAverage() {
119 | return playoffAverage;
120 | }
121 |
122 | public void setPlayoffAverage(double playoffAverage) {
123 | this.playoffAverage = playoffAverage;
124 | }
125 |
126 | public long getRecordLosses() {
127 | return recordLosses;
128 | }
129 |
130 | public void setRecordLosses(long recordLosses) {
131 | this.recordLosses = recordLosses;
132 | }
133 |
134 | public long getRecordWins() {
135 | return recordWins;
136 | }
137 |
138 | public void setRecordWins(long recordWins) {
139 | this.recordWins = recordWins;
140 | }
141 |
142 | public long getRecordTies() {
143 | return recordTies;
144 | }
145 |
146 | public void setRecordTies(long recordTies) {
147 | this.recordTies = recordTies;
148 | }
149 |
150 | @Override
151 | public String toString() {
152 | return "Alliance{" +
153 | "name='" + name + '\'' +
154 | ", backupOut='" + backupOut + '\'' +
155 | ", backupIn='" + backupIn + '\'' +
156 | ", declines=" + Arrays.toString(declines) +
157 | ", picks=" + Arrays.toString(picks) +
158 | ", status='" + status + '\'' +
159 | ", currentLevelRecord_Losses=" + currentLevelRecord_Losses +
160 | ", currentLevelRecord_Wins=" + currentLevelRecord_Wins +
161 | ", currentLevelRecord_Ties=" + currentLevelRecord_Ties +
162 | ", level='" + level + '\'' +
163 | ", playoffAverage=" + playoffAverage +
164 | ", recordLosses=" + recordLosses +
165 | ", recordWins=" + recordWins +
166 | ", recordTies=" + recordTies +
167 | '}';
168 | }
169 | }
170 |
--------------------------------------------------------------------------------
/src/main/java/com/cpjd/models/events/Award.java:
--------------------------------------------------------------------------------
1 | package com.cpjd.models.events;
2 |
3 | import java.io.Serializable;
4 | import java.util.Arrays;
5 |
6 | /**
7 | * @since 1.0.0
8 | * @author Will Davies
9 | */
10 | public class Award implements Serializable{
11 | /**
12 | * The name of the award as provided by FIRST. May vary for the same award type.
13 | */
14 | private String name;
15 | /**
16 | * SortingType of award given. See https://github.com/the-blue-alliance/the-blue-alliance/blob/master/consts/award_type.py#L6
17 | */
18 | private long awardType;
19 | /**
20 | * The event_key of the event the award was won at.
21 | */
22 | private String eventKey;
23 | /**
24 | * A list of recipients of the award at the event. Either team_key and/or awardee for individual awards.
25 | */
26 | private AwardRecipient[] recipients;
27 | /**
28 | * The year this award was won.
29 | */
30 | private long year;
31 |
32 | public String getName() {
33 | return name;
34 | }
35 |
36 | public void setName(String name) {
37 | this.name = name;
38 | }
39 |
40 | public long getAwardType() {
41 | return awardType;
42 | }
43 |
44 | public void setAwardType(long awardType) {
45 | this.awardType = awardType;
46 | }
47 |
48 | public String getEventKey() {
49 | return eventKey;
50 | }
51 |
52 | public void setEventKey(String eventKey) {
53 | this.eventKey = eventKey;
54 | }
55 |
56 | public AwardRecipient[] getRecipients() {
57 | return recipients;
58 | }
59 |
60 | public void setRecipients(AwardRecipient[] recipients) {
61 | this.recipients = recipients;
62 | }
63 |
64 | public long getYear() {
65 | return year;
66 | }
67 |
68 | public void setYear(long year) {
69 | this.year = year;
70 | }
71 |
72 | @Override
73 | public String toString() {
74 | return "Award{" +
75 | "name='" + name + '\'' +
76 | ", awardType=" + awardType +
77 | ", eventKey='" + eventKey + '\'' +
78 | ", recipients=" + Arrays.toString(recipients) +
79 | ", year=" + year +
80 | '}';
81 | }
82 | }
83 |
--------------------------------------------------------------------------------
/src/main/java/com/cpjd/models/events/AwardRecipient.java:
--------------------------------------------------------------------------------
1 | package com.cpjd.models.events;
2 |
3 | import java.io.Serializable;
4 |
5 | /**
6 | * An Award_Recipient object represents the team and/or person who received an award at an event.
7 | */
8 | public class AwardRecipient implements Serializable {
9 | /**
10 | * The TBA team key for the team that was given the award. May be null.
11 | */
12 | private String teamKey;
13 | /**
14 | * The name of the individual given the award. May be null.
15 | */
16 | private String awardee;
17 |
18 | public String getTeamKey() {
19 | return teamKey;
20 | }
21 |
22 | public void setTeamKey(String teamKey) {
23 | this.teamKey = teamKey;
24 | }
25 |
26 | public String getAwardee() {
27 | return awardee;
28 | }
29 |
30 | public void setAwardee(String awardee) {
31 | this.awardee = awardee;
32 | }
33 |
34 | @Override
35 | public String toString() {
36 | return "AwardRecipient{" +
37 | "teamKey='" + teamKey + '\'' +
38 | ", awardee='" + awardee + '\'' +
39 | '}';
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/src/main/java/com/cpjd/models/events/Event.java:
--------------------------------------------------------------------------------
1 | package com.cpjd.models.events;
2 |
3 | import java.util.Arrays;
4 |
5 | /**
6 | * Events represent FIRST Robotics Competition events, both official and unofficial.
7 | * key_name is like '2010ct'
8 | *
9 | * This is the standard Event model, simple models can be found in com.cpjd.models.simple
10 | *
11 | * This class is a child of SEvent.
12 | *
13 | * @since 1.0.0
14 | * @author Will Davies
15 | */
16 | public class Event extends SEvent {
17 |
18 | /**
19 | * Same as name but doesn’t include event specifiers, such as ‘Regional’ or 'District’. May be null.
20 | */
21 | private String shortName;
22 | /**
23 | * Event SortingType, eg Regional, District, or Offseason.
24 | */
25 | private String eventTypeString;
26 | /**
27 | * The event’s website, if any.
28 | */
29 | private String website;
30 | /**
31 | * The FIRST internal Event ID, used to link to the event on the FRC webpage.
32 | */
33 | private String firstEventID;
34 | /**
35 | * The TBA Event key that represents the event’s parent. Used to link back to the event from a division event. It is also the inverse relation of divison_keys.
36 | */
37 | private String parentEventkey;
38 | /**
39 | * Playoff SortingType, as defined here: https://github.com/the-blue-alliance/the-blue-alliance/blob/master/consts/playoff_type.py#L4, or null.
40 | */
41 | private long playoffType;
42 | /**
43 | * String representation of the playoff_type, or null.
44 | */
45 | private String playoffTypeString;
46 | /**
47 | * An array of event keys for the divisions at this event.
48 | */
49 | private String[] divisonKeys;
50 |
51 | /**
52 | * City, town, village, etc. the event is located in.
53 | */
54 | private String city;
55 | /**
56 | * Address of the event’s venue, if available.
57 | */
58 | private String address;
59 | /**
60 | * Postal code from the event address.
61 | */
62 | private String postalCode;
63 | /**
64 | * Google Maps Place ID for the event address.
65 | */
66 | private String GMAPSPlaceID;
67 | /**
68 | * Link to address location on Google Maps.
69 | */
70 | private String GMAPSURL;
71 | /**
72 | * Latitude for the event address.
73 | */
74 | private double latitude;
75 | /**
76 | * Longitude for the event address.
77 | */
78 | private double longitude;
79 | /**
80 | * Name of the location at the address for the event, eg. Blue Alliance High School.
81 | */
82 | private String locationName;
83 | /**
84 | * Week of the competition season this event is in.
85 | */
86 | private long week;
87 | /**
88 | * Timezone name.
89 | */
90 | private String timezone;
91 |
92 | /**
93 | * An array of webcasts this event contains
94 | */
95 | private Webcast[] webcasts;
96 |
97 |
98 | public String getShortName() {
99 | return shortName;
100 | }
101 |
102 | public void setShortName(String shortName) {
103 | this.shortName = shortName;
104 | }
105 |
106 | public String getEventTypeString() {
107 | return eventTypeString;
108 | }
109 |
110 | public void setEventTypeString(String eventTypeString) {
111 | this.eventTypeString = eventTypeString;
112 | }
113 |
114 | public String getWebsite() {
115 | return website;
116 | }
117 |
118 | public void setWebsite(String website) {
119 | this.website = website;
120 | }
121 |
122 | public String getFirstEventID() {
123 | return firstEventID;
124 | }
125 |
126 | public void setFirstEventID(String firstEventID) {
127 | this.firstEventID = firstEventID;
128 | }
129 |
130 | public String getParentEventkey() {
131 | return parentEventkey;
132 | }
133 |
134 | public void setParentEventkey(String parentEventkey) {
135 | this.parentEventkey = parentEventkey;
136 | }
137 |
138 | public long getPlayoffType() {
139 | return playoffType;
140 | }
141 |
142 | public void setPlayoffType(long playoffType) {
143 | this.playoffType = playoffType;
144 | }
145 |
146 | public String getPlayoffTypeString() {
147 | return playoffTypeString;
148 | }
149 |
150 | public void setPlayoffTypeString(String playoffTypeString) {
151 | this.playoffTypeString = playoffTypeString;
152 | }
153 |
154 | public String[] getDivisonKeys() {
155 | return divisonKeys;
156 | }
157 |
158 | public void setDivisonKeys(String[] divisonKeys) {
159 | this.divisonKeys = divisonKeys;
160 | }
161 |
162 | public String getCity() {
163 | return city;
164 | }
165 |
166 | public void setCity(String city) {
167 | this.city = city;
168 | }
169 |
170 | public String getAddress() {
171 | return address;
172 | }
173 |
174 | public void setAddress(String address) {
175 | this.address = address;
176 | }
177 |
178 | public String getPostalCode() {
179 | return postalCode;
180 | }
181 |
182 | public void setPostalCode(String postalCode) {
183 | this.postalCode = postalCode;
184 | }
185 |
186 | public String getGMAPSPlaceID() {
187 | return GMAPSPlaceID;
188 | }
189 |
190 | public void setGMAPSPlaceID(String GMAPSPlaceID) {
191 | this.GMAPSPlaceID = GMAPSPlaceID;
192 | }
193 |
194 | public String getGMAPSURL() {
195 | return GMAPSURL;
196 | }
197 |
198 | public void setGMAPSURL(String GMAPSURL) {
199 | this.GMAPSURL = GMAPSURL;
200 | }
201 |
202 | public double getLatitude() {
203 | return latitude;
204 | }
205 |
206 | public void setLatitude(double latitude) {
207 | this.latitude = latitude;
208 | }
209 |
210 | public double getLongitude() {
211 | return longitude;
212 | }
213 |
214 | public void setLongitude(double longitude) {
215 | this.longitude = longitude;
216 | }
217 |
218 | public String getLocationName() {
219 | return locationName;
220 | }
221 |
222 | public void setLocationName(String locationName) {
223 | this.locationName = locationName;
224 | }
225 |
226 | public long getWeek() {
227 | return week;
228 | }
229 |
230 | public void setWeek(long week) {
231 | this.week = week;
232 | }
233 |
234 | public String getTimezone() {
235 | return timezone;
236 | }
237 |
238 | public void setTimezone(String timezone) {
239 | this.timezone = timezone;
240 | }
241 |
242 | public Webcast[] getWebcasts() {
243 | return webcasts;
244 | }
245 |
246 | public void setWebcasts(Webcast[] webcasts) {
247 | this.webcasts = webcasts;
248 | }
249 |
250 | @Override
251 | public String toString() {
252 | return "Event{" +
253 | "shortName='" + shortName + '\'' +
254 | ", eventTypeString='" + eventTypeString + '\'' +
255 | ", website='" + website + '\'' +
256 | ", firstEventID='" + firstEventID + '\'' +
257 | ", parentEventkey='" + parentEventkey + '\'' +
258 | ", playoffType=" + playoffType +
259 | ", playoffTypeString='" + playoffTypeString + '\'' +
260 | ", divisonKeys=" + Arrays.toString(divisonKeys) +
261 | ", city='" + city + '\'' +
262 | ", address='" + address + '\'' +
263 | ", postalCode='" + postalCode + '\'' +
264 | ", GMAPSPlaceID='" + GMAPSPlaceID + '\'' +
265 | ", GMAPSURL='" + GMAPSURL + '\'' +
266 | ", latitude=" + latitude +
267 | ", longitude=" + longitude +
268 | ", locationName='" + locationName + '\'' +
269 | ", week=" + week +
270 | ", timezone='" + timezone + '\'' +
271 | ", webcasts=" + Arrays.toString(webcasts) +
272 | '}';
273 | }
274 | }
275 |
--------------------------------------------------------------------------------
/src/main/java/com/cpjd/models/events/EventOPR.java:
--------------------------------------------------------------------------------
1 | package com.cpjd.models.events;
2 |
3 | import com.cpjd.sorting.Sortable;
4 | import com.cpjd.sorting.SortingType;
5 |
6 | import java.io.Serializable;
7 |
8 | /**
9 | * OPR, DPR, and CCWM for a single team
10 | * @since 1.0.0
11 | * @author Will Davies
12 | */
13 | public class EventOPR extends Sortable implements Serializable {
14 | /**
15 | * The team's key
16 | */
17 | private String teamKey;
18 | /**
19 | * The team's opr
20 | */
21 | private double opr;
22 | /**
23 | * The team's dpr
24 | */
25 | private double dpr;
26 | /**
27 | * The team's ccwm
28 | */
29 | private double ccwm;
30 |
31 | @Override
32 | public int sort(SortingType type, boolean ascending, EventOPR t2) {
33 | if(type == SortingType.DEFAULT || type == SortingType.RANK) {
34 | return Double.compare(opr, t2.getOpr());
35 | } else if(type == SortingType.TEAM) return teamKey.compareTo(t2.getTeamKey());
36 |
37 | throw new RuntimeException("Unsupported sort type for EventOPR.");
38 | }
39 |
40 | public String getTeamKey() {
41 | return teamKey;
42 | }
43 |
44 | public void setTeamKey(String teamKey) {
45 | this.teamKey = teamKey;
46 | }
47 |
48 | public double getOpr() {
49 | return opr;
50 | }
51 |
52 | public void setOpr(double opr) {
53 | this.opr = opr;
54 | }
55 |
56 | public double getDpr() {
57 | return dpr;
58 | }
59 |
60 | public void setDpr(double dpr) {
61 | this.dpr = dpr;
62 | }
63 |
64 | public double getCcwm() {
65 | return ccwm;
66 | }
67 |
68 | public void setCcwm(double ccwm) {
69 | this.ccwm = ccwm;
70 | }
71 |
72 | @Override
73 | public String toString() {
74 | return "EventOPR{" +
75 | "teamKey='" + teamKey + '\'' +
76 | ", opr=" + opr +
77 | ", dpr=" + dpr +
78 | ", ccwm=" + ccwm +
79 | '}';
80 | }
81 | }
82 |
--------------------------------------------------------------------------------
/src/main/java/com/cpjd/models/events/EventRanking.java:
--------------------------------------------------------------------------------
1 | package com.cpjd.models.events;
2 |
3 | import com.cpjd.sorting.Sortable;
4 | import com.cpjd.sorting.SortingType;
5 |
6 | import java.io.Serializable;
7 | import java.util.Arrays;
8 |
9 | /**
10 | * Created by Will Davies on 7/7/2017.
11 | */
12 | public class EventRanking extends Sortable implements Serializable {
13 | /**
14 | * The team with this rank.
15 | */
16 | private String teamKey;
17 | /**
18 | * Number of times disqualified.
19 | */
20 | private long dq;
21 |
22 | private long[] extraStats;
23 | private long qualAverage;
24 | private long matchesPlayed;
25 | private double[] sortOrders;
26 | private long wins, ties, losses;
27 | private long rank;
28 |
29 | @Override
30 | public int sort(SortingType type, boolean ascending, EventRanking t2) {
31 | if(type == SortingType.DEFAULT || type == SortingType.RANK) {
32 | return Long.compare(rank, t2.getRank());
33 | } else if(type == SortingType.TEAM) {
34 | return teamKey.compareTo(t2.getTeamKey());
35 | }
36 |
37 | throw new RuntimeException("Unsupported sort type for model EventRanking.");
38 | }
39 |
40 | public String getTeamKey() {
41 | return teamKey;
42 | }
43 |
44 | public void setTeamKey(String teamKey) {
45 | this.teamKey = teamKey;
46 | }
47 |
48 | public long getDq() {
49 | return dq;
50 | }
51 |
52 | public void setDq(long dq) {
53 | this.dq = dq;
54 | }
55 |
56 | public long[] getExtraStats() {
57 | return extraStats;
58 | }
59 |
60 | public void setExtraStats(long[] extraStats) {
61 | this.extraStats = extraStats;
62 | }
63 |
64 | public long getQualAverage() {
65 | return qualAverage;
66 | }
67 |
68 | public void setQualAverage(long qualAverage) {
69 | this.qualAverage = qualAverage;
70 | }
71 |
72 | public long getMatchesPlayed() {
73 | return matchesPlayed;
74 | }
75 |
76 | public void setMatchesPlayed(long matchesPlayed) {
77 | this.matchesPlayed = matchesPlayed;
78 | }
79 |
80 | public double[] getSortOrders() {
81 | return sortOrders;
82 | }
83 |
84 | public void setSortOrders(double[] sortOrders) {
85 | this.sortOrders = sortOrders;
86 | }
87 |
88 | public long getWins() {
89 | return wins;
90 | }
91 |
92 | public void setWins(long wins) {
93 | this.wins = wins;
94 | }
95 |
96 | public long getTies() {
97 | return ties;
98 | }
99 |
100 | public void setTies(long ties) {
101 | this.ties = ties;
102 | }
103 |
104 | public long getLosses() {
105 | return losses;
106 | }
107 |
108 | public void setLosses(long losses) {
109 | this.losses = losses;
110 | }
111 |
112 | public long getRank() {
113 | return rank;
114 | }
115 |
116 | public void setRank(long rank) {
117 | this.rank = rank;
118 | }
119 |
120 | @Override
121 | public String toString() {
122 | return "EventRanking{" +
123 | "teamKey='" + teamKey + '\'' +
124 | ", dq=" + dq +
125 | ", extraStats=" + Arrays.toString(extraStats) +
126 | ", qualAverage=" + qualAverage +
127 | ", matchesPlayed=" + matchesPlayed +
128 | ", sortOrders=" + Arrays.toString(sortOrders) +
129 | ", wins=" + wins +
130 | ", ties=" + ties +
131 | ", losses=" + losses +
132 | ", rank=" + rank +
133 | '}';
134 | }
135 | }
136 |
137 |
--------------------------------------------------------------------------------
/src/main/java/com/cpjd/models/events/Insight.java:
--------------------------------------------------------------------------------
1 | package com.cpjd.models.events;
2 |
3 | import java.util.HashMap;
4 |
5 | public class Insight {
6 |
7 | /**
8 | * These are year specific, so it's up to you to determine what you'd like to fetch.
9 | *
10 | */
11 |
12 | private HashMap qual;
13 | private HashMap playoff;
14 |
15 | public HashMap getQual() {
16 | return qual;
17 | }
18 |
19 | public void setQual(HashMap qual) {
20 | this.qual = qual;
21 | }
22 |
23 | public HashMap getPlayoff() {
24 | return playoff;
25 | }
26 |
27 | public void setPlayoff(HashMap playoff) {
28 | this.playoff = playoff;
29 | }
30 |
31 | @Override
32 | public String toString() {
33 | return "Insight{" +
34 | "qual=" + qual +
35 | ", playoff=" + playoff +
36 | '}';
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/src/main/java/com/cpjd/models/events/Media.java:
--------------------------------------------------------------------------------
1 | package com.cpjd.models.events;
2 |
3 | import java.io.Serializable;
4 |
5 | /**
6 | * @since 1.0.0
7 | * @author Will Davies
8 | */
9 | public class Media implements Serializable {
10 | /**
11 | * TBA identifier for this media.
12 | */
13 | private String key;
14 | /**
15 | * String type of the media element.
16 | */
17 | private String type;
18 | /**
19 | * The key used to identify this media on the media site.
20 | */
21 | private String foreignKey;
22 | /**
23 | * If required, a JSON dict of additional media information.
24 | */
25 | private String details;
26 | /**
27 | * True if the media is of high quality.
28 | */
29 | private boolean preferred;
30 |
31 | public String getKey() {
32 | return key;
33 | }
34 |
35 | public void setKey(String key) {
36 | this.key = key;
37 | }
38 |
39 | public String getType() {
40 | return type;
41 | }
42 |
43 | public void setType(String type) {
44 | this.type = type;
45 | }
46 |
47 | public String getForeignKey() {
48 | return foreignKey;
49 | }
50 |
51 | public void setForeignKey(String foreignKey) {
52 | this.foreignKey = foreignKey;
53 | }
54 |
55 | public String getDetails() {
56 | return details;
57 | }
58 |
59 | public void setDetails(String details) {
60 | this.details = details;
61 | }
62 |
63 | public boolean isPreferred() {
64 | return preferred;
65 | }
66 |
67 | public void setPreferred(boolean preferred) {
68 | this.preferred = preferred;
69 | }
70 |
71 | @Override
72 | public String toString() {
73 | return "Media{" +
74 | "key='" + key + '\'' +
75 | ", type='" + type + '\'' +
76 | ", foreignKey='" + foreignKey + '\'' +
77 | ", details='" + details + '\'' +
78 | ", preferred=" + preferred +
79 | '}';
80 | }
81 | }
82 |
--------------------------------------------------------------------------------
/src/main/java/com/cpjd/models/events/SEvent.java:
--------------------------------------------------------------------------------
1 | package com.cpjd.models.events;
2 |
3 | import com.cpjd.sorting.Sortable;
4 | import com.cpjd.sorting.SortingType;
5 | import com.cpjd.models.districts.District;
6 |
7 | import java.io.Serializable;
8 | import java.util.Calendar;
9 |
10 | /**
11 | * This is the Simple Event Model, as defined by the V3 TBA api.
12 | *
13 | * @since 1.0.0
14 | * @author Will Davies
15 | */
16 | public class SEvent extends Sortable implements Serializable {
17 | /**
18 | * TBA event key with the format yyyy[EVENT_CODE], where yyyy is the year, and EVENT_CODE is the event code of the event.
19 | */
20 | private String key;
21 | /**
22 | * Official name of event on record either provided by FIRST or organizers of offseason event.
23 | */
24 | private String name;
25 | /**
26 | * Event short code, as provided by FIRST.
27 | */
28 | private String eventCode;
29 | /**
30 | * Event SortingType, as defined here: https://github.com/the-blue-alliance/the-blue-alliance/blob/master/consts/event_type.py#L2
31 | */
32 | private long eventType;
33 |
34 | /**
35 | * Districts array
36 | */
37 | private District district;
38 |
39 | /**
40 | * State or Province the event is located in.
41 | */
42 | private String stateProv;
43 | /**
44 | * Country the event is located in.
45 | */
46 | private String country;
47 | /**
48 | * Event start date in yyyy-mm-dd format.
49 | */
50 | private String startDate;
51 | /**
52 | * Event end date in yyyy-mm-dd format.
53 | */
54 | private String endDate;
55 |
56 | /**
57 | * Year the event data is for.
58 | */
59 | private long year;
60 |
61 | public long getTimeInMillis(String date) {
62 | String[] tokens = date.split("-");
63 |
64 | Calendar c = Calendar.getInstance();
65 | c.set(Calendar.YEAR, Integer.parseInt(tokens[0]));
66 | c.set(Calendar.MONTH, Integer.parseInt(tokens[1]));
67 | c.set(Calendar.DAY_OF_MONTH, Integer.parseInt(tokens[2]));
68 | return c.getTimeInMillis();
69 | }
70 |
71 | @Override
72 | public int sort(SortingType type, boolean ascending, SEvent t2) {
73 | if(type == SortingType.DEFAULT || type == SortingType.DATE) {
74 | return Long.compare(getTimeInMillis(startDate), getTimeInMillis(t2.getStartDate()));
75 | } else if(type == SortingType.NAME) {
76 | return name.compareTo(t2.getName());
77 | }
78 |
79 | throw new RuntimeException("Unsupported sorting type for event model type.");
80 | }
81 |
82 | public String getKey() {
83 | return key;
84 | }
85 |
86 | public void setKey(String key) {
87 | this.key = key;
88 | }
89 |
90 | public String getName() {
91 | return name;
92 | }
93 |
94 | public void setName(String name) {
95 | this.name = name;
96 | }
97 |
98 | public String getEventCode() {
99 | return eventCode;
100 | }
101 |
102 | public void setEventCode(String eventCode) {
103 | this.eventCode = eventCode;
104 | }
105 |
106 | public long getEventType() {
107 | return eventType;
108 | }
109 |
110 | public void setEventType(long eventType) {
111 | this.eventType = eventType;
112 | }
113 |
114 | public District getDistrict() {
115 | return district;
116 | }
117 |
118 | public void setDistrict(District district) {
119 | this.district = district;
120 | }
121 |
122 | public String getStateProv() {
123 | return stateProv;
124 | }
125 |
126 | public void setStateProv(String stateProv) {
127 | this.stateProv = stateProv;
128 | }
129 |
130 | public String getCountry() {
131 | return country;
132 | }
133 |
134 | public void setCountry(String country) {
135 | this.country = country;
136 | }
137 |
138 | public String getStartDate() {
139 | return startDate;
140 | }
141 |
142 | public void setStartDate(String startDate) {
143 | this.startDate = startDate;
144 | }
145 |
146 | public String getEndDate() {
147 | return endDate;
148 | }
149 |
150 | public void setEndDate(String endDate) {
151 | this.endDate = endDate;
152 | }
153 |
154 | public long getYear() {
155 | return year;
156 | }
157 |
158 | public void setYear(long year) {
159 | this.year = year;
160 | }
161 |
162 | @Override
163 | public String toString() {
164 | return "SEvent{" +
165 | "key='" + key + '\'' +
166 | ", name='" + name + '\'' +
167 | ", eventCode='" + eventCode + '\'' +
168 | ", eventType=" + eventType +
169 | ", district=" + district +
170 | ", stateProv='" + stateProv + '\'' +
171 | ", country='" + country + '\'' +
172 | ", startDate='" + startDate + '\'' +
173 | ", endDate='" + endDate + '\'' +
174 | ", year=" + year +
175 | '}';
176 | }
177 | }
178 |
--------------------------------------------------------------------------------
/src/main/java/com/cpjd/models/events/Webcast.java:
--------------------------------------------------------------------------------
1 | package com.cpjd.models.events;
2 |
3 | import java.io.Serializable;
4 |
5 | /**
6 | * @since 1.0.0
7 | * @author Will Davies
8 | */
9 | public class Webcast implements Serializable {
10 | private String type;
11 | private String channel;
12 | private String file;
13 |
14 | public String getType() {
15 | return type;
16 | }
17 |
18 | public void setType(String type) {
19 | this.type = type;
20 | }
21 |
22 | public String getChannel() {
23 | return channel;
24 | }
25 |
26 | public void setChannel(String channel) {
27 | this.channel = channel;
28 | }
29 |
30 | public String getFile() {
31 | return file;
32 | }
33 |
34 | public void setFile(String file) {
35 | this.file = file;
36 | }
37 |
38 | @Override
39 | public String toString() {
40 | return "Webcast{" +
41 | "type='" + type + '\'' +
42 | ", channel='" + channel + '\'' +
43 | ", file='" + file + '\'' +
44 | '}';
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/src/main/java/com/cpjd/models/matches/Match.java:
--------------------------------------------------------------------------------
1 | package com.cpjd.models.matches;
2 |
3 | import com.cpjd.models.events.Media;
4 |
5 | import java.util.Arrays;
6 | import java.util.HashMap;
7 |
8 | /**
9 | * @since 1.0.0
10 | * @author Will Davies
11 | */
12 |
13 | public class Match extends SMatch {
14 | /**
15 | * UNIX timestamp (seconds since 1-Jan-1970 00:00:00) when the match result was posted.
16 | */
17 | private long postResultTime;
18 | /**
19 | *
20 | Score breakdown for auto, teleop, etc. points. Varies from year to year. May be null.
21 |
22 | These are year specific, so it's up to you to determine what you'd like to fetch.
23 |
24 | */
25 | private HashMap redScoreBreakdown;
26 | private HashMap blueScoreBreakdown;
27 | /**
28 | * Array of `Media` objects associated with this match.
29 | */
30 | private Media[] videos;
31 |
32 | public long getPostResultTime() {
33 | return postResultTime;
34 | }
35 |
36 | public void setPostResultTime(long postResultTime) {
37 | this.postResultTime = postResultTime;
38 | }
39 |
40 | public HashMap getRedScoreBreakdown() {
41 | return redScoreBreakdown;
42 | }
43 |
44 | public void setRedScoreBreakdown(HashMap redScoreBreakdown) {
45 | this.redScoreBreakdown = redScoreBreakdown;
46 | }
47 |
48 | public HashMap getBlueScoreBreakdown() {
49 | return blueScoreBreakdown;
50 | }
51 |
52 | public void setBlueScoreBreakdown(HashMap blueScoreBreakdown) {
53 | this.blueScoreBreakdown = blueScoreBreakdown;
54 | }
55 |
56 | public Media[] getVideos() {
57 | return videos;
58 | }
59 |
60 | public void setVideos(Media[] videos) {
61 | this.videos = videos;
62 | }
63 |
64 | @Override
65 | public String toString() {
66 | return "Match{" +
67 | "postResultTime=" + postResultTime +
68 | ", redScoreBreakdown=" + redScoreBreakdown +
69 | ", blueScoreBreakdown=" + blueScoreBreakdown +
70 | ", videos=" + Arrays.toString(videos) +
71 | '}';
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/src/main/java/com/cpjd/models/matches/MatchAlliance.java:
--------------------------------------------------------------------------------
1 | package com.cpjd.models.matches;
2 |
3 | import java.io.Serializable;
4 | import java.util.Arrays;
5 |
6 | /**
7 | * @since 1.0.0
8 | * @author Will Davies
9 | */
10 | public class MatchAlliance implements Serializable {
11 | /**
12 | * Score for this alliance. Will be null or -1 for an unplayed match.
13 | */
14 | private long score;
15 | /**
16 | * TBA Team keys (eg frc254) for teams on this alliance.
17 | */
18 | private String[] teamKeys;
19 | /**
20 | * TBA team keys (eg `frc254`) of any teams playing as a surrogate.
21 | */
22 | private String[] surrogateTeamKeys;
23 |
24 | public long getScore() {
25 | return score;
26 | }
27 |
28 | public void setScore(long score) {
29 | this.score = score;
30 | }
31 |
32 | public String[] getTeamKeys() {
33 | return teamKeys;
34 | }
35 |
36 | public void setTeamKeys(String[] teamKeys) {
37 | this.teamKeys = teamKeys;
38 | }
39 |
40 | public String[] getSurrogateTeamKeys() {
41 | return surrogateTeamKeys;
42 | }
43 |
44 | public void setSurrogateTeamKeys(String[] surrogateTeamKeys) {
45 | this.surrogateTeamKeys = surrogateTeamKeys;
46 | }
47 |
48 | @Override
49 | public String toString() {
50 | return "MatchAlliance{" +
51 | "score=" + score +
52 | ", teamKeys=" + Arrays.toString(teamKeys) +
53 | ", surrogateTeamKeys=" + Arrays.toString(surrogateTeamKeys) +
54 | '}';
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/src/main/java/com/cpjd/models/matches/SMatch.java:
--------------------------------------------------------------------------------
1 | package com.cpjd.models.matches;
2 |
3 | import com.cpjd.sorting.Sortable;
4 | import com.cpjd.sorting.SortingType;
5 |
6 | import java.io.Serializable;
7 | import java.util.HashMap;
8 |
9 | /**
10 | * @since 1.0.0
11 | * @author Will Davies
12 | */
13 | public class SMatch extends Sortable implements Serializable {
14 | /**
15 | * TBA event key with the format yyyy[EVENT_CODE]_[COMP_LEVEL]m[MATCH_NUMBER], where yyyy is the year, and EVENT_CODE is the event code of the event, COMP_LEVEL is (qm, ef, qf, sf, f), and MATCH_NUMBER is the match number in the competition level. A set number may append the competition level if more than one match in required per set.
16 | *
17 | *
18 | */
19 | private String key;
20 | /**
21 | * The competition level the match was played at.
22 | */
23 | private String compLevel;
24 | /**
25 | * The set number in a series of matches where more than one match is required in the match series.
26 | */
27 | private long setNumber;
28 | /**
29 | * The match number of the match in the competition level.
30 | */
31 | private long matchNumber;
32 | /**
33 | * A list of alliances, the teams on the alliances, and their score.
34 | */
35 | private MatchAlliance blue;
36 | /**
37 | * A list of alliances, the teams on the alliances, and their score.
38 | */
39 | private MatchAlliance red;
40 | /**
41 | * The color (red/blue) of the winning alliance. Will contain an empty string in the event of no winner, or a tie.
42 | */
43 | private String winningAlliance;
44 | /**
45 | * Event key of the event the match was played at.
46 | */
47 | private String eventKey;
48 | /**
49 | * UNIX timestamp (seconds since 1-Jan-1970 00:00:00) of the scheduled match time, as taken from the published schedule.
50 | */
51 | private long time;
52 | /**
53 | * UNIX timestamp (seconds since 1-Jan-1970 00:00:00) of the TBA predicted match start time.
54 | */
55 | private long predictedTime;
56 | /**
57 | * UNIX timestamp (seconds since 1-Jan-1970 00:00:00) of actual match start time.
58 | */
59 | private long actualTime;
60 |
61 | @Override
62 | public int sort(SortingType type, boolean ascending, SMatch t2) {
63 | if(type == SortingType.DEFAULT || type == SortingType.NUMBER) {
64 | /*
65 | * Sorts matches by:
66 | * -Quals
67 | * -Quarters
68 | * -Semis
69 | * -Finals
70 | */
71 | String comp1 = compLevel;
72 | String comp2 = t2.getCompLevel();
73 |
74 | HashMap map = new HashMap<>();
75 | map.put("qm", 1);
76 | map.put("ef", 2);
77 | map.put("qf", 3);
78 | map.put("sf", 4);
79 | map.put("f", 5);
80 |
81 | if(comp1.equals(comp2)) return Long.compare(matchNumber, t2.getMatchNumber());
82 | else return Integer.compare(map.get(comp1), map.get(comp2));
83 | } else if(type == SortingType.DATE) {
84 | return Long.compare(time, t2.getTime());
85 | }
86 |
87 | throw new RuntimeException("Unsupported sorting type for match model.");
88 | }
89 |
90 | public String getKey() {
91 | return key;
92 | }
93 |
94 | public void setKey(String key) {
95 | this.key = key;
96 | }
97 |
98 | public String getCompLevel() {
99 | return compLevel;
100 | }
101 |
102 | public void setCompLevel(String compLevel) {
103 | this.compLevel = compLevel;
104 | }
105 |
106 | public long getSetNumber() {
107 | return setNumber;
108 | }
109 |
110 | public void setSetNumber(long setNumber) {
111 | this.setNumber = setNumber;
112 | }
113 |
114 | public long getMatchNumber() {
115 | return matchNumber;
116 | }
117 |
118 | public void setMatchNumber(long matchNumber) {
119 | this.matchNumber = matchNumber;
120 | }
121 |
122 | public MatchAlliance getBlue() {
123 | return blue;
124 | }
125 |
126 | public void setBlue(MatchAlliance blue) {
127 | this.blue = blue;
128 | }
129 |
130 | public MatchAlliance getRed() {
131 | return red;
132 | }
133 |
134 | public void setRed(MatchAlliance red) {
135 | this.red = red;
136 | }
137 |
138 | public String getWinningAlliance() {
139 | return winningAlliance;
140 | }
141 |
142 | public void setWinningAlliance(String winningAlliance) {
143 | this.winningAlliance = winningAlliance;
144 | }
145 |
146 | public String getEventKey() {
147 | return eventKey;
148 | }
149 |
150 | public void setEventKey(String eventKey) {
151 | this.eventKey = eventKey;
152 | }
153 |
154 | public long getTime() {
155 | return time;
156 | }
157 |
158 | public void setTime(long time) {
159 | this.time = time;
160 | }
161 |
162 | public long getPredictedTime() {
163 | return predictedTime;
164 | }
165 |
166 | public void setPredictedTime(long predictedTime) {
167 | this.predictedTime = predictedTime;
168 | }
169 |
170 | public long getActualTime() {
171 | return actualTime;
172 | }
173 |
174 | public void setActualTime(long actualTime) {
175 | this.actualTime = actualTime;
176 | }
177 |
178 | @Override
179 | public String toString() {
180 | return "SMatch{" +
181 | "key='" + key + '\'' +
182 | ", compLevel='" + compLevel + '\'' +
183 | ", setNumber=" + setNumber +
184 | ", matchNumber=" + matchNumber +
185 | ", blue=" + blue +
186 | ", red=" + red +
187 | ", winningAlliance='" + winningAlliance + '\'' +
188 | ", eventKey='" + eventKey + '\'' +
189 | ", time=" + time +
190 | ", predictedTime=" + predictedTime +
191 | ", actualTime=" + actualTime +
192 | '}';
193 | }
194 | }
195 |
--------------------------------------------------------------------------------
/src/main/java/com/cpjd/models/teams/Robot.java:
--------------------------------------------------------------------------------
1 | package com.cpjd.models.teams;
2 |
3 | import com.cpjd.sorting.Sortable;
4 | import com.cpjd.sorting.SortingType;
5 |
6 | import java.io.Serializable;
7 |
8 | public class Robot extends Sortable implements Serializable {
9 | /**
10 | * Year this robot competed in.
11 | */
12 | private long year;
13 | /**
14 | * Name of the robot as provided by the team.
15 | */
16 | private String robotName;
17 | /**
18 | * Internal TBA identifier for this robot.
19 | */
20 | private String key;
21 | /**
22 | * TBA team key for this robot.
23 | */
24 | private String teamKey;
25 |
26 | @Override
27 | public int sort(SortingType type, boolean ascending, Robot t2) {
28 | if(type == SortingType.DEFAULT || type == SortingType.DATE) {
29 | return Long.compare(year, t2.getYear());
30 | }
31 |
32 | throw new RuntimeException("Unsupported sort type for model robot.");
33 | }
34 |
35 | public long getYear() {
36 | return year;
37 | }
38 |
39 | public void setYear(long year) {
40 | this.year = year;
41 | }
42 |
43 | public String getRobotName() {
44 | return robotName;
45 | }
46 |
47 | public void setRobotName(String robotName) {
48 | this.robotName = robotName;
49 | }
50 |
51 | public String getKey() {
52 | return key;
53 | }
54 |
55 | public void setKey(String key) {
56 | this.key = key;
57 | }
58 |
59 | public String getTeamKey() {
60 | return teamKey;
61 | }
62 |
63 | public void setTeamKey(String teamKey) {
64 | this.teamKey = teamKey;
65 | }
66 |
67 | @Override
68 | public String toString() {
69 | return "Robot{" +
70 | "year=" + year +
71 | ", robotName='" + robotName + '\'' +
72 | ", key='" + key + '\'' +
73 | ", teamKey='" + teamKey + '\'' +
74 | '}';
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/src/main/java/com/cpjd/models/teams/STeam.java:
--------------------------------------------------------------------------------
1 | package com.cpjd.models.teams;
2 |
3 | import com.cpjd.sorting.Sortable;
4 | import com.cpjd.sorting.SortingType;
5 |
6 | import java.io.Serializable;
7 |
8 | /**
9 | * The simple Team model as defined by the V3 TPA api.
10 | *
11 | * @since 1.0.0
12 | * @author Will Davies
13 | */
14 | public class STeam extends Sortable implements Serializable {
15 | /**
16 | * TBA team key with the format frcXXXX with XXXX representing the team number.
17 | */
18 | private String key;
19 | /**
20 | * Official team number issued by FIRST.
21 | */
22 | private long teamNumber;
23 | /**
24 | * Team nickname provided by FIRST.
25 | */
26 | private String nickname;
27 | /**
28 | * Official long name registered with FIRST.
29 | */
30 | private String name;
31 | /**
32 | * City of team derived from parsing the address registered with FIRST.
33 | */
34 | private String city;
35 | /**
36 | * State of team derived from parsing the address registered with FIRST.
37 | */
38 | private String stateProv;
39 | /**
40 | * Country of team derived from parsing the address registered with FIRST.
41 | */
42 | private String country;
43 |
44 | @Override
45 | public int sort(SortingType type, boolean ascending, STeam t2) {
46 | if(type == SortingType.DEFAULT || type == SortingType.NUMBER) {
47 | return Long.compare(teamNumber, t2.getTeamNumber());
48 | }
49 |
50 | throw new RuntimeException("Unsupported sort type for team model.");
51 | }
52 |
53 | public String getKey() {
54 | return key;
55 | }
56 |
57 | public void setKey(String key) {
58 | this.key = key;
59 | }
60 |
61 | public long getTeamNumber() {
62 | return teamNumber;
63 | }
64 |
65 | public void setTeamNumber(long teamNumber) {
66 | this.teamNumber = teamNumber;
67 | }
68 |
69 | public String getNickname() {
70 | return nickname;
71 | }
72 |
73 | public void setNickname(String nickname) {
74 | this.nickname = nickname;
75 | }
76 |
77 | public String getName() {
78 | return name;
79 | }
80 |
81 | public void setName(String name) {
82 | this.name = name;
83 | }
84 |
85 | public String getCity() {
86 | return city;
87 | }
88 |
89 | public void setCity(String city) {
90 | this.city = city;
91 | }
92 |
93 | public String getStateProv() {
94 | return stateProv;
95 | }
96 |
97 | public void setStateProv(String stateProv) {
98 | this.stateProv = stateProv;
99 | }
100 |
101 | public String getCountry() {
102 | return country;
103 | }
104 |
105 | public void setCountry(String country) {
106 | this.country = country;
107 | }
108 |
109 | @Override
110 | public String toString() {
111 | return "STeam{" +
112 | "key='" + key + '\'' +
113 | ", teamNumber=" + teamNumber +
114 | ", nickname='" + nickname + '\'' +
115 | ", name='" + name + '\'' +
116 | ", city='" + city + '\'' +
117 | ", stateProv='" + stateProv + '\'' +
118 | ", country='" + country + '\'' +
119 | '}';
120 | }
121 | }
122 |
--------------------------------------------------------------------------------
/src/main/java/com/cpjd/models/teams/Team.java:
--------------------------------------------------------------------------------
1 | package com.cpjd.models.teams;
2 |
3 | /**
4 | * The standard team model
5 | *
6 | * Extends the simple team model
7 | */
8 |
9 | public class Team extends STeam {
10 | /**
11 | * Will be NULL, for future development.
12 | */
13 | private String address;
14 | /**
15 | * Postal code from the team address.
16 | */
17 | private String postalCode;
18 | /**
19 | * Will be NULL, for future development.
20 | */
21 | private String GMAPSPlaceID;
22 | /**
23 | * Will be NULL, for future development.
24 | */
25 | private String GMAPURL;
26 | /**
27 | * Will be NULL, for future development.
28 | */
29 | private double latitude;
30 | /**
31 | * Will be NULL, for future development.
32 | */
33 | private double longitude;
34 | /**
35 | * Will be NULL, for future development.
36 | */
37 | private String locationName;
38 | /**
39 | * Official website associated with the team.
40 | */
41 | private String website;
42 | /**
43 | * First year the team officially competed.
44 | */
45 | private long rookieYear;
46 | /**
47 | * Team’s motto as provided by FIRST.
48 | */
49 | private String motto;
50 |
51 | public String getAddress() {
52 | return address;
53 | }
54 |
55 | public void setAddress(String address) {
56 | this.address = address;
57 | }
58 |
59 | public String getPostalCode() {
60 | return postalCode;
61 | }
62 |
63 | public void setPostalCode(String postalCode) {
64 | this.postalCode = postalCode;
65 | }
66 |
67 | public String getGMAPSPlaceID() {
68 | return GMAPSPlaceID;
69 | }
70 |
71 | public void setGMAPSPlaceID(String GMAPSPlaceID) {
72 | this.GMAPSPlaceID = GMAPSPlaceID;
73 | }
74 |
75 | public String getGMAPURL() {
76 | return GMAPURL;
77 | }
78 |
79 | public void setGMAPURL(String GMAPURL) {
80 | this.GMAPURL = GMAPURL;
81 | }
82 |
83 | public double getLatitude() {
84 | return latitude;
85 | }
86 |
87 | public void setLatitude(double latitude) {
88 | this.latitude = latitude;
89 | }
90 |
91 | public double getLongitude() {
92 | return longitude;
93 | }
94 |
95 | public void setLongitude(double longitude) {
96 | this.longitude = longitude;
97 | }
98 |
99 | public String getLocationName() {
100 | return locationName;
101 | }
102 |
103 | public void setLocationName(String locationName) {
104 | this.locationName = locationName;
105 | }
106 |
107 | public String getWebsite() {
108 | return website;
109 | }
110 |
111 | public void setWebsite(String website) {
112 | this.website = website;
113 | }
114 |
115 | public long getRookieYear() {
116 | return rookieYear;
117 | }
118 |
119 | public void setRookieYear(long rookieYear) {
120 | this.rookieYear = rookieYear;
121 | }
122 |
123 | public String getMotto() {
124 | return motto;
125 | }
126 |
127 | public void setMotto(String motto) {
128 | this.motto = motto;
129 | }
130 |
131 | @Override
132 | public String toString() {
133 | return "Team{" +
134 | "address='" + address + '\'' +
135 | ", postalCode='" + postalCode + '\'' +
136 | ", GMAPSPlaceID='" + GMAPSPlaceID + '\'' +
137 | ", GMAPURL='" + GMAPURL + '\'' +
138 | ", latitude=" + latitude +
139 | ", longitude=" + longitude +
140 | ", locationName='" + locationName + '\'' +
141 | ", website='" + website + '\'' +
142 | ", rookieYear=" + rookieYear +
143 | ", motto='" + motto + '\'' +
144 | '}';
145 | }
146 | }
147 |
--------------------------------------------------------------------------------
/src/main/java/com/cpjd/requests/DistrictRequest.java:
--------------------------------------------------------------------------------
1 | package com.cpjd.requests;
2 |
3 | import com.cpjd.main.TBA;
4 | import com.cpjd.models.districts.District;
5 | import com.cpjd.models.events.SEvent;
6 | import com.cpjd.models.teams.STeam;
7 | import com.cpjd.models.events.Event;
8 | import com.cpjd.models.teams.Team;
9 | import org.json.simple.JSONArray;
10 | import com.cpjd.utils.IO;
11 | import com.cpjd.utils.Parser;
12 | import com.cpjd.utils.Utils;
13 | import com.cpjd.utils.exceptions.DataNotFoundException;
14 |
15 | /**
16 | * In an attempt to keep this API organized, if you look at the blue alliance v3 documentation, all calls that start with /district/ or /districts/
17 | * will be accessed from this class.
18 | *
19 | * API calls not implemented yet:
20 | * /district/{district_key}/rankings
21 | *
22 | * @since 1.0.0
23 | * @author Will Davies
24 | */
25 | public class DistrictRequest extends Parser {
26 |
27 | /**
28 | * Mirror of: /district/{district_key}/teams
29 | *
30 | * @param districtKey TBA District Key, eg 2016fim
31 | * @return Team[] including a Team object for every team in the specified district
32 | */
33 | public Team[] getDistrictTeams(String districtKey) {
34 | JSONArray teams = (JSONArray) IO.doRequest("district/"+districtKey+"/teams");
35 | if(teams == null) throw new DataNotFoundException("Couldn't find any teams in district with key: "+districtKey);
36 | Team[] toGet = new Team[teams.size()];
37 | for(int i = 0; i < teams.size(); i++) toGet[i] = parseTeam(teams.get(i));
38 | TBA.sort(toGet);
39 | return toGet;
40 | }
41 |
42 | /**
43 | * Mirror of: /district/{district_key}/teams/simple
44 | *
45 | * @param districtKey TBA District Key, eg 2016fim
46 | * @return STeam[] including a STeam object for every team in the specified district (simple model)
47 | */
48 | public STeam[] getDistrictSTeams(String districtKey) {
49 | JSONArray teams = (JSONArray) IO.doRequest("district/"+districtKey+"/teams/simple");
50 | if(teams == null) throw new DataNotFoundException("Couldn't find any simple teams in district with key: "+districtKey);
51 | STeam[] toGet = new STeam[teams.size()];
52 | for(int i = 0; i < teams.size(); i++) toGet[i] = parseSTeam(teams.get(i));
53 | TBA.sort(toGet);
54 | return toGet;
55 | }
56 |
57 | /**
58 | * Mirror of: /district/{district_key}/teams/keys
59 | *
60 | * Gets a list of Team objects that competed in events in the given district.
61 | * @param districtKey TBA District Key, eg 2016fim
62 | * @return String[] containing all the team keys in this district
63 | */
64 | public String[] getDistrictTeamKeys(String districtKey) {
65 | JSONArray keys = (JSONArray) IO.doRequest("district/"+districtKey+"/teams/keys");
66 | if(keys == null) throw new DataNotFoundException("Couldn't find any team keys in district with key: "+districtKey);
67 | return Utils.jsonArrayToStringArray(keys);
68 | }
69 |
70 | /**
71 | * Mirror of: /district/{district_key}/events
72 | *
73 | * @param districtKey TBA District Key, eg 2016fim
74 | * @return Event[] including an Event object for every event in the specified district
75 | */
76 | public Event[] getDistrictEvents(String districtKey) {
77 | JSONArray teams = (JSONArray) IO.doRequest("district/"+districtKey+"/events");
78 | if(teams == null) throw new DataNotFoundException("Couldn't find any events in district with key: "+districtKey);
79 | Event[] toGet = new Event[teams.size()];
80 | for(int i = 0; i < teams.size(); i++) toGet[i] = parseEvent(teams.get(i));
81 | TBA.sort(toGet);
82 | return toGet;
83 | }
84 |
85 | /**
86 | * Mirror of: /district/{district_key}/events/simple
87 | *
88 | * @param districtKey TBA District Key, eg 2016fim
89 | * @return SEvent[] including an SEvent object for every event in the specified district (simple model)
90 | */
91 | public SEvent[] getDistrictSEvents(String districtKey) {
92 | JSONArray teams = (JSONArray) IO.doRequest("district/"+districtKey+"/events/simple");
93 | if(teams == null) throw new DataNotFoundException("Couldn't find any simple events in district with key: "+districtKey);
94 | SEvent[] toGet = new SEvent[teams.size()];
95 | for(int i = 0; i < teams.size(); i++) toGet[i] = parseSEvent(teams.get(i));
96 | TBA.sort(toGet);
97 | return toGet;
98 | }
99 |
100 | /**
101 | * Mirror of: /district/{district_key}/events/keys
102 | *
103 | * Gets a list of Team objects that competed in events in the given district.
104 | * @param districtKey TBA District Key, eg 2016fim
105 | * @return String[] containing all the team keys in this district
106 | */
107 | public String[] getDistrictEventKeys(String districtKey) {
108 | JSONArray keys = (JSONArray) IO.doRequest("district/"+districtKey+"/events/keys");
109 | if(keys == null) throw new DataNotFoundException("Couldn't find any event keys in district with key: "+districtKey);
110 | return Utils.jsonArrayToStringArray(keys);
111 | }
112 |
113 | /**
114 | * Mirror of: /districts/{year}
115 | *
116 | * Gets a list of districts and their corresponding district key, for the given year.
117 | * @param year Competition Year (or Season). Must be 4 digits.
118 | * @return District[] containing a District for each active district in the specified year
119 | */
120 | public District[] getDistricts(int year) {
121 | JSONArray districts = (JSONArray) IO.doRequest("districts/"+year);
122 | if(districts == null) throw new DataNotFoundException("Couldn't find any districts in year: "+year);
123 | District[] toReturn = new District[districts.size()];
124 | for(int i = 0; i < districts.size(); i++) toReturn[i] = parseDistrict(districts.get(i));
125 | TBA.sort(toReturn);
126 | return toReturn;
127 | }
128 |
129 | }
130 |
--------------------------------------------------------------------------------
/src/main/java/com/cpjd/requests/EventRequest.java:
--------------------------------------------------------------------------------
1 | package com.cpjd.requests;
2 |
3 | import com.cpjd.main.TBA;
4 | import com.cpjd.models.events.*;
5 | import com.cpjd.models.matches.SMatch;
6 | import com.cpjd.models.teams.STeam;
7 | import com.cpjd.models.matches.Match;
8 | import com.cpjd.models.teams.Team;
9 | import org.json.simple.JSONArray;
10 | import com.cpjd.utils.IO;
11 | import com.cpjd.utils.Parser;
12 | import com.cpjd.utils.Utils;
13 | import com.cpjd.utils.exceptions.DataNotFoundException;
14 | import org.json.simple.JSONObject;
15 |
16 | import java.util.HashMap;
17 |
18 | /**
19 | * In an attempt to keep this API organized, if you look at the blue alliance v3 documentation, all calls that start with /events/ or /event/
20 | * will be accessed from this class.
21 | *
22 | * API calls not implemented yet:
23 | * /event/{event_key}/district_points
24 | * /event/{event_key}/alliances
25 | * /event/{event_key}/insights
26 | * /event/{event_key}/rankings
27 | *
28 | * @since 1.0.0
29 | * @author Will Davies
30 | */
31 | public class EventRequest extends Parser {
32 |
33 | /**
34 | * Mirror of: /event/{event_key}/teams
35 | *
36 | * Gets a list of Team objects that competed in the given event.
37 | * @param eventKey TBA Event Key, eg 2016nytr
38 | * @return the Team[] array that this event includes
39 | */
40 | public Team[] getEventTeams(String eventKey) {
41 | JSONArray teams = (JSONArray) IO.doRequest("event/"+eventKey+"/teams");
42 | if(teams == null) throw new DataNotFoundException("Couldn't find any teams in event with key: "+eventKey);
43 | Team[] toGet = new Team[teams.size()];
44 | for(int i = 0; i < teams.size(); i++) toGet[i] = parseTeam(teams.get(i));
45 | TBA.sort(toGet);
46 | return toGet;
47 | }
48 |
49 | /**
50 | * Mirror of: /event/{event_key}/teams/simple
51 | *
52 | * Gets a list of Team objects that competed in the given event.
53 | * @param eventKey TBA Event Key, eg 2016nytr
54 | * @return the STeam[] array that this event includes (simple model)
55 | */
56 | public STeam[] getSEventTeams(String eventKey) {
57 | JSONArray teams = (JSONArray) IO.doRequest("event/"+eventKey+"/teams/simple");
58 | if(teams == null) throw new DataNotFoundException("Couldn't find any simple teams in event with key: "+eventKey);
59 | STeam[] toGet = new STeam[teams.size()];
60 | for(int i = 0; i < teams.size(); i++) toGet[i] = parseSTeam(teams.get(i));
61 | TBA.sort(toGet);
62 | return toGet;
63 | }
64 |
65 | /**
66 | * Mirror of: /event/{event_key}/teams/keys
67 | *
68 | * Gets a list of Team keys that competed in the given event.
69 | * @param eventKey TBA Event Key, eg 2016nytr
70 | * @return String[] containing all the team keys in this event
71 | */
72 | public String[] getTeamKeys(String eventKey) {
73 | JSONArray keys = (JSONArray) IO.doRequest("event/"+eventKey+"/teams/keys");
74 | if(keys == null) throw new DataNotFoundException("Couldn't find any team keys in event with key: "+eventKey);
75 | return Utils.jsonArrayToStringArray(keys);
76 | }
77 |
78 | /**
79 | * Mirror of: /events/{year}
80 | *
81 | * Gets a list of events in the given year.
82 | * @param year Competition Year (or Season). Must be 4 digits.
83 | * @return Event[] containing all the events in the specified year
84 | */
85 | public Event[] getEvents(int year) {
86 | JSONArray events = (JSONArray) IO.doRequest("events/"+year);
87 | if(events == null) throw new DataNotFoundException("Couldn't find any events in year: "+year);
88 | Event[] toGet = new Event[events.size()];
89 | for(int i = 0; i < events.size(); i++) toGet[i] = parseEvent(events.get(i));
90 | TBA.sort(toGet);
91 | return toGet;
92 | }
93 |
94 | /**
95 | * Mirror of: /events/{year}/simple
96 | *
97 | * Gets a list of events in the given year.
98 | * @param year Competition Year (or Season). Must be 4 digits.
99 | * @return SEvent[] containing all the events in the specified year
100 | */
101 | public SEvent[] getSEvents(int year) {
102 | JSONArray events = (JSONArray) IO.doRequest("events/"+year+"/simple");
103 | if(events == null) throw new DataNotFoundException("Couldn't find any simple events in year: "+year);
104 | SEvent[] toGet = new SEvent[events.size()];
105 | for(int i = 0; i < events.size(); i++) toGet[i] = parseSEvent(events.get(i));
106 | TBA.sort(toGet);
107 | return toGet;
108 | }
109 |
110 | /**
111 | * Mirror of: /events/{year}/keys
112 | *
113 | * Gets a list of event keys in the given year.
114 | * @param year Competition Year (or Season). Must be 4 digits.
115 | * @return String[] containing event keys for the specified year
116 | */
117 | public String[] getEventKeys(int year) {
118 | JSONArray keys = (JSONArray) IO.doRequest("events/"+year+"/keys");
119 | if(keys == null) throw new DataNotFoundException("Couldn't find any event keys in year: "+year);
120 | return Utils.jsonArrayToStringArray(keys);
121 | }
122 |
123 | /**
124 | * Mirror of: /event/{event_key}
125 | *
126 | * Gets an Event.
127 | * @param eventKey TBA Event Key, eg 2016nytr
128 | * @return Event model representing the event associated with the event key
129 | */
130 | public Event getEvent(String eventKey) {
131 | Event event = parseEvent(IO.doRequest("event/"+eventKey));
132 | if(event == null) throw new DataNotFoundException("No event found with key: "+eventKey);
133 | return event;
134 | }
135 |
136 | /**
137 | * Mirror of: /event/{event_key}/simple
138 | *
139 | * Gets an Event.
140 | * @param eventKey TBA Event Key, eg 2016nytr
141 | * @return Event model representing the event associated with the event key
142 | */
143 | public SEvent getSEvent(String eventKey) {
144 | SEvent event = parseSEvent(IO.doRequest("event/"+eventKey+"/simple"));
145 | if(event == null) throw new DataNotFoundException("No simple event found with key: "+eventKey);
146 | return event;
147 | }
148 |
149 | /**
150 | * Mirror of: /event/{event_key}/alliances
151 | *
152 | * @param eventKey TBA Event Key, eg 2016nytr
153 | * @return List of all alliances in this event
154 | */
155 | public Alliance[] getEventAlliances(String eventKey) {
156 | JSONArray alliances = (JSONArray) IO.doRequest("event/"+eventKey+"/alliances");
157 | if(alliances == null) throw new DataNotFoundException("No alliances found for event with key: "+eventKey);
158 | Alliance[] toGet = new Alliance[alliances.size()];
159 | for(int i = 0; i < alliances.size(); i++) toGet[i] = parseEventAlliance(alliances.get(i));
160 | TBA.sort(toGet);
161 | return toGet;
162 | }
163 |
164 | /**
165 | * Mirror of: /event/{event_key}/insights
166 | *
167 | * @param eventKey TBA Event Key, eg 2016nytr
168 | * @return Insights for this event
169 | */
170 | public Insight getEventInsights(String eventKey) {
171 | JSONObject insights = (JSONObject) IO.doRequest("event/"+eventKey+"/insights");
172 | Insight toReturn = parseInsight(insights);
173 | if(toReturn == null) throw new DataNotFoundException("No insights found for event with key: "+eventKey);
174 | return toReturn;
175 | }
176 |
177 | /**
178 | * Mirror of: /event/{event_key}/oprs
179 | *
180 | * Gets a set of Event OPRs (including OPR, DPR, and CCWM) for the given Event.
181 | * @param eventKey TBA Event Key, eg 2016nytr
182 | * @return EventOPR[] containing an EventOPR for each team
183 | */
184 | public EventOPR[] getOprs(String eventKey) {
185 | EventOPR[] oprs = parseOPRs(IO.doRequest("event/"+eventKey+"/oprs"));
186 | if(oprs == null) throw new DataNotFoundException("No oprs found for event with key: "+eventKey);
187 | TBA.sort(oprs);
188 | return oprs;
189 | }
190 |
191 | /**
192 | * Mirror of: /event/{event_key}/predictions
193 | *
194 | * Gets information on TBA-generated predictions for the given Event. Contains year-specific information. WARNING This endpoint is currently under development and may change at any time.
195 | *
196 | * Not stable! No official model for this yet.
197 | * @param eventKey TBA Event Key, eg 2016nytr
198 | * @return JSON String containing prediction information
199 | */
200 | public String getPredictions(String eventKey) {
201 | String s = (String) IO.doRequest("event/"+eventKey+"predictions");
202 | if(s == null) throw new DataNotFoundException("No predictions found for event with key: "+eventKey);
203 | return s;
204 | }
205 |
206 | /**
207 | * Mirror of: /event/{event_key}/matches
208 | *
209 | * Gets a list of matches for the given event.
210 | * @param eventKey TBA Event Key, eg 2016nytr
211 | * @return Match[] containing a Match object for each match in the specified event
212 | */
213 | public Match[] getMatches(String eventKey) {
214 | JSONArray matches = (JSONArray) IO.doRequest("event/"+eventKey+"/matches");
215 | if(matches == null) throw new DataNotFoundException("No matches found for event with key: "+eventKey);
216 | Match[] toGet = new Match[matches.size()];
217 | for(int i = 0; i < matches.size(); i++) toGet[i] = parseMatch(matches.get(i));
218 | TBA.sort(toGet);
219 | return toGet;
220 | }
221 |
222 | /**
223 | * Mirror of: /event/{event_key}/matches/simple
224 | *
225 | * Gets a list of matches for the given event.
226 | * @param eventKey TBA Event Key, eg 2016nytr
227 | * @return Match[] containing a Match object for each match in the specified event
228 | */
229 | public SMatch[] getSMatches(String eventKey) {
230 | JSONArray matches = (JSONArray) IO.doRequest("event/"+eventKey+"/matches/simple");
231 | if(matches == null) throw new DataNotFoundException("No simple matches found for event with key: "+eventKey);
232 | SMatch[] toGet = new SMatch[matches.size()];
233 | for(int i = 0; i < matches.size(); i++) toGet[i] = parseSMatch(matches.get(i));
234 | TBA.sort(toGet);
235 | return toGet;
236 | }
237 |
238 | /**
239 | * Mirror of: /event/{event_key}/matches/keys
240 | *
241 | * GGets a list of match keys for the given event.
242 | * @param eventKey TBA Event Key, eg 2016nytr
243 | * @return String[] containing matches keys for the specified event
244 | */
245 | public String[] getMatchKeys(String eventKey) {
246 | JSONArray keys = (JSONArray) IO.doRequest("event/"+eventKey+"/matches/keys");
247 | if(keys == null) throw new DataNotFoundException("No match keys found for event with key: "+eventKey);
248 | return Utils.jsonArrayToStringArray(keys);
249 | }
250 |
251 | /**
252 | * Mirror of: /event/{event_key}/awards
253 | *
254 | * Gets a list of awards from the given event.
255 | * @param eventKey TBA Event Key, eg 2016nytr
256 | * @return Award[] containing all the awards won in this event
257 | */
258 | public Award[] getEventAwards(String eventKey) {
259 | JSONArray array = (JSONArray) IO.doRequest("event/"+eventKey+"/awards");
260 | if(array == null) throw new DataNotFoundException("No awards found for event with key: "+eventKey);
261 | Award[] toReturn = new Award[array.size()];
262 | for(int i = 0; i < array.size(); i++) toReturn[i] = parseAward(array.get(i));
263 | return toReturn;
264 | }
265 |
266 | /**
267 | * Mirror of: /event/{event_key}/rankings
268 | * @param eventKey TBA Event Key, eg 2016nytr
269 | * @return EventRanking[] containing rankings of teams in this event
270 | */
271 | public EventRanking[] getEventRankings(String eventKey) {
272 | JSONObject ranking = (JSONObject) (IO.doRequest("event/"+eventKey+"/rankings"));
273 |
274 | if(ranking == null) throw new DataNotFoundException("No rankings found for event with key: "+eventKey);
275 | JSONArray rankings = (JSONArray) ranking.get("rankings");
276 | EventRanking[] toGet = new EventRanking[rankings.size()];
277 | for(int i = 0; i < rankings.size(); i++) toGet[i] = parseEventRanking(rankings.get(i));
278 | TBA.sort(toGet);
279 | return toGet;
280 | }
281 |
282 | }
283 |
--------------------------------------------------------------------------------
/src/main/java/com/cpjd/requests/MatchRequest.java:
--------------------------------------------------------------------------------
1 | package com.cpjd.requests;
2 |
3 | import com.cpjd.models.matches.SMatch;
4 | import com.cpjd.models.matches.Match;
5 | import com.cpjd.utils.IO;
6 | import com.cpjd.utils.Parser;
7 | import com.cpjd.utils.exceptions.DataNotFoundException;
8 |
9 | /**
10 | * In an attempt to keep this API organized, if you look at the blue alliance v3 documentation, all calls that start with /match/
11 | * will be accessed from this class.
12 | *
13 | * @since 1.0.0
14 | * @author Will Davies
15 | */
16 | public class MatchRequest extends Parser {
17 |
18 | /**
19 | * Mirror of: /match/{match_key}
20 | *
21 | * Gets a Match object for the given match key.
22 | * @param matchKey TBA Match Key, eg 2016nytr_qm1
23 | * @return Match object represented by the match key
24 | */
25 | public Match getMatch(String matchKey) {
26 | Match m = parseMatch(IO.doRequest("match/"+matchKey));
27 | if(m == null) throw new DataNotFoundException("No match found with key: "+matchKey);
28 | return m;
29 | }
30 |
31 | /**
32 | * Mirror of: /match/{match_key}/simple
33 | *
34 | * Gets a Match object for the given match key.
35 | * @param matchKey TBA Match Key, eg 2016nytr_qm1
36 | * @return SMatch object represented by the match key (simple model)
37 | */
38 | public SMatch getSMatch(String matchKey) {
39 | SMatch m = parseSMatch(IO.doRequest("match/"+matchKey+"/simple"));
40 | if(m == null) throw new DataNotFoundException("No match found with key: "+matchKey);
41 | return m;
42 | }
43 |
44 |
45 |
46 | }
47 |
--------------------------------------------------------------------------------
/src/main/java/com/cpjd/requests/OtherRequest.java:
--------------------------------------------------------------------------------
1 | package com.cpjd.requests;
2 |
3 | import com.cpjd.models.APIStatus;
4 | import com.cpjd.utils.IO;
5 | import com.cpjd.utils.Parser;
6 | import com.cpjd.utils.exceptions.DataNotFoundException;
7 |
8 | /**
9 | * @since 1.0.0
10 | * @author Will Davies
11 | */
12 | public class OtherRequest extends Parser {
13 |
14 | /**
15 | * Returns API status, and TBA status information.
16 | * @return APIStatus representing the state of the TBA API interface
17 | */
18 | public APIStatus getStatus() {
19 | APIStatus status = parseStatus(IO.doRequest("status"));
20 | if (status == null) throw new DataNotFoundException("Unable to fetch API status.");
21 | return status;
22 | }
23 |
24 | /**
25 | * Makes a custom call to the URL
26 | * @param URL the URL suffix to make a call to, this API automatically fills in Constants.URL for you, so an example parameter here might be 'teams/{page_num}'
27 | * @return an Object (json formatted), representing the data received from the server
28 | */
29 | public Object customCall(String URL) {
30 | Object o = IO.doRequest(URL);
31 | if(o == null) throw new DataNotFoundException("No response for your custom URL call");
32 | return o;
33 | }
34 |
35 | }
--------------------------------------------------------------------------------
/src/main/java/com/cpjd/requests/TeamRequest.java:
--------------------------------------------------------------------------------
1 | package com.cpjd.requests;
2 |
3 | import com.cpjd.main.TBA;
4 | import com.cpjd.models.events.Award;
5 | import com.cpjd.models.events.Media;
6 | import com.cpjd.models.teams.Robot;
7 | import com.cpjd.models.events.SEvent;
8 | import com.cpjd.models.matches.SMatch;
9 | import com.cpjd.models.teams.STeam;
10 | import com.cpjd.models.events.Event;
11 | import com.cpjd.models.matches.Match;
12 | import com.cpjd.models.teams.Team;
13 | import org.json.simple.JSONArray;
14 | import com.cpjd.utils.IO;
15 | import com.cpjd.utils.Parser;
16 | import com.cpjd.utils.Utils;
17 | import com.cpjd.utils.exceptions.DataNotFoundException;
18 |
19 | /**
20 | * In an attempt to keep this API organized, if you look at the blue alliance v3 documentation, all calls that start with /teams/ or /team/
21 | * will be accessed from this class.
22 | *
23 | * API calls not implemented yet:
24 | * /team/{team_key}/event/{event_key}/status
25 | *
26 | * @since 1.0.0
27 | * @author Will Davies
28 | */
29 | public class TeamRequest extends Parser {
30 |
31 | /**
32 | * Mirror of: /teams/{page_num}
33 | *
34 | * Gets a list of Team objects, paginated in groups of 500.
35 | * @param pageNum the page number, eg: 0 for the first 500, 1 for the second 500, etc.
36 | * @return list of Team objects (full team models)
37 | */
38 | public Team[] getTeams(int pageNum) {
39 | JSONArray teams = (JSONArray) IO.doRequest("teams/"+pageNum);
40 | if(teams == null) throw new DataNotFoundException("No teams were found with pageNum: "+pageNum);
41 | Team[] toGet = new Team[teams.size()];
42 | for(int i = 0; i < toGet.length; i++) toGet[i] = parseTeam(teams.get(i));
43 | TBA.sort(toGet);
44 | return toGet;
45 | }
46 |
47 | /**
48 | * Mirror of: /teams/{page_num}/simple
49 | *
50 | * Gets a list of STeam objects, paginated in groups of 500.
51 | * @param pageNum the page number, eg: 0 for the first 500, 1 for the second 500, etc.
52 | * @return list of STeam objects (simple team models)
53 | */
54 | public STeam[] getSTeams(int pageNum) {
55 | JSONArray teams = (JSONArray) IO.doRequest("teams/"+pageNum+"/simple");
56 | if(teams == null) throw new DataNotFoundException("No simple teams were found with pageNum: "+pageNum);
57 | STeam[] toGet = new STeam[teams.size()];
58 | for(int i = 0; i < toGet.length; i++) toGet[i] = parseSTeam(teams.get(i));
59 | TBA.sort(toGet);
60 | return toGet;
61 | }
62 |
63 | /**
64 | * Mirror of: /teams/{page_num}/keys
65 | *
66 | * Gets a list of Team keys, paginated in groups of 500. (Note, each page will not have 500 teams, but will include the teams within that range of 500.)
67 | * @param pageNum the page number, eg: 0 for the first 500, 1 for the second 500, etc.
68 | * @return String[] of team keys in the format 'frc254'
69 | */
70 | public String[] getTeamKeys(int pageNum) {
71 | JSONArray keys = (JSONArray) IO.doRequest("teams/"+pageNum+"/keys");
72 | if(keys == null) throw new DataNotFoundException("No team key was found with pageNum: "+pageNum);
73 | return Utils.jsonArrayToStringArray(keys);
74 | }
75 |
76 | /**
77 | * Mirror of: /teams/{year}/{page_num}
78 | *
79 | * Gets a list of Team objects that competed in the given year, paginated in groups of 500.
80 | * @param year the year to get teams from
81 | * @param pageNum the page number, eg: 0 for the first 500, 1 for the second 500, etc.
82 | * @return list of Team objects (full models)
83 | */
84 | public Team[] getTeams(int year, int pageNum) {
85 | JSONArray teams = (JSONArray) IO.doRequest("teams/"+year+"/"+pageNum);
86 | if(teams == null) throw new DataNotFoundException("No teams were found with pageNum: "+pageNum+", year: "+year);
87 | Team[] toGet = new Team[teams.size()];
88 | for(int i = 0; i < toGet.length; i++) toGet[i] = parseTeam(teams.get(i));
89 | TBA.sort(toGet);
90 | return toGet;
91 | }
92 |
93 | /**
94 | * Mirror of: /teams/{year}/{page_num}/simple
95 | *
96 | * Gets a list of Team objects that competed in the given year, paginated in groups of 500.
97 | * @param year the year to get teams from
98 | * @param pageNum the page number, eg: 0 for the first 500, 1 for the second 500, etc.
99 | * @return list of Team objects (simple models)
100 | */
101 | public STeam[] getSTeams(int year, int pageNum) {
102 | JSONArray teams = (JSONArray) IO.doRequest("teams/"+year+"/"+pageNum+"/simple");
103 | if(teams == null) throw new DataNotFoundException("No simple teams were found with pageNum: "+pageNum+", year: "+year);
104 | STeam[] toGet = new STeam[teams.size()];
105 | for(int i = 0; i < toGet.length; i++) toGet[i] = parseSTeam(teams.get(i));
106 | TBA.sort(toGet);
107 | return toGet;
108 | }
109 |
110 | /**
111 | * Mirror of: /team/{year}/{page_num}/keys
112 | *
113 | * Gets a list Team Keys that competed in the given year, paginated in groups of 500.
114 | * @param year the year to get teams from
115 | * @return String[] of team keys in format 'frc254'
116 | */
117 | public String[] getTeamKeys(int year, int pageNum) {
118 | JSONArray keys = (JSONArray) IO.doRequest("teams/"+year+"/"+pageNum+"/keys");
119 | if(keys == null) throw new DataNotFoundException("No team keys were found with pageNum: "+pageNum+", year: "+year);
120 | return Utils.jsonArrayToStringArray(keys);
121 | }
122 |
123 | /**
124 | * Mirror of: /team/{team_key}
125 | *
126 | * Gets the specified team (full team model)
127 | * @param number the team's frc number
128 | * @return Team object (full model)
129 | */
130 | public Team getTeam(int number) {
131 | Team team = parseTeam(IO.doRequest("team/frc"+number));
132 | if(team == null) throw new DataNotFoundException("No team found with number: "+number);
133 | return team;
134 | }
135 |
136 | /**
137 | * Mirror of: /team{team_key}/simple
138 | *
139 | * Gets the specified team (simple team model)
140 | * @param number the team's frc number
141 | * @return STeam object (simple model)
142 | */
143 | public STeam getSTeam(int number) {
144 | STeam team = parseSTeam(IO.doRequest("team/frc"+number));
145 | if(team == null) throw new DataNotFoundException("No simple team found with number: "+number);
146 | return team;
147 | }
148 |
149 | /**
150 | * Mirror of: /team/{team_key}/years_participated
151 | *
152 | * Returns an array containing the years that a particular team participated in FRC events
153 | * @param number the team's frc number
154 | * @return long[] containing years participated
155 | */
156 | public long[] getYearsParticipated(int number) {
157 | JSONArray keys = (JSONArray) IO.doRequest("team/frc"+number+"/years_participated");
158 | if(keys == null) throw new DataNotFoundException("Couldn't find years participated for team with number: "+number);
159 | String[] data = Utils.jsonArrayToStringArray(keys);
160 | long[] years = new long[data.length];
161 | for(int i = 0; i < years.length; i++) {
162 | years[i] = Long.parseLong(data[i]);
163 | }
164 | return years;
165 | }
166 |
167 | /**
168 | * Mirror of: /team/{team_key}/districts
169 | *
170 | * Gets the districts this team was in, empty array if none
171 | * @param number the team's frc number
172 | * @return District[] containing a District object for each district this team was in
173 | */
174 | public String[] getTeamDistricts(int number) {
175 | JSONArray keys = (JSONArray) IO.doRequest("team/frc"+number+"/districts");
176 | if(keys == null) throw new DataNotFoundException("Couldn't find any district keys for team with number: "+number);
177 | return Utils.jsonArrayToStringArray(keys);
178 | }
179 |
180 | /**
181 | * Mirror of: /team{team_key}/robots
182 | *
183 | * Gets the robots that this team has had
184 | * @param number the team's frc number
185 | * @return Robot[] containing a Robot object for each robot this team has built
186 | */
187 | public Robot[] getRobots(int number) {
188 | Robot[] robots = parseRobots(IO.doRequest("team/frc"+number+"/robots"));
189 | if(robots == null) throw new DataNotFoundException("Couldn't robots for team with number: "+number);
190 | TBA.sort(robots);
191 | return robots;
192 | }
193 |
194 | /**
195 | * Mirror of: /team/{team_key}/events
196 | *
197 | * Gets a list of all events this team has competed at.
198 | * @param number the team's frc number
199 | * @return Event[] containing an Event object for each event this team was in
200 | */
201 | public Event[] getTeamEvents(int number) {
202 | JSONArray events = (JSONArray) IO.doRequest("team/frc"+number+"/events");
203 | if(events == null) throw new DataNotFoundException("Couldn't find any events for team with number: "+number);
204 | Event[] toGet = new Event[events.size()];
205 | for(int i = 0; i < events.size(); i++) {
206 | toGet[i] = parseEvent(events.get(i));
207 | }
208 | TBA.sort(toGet);
209 | return toGet;
210 | }
211 |
212 | /**
213 | * Mirror of: /team/{team_key}/events/simple
214 | *
215 | * Gets a list of all events this team has competed at.
216 | * @param number the team's frc number
217 | * @return SEvent[] containing an Event object for each event this team was in (simple model)
218 | */
219 | public SEvent[] getTeamSEvents(int number) {
220 | JSONArray events = (JSONArray) IO.doRequest("team/frc"+number+"/events/simple");
221 | if(events == null) throw new DataNotFoundException("Couldn't find any simple events for team with number: "+number);
222 | SEvent[] toGet = new SEvent[events.size()];
223 | for(int i = 0; i < events.size(); i++) {
224 | toGet[i] = parseSEvent(events.get(i));
225 | }
226 | TBA.sort(toGet);
227 | return toGet;
228 | }
229 |
230 | /**
231 | * Mirror of: /team/{team_key}/events_keys
232 | *
233 | * Gets a list of the event keys for all events this team has competed at.
234 | * @param number the team's frc number
235 | * @return String[] containg all the event keys for events this team is in
236 | */
237 | public String[] getTeamEventKeys(int number) {
238 | JSONArray keys = (JSONArray) IO.doRequest("team/frc"+number+"/events/keys");
239 | if(keys == null) throw new DataNotFoundException("Couldn't find any event keys for team with number: "+number);
240 | return Utils.jsonArrayToStringArray(keys);
241 | }
242 |
243 | /**
244 | * Mirror of: /team/{team_key}/events/{year}
245 | *
246 | * Gets a list of events this team has competed at in the given year.
247 | * @param number the team's frc number
248 | * @param year the year to get events from
249 | * @return Event[] containing an Event object for each event this team was in the specified year (full model)
250 | */
251 | public Event[] getEvents(int number, int year) {
252 | JSONArray events = (JSONArray) IO.doRequest("team/frc"+number+"/events/"+year);
253 | if(events == null) throw new DataNotFoundException("Couldn't find any events for team with number: "+number+", year: "+year);
254 | Event[] toGet = new Event[events.size()];
255 | for(int i = 0; i < events.size(); i++) {
256 | toGet[i] = parseEvent(events.get(i));
257 | }
258 | TBA.sort(toGet);
259 | return toGet;
260 | }
261 |
262 | /**
263 | * Mirror of: /team/{team_key}/events/{year}/simple
264 | *
265 | * Gets a short-form list of events this team has competed at in the given year.
266 | * @param number the team's frc number
267 | * @param year the year to get events from
268 | * @return Event[] containing an Event object for each event this team was in the specified year (simple model)
269 | */
270 | public SEvent[] getSEvents(int number, int year) {
271 | JSONArray events = (JSONArray) IO.doRequest("team/frc"+number+"/events/"+year+"/simple");
272 | if(events == null) throw new DataNotFoundException("Couldn't find any simple events for team with number: "+number+", year: "+year);
273 | SEvent[] toGet = new SEvent[events.size()];
274 | for(int i = 0; i < events.size(); i++) {
275 | toGet[i] = parseSEvent(events.get(i));
276 | }
277 | TBA.sort(toGet);
278 | return toGet;
279 | }
280 |
281 | /**
282 | * Mirror of: /team/{team_key}/events/{year}/keys
283 | *
284 | * Gets a list of the event keys for events this team has competed at in the given year.
285 | * @param number the team's frc number
286 | * @param year the year to get events from
287 | * @return String[] containing an event key for each event this team has participated in
288 | */
289 | public String[] getEventKeys(int number, int year) {
290 | JSONArray keys = (JSONArray) IO.doRequest("team/frc"+number+"/events/"+year+"/keys");
291 | if(keys == null) throw new DataNotFoundException("Couldn't find any event keys for team with number: "+number+", year: "+year);
292 | return Utils.jsonArrayToStringArray(keys);
293 | }
294 |
295 | /**
296 | * Mirror of: /team/{team_key}/event/{event_key}/matches
297 | *
298 | * Gets a list of matches for the given team and event.
299 | * @param number the team's frc number
300 | * @param eventKey the event's key code (example: '2016nytr')
301 | * @return Match[] containing a match for each match this team was in in the specified event
302 | */
303 | public Match[] getTeamEventMatches(int number, String eventKey) {
304 | JSONArray matches = (JSONArray) IO.doRequest("team/frc"+number+"/event/"+eventKey+"/matches");
305 | if(matches == null) throw new DataNotFoundException("Couldn't find any matches for team with number: "+number+", event key: "+eventKey);
306 | Match[] toGet = new Match[matches.size()];
307 | for(int i = 0; i < matches.size(); i++) {
308 | toGet[i] = parseMatch(matches.get(i));
309 | }
310 | TBA.sort(toGet);
311 | return toGet;
312 | }
313 |
314 | /**
315 | * Mirror of: /team/{team_key}/event/{event_key}/matches/simple
316 | *
317 | * Gets a short-form list of matches for the given team and event.
318 | * @param number the team's frc number
319 | * @param eventKey the event's key code (example: '2016nytr')
320 | * @return SMatch[] containing a match for each match this team was in in the specified event (simple model)
321 | */
322 | public SMatch[] getTeamEventSMatches(int number, String eventKey) {
323 | JSONArray matches = (JSONArray) IO.doRequest("team/frc"+number+"/event/"+eventKey+"/matches/simple");
324 | if(matches == null) throw new DataNotFoundException("Couldn't find any simple matches for team with number: "+number+", event key: "+eventKey);
325 | SMatch[] toGet = new SMatch[matches.size()];
326 | for(int i = 0; i < matches.size(); i++) {
327 | toGet[i] = parseSMatch(matches.get(i));
328 | }
329 | TBA.sort(toGet);
330 | return toGet;
331 | }
332 |
333 | /**
334 | * Mirror of: /team/{team_key}/event/{event_key}/matches/keys
335 | *
336 | * Gets a list of the event keys for events this team has competed at in the given year.
337 | * @param number the team's frc number
338 | * @param eventKey the event's key code (example: '2016nytr')
339 | * @return String[] containing an event key for each event this team has participated in
340 | */
341 | public String[] getMatchKeys(int number, String eventKey) {
342 | JSONArray keys = (JSONArray) IO.doRequest("team/frc"+number+"/event/"+eventKey+"/matches/keys");
343 | if(keys == null) throw new DataNotFoundException("Couldn't find any matche keys for team with number: "+number+", event key: "+eventKey);
344 | return Utils.jsonArrayToStringArray(keys);
345 | }
346 |
347 | /**
348 | * Mirror of: /team/{team_key}/event/{event_key}/awards
349 | *
350 | * Gets a list of awards the given team won at the given event.
351 | * @param number the team's frc number
352 | * @param eventKey the event's key code (example: '2016nytr')
353 | * @return Award[] containing n award object for each award this team won in the specified event
354 | */
355 | public Award[] getTeamEventAwards(int number, String eventKey) {
356 | JSONArray awards = (JSONArray) IO.doRequest("team/frc"+number+"/event/"+eventKey+"/awards");
357 | if(awards == null) throw new DataNotFoundException("Couldn't find any awards for team with number: "+number+", event key: "+eventKey);
358 | Award[] toGet= new Award[awards.size()];
359 | for(int i = 0; i < awards.size(); i++) toGet[i] = parseAward(awards.get(i));
360 | return toGet;
361 | }
362 |
363 | /**
364 | * Mirror of: /team/{team_key}/awards
365 | *
366 | * Gets a list of awards the given team has won.
367 | * @param number the team's frc number
368 | * @return Award[] containing all the awards this team has won
369 | */
370 | public Award[] getTeamAwards(int number) {
371 | JSONArray awards = (JSONArray) IO.doRequest("team/frc"+number+"/awards");
372 | if(awards == null) throw new DataNotFoundException("Couldn't find any awards for team with number: "+number);
373 | Award[] toGet= new Award[awards.size()];
374 | for(int i = 0; i < awards.size(); i++) toGet[i] = parseAward(awards.get(i));
375 | return toGet;
376 | }
377 |
378 | /**
379 | * Mirror of: /team/{team_key}/awards/{year}
380 | *
381 | * Gets a list of awards the given team has won.
382 | * @param number the team's frc number
383 | * @param year the year
384 | * @return Award[] containing all the awards this team has won
385 | */
386 | public Award[] getTeamAwards(int number, int year) {
387 | JSONArray awards = (JSONArray) IO.doRequest("team/frc"+number+"/awards/"+year);
388 | if(awards == null) throw new DataNotFoundException("Couldn't find any awards for team with number: "+number+", year: "+year);
389 | Award[] toGet= new Award[awards.size()];
390 | for(int i = 0; i < awards.size(); i++) toGet[i] = parseAward(awards.get(i));
391 | return toGet;
392 | }
393 |
394 | /**
395 | * Mirror of: /team/{team_key}/matches/{year}
396 | *
397 | * Gets a list of matches for the given team and year.
398 | * @param number the team's frc number
399 | * @param year the year
400 | * @return Match[] containing all the matches the specified team was in for the specified year
401 | */
402 | public Match[] getTeamMatches(int number, int year) {
403 | JSONArray matches = (JSONArray) IO.doRequest("team/frc"+number+"/matches/"+year);
404 | if(matches == null) throw new DataNotFoundException("Couldn't find any matches for team with number: "+number+", year: "+year);
405 | Match[] toGet = new Match[matches.size()];
406 | for(int i = 0; i < matches.size(); i++) toGet[i] = parseMatch(matches.get(i));
407 | TBA.sort(toGet);
408 | return toGet;
409 | }
410 |
411 | /**
412 | * Mirror of: /team/{team_key}/matches/{year}/simple
413 | *
414 | * Gets a list of matches for the given team and year.
415 | * @param number the team's frc number
416 | * @param year the year
417 | * @return SMatch[] containing all the matches the specified team was in for the specified year (simple models)
418 | */
419 | public SMatch[] getTeamSMatches(int number, int year) {
420 | JSONArray matches = (JSONArray) IO.doRequest("team/frc"+number+"/matches/"+year+"/simple");
421 | if(matches == null) throw new DataNotFoundException("Couldn't find any simple matches for team with number: "+number+", year: "+year);
422 | SMatch[] toGet = new SMatch[matches.size()];
423 | for(int i = 0; i < matches.size(); i++) toGet[i] = parseSMatch(matches.get(i));
424 | TBA.sort(toGet);
425 | return toGet;
426 | }
427 |
428 | /**
429 | * Mirror of: /team/{team_key}/matches/{year}/keys
430 | *
431 | * Gets a list of match keys for matches for the given team and year.
432 | * @param number the team's frc number
433 | * @param year the year to get match keys from
434 | * @return String[] containing match string keys for each match
435 | */
436 | public String[] getTeamMatchKeys(int number, int year) {
437 | JSONArray keys = (JSONArray) IO.doRequest("team/frc"+number+"/matches/"+year+"/keys");
438 | if(keys == null) throw new DataNotFoundException("Couldn't find any match keys for team with number: "+number+", year: "+year);
439 | return Utils.jsonArrayToStringArray(keys);
440 | }
441 |
442 | /**
443 | * Mirror of: /team/{team_key}/media/{year}
444 | *
445 | * Gets a list of Media (videos / pictures) for the given team and year.
446 | * @param number the team's frc number
447 | * @param year the year
448 | * @return Media[] containing all the media associated with this team for the specified year
449 | */
450 | public Media[] getTeamMedia(int number, int year) {
451 | JSONArray medias = (JSONArray) IO.doRequest("team/frc"+number+"/media/"+year);
452 | if(medias == null) throw new DataNotFoundException("Couldn't find any media for team with number: "+number+", year: "+year);
453 | Media[] toGet = new Media[medias.size()];
454 | for(int i = 0; i < medias.size(); i++) toGet[i] = parseMedia(medias.get(i));
455 | return toGet;
456 | }
457 |
458 | /**
459 | * Mirror of: /team/{team_key}/social_media
460 | *
461 | * Gets a list of Media (social media) for the given team.
462 | * @param number the team's frc number
463 | * @return Media[] containing all social media associated with this team
464 | */
465 | public Media[] getTeamSocialMedia(int number) {
466 | JSONArray medias = (JSONArray) IO.doRequest("team/frc"+number+"/social_media");
467 | if(medias == null) throw new DataNotFoundException("Couldn't find any social media for team with number: "+number);
468 | Media[] toGet = new Media[medias.size()];
469 | for(int i = 0; i < medias.size(); i++) toGet[i] = parseMedia(medias.get(i));
470 | return toGet;
471 | }
472 | }
473 |
--------------------------------------------------------------------------------
/src/main/java/com/cpjd/sorting/Sortable.java:
--------------------------------------------------------------------------------
1 | package com.cpjd.sorting;
2 |
3 | public abstract class Sortable {
4 |
5 | public abstract int sort(SortingType type, boolean ascending, T t2);
6 |
7 | }
8 |
--------------------------------------------------------------------------------
/src/main/java/com/cpjd/sorting/SortingType.java:
--------------------------------------------------------------------------------
1 | package com.cpjd.sorting;
2 |
3 | public enum SortingType {
4 | DEFAULT,
5 | NAME,
6 | NUMBER,
7 | DATE,
8 | RANK,
9 | TEAM
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/com/cpjd/tests/Test.java:
--------------------------------------------------------------------------------
1 | package com.cpjd.tests;
2 |
3 | import com.cpjd.main.TBA;
4 | import com.cpjd.models.events.Alliance;
5 | import com.cpjd.models.events.Event;
6 | import com.cpjd.models.events.Insight;
7 | import com.cpjd.requests.EventRequest;
8 | import com.cpjd.sorting.Sortable;
9 | import com.cpjd.sorting.SortingType;
10 | import com.cpjd.utils.IO;
11 |
12 | public class Test {
13 | public static void main(String[] args) {
14 | TBA.setAuthToken("xgqQi9cACRSUt4xanOto70jLPxhz4lR2Mf83e2iikyR2vhOmr1Kvg1rDBlAQcOJg");
15 |
16 | // Case 1
17 | // Match[] matches = new TBA().getMatches("2018txpa");
18 | // System.out.println(matches.length);
19 | //
20 | // // Case 2
21 | // Team[] teams = new TBA().getEventTeams("2018txpa");
22 | // System.out.println(teams.length);
23 | //
24 | // // Case 3
25 | // EventOPR[] oprs = new TBA().getOprs("2018txpa");
26 | ////
27 | // Event e = new TBA().getEvent("2018code");
28 | //
29 | // Match[] colorado = new TBA().getMatches("2018code");
30 | // Match m = colorado[0]; // choose a match you're interested in
31 | // System.out.println("Match number: "+m.getMatchNumber());
32 | // System.out.println("Red team #1: "+m.getRed().getTeamKeys()[0]);
33 | // System.out.println("Blue team #3: "+m.getBlue().getTeamKeys()[2]);
34 | // You can take a look at:
35 | // https://github.com/wdavies973/TBA-API-V3/blob/master/src/main/java/com/cpjd/models/simple/SMatch.java
36 | // For a list of variables you can get.
37 |
38 |
39 | Insight alliances = new EventRequest().getEventInsights("2016nytr");
40 | System.out.println(IO.doRequest("event/2016nytr/district_points"));
41 |
42 |
43 | }
44 |
45 | }
46 |
--------------------------------------------------------------------------------
/src/main/java/com/cpjd/utils/IO.java:
--------------------------------------------------------------------------------
1 | package com.cpjd.utils;
2 |
3 | import com.cpjd.main.Constants;
4 | import org.json.simple.parser.JSONParser;
5 | import com.cpjd.utils.exceptions.AuthTokenNotFoundException;
6 |
7 | import java.io.BufferedReader;
8 | import java.io.InputStream;
9 | import java.io.InputStreamReader;
10 | import java.net.HttpURLConnection;
11 | import java.net.URL;
12 |
13 | /**
14 | * Pulls raw data from the server.
15 | * @since 1.0.0
16 | * @author Will Davies
17 | *
18 | */
19 | public class IO {
20 | private static final JSONParser parser = new JSONParser();
21 |
22 | public static Object doRequest(String targetURL) {
23 | if(Constants.AUTH_TOKEN == null || Constants.AUTH_TOKEN.equals("")) throw new AuthTokenNotFoundException("You have not set an auth token for TBA-API-V3. Please set it with TBA.setAuthToken(String token).");
24 |
25 | HttpURLConnection connection = null;
26 | try {
27 | URL url = new URL( Constants.URL + targetURL);
28 | connection = (HttpURLConnection) url.openConnection();
29 | connection.setRequestMethod("GET");
30 | connection.setRequestProperty("User-Agent", "TBA-API-V3");
31 | connection.setRequestProperty("X-TBA-Auth-Key", Constants.AUTH_TOKEN);
32 | connection.setRequestProperty("Content-SortingType", "application/x-www-form-urlencoded");
33 | connection.setRequestProperty("charset", "utf-8");
34 | connection.setUseCaches(false);
35 |
36 | InputStream is = connection.getInputStream();
37 | BufferedReader rd = new BufferedReader(new InputStreamReader(is));
38 | StringBuilder response = new StringBuilder();
39 | String line;
40 | while ((line = rd.readLine()) != null) {
41 | response.append(line);
42 | response.append('\r');
43 | }
44 | rd.close();
45 | return parser.parse(response.toString());
46 | } catch(Exception e) {
47 | // do nothing, should be handled somewhere else
48 | } finally {
49 | if(connection != null) connection.disconnect();
50 | }
51 | return null;
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/src/main/java/com/cpjd/utils/Parser.java:
--------------------------------------------------------------------------------
1 | package com.cpjd.utils;
2 |
3 | import com.cpjd.models.APIStatus;
4 | import com.cpjd.models.districts.District;
5 | import com.cpjd.models.events.*;
6 | import com.cpjd.models.matches.MatchAlliance;
7 | import com.cpjd.models.teams.Robot;
8 | import com.cpjd.models.matches.SMatch;
9 | import com.cpjd.models.teams.STeam;
10 | import com.cpjd.models.matches.Match;
11 | import com.cpjd.models.teams.Team;
12 | import org.json.simple.JSONArray;
13 | import org.json.simple.JSONObject;
14 |
15 | import java.util.HashMap;
16 |
17 | /**
18 | * Converts the data received from the server into the models found in models/
19 | *
20 | *
21 | * @since 1.0.0
22 | * @author Will Davies
23 | */
24 | public class Parser {
25 |
26 | protected APIStatus parseStatus(Object object) {
27 | APIStatus status = new APIStatus();
28 | HashMap hash = (HashMap) object;
29 | if(hash == null) return null;
30 |
31 | status.setCurrentSeason((long)hash.get("current_season"));
32 | status.setMaxSeason((long)hash.get("max_season"));
33 | status.setDatafeedDown((boolean)hash.get("is_datafeed_down"));
34 | JSONArray downEvents = (JSONArray)hash.get("down_events");
35 | status.setDownEvents(Utils.jsonArrayToStringArray(downEvents));
36 | status.setAndroidMinAppVersion((long) ((JSONObject) hash.get("android")).get("min_app_version"));
37 | status.setAndroidLatestAppVersion((long) ((JSONObject) hash.get("android")).get("latest_app_version"));
38 | status.setIosMinAppVersion((long) ((JSONObject) hash.get("ios")).get("min_app_version"));
39 | status.setIosLatestAppVersion((long) ((JSONObject) hash.get("ios")).get("latest_app_version"));
40 | return status;
41 | }
42 |
43 | protected Team parseTeam(Object object) {
44 | Team team = new Team();
45 | HashMap hash = (HashMap) object;
46 | if(hash == null) return null;
47 |
48 | team.setKey((String)hash.get("key"));
49 | team.setTeamNumber((long)hash.get("team_number"));
50 | team.setNickname((String)hash.get("nickname"));
51 | team.setName((String)hash.get("name"));
52 | team.setCity((String)hash.get("city"));
53 | team.setStateProv((String)hash.get("state_prov"));
54 | team.setCountry((String)hash.get("country"));
55 | team.setAddress((String)hash.get("address"));
56 | team.setPostalCode((String)hash.get("postal_code"));
57 | team.setGMAPSPlaceID((String)hash.get("gmaps_place_id"));
58 | team.setGMAPURL((String)hash.get("gmaps_url"));
59 | team.setLatitude(Utils.cleanDouble(hash.get("lat")));
60 | team.setLongitude(Utils.cleanDouble(hash.get("lng")));
61 | team.setLocationName((String)hash.get("location_name"));
62 | team.setWebsite((String)hash.get("website"));
63 | team.setRookieYear(Utils.cleanLong(hash.get("rookie_year")));
64 | team.setMotto((String)hash.get("motto"));
65 | return team;
66 | }
67 |
68 | protected STeam parseSTeam(Object object) {
69 | STeam team = new STeam();
70 | HashMap hash = (HashMap) object;
71 | if(hash == null) return null;
72 |
73 | team.setKey((String)hash.get("key"));
74 | team.setTeamNumber((long)hash.get("team_number"));
75 | team.setNickname((String)hash.get("nickname"));
76 | team.setName((String)hash.get("name"));
77 | team.setCity((String)hash.get("city"));
78 | team.setStateProv((String)hash.get("state_prov"));
79 | team.setCountry((String)hash.get("country"));
80 | return team;
81 | }
82 |
83 | protected District parseDistrict(Object object) {
84 | HashMap hash = (HashMap) object;
85 | District d = new District();
86 | if(hash == null) return null;
87 |
88 | d.setAbbreviation((String)hash.get("abbreviation"));
89 | d.setDisplayName((String)hash.get("display_name"));
90 | d.setKey((String)hash.get("key"));
91 | d.setYear(Utils.cleanLong(hash.get("year")));
92 | return d;
93 | }
94 |
95 | protected Robot[] parseRobots(Object object) {
96 | JSONArray robotsList = (JSONArray) object;
97 | Robot[] robots = new Robot[robotsList.size()];
98 | for(int i = 0; i < robotsList.size(); i++) {
99 | Robot r = new Robot();
100 | JSONObject o = (JSONObject) robotsList.get(i);
101 | r.setYear(Utils.cleanLong(o.get("year")));
102 | r.setRobotName((String)o.get("robot_name"));
103 | r.setKey((String)o.get("key"));
104 | r.setTeamKey((String)o.get("team_key"));
105 | robots[i] = r;
106 | }
107 | return robots;
108 | }
109 |
110 | protected Event parseEvent(Object object) {
111 | Event e = new Event();
112 | HashMap hash = (HashMap) object;
113 | if(hash == null) return null;
114 |
115 | e.setKey((String)hash.get("key"));
116 | e.setName((String)hash.get("name"));
117 | e.setEventCode((String)hash.get("event_code"));
118 | e.setEventType(Utils.cleanLong(hash.get("event_type")));
119 | e.setStateProv((String)hash.get("state_prov"));
120 | e.setCountry((String)hash.get("country"));
121 | e.setStartDate((String)hash.get("start_date"));
122 | e.setEndDate((String)hash.get("end_Date"));
123 | e.setYear(Utils.cleanLong(hash.get("year")));
124 | e.setDistrict(parseDistrict(hash.get("district")));
125 | e.setCity((String)hash.get("city"));
126 | e.setShortName((String)hash.get("short_name"));
127 | e.setEventTypeString((String)hash.get("event_type_string"));
128 | e.setWeek(Utils.cleanLong(hash.get("week")));
129 | e.setAddress((String)hash.get("address"));
130 | e.setPostalCode((String)hash.get("postal_code"));
131 | e.setGMAPSPlaceID((String)hash.get("gmaps_place_id"));
132 | e.setGMAPSURL((String)hash.get("gmaps_url"));
133 | e.setLongitude(Utils.cleanDouble(hash.get("lng")));
134 | e.setLatitude(Utils.cleanDouble(hash.get("lat")));
135 | e.setLocationName((String)hash.get("location_name"));
136 | e.setTimezone((String)hash.get("timezone"));
137 | e.setWebsite((String)hash.get("website"));
138 | e.setFirstEventID((String)hash.get("first_event_id"));
139 | e.setParentEventkey((String)hash.get("parent_event_key"));
140 | e.setPlayoffType(Utils.cleanLong(hash.get("playoff_type")));
141 | e.setPlayoffTypeString((String)hash.get("playoff_type_string"));
142 | JSONArray keys = (JSONArray) hash.get("division_keys");
143 | e.setDivisonKeys(Utils.jsonArrayToStringArray(keys));
144 | JSONArray webcasts = (JSONArray) hash.get("webcasts");
145 | Webcast[] casts = new Webcast[webcasts.size()];
146 | for(int i = 0; i < webcasts.size(); i++) {
147 | Webcast w = new Webcast();
148 | JSONObject o = (JSONObject) webcasts.get(i);
149 | w.setChannel((String)o.get("channel"));
150 | w.setType((String)o.get("type"));
151 | w.setFile((String)o.get("file"));
152 | casts[i] = w;
153 | }
154 | e.setWebcasts(casts);
155 | return e;
156 | }
157 |
158 | protected SEvent parseSEvent(Object object) {
159 | SEvent e = new SEvent();
160 | HashMap hash = (HashMap) object;
161 | if(hash == null) return null;
162 |
163 | e.setKey((String)hash.get("key"));
164 | e.setName((String)hash.get("name"));
165 | e.setEventCode((String)hash.get("event_code"));
166 | e.setEventType(Utils.cleanLong(hash.get("event_type")));
167 | e.setStateProv((String)hash.get("state_prov"));
168 | e.setCountry((String)hash.get("country"));
169 | e.setStartDate((String)hash.get("start_date"));
170 | e.setEndDate((String)hash.get("end_Date"));
171 | e.setYear(Utils.cleanLong(hash.get("year")));
172 | e.setDistrict(parseDistrict(hash.get("district")));
173 | return e;
174 | }
175 |
176 | protected Media parseMedia(Object object) {
177 | Media media = new Media();
178 | HashMap hash = (HashMap)object;
179 | if(hash == null) return null;
180 |
181 | media.setKey((String)hash.get("key"));
182 | media.setType((String)hash.get("type"));
183 | media.setForeignKey((String)hash.get("foreign_key"));
184 | media.setDetails((String)hash.get("details"));
185 | media.setPreferred(Utils.cleanBoolean(hash.get("preferred")));
186 | return media;
187 | }
188 |
189 | protected Match parseMatch(Object object) {
190 | Match m = new Match();
191 | HashMap hash = (HashMap) object;
192 | if(hash == null) return null;
193 |
194 | m.setKey((String)hash.get("key"));
195 | m.setCompLevel((String)hash.get("comp_level"));
196 | m.setSetNumber(Utils.cleanLong(hash.get("set_number")));
197 | m.setMatchNumber(Utils.cleanLong(hash.get("match_number")));
198 | m.setWinningAlliance((String)hash.get("winning_alliance"));
199 | m.setEventKey((String)hash.get("event_key"));
200 | m.setTime(Utils.cleanLong(hash.get("time")));
201 | m.setActualTime(Utils.cleanLong(hash.get("actual_time")));
202 | m.setPredictedTime(Utils.cleanLong(hash.get("predicted_time")));
203 | m.setPostResultTime(Utils.cleanLong(hash.get("post_result_time")));
204 | try {
205 | JSONObject obj = (JSONObject)hash.get("score_breakdown");
206 | m.setRedScoreBreakdown(new HashMap((JSONObject)obj.get("red")));
207 | m.setBlueScoreBreakdown(new HashMap((JSONObject)obj.get("blue")));
208 | } catch(Exception e) {}
209 |
210 | JSONObject allies = (JSONObject) hash.get("alliances");
211 | if(allies != null) {
212 | JSONObject blue = (JSONObject) allies.get("blue");
213 | JSONObject red = (JSONObject) allies.get("red");
214 | MatchAlliance redAlly = new MatchAlliance();
215 | MatchAlliance blueAlly = new MatchAlliance();
216 | redAlly.setScore(Utils.cleanLong(red.get("score")));
217 | blueAlly.setScore(Utils.cleanLong(blue.get("score")));
218 | JSONArray redTeamKeys = (JSONArray) red.get("team_keys");
219 | JSONArray blueTeamKeys = (JSONArray) blue.get("team_keys");
220 | redAlly.setTeamKeys(Utils.jsonArrayToStringArray(redTeamKeys));
221 | blueAlly.setTeamKeys(Utils.jsonArrayToStringArray(blueTeamKeys));
222 | JSONArray redSurrogateKeys = (JSONArray) red.get("surrogate_team_keys");
223 | JSONArray blueSurrogateKeys = (JSONArray) blue.get("surrogate_team_keys");
224 | redAlly.setSurrogateTeamKeys(Utils.jsonArrayToStringArray(redSurrogateKeys));
225 | blueAlly.setSurrogateTeamKeys(Utils.jsonArrayToStringArray(blueSurrogateKeys));
226 | m.setRed(redAlly);
227 | m.setBlue(blueAlly);
228 | }
229 | JSONArray videos = (JSONArray) hash.get("videos");
230 | Media[] medias = new Media[videos.size()];
231 | for(int i = 0; i < videos.size(); i++) medias[i] = parseMedia(videos.get(i));
232 | m.setVideos(medias);
233 | return m;
234 | }
235 |
236 | protected Alliance parseEventAlliance(Object object) {
237 | Alliance alliance = new Alliance();
238 | HashMap hash = (HashMap) object;
239 | if(hash == null) return null;
240 |
241 | alliance.setName((String)hash.get("name"));
242 | if(hash.get("backup") != null) alliance.setBackupOut((String)(((JSONObject) hash.get("backup")).get("out")));
243 | if(hash.get("backup") != null) alliance.setBackupIn((String)(((JSONObject) hash.get("backup")).get("in")));
244 | alliance.setDeclines(Utils.jsonArrayToStringArray((JSONArray)hash.get("declines")));
245 | alliance.setPicks(Utils.jsonArrayToStringArray((JSONArray)hash.get("picks")));
246 | alliance.setStatus((String) (((JSONObject) hash.get("status")).get("status")));
247 | alliance.setCurrentLevelRecord_Wins(Utils.cleanLong(((JSONObject)(((JSONObject)hash.get("status")).get("current_level_record"))).get("wins")));
248 | alliance.setCurrentLevelRecord_Losses(Utils.cleanLong(((JSONObject)(((JSONObject)hash.get("status")).get("current_level_record"))).get("losses")));
249 | alliance.setCurrentLevelRecord_Ties(Utils.cleanLong(((JSONObject)(((JSONObject)hash.get("status")).get("current_level_record"))).get("ties")));
250 | alliance.setLevel((String) (((JSONObject) hash.get("status")).get("level")));
251 | alliance.setPlayoffAverage(Utils.cleanDouble(((JSONObject) hash.get("status")).get("playoff_average")));
252 | alliance.setRecordWins(Utils.cleanLong(((JSONObject)(((JSONObject)hash.get("status")).get("record"))).get("wins")));
253 | alliance.setRecordLosses(Utils.cleanLong(((JSONObject)(((JSONObject)hash.get("status")).get("record"))).get("losses")));
254 | alliance.setRecordTies(Utils.cleanLong(((JSONObject)(((JSONObject)hash.get("status")).get("record"))).get("ties")));
255 |
256 | return alliance;
257 | }
258 |
259 | protected Insight parseInsight(Object object) {
260 | Insight insight = new Insight();
261 |
262 | HashMap hash = (HashMap) object;
263 | if(hash == null) return null;
264 |
265 | insight.setQual(new HashMap((JSONObject)hash.get("qual")));
266 | insight.setPlayoff(new HashMap((JSONObject)hash.get("playoff")));
267 |
268 | return insight;
269 | }
270 |
271 | protected EventRanking parseEventRanking(Object object) {
272 | EventRanking ranking = new EventRanking();
273 | HashMap hash = (HashMap) object;
274 | if(hash == null) return null;
275 |
276 | ranking.setMatchesPlayed(Utils.cleanLong(hash.get("matches_played")));
277 | ranking.setQualAverage(Utils.cleanLong(hash.get("qual_average")));
278 | ranking.setRank(Utils.cleanLong(hash.get("rank")));
279 | ranking.setDq(Utils.cleanLong(hash.get("dq")));
280 | ranking.setTeamKey((String)hash.get("team_key"));
281 | ranking.setSortOrders(Utils.jsonArrayToDoubleArray((JSONArray)hash.get("sort_orders")));
282 | ranking.setExtraStats(Utils.jsonArrayToLongArray((JSONArray)hash.get("extra_stats")));
283 | ranking.setWins(Utils.cleanLong(((JSONObject) hash.get("record")).get("wins")));
284 | ranking.setTies(Utils.cleanLong(((JSONObject) hash.get("record")).get("ties")));
285 | ranking.setLosses(Utils.cleanLong(((JSONObject) hash.get("record")).get("losses")));
286 | return ranking;
287 | }
288 |
289 | protected SMatch parseSMatch(Object object) {
290 | SMatch m = new SMatch();
291 | HashMap hash = (HashMap) object;
292 | if(hash == null) return null;
293 |
294 | m.setKey((String)hash.get("key"));
295 | m.setCompLevel((String)hash.get("comp_level"));
296 | m.setSetNumber(Utils.cleanLong(hash.get("set_number")));
297 | m.setMatchNumber(Utils.cleanLong(hash.get("match_number")));
298 | m.setWinningAlliance((String)hash.get("winning_alliance"));
299 | m.setEventKey((String)hash.get("event_key"));
300 | m.setTime(Utils.cleanLong(hash.get("time")));
301 | m.setActualTime(Utils.cleanLong(hash.get("actual_time")));
302 | m.setPredictedTime(Utils.cleanLong(hash.get("predicted_time")));
303 | JSONObject allies = (JSONObject) hash.get("alliances");
304 | if(allies != null) {
305 | JSONObject blue = (JSONObject) allies.get("blue");
306 | JSONObject red = (JSONObject) allies.get("red");
307 | MatchAlliance redAlly = new MatchAlliance();
308 | MatchAlliance blueAlly = new MatchAlliance();
309 | redAlly.setScore(Utils.cleanLong(red.get("score")));
310 | blueAlly.setScore(Utils.cleanLong(blue.get("score")));
311 | JSONArray redTeamKeys = (JSONArray) red.get("team_keys");
312 | JSONArray blueTeamKeys = (JSONArray) blue.get("team_keys");
313 | redAlly.setTeamKeys(Utils.jsonArrayToStringArray(redTeamKeys));
314 | blueAlly.setTeamKeys(Utils.jsonArrayToStringArray(blueTeamKeys));
315 | JSONArray redSurrogateKeys = (JSONArray) red.get("surrogate_team_keys");
316 | JSONArray blueSurrogateKeys = (JSONArray) blue.get("surrogate_team_keys");
317 | redAlly.setSurrogateTeamKeys(Utils.jsonArrayToStringArray(redSurrogateKeys));
318 | blueAlly.setSurrogateTeamKeys(Utils.jsonArrayToStringArray(blueSurrogateKeys));
319 | m.setRed(redAlly);
320 | m.setBlue(blueAlly);
321 | }
322 | return m;
323 | }
324 |
325 | protected Award parseAward(Object object) {
326 | Award a = new Award();
327 | HashMap hash = (HashMap)object;
328 | if(hash == null) return null;
329 |
330 | a.setName((String)hash.get("name"));
331 | a.setAwardType(Utils.cleanLong(hash.get("award_type")));
332 | a.setEventKey((String)hash.get("event_key"));
333 | a.setYear(Utils.cleanLong(hash.get("year")));
334 | JSONArray array = (JSONArray) hash.get("recipient_list");
335 | AwardRecipient[] recipientsList = new AwardRecipient[array.size()];
336 | for(int i = 0; i < array.size(); i++) {
337 | AwardRecipient ar = new AwardRecipient();
338 | JSONObject obj = (JSONObject) array.get(i);
339 | ar.setAwardee((String)obj.get("awardee"));
340 | ar.setTeamKey((String)obj.get("team_key"));
341 | recipientsList[i] = ar;
342 | }
343 | a.setRecipients(recipientsList);
344 | return a;
345 | }
346 |
347 | protected EventOPR[] parseOPRs(Object object) {
348 | HashMap hash = (HashMap) object;
349 | if(hash == null) return null;
350 |
351 | JSONObject oprs = (JSONObject) hash.get("oprs");
352 | JSONObject dprs = (JSONObject) hash.get("dprs");
353 | JSONObject ccwms = (JSONObject) hash.get("ccwms");
354 | EventOPR[] toReturn = new EventOPR[oprs.size()];
355 | for(int i = 0; i < oprs.keySet().size(); i++) {
356 | EventOPR opr = new EventOPR();
357 | opr.setOpr(Utils.cleanDouble(oprs.get(oprs.keySet().toArray()[i])));
358 | opr.setDpr(Utils.cleanDouble(dprs.get(dprs.keySet().toArray()[i])));
359 | opr.setCcwm(Utils.cleanDouble(ccwms.get(ccwms.keySet().toArray()[i])));
360 | opr.setTeamKey((String)oprs.keySet().toArray()[i]);
361 | toReturn[i] = opr;
362 | }
363 | return toReturn;
364 | }
365 | }
366 |
--------------------------------------------------------------------------------
/src/main/java/com/cpjd/utils/Utils.java:
--------------------------------------------------------------------------------
1 | package com.cpjd.utils;
2 |
3 | import org.json.simple.JSONArray;
4 |
5 | /**
6 | * Created by Will Davies on 7/7/2017.
7 | */
8 | public class Utils {
9 |
10 | public static long cleanLong(Object object) {
11 | if(object == null) return 0;
12 | else return (long)object;
13 | }
14 |
15 | public static int cleanInt(Object object) {
16 | if(object == null) return 0;
17 | else return (int)object;
18 | }
19 |
20 | public static double cleanDouble(Object object) {
21 | if(object == null) return 0;
22 | else return (double)object;
23 | }
24 |
25 | public static boolean cleanBoolean(Object object) {
26 | if(object == null) return false;
27 | else return (boolean)object;
28 | }
29 |
30 | public static String[] jsonArrayToStringArray(JSONArray jsonArray) {
31 | if(jsonArray == null) return null;
32 | String[] toReturn = new String[jsonArray.size()];
33 | for(int i = 0; i < jsonArray.size(); i++) toReturn[i] = (String)jsonArray.get(i);
34 | return toReturn;
35 | }
36 |
37 | public static double[] jsonArrayToDoubleArray(JSONArray jsonArray) {
38 | if(jsonArray == null) return null;
39 | double[] toReturn = new double[jsonArray.size()];
40 | for(int i = 0; i < jsonArray.size(); i++) toReturn[i] = (Double)jsonArray.get(i);
41 | return toReturn;
42 | }
43 |
44 | public static long[] jsonArrayToLongArray(JSONArray jsonArray) {
45 | if(jsonArray == null) return null;
46 | long[] toReturn = new long[jsonArray.size()];
47 | for(int i = 0; i < jsonArray.size(); i++) toReturn[i] = (long)jsonArray.get(i);
48 | return toReturn;
49 | }
50 |
51 | }
52 |
--------------------------------------------------------------------------------
/src/main/java/com/cpjd/utils/exceptions/AuthTokenNotFoundException.java:
--------------------------------------------------------------------------------
1 | package com.cpjd.utils.exceptions;
2 |
3 | /**
4 | * Thrown when the user forgets to set their Auth token with TBA.setAuthToken()
5 | *
6 | * @since 1.0.0
7 | * @author Will Davies
8 | */
9 | public class AuthTokenNotFoundException extends RuntimeException {
10 |
11 | public AuthTokenNotFoundException(String msg) {
12 | super(msg);
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/src/main/java/com/cpjd/utils/exceptions/DataNotFoundException.java:
--------------------------------------------------------------------------------
1 | package com.cpjd.utils.exceptions;
2 |
3 | /**
4 | * This exception is thrown when the user tries to call data that isn't there
5 | *
6 | * @since 1.0.0
7 | * @author Will Davies
8 | */
9 | public class DataNotFoundException extends RuntimeException {
10 |
11 | public DataNotFoundException(String msg) {
12 | super(msg+". Please double check the parameters you passed in and make sure you have an internet connection.");
13 | }
14 |
15 | }
16 |
--------------------------------------------------------------------------------