-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUpdater.java
More file actions
64 lines (52 loc) · 2.82 KB
/
Updater.java
File metadata and controls
64 lines (52 loc) · 2.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import org.json.*;
import java.util.*;
public class Updater {
// Arrays containing all the keys of interest
// This array contains all the keys where the values are the same for each team on the same alliance
private final static String[] genericKeys = {"teleopScaleOwnershipSec", "autoScaleOwnershipSec", "vaultPoints", "autoSwitchAtZero", "teleopOwnershipPoints", "teleopPoints", "autoOwnershipPoints", "autoPoints", "teleopSwitchOwnershipSec"};
private final static String[] tempKeys = {"vaultPoints", "teleopPoints", "autoPoints"};
// This array contains all the keys where the values differ between teams on the same alliance
private final static String[] uniqueKeys = {};
// Returns a HashMap<String, Object> array that contains the match data for each team
@SuppressWarnings("unchecked")
public static HashMap<String, Object>[] getMatchData(JSONObject matchJSON) {
HashMap<String, Object>[] infoTable = (HashMap<String, Object>[]) new HashMap[6];
for(int x = 0; x < infoTable.length; x++) {
infoTable[x] = new HashMap<String, Object>();
}
//JSONObject json = TBA.getJSON(TBA.getMatch(matchNum));
// Gets the team number for each team
JSONObject allianceJSON = matchJSON.getJSONObject("alliances");
JSONObject blueJSON = allianceJSON.getJSONObject("blue");
JSONObject redJSON = allianceJSON.getJSONObject("red");
for(int x = 0; x < 3; x++) {
infoTable[x].put("teamNumber", blueJSON.getJSONArray("team_keys").get(x).toString().substring(3));
infoTable[x+3].put("teamNumber", redJSON.getJSONArray("team_keys").get(x).toString().substring(3));
}
JSONObject breakdownJSON = matchJSON.getJSONObject("score_breakdown");
blueJSON = breakdownJSON.getJSONObject("blue");
redJSON = breakdownJSON.getJSONObject("red");
// Extracts all the values associated with all the uniqueKeys
for(int k = 0; k < uniqueKeys.length; k++) {
for(int x = 0; x < 3; x++) {
infoTable[x].put(uniqueKeys[k], blueJSON.get(uniqueKeys[k] + (x+1)));
infoTable[x+3].put(uniqueKeys[k], redJSON.get(uniqueKeys[k] + (x+1)));
}
}
// Extracts all the values associated with all the genericKeys
for(int k = 0; k < tempKeys.length; k++) {
for(int x = 0; x < 3; x++) {
infoTable[x].put(tempKeys[k], blueJSON.get(tempKeys[k]));
infoTable[x+3].put(tempKeys[k], redJSON.get(tempKeys[k]));
}
}
// This section handles specific keys and information that is structurally different from the rest
for(int x = 0; x < 3; x++) {
infoTable[x].put("endgameClimb", blueJSON.get("endgameRobot" + (x+1)).equals("Climbing"));
infoTable[x+3].put("endgameClimb", redJSON.get("endgameRobot" + (x+1)).equals("Climbing"));
infoTable[x].put("autoRun", blueJSON.get("autoRobot"+(x+1)).equals("AutoRun"));
infoTable[x+3].put("autoRun", redJSON.get("autoRobot"+(x+1)).equals("AutoRun"));
}
return infoTable;
}
}