-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathEntriesToTeamObjects.java
131 lines (126 loc) · 4.55 KB
/
EntriesToTeamObjects.java
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Scanner;
public class EntriesToTeamObjects {
static ArrayList<Entry> listOfEntriesInFile;
static ArrayList<Team> teams = new ArrayList<Team>();//List of summed up team data
public static void getAllEntriesInFileIntoObjectForm(File entries, String fileText)
throws FileNotFoundException {
String[] lines = fileText.split("\tn");
ArrayList<String> lineList = new ArrayList<String>();
for (String a : lines) {
if (!a.equals("")) {
lineList.add(a);
}
}
for (String line : lineList) {
String[] properties = line.split("\t");
Entry newEntry = new Entry();
// USE AN INITIALIZER TO DO THE THING DONE BELOW USING A LOOP AND
// WITH A LOT LESS CODE
String[] matchNum = properties[0].split(":");
newEntry.matchNumber = Integer.parseInt(matchNum[1]);
String[] gears = properties[1].split(":");
newEntry.gearsRetrieved = Integer.parseInt(gears[1]);
String[] autoGears = properties[2].split(":");
newEntry.autoGearsRetrieved = Integer.parseInt(autoGears[1]);
String[] balls = properties[3].split(":");
newEntry.ballsShot = Integer.parseInt(balls[1]);
String[] autoBalls = properties[4].split(":");
newEntry.autoBallsShot = Integer.parseInt(autoBalls[1]);
String[] rating = properties[5].split(":");
newEntry.rating = Integer.parseInt(rating[1].replaceAll(".0", ""));
String[] death = properties[6].split(":");
newEntry.death = Boolean.getBoolean(death[1]);
String[] baseline = properties[7].split(":");
newEntry.crossedBaseline = Boolean.getBoolean(baseline[1]);
String[] rope = properties[8].split(":");
newEntry.climbsRope = Boolean.getBoolean(rope[1]);
String[] name = properties[9].split(":");
newEntry.teamName = name[1];
String[] position = properties[10].split(":");
newEntry.position = getPosition(position[1]);
// ADD THE NEW ENTRY IN THE LINE TO THE LISTOFENTRIES ARRAYLIST
// OBJECT
listOfEntriesInFile.add(newEntry);
}
combineTeams();
}
public static Entry.Position getPosition(String str) {
if (str.equals("RED1"))
return Entry.Position.RED1;
else if (str.equals("RED2"))
return Entry.Position.RED2;
else if (str.equals("RED3"))
return Entry.Position.RED3;
else if (str.equals("BLUE1"))
return Entry.Position.BLUE1;
else if (str.equals("BLUE2"))
return Entry.Position.BLUE2;
return Entry.Position.BLUE3;
}
public static ArrayList<Team> combineTeams() {
for (Entry a : listOfEntriesInFile) {
Team matchingTeam = teamNameThatMatches(a);
if(matchingTeam!=null){
setValues(matchingTeam,a);
}
else{
Team newOne = new Team();
teams.add(newOne);
setValues(newOne,a);
}
}
return teams;
}
public static void setValues(Team b, Entry a) {
b.name=a.teamName;
if (a.position == Entry.Position.BLUE1) {
b.totalBallsScoredBlue1Auto += a.autoBallsShot;
b.totalGearsOnHookAutoMatchesBlue1 += a.autoGearsRetrieved;
b.totalMatchesPlayedInBlue1+=1;
} else if (a.position == Entry.Position.BLUE2) {
b.totalBallsScoredBlue2Auto += a.autoBallsShot;
b.totalGearsOnHookAutoMatchesBlue2 += a.autoGearsRetrieved;
b.totalMatchesPlayedInBlue2+=1;
} else if (a.position == Entry.Position.BLUE3) {
b.totalBallsScoredBlue3Auto += a.autoBallsShot;
b.totalGearsOnHookAutoMatchesBlue3 += a.autoGearsRetrieved;
b.totalMatchesPlayedInBlue3+=1;
} else if (a.position == Entry.Position.RED1) {
b.totalBallsScoredRed1Auto += a.autoBallsShot;
b.totalGearsOnHookAutoMatchesRed1 += a.autoGearsRetrieved;
b.totalMatchesPlayedInRed1+=1;
} else if (a.position == Entry.Position.RED2) {
b.totalBallsScoredRed2Auto += a.autoBallsShot;
b.totalGearsOnHookAutoMatchesRed2 += a.autoGearsRetrieved;
b.totalMatchesPlayedInRed2+=1;
} else if (a.position == Entry.Position.RED3) {
b.totalBallsScoredRed3Auto += a.autoBallsShot;
b.totalGearsOnHookAutoMatchesRed3 += a.autoGearsRetrieved;
b.totalMatchesPlayedInRed3+=1;
}
b.totalMatchesPlayedInAllPositions+=1;
b.totalBallsScoredTeleop += a.ballsShot;
b.totalGearsRetrievedTeleop+=a.gearsRetrieved;
b.totalDeaths += (a.death == true) ? 1 : 0;
b.totalCrossesBaseLineMatches += (a.crossedBaseline == true) ? 1 : 0;
}
public static Team teamNameThatMatches(Entry a){
for(Team i:teams){
if(i.name.equals(a.teamName)){
return i;
}
}
return null;
}
public static String readFile(File entries) throws FileNotFoundException{
String fileText="";
Scanner scanner=new Scanner(entries);
while(scanner.hasNextLine()){
fileText+=scanner.nextLine();
}
return fileText;
}
}