Skip to content

Commit 5b28b73

Browse files
committed
pre dcmp changes + debugging
1 parent 8ca3c42 commit 5b28b73

File tree

15 files changed

+250
-130
lines changed

15 files changed

+250
-130
lines changed

src/main/java/org/texastorque/App.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ private void switchToMain() {
6666
switchToScoring();
6767
});
6868
window.getExportEntries().setOnAction(e -> {
69-
dataWriter.export(stage);
69+
dataWriter.exportTSR(stage);
7070
});
7171
window.getLoadEntries().setOnAction(e -> {
7272
dataReader.loadEntries(stage);
@@ -114,12 +114,17 @@ private void switchToHub() {
114114
Hub window = new Hub(dataReader.getDataWrapper());
115115

116116
window.getBackButton().setOnAction(e -> {
117-
switchToMain();
117+
switchToAverages();
118118
});
119119
window.getAveragesButton().setOnAction(e -> {
120120
switchToAverages();
121121
});
122122

123+
window.getExportButton().setOnAction(e -> {
124+
dataWriter.exportCSV(stage, dataReader.getDataWrapper().getEntries());
125+
});
126+
127+
123128
switchStageScene(window.getPanel());
124129
}
125130

@@ -138,10 +143,15 @@ public Void call(Integer team) {
138143
window.getBackButton().setOnAction(e -> {
139144
switchToMain();
140145
});
146+
141147
window.getHubButton().setOnAction(e -> {
142148
switchToHub();
143149
});
144150

151+
window.getExportButton().setOnAction(e -> {
152+
dataWriter.exportCSV(stage, dataReader.getDataWrapper().getAverages());
153+
});
154+
145155
switchStageScene(window.getPanel());
146156
}
147157

@@ -152,6 +162,10 @@ private void switchToTeam(Integer team) {
152162
switchToAverages();
153163
});
154164

165+
window.getExportButton().setOnAction(e -> {
166+
dataWriter.exportCSV(stage, dataReader.getDataWrapper().getTeamEntries().get(team));
167+
});
168+
155169
switchStageScene(window.getPanel());
156170
}
157171

src/main/java/org/texastorque/pages/Averages.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,20 +40,25 @@ public Pane getPanel() {
4040
final Label label = new Label("Torque Scout");
4141
private Button back = new Button("Back to home");
4242
private Button hub = new Button("View all entries");
43+
private Button export = new Button("Export");
4344

4445
public Averages(DataWrapper entries, Callback<Integer, Void> callback) {
4546
label.setTextFill(Color.WHITE);
4647
label.setFont(LayoutUtils.getStandardFont(44));
4748
table.setEditable(false);
4849

4950
back.setFont(LayoutUtils.getStandardFont(24));
50-
hub.setFont(LayoutUtils.getStandardFont(24));
5151
back.setTextFill(Color.WHITE);
5252
back.setStyle("-fx-text-fill: black");
53+
54+
hub.setFont(LayoutUtils.getStandardFont(24));
5355
hub.setTextFill(Color.WHITE);
5456
hub.setStyle("-fx-text-fill: black");
5557

56-
// table.setItems(entries);
58+
export.setFont(LayoutUtils.getStandardFont(24));
59+
export.setTextFill(Color.WHITE);
60+
export.setStyle("-fx-text-fill: black");
61+
5762
ObservableList<Entry> averages = entries.getAverages();
5863
for (Entry average : averages)
5964
average.getTeamButton().setOnAction(e -> {
@@ -127,7 +132,7 @@ public Averages(DataWrapper entries, Callback<Integer, Void> callback) {
127132
vbox.setSpacing(20);
128133
vbox.setPadding(new Insets(10, 0, 0, 10));
129134
vbox.getChildren().addAll(label, table,
130-
LayoutUtils.bundleIntoHBox(back, hub));
135+
LayoutUtils.bundleIntoHBox(back, hub, export));
131136

132137
scoreColumn.setSortType(TableColumn.SortType.DESCENDING);
133138
table.getSortOrder().add(scoreColumn);
@@ -145,4 +150,8 @@ public Button getHubButton() {
145150
return hub;
146151
}
147152

153+
public Button getExportButton() {
154+
return export;
155+
}
156+
148157
}

src/main/java/org/texastorque/pages/Hub.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,21 +56,27 @@ public Pane getPanel() {
5656

5757
private TableView<Entry> table = new TableView<Entry>();
5858
Label label = new Label("Torque Scout");
59-
private Button back = new Button("Back to home");
59+
private Button back = new Button("Back");
6060
private Button average = new Button("View averages");
61+
private Button export = new Button("Export");
6162

6263
public Hub(DataWrapper entries) {
6364
label.setTextFill(Color.WHITE);
6465
label.setFont(LayoutUtils.getStandardFont(44));
6566
table.setEditable(false);
6667

6768
back.setFont(LayoutUtils.getStandardFont(24));
68-
average.setFont(LayoutUtils.getStandardFont(24));
6969
back.setTextFill(Color.WHITE);
7070
back.setStyle("-fx-text-fill: black");
71+
72+
average.setFont(LayoutUtils.getStandardFont(24));
7173
average.setTextFill(Color.WHITE);
7274
average.setStyle("-fx-text-fill: black");
7375

76+
export.setFont(LayoutUtils.getStandardFont(24));
77+
export.setTextFill(Color.WHITE);
78+
export.setStyle("-fx-text-fill: black");
79+
7480
table.getItems().addAll(entries.getEntries());
7581

7682
TableColumn<Entry, String> taxiColumn = (TableColumn<Entry, String>) Entry.createColumn("taxi");
@@ -151,7 +157,7 @@ public Hub(DataWrapper entries) {
151157
vbox.setPadding(new Insets(10, 0, 0, 10));
152158
// table.setMinHeight(700);
153159
vbox.getChildren().addAll(label, table,
154-
LayoutUtils.bundleIntoHBox(back, average));
160+
LayoutUtils.bundleIntoHBox(back, average, export));
155161

156162
scoreColumn.setSortType(TableColumn.SortType.DESCENDING);
157163
table.getSortOrder().add(scoreColumn);
@@ -169,4 +175,7 @@ public Button getAveragesButton() {
169175
return average;
170176
}
171177

178+
public Button getExportButton() {
179+
return export;
180+
}
172181
}

src/main/java/org/texastorque/pages/Scoring.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public class Scoring extends Page {
3838
private ValueDisplay teamNumberDisplay = new ValueDisplay("Team Number", 0000);
3939
private ValueDisplay matchNumberDisplay = new ValueDisplay("Match Number", 0);
4040

41-
private ToggleSingle allianceColor = new ToggleSingle("Alliance Color", "blue", "", "red", "");
41+
private ToggleSingle allianceColor = new ToggleSingle("Alliance Color", "Blue", "", "Red", "");
4242

4343
private ToggleSingle taxi = new ToggleSingle("Auto Taxi");
4444
private Numeric autoLower = new Numeric("Auto lower");

src/main/java/org/texastorque/pages/Team.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ public Pane getPanel() {
5656
private TableView<Entry> table = new TableView<Entry>();
5757
final Label label = new Label("Torque Scout");
5858
private Button back = new Button("Back");
59+
private Button export = new Button("Export");
5960

6061
public Team(DataWrapper entries, int team) {
6162
label.setTextFill(Color.WHITE);
@@ -66,6 +67,10 @@ public Team(DataWrapper entries, int team) {
6667
back.setTextFill(Color.WHITE);
6768
back.setStyle("-fx-text-fill: black;");
6869

70+
export.setFont(LayoutUtils.getStandardFont(24));
71+
export.setTextFill(Color.WHITE);
72+
export.setStyle("-fx-text-fill: black;");
73+
6974
table.getItems().addAll(entries.getTeamEntries().get(team));
7075

7176
TableColumn<Entry, String> taxiColumn = (TableColumn<Entry, String>) Entry.createColumn("taxi");
@@ -137,7 +142,7 @@ public Team(DataWrapper entries, int team) {
137142
vbox.setSpacing(20);
138143
vbox.setPadding(new Insets(10, 0, 0, 10));
139144

140-
vbox.getChildren().addAll(label, table, back);
145+
vbox.getChildren().addAll(label, table, LayoutUtils.bundleIntoHBox(back, export));
141146

142147
scoreColumn.setSortType(TableColumn.SortType.DESCENDING);
143148
table.getSortOrder().add(scoreColumn);
@@ -151,4 +156,8 @@ public Button getBackButton() {
151156
return back;
152157
}
153158

159+
public Button getExportButton() {
160+
return export;
161+
}
162+
154163
}

src/main/java/org/texastorque/utils/DataReader.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public boolean loadEntries(Stage s) {
4848
for (String fileName : fileNames) {
4949
if (fileName.contains(".tsr")) {
5050
path = selectedDirectory.getAbsolutePath() + "/" + fileName;
51-
content += Files.readString(Path.of(path)).replace(Entry.header, "");
51+
content += Files.readString(Path.of(path));
5252
}
5353
}
5454

src/main/java/org/texastorque/utils/DataWriter.java

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import java.nio.file.Path;
1616
import java.nio.file.StandardOpenOption;
1717

18+
import javafx.collections.ObservableList;
1819
import javafx.stage.DirectoryChooser;
1920
import javafx.stage.Stage;
2021

@@ -34,10 +35,8 @@ private void appendString(String s) throws IOException {
3435

3536
public boolean writeEntry(Entry entry) {
3637
try {
37-
if (!Files.exists(Path.of(path))) {
38+
if (!Files.exists(Path.of(path)))
3839
Files.createFile(Path.of(path));
39-
appendString(Entry.header);
40-
}
4140
appendString(entry.toCSV());
4241
return true;
4342
} catch (IOException e) {
@@ -56,12 +55,12 @@ public boolean clearDatabase() {
5655
}
5756
}
5857

59-
public boolean export(Stage s) {
58+
public boolean exportTSR(Stage s) {
6059
try {
6160
String content = Files.readString(Path.of(path));
6261
File selectedDirectory = directoryChooser.showDialog(s);
63-
Path exportPath = Path.of(selectedDirectory.getAbsolutePath() + "/" + "" //"scouting-data-"
64-
+ System.getProperty("user.name") + ".tsr"); // .csv
62+
Path exportPath = Path.of(selectedDirectory.getAbsolutePath() + "/" + ""
63+
+ System.getProperty("user.name") + ".tsr");
6564
Files.writeString(exportPath, content);
6665
NoticeUtils.displayInfo("Data Exported Success", "Successfully exported scouting entry");
6766
return true;
@@ -71,4 +70,21 @@ public boolean export(Stage s) {
7170
}
7271
}
7372

73+
public boolean exportCSV(Stage s, ObservableList<Entry> entries) {
74+
try {
75+
String name = NoticeUtils.promptString("Export Table As", "Please enter a name for the table").replaceAll("\\W+", "");;
76+
File selectedDirectory = directoryChooser.showDialog(s);
77+
Path exportPath = Path.of(selectedDirectory.getAbsolutePath() + "/" + name + ".csv");
78+
StringBuilder builder = new StringBuilder();
79+
builder.append(Entry.header + "\n");
80+
for (Entry entry : entries)
81+
builder.append(entry.toCSV() + ",\n");
82+
Files.writeString(exportPath, builder.toString());
83+
NoticeUtils.displayInfo("Table Exported Success", "Successfully exported table");
84+
return true;
85+
} catch (IOException e) {
86+
NoticeUtils.displayError("Table Exporter Error", "Could not export table");
87+
return false;
88+
}
89+
}
7490
}

src/main/java/org/texastorque/utils/Entry.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ public class Entry {
1818
public final static Integer[] climbScores = {0, 4, 6, 10, 15};
1919
public final static String[] climbNames = {"None", "Low", "Mid", "High", "Traversal"};
2020

21-
public static final String header = "teamNumber,matchNumber,"
22-
+ "allianceColor,taxi,autoLower,autoUpper,autoMissed,autoIntaken,"
23-
+ "teleopLower,teleopUpper,teleopMissed,teleopIntaken,climb,comment";
21+
public static final String header = "Team Number,Match Number,"
22+
+ "Alliance Color,Taxi,Auto Lower,Auto Upper,Auto Missed,Auto Intaken,"
23+
+ "Teleop Lower,Teleop Upper,Teleop Missed,Teleop Intaken,Climb Level,Climb Time,Comment,";
2424

2525
public static int valueOfClimb(String climb) {
2626
for (int i = 0; i < climbNames.length; i++)

test/generate.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def randomBool():
1717
f = open("user" + str(n) + ".tsr", 'w')
1818
content = ""
1919
for i in range(0, 2):
20-
for team in [118, 148, 254, 1477, 1678, 1690, 2910, 3310, 4414]:
20+
for team in [118, 148, 254, 624, 1477, 1678, 1690, 2468, 2910, 3005, 3310, 3847, 4414, 6800]:
2121
match = randint(1, 35)
2222
allainceColor = "red" if randomBool() else "blue"
2323
taxi = "true" if randomBool() else "false"
@@ -49,6 +49,9 @@ def randomBool():
4949
teleopUpper = teleopIntaken - teleopMissed
5050
if teleopUpper <= 0:
5151
teleopUpper = 0
52+
5253
climb = randint(0, 4)
53-
content += f"{team},{match},{allainceColor},{taxi},{autoLower},{autoUpper},{autoMissed},{autoIntaken},{teleopLower},{teleopUpper},{teleopMissed},{teleopIntaken},{climb},comment \n"
54+
climbTime = randint(5,15) * climb
55+
56+
content += f"{team},{match},{allainceColor},{taxi},{autoLower},{autoUpper},{autoMissed},{autoIntaken},{teleopLower},{teleopUpper},{teleopMissed},{teleopIntaken},{climb},{climbTime},comment \n"
5457
f.write(content)

test/user1.tsr

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,28 @@
1-
118,30,red,true,0,3,0,3,0,3,9,12,2,comment
2-
148,25,blue,true,0,0,2,2,3,0,0,3,0,comment
3-
254,29,red,true,0,1,1,2,0,3,10,13,1,comment
4-
1477,34,blue,false,0,0,0,0,5,0,7,12,0,comment
5-
1678,34,blue,true,0,1,1,2,0,3,9,12,2,comment
6-
1690,20,blue,false,0,0,1,0,5,0,9,14,1,comment
7-
2910,10,blue,true,0,0,2,1,0,2,0,2,4,comment
8-
3310,23,red,true,0,2,0,2,0,4,2,6,4,comment
9-
4414,18,red,false,0,0,0,0,0,0,3,3,1,comment
10-
118,18,red,true,0,0,4,3,1,0,4,5,2,comment
11-
148,34,blue,false,0,0,0,0,0,9,0,9,0,comment
12-
254,32,blue,true,0,2,0,2,0,0,4,3,0,comment
13-
1477,22,red,false,0,0,1,0,0,0,6,5,4,comment
14-
1678,25,red,false,0,0,0,0,0,0,1,0,3,comment
15-
1690,7,red,false,0,0,1,0,0,8,4,12,3,comment
16-
2910,25,blue,true,0,0,1,0,0,1,0,1,2,comment
17-
3310,28,blue,true,0,0,5,4,1,0,2,3,3,comment
18-
4414,27,blue,false,0,0,1,0,0,0,13,12,1,comment
1+
118,16,blue,true,0,0,4,4,0,1,5,6,3,36,comment
2+
148,25,blue,false,0,0,1,0,0,4,8,12,2,22,comment
3+
254,33,blue,false,0,0,1,0,0,3,1,4,0,0,comment
4+
624,16,blue,true,1,0,0,1,0,0,5,5,4,44,comment
5+
1477,1,red,false,0,0,1,0,1,0,2,3,2,20,comment
6+
1678,33,blue,false,0,0,1,0,0,4,0,4,2,18,comment
7+
1690,14,red,true,0,0,4,4,5,0,0,5,2,12,comment
8+
2468,26,red,true,0,0,5,4,0,3,3,6,0,0,comment
9+
2910,23,red,false,0,0,1,0,5,0,0,5,3,15,comment
10+
3005,1,red,true,0,0,1,1,0,0,0,0,0,0,comment
11+
3310,18,blue,true,0,0,3,3,4,0,3,7,4,20,comment
12+
3847,25,blue,false,0,0,1,0,0,3,6,9,0,0,comment
13+
4414,11,red,false,0,0,0,0,0,1,12,13,3,21,comment
14+
6800,22,blue,true,0,0,5,4,0,0,14,13,0,0,comment
15+
118,2,red,false,0,0,0,0,0,11,0,11,1,8,comment
16+
148,5,blue,true,0,1,0,1,0,0,4,3,2,18,comment
17+
254,26,red,false,0,0,0,0,0,1,0,1,3,15,comment
18+
624,3,blue,false,0,0,0,0,0,0,4,3,2,24,comment
19+
1477,2,red,false,0,0,0,0,0,0,0,0,4,20,comment
20+
1678,6,red,false,0,0,1,0,2,0,3,5,1,9,comment
21+
1690,26,red,true,1,0,3,4,7,0,0,7,2,14,comment
22+
2468,6,red,true,0,0,2,1,0,0,10,9,3,18,comment
23+
2910,2,blue,true,0,0,1,0,0,0,6,6,1,14,comment
24+
3005,3,blue,true,2,0,0,2,1,0,9,10,0,0,comment
25+
3310,24,red,false,0,0,0,0,0,4,5,9,4,44,comment
26+
3847,16,blue,true,0,0,4,3,0,7,7,14,3,30,comment
27+
4414,9,red,false,0,0,1,0,0,9,4,13,0,0,comment
28+
6800,23,blue,true,0,1,3,4,0,0,5,4,3,39,comment

0 commit comments

Comments
 (0)