Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- boolean doExit = false;
- import java.text.DecimalFormat;
- //Rubik's cube times generalish API
- class Time {
- float t;
- boolean dnf;
- boolean dns;
- Time(String input) {
- if (input.equals("DNF")) {
- t = 0;
- dnf = true;
- dns = false;
- } else if (input.equals("DNS")) {
- t = 0;
- dnf = true;
- dns = true;
- } else {
- if (input.split(":").length == 1) {
- t = parseFloat(input);
- dnf = false;
- } else if (input.split(":").length == 2) {
- t = parseFloat(input.split(":")[1]) + 60*parseInt(input.split(":")[0]);
- } else {
- t = 0;
- dnf = true;
- }
- }
- }
- Time duplicate() {
- Time r = new Time("DNF");
- r.dnf = dnf;
- r.dns = dns;
- r.t = t;
- return r;
- }
- String asString() {
- if (dnf) {
- if (dns) {
- return "DNS";
- }
- return "DNF";
- } else {
- if (t < 60) {
- return new DecimalFormat("0.00").format(t);
- } else {
- return floor(t - (t%60))/60 + ":" + new DecimalFormat("00.00").format(t%60);
- }
- }
- }
- boolean isBetterThan(Time _t) {
- if (dnf) return false;
- if (_t.dnf) return true;
- else return t<_t.t;
- }
- }
- Time average(Time[] times, String mode) {
- if (mode.equals("a") || mode.equals("an")) {
- for(int i = 0; i < times.length - 1; i++) {
- for(int j = 0; j < times.length - 1 - i; j++) {
- if(times[i+j+1].isBetterThan(times[i])) {
- Time a = times[i].duplicate();
- times[i] = times[i+j+1];
- times[i+j+1] = a;
- }
- }
- }
- Time[] temp = new Time[times.length - 2];
- for(int i = 1; i < times.length - 1; i++) {
- temp[i-1] = times[i];
- }
- return average(temp, "m");
- }
- else if (mode.equals("m") || mode.equals("mn")) {
- float sumOfTimes = 0;
- for (int i = 0; i < times.length; i++) {
- if (times[i].dnf) return new Time("DNF");
- else sumOfTimes+=times[i].t;
- }
- return new Time("" + sumOfTimes/times.length);
- }
- else if(mode.equals("s") || mode.equals("sn")) {
- return new Time("DNS");
- }
- else return new Time("DNF");
- }
- //End generalish API
- class Person {
- String WCA, name;
- int competitions;
- Time[] comp1;
- Time[] comp2;
- Time[] comp3;
- float comp1Weight;
- float comp2Weight;
- float comp3Weight;
- Person(String WCA_, String name_) {
- WCA = WCA_;
- name = name_;
- }
- }
- Person[] competitors = {
- new Person("2013BARK01", "Justin Barker"),
- new Person("2015WEBS01", "Garrett Webster"),
- new Person("2015BUCK03", "Asher Buckner"),
- new Person("2015SPEC01", "Tyler Specht"),
- new Person("2009OLSO01", "Christopher Olson")
- };
- void setup() {
- for(int i = 0; i < competitors.length; i++) {
- if(loadStrings(competitors[i].WCA + ".txt") == null) {
- saveStrings(competitors[i].WCA + ".txt", new String[]{});
- doExit = true;
- }
- }
- if(doExit) {
- exit();
- }
- for(int i = 0; i < competitors.length; i++) {
- if(loadStrings(competitors[i].WCA + ".txt").length == 0) {
- println("Empty file for " + competitors[i].WCA);
- doExit = true;
- }
- if(loadStrings(competitors[i].WCA + ".txt").length >= 4) {
- println("More than 3 competitions listed for " + competitors[i].WCA);
- doExit = true;
- }
- if(loadStrings(competitors[i].WCA + ".txt").length == 1) {
- competitors[i].competitions = 1;
- competitors[i].comp1 = new Time[loadStrings(competitors[i].WCA + ".txt")[0].split(";")[1].split(",").length];
- for(int j = 0; j < competitors[i].comp1.length; j++) {
- competitors[i].comp1[j] = new Time(loadStrings(competitors[i].WCA + ".txt")[0].split(";")[1].split(",")[j]);
- }
- }
- if(loadStrings(competitors[i].WCA + ".txt").length == 2) {
- competitors[i].competitions = 2;
- competitors[i].comp1 = new Time[loadStrings(competitors[i].WCA + ".txt")[0].split(";")[1].split(",").length];
- competitors[i].comp2 = new Time[loadStrings(competitors[i].WCA + ".txt")[1].split(";")[1].split(",").length];
- for(int j = 0; j < competitors[i].comp1.length; j++) {
- competitors[i].comp1[j] = new Time(loadStrings(competitors[i].WCA + ".txt")[0].split(";")[1].split(",")[j]);
- }
- for(int j = 0; j < competitors[i].comp2.length; j++) {
- competitors[i].comp1[j] = new Time(loadStrings(competitors[i].WCA + ".txt")[1].split(";")[1].split(",")[j]);
- }
- }
- if(loadStrings(competitors[i].WCA + ".txt").length == 3) {
- competitors[i].competitions = 3;
- competitors[i].comp1 = new Time[loadStrings(competitors[i].WCA + ".txt")[0].split(";")[1].split(",").length];
- competitors[i].comp2 = new Time[loadStrings(competitors[i].WCA + ".txt")[1].split(";")[1].split(",").length];
- competitors[i].comp3 = new Time[loadStrings(competitors[i].WCA + ".txt")[2].split(";")[1].split(",").length];
- for(int j = 0; j < competitors[i].comp1.length; j++) {
- competitors[i].comp1[j] = new Time(loadStrings(competitors[i].WCA + ".txt")[0].split(";")[1].split(",")[j]);
- }
- for(int j = 0; j < competitors[i].comp2.length; j++) {
- competitors[i].comp1[j] = new Time(loadStrings(competitors[i].WCA + ".txt")[1].split(";")[1].split(",")[j]);
- }
- for(int j = 0; j < competitors[i].comp3.length; j++) {
- competitors[i].comp1[j] = new Time(loadStrings(competitors[i].WCA + ".txt")[2].split(";")[1].split(",")[j]);
- }
- }
- if(doExit) {
- exit();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment