- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcombineStats.java
More file actions
Latest commit
218 lines (210 loc) · 7.67 KB
/
Copy pathcombineStats.java
File metadata and controls
218 lines (210 loc) · 7.67 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
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
/*
Designed to compile information (aka save human labor) about all of Troy High Project LEAD's members into an easy-to-read
spreadsheet
*/
importjava.io.BufferedReader;
importjava.io.File;
importjava.io.FileInputStream;
importjava.io.FileOutputStream;
importjava.io.IOException;
importjava.io.InputStreamReader;
importjava.net.URL;
importjava.util.HashSet;
importorg.apache.poi.ss.usermodel.Cell;
importorg.apache.poi.ss.usermodel.CellStyle;
importorg.apache.poi.ss.usermodel.FillPatternType;
importorg.apache.poi.ss.usermodel.HorizontalAlignment;
importorg.apache.poi.ss.usermodel.IndexedColors;
importorg.apache.poi.xssf.usermodel.XSSFRow;
importorg.apache.poi.xssf.usermodel.XSSFSheet;
importorg.apache.poi.xssf.usermodel.XSSFWorkbook;
// Note: cannot have the spreadsheet open while the program is running
publicclasscombineStats {
publicstaticvoidmain(String[] args) throwsIOException {
doublestart = System.currentTimeMillis();
XSSFWorkbookwb = newXSSFWorkbook(newFileInputStream(newFile("Project LEAD 18-19.xlsx")));
System.out.println(System.currentTimeMillis() - start);
XSSFSheetst = wb.getSheetAt(0);
for (intr = 2; r <= 264; r++) {
XSSFRowrow = (XSSFRow) st.getRow(r - 1);
for (inti = 3; i != 8; i++) // so we don't get a null pointer exception randomly
row.createCell(i);
Stringfirst = row.getCell(0).toString();
Stringsecond = row.getCell(1).toString();
Stringname = getName(first) + getName(second);
double[] hrs = seeStudent(name);
if (hrs.length == 0) { // website not found
changeCol(row.getCell(0), IndexedColors.GOLD.getIndex(), wb);
continue;
}
row.getCell(3).setCellValue((hrs[3] + hrs[0] - hrs[4])); // PL points
if (row.getCell(3).getNumericCellValue() >= 30) {
changeCol(row.getCell(3), IndexedColors.LAVENDER.getIndex(), wb);
}
row.getCell(4).setCellValue((hrs[1] + hrs[0])); // PVSA total hours
if (hrs[5] < 3) {
row.getCell(5).setCellValue(false);
} elseif (hrs[5] < 6) { // program counts 3-5 diff events=double check manually
row.getCell(5).setCellValue("?");
changeCol(row.getCell(5), IndexedColors.LIME.getIndex(), wb);
} else {
row.getCell(5).setCellValue(true);
}
row.getCell(6).setCellValue((hrs[0] + hrs[1]) >= 20);
row.getCell(7).setCellValue(hrs[2] == 1);
System.out.println(name);
}
// double[] hrs = seeStudent("shaunawang");
// System.out.println(Arrays.toString(hrs));
// System.out.println("Project Lead Hours: " + hrs[0] + ", PVSA Hours: " + hrs[1] + ", over 20?"
// + (hrs[0] + hrs[1] >= 20) + ", paid dues? " + (hrs[2] == 1)
// + ", total Project Lead points: " + (hrs[3] + hrs[0]) + ", negative points: " + hrs[4]);
System.out.println(System.currentTimeMillis() - start);
FileOutputStreamoutFile = newFileOutputStream(newFile("Project LEAD 18-19.xlsx"));
wb.write(outFile);
System.out.println(System.currentTimeMillis() - start);
outFile.close();
}
publicstaticvoidchangeCol(Cellcell, shortid, XSSFWorkbookwb) {
CellStylestyle = wb.createCellStyle();
style.setFillForegroundColor(id);
style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
style.setAlignment(HorizontalAlignment.CENTER);
cell.setCellStyle(style);
}
publicstaticStringgetName(Stringname) {
StringBuildersb = newStringBuilder();
for (inti = 0; i != name.length(); i++) {
charc = name.charAt(i);
if (c >= 'a' && c <= 'z')
sb.append(c);
elseif (c >= 'A' && c <= 'Z')
sb.append((char) (c + ('a' - 'A')));
}
returnsb.toString();
}
publicstaticdouble[] seeStudent(Stringname) throwsIOException {
doublepldHrs = 0, pvsaHrs = 0, dues = 0, extra = 0, neg = 0, thrAct = 0; // extra project lead
// pts
URLoracle = newURL("https://www.thsprojectlead.com/" + name + ".html");
try (BufferedReaderin = newBufferedReader(newInputStreamReader(oracle.openStream()));) {
for (inti = 1; i < 345; i++) { // first 344 lines
in.readLine();
}
StringinputLine = in.readLine(); // 345th
// System.out.println(inputLine);
if (inputLine.indexOf("es") != -1) // "Y/y es"
dues = 1;
for (inti = 346; i < 351; i++) {
inputLine = in.readLine();
if (i == 348)
continue;
// System.out.println(inputLine);
doublee = extraPoints(inputLine);
if (e == -1)
returnnewdouble[] {};
extra += e;
}
for (inti = 351; i < 486; i++) { // end limit is where i ends after loop
in.readLine();
// System.out.println(
}
inputLine = in.readLine(); // 486th line
// System.out.println(inputLine);
pldHrs = getHrs(inputLine);
neg = negPoints(inputLine);
thrAct = threeActivities(inputLine);
for (inti = 487; i < 490; i++)
in.readLine();
inputLine = in.readLine(); // 490th line
if (inputLine.length() > 30
&& inputLine.substring(0, 31).equals("<div class=\"paragraph\"><ul><li>")) {
// System.out.println(inputLine);
pvsaHrs = getHrs(inputLine);
}
} catch (IOExceptione) {
System.out.println("Website not found for " + name);
returnnewdouble[] {};
}
returnnewdouble[] {pldHrs, pvsaHrs, dues, extra, neg, thrAct};
}
publicstaticintthreeActivities(Strings) {
inti = s.indexOf(':'), j = s.indexOf('-');
HashSet<String> set = newHashSet<>();
while (i != -1 && j != -1) {
if (j > i) {
Stringevent = s.substring(i + 1, j).trim();
set.add(event);
}
s = s.substring(j + 1); // neg sign interferes, cut it out and move on
i = s.indexOf(':');
j = s.indexOf('-');
}
// System.out.println(set);
returnset.size();
}
publicstaticdoublenegPoints(Strings) {
intind = s.indexOf("not show");
doubleres = 0;
while (ind != -1) {
while (s.charAt(ind) != '-') {
ind++;
}
ind++; // now on actual number, without '-'
Stringn = "";
while (s.charAt(ind) >= '0' && s.charAt(ind) <= '9' || s.charAt(ind) == '.') {
n += s.charAt(ind);
ind++;
}
res += Double.parseDouble(n);
s = s.substring(ind + 4);
ind = s.indexOf("not show");
}
returnres;
}
publicstaticdoubleextraPoints(Strings) {
Stringn = "";
inti = 50;
if (s.charAt(i) == '&') // blank space and then number
i += 6;
while (s.charAt(i) >= '0' && s.charAt(i) <= '9' || s.charAt(i) == '.') {
n += s.charAt(i);
// System.out.println(n);
i++;
}
// System.out.println(n);
if (n.length() == 0)
return0; // empty box
returnDouble.parseDouble(n);
}
publicstaticdoublegetHrs(Strings) {
doublesum = 0;
intind = s.indexOf("our");
while (ind != -1) {
Stringn = "";
inti = ind - 3;
while (s.charAt(i) >= '0' && s.charAt(i) <= '9' || s.charAt(i) == '.') {
n = s.charAt(i) + n;
// System.out.println(n);
i--;
}
// System.out.print(n + " ");
if (n.length() == 0 && s.charAt(ind - 7) == '&') { // in case of nbsp
i = ind - 8;
while (s.charAt(i) >= '0' && s.charAt(i) <= '9' || s.charAt(i) == '.') {
n = s.charAt(i) + n;
// System.out.println(n);
i--;
}
}
if (n.length() != 0) { // ex. program finds "house"
doublenum = Double.parseDouble(n);
// System.out.println(num);
sum += num;
}
s = s.substring(ind + 4);
ind = s.indexOf("our");
}
returnsum;
}
}