Guest User

Untitled

a guest
Apr 4th, 2017
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.44 KB | None | 0 0
  1. boolean doExit = false;
  2. import java.text.DecimalFormat;
  3. //Rubik's cube times generalish API
  4. class Time {
  5.   float t;
  6.   boolean dnf;
  7.   boolean dns;
  8.   Time(String input) {
  9.     if (input.equals("DNF")) {
  10.       t = 0;
  11.       dnf = true;
  12.       dns = false;
  13.     } else if (input.equals("DNS")) {
  14.       t = 0;
  15.       dnf = true;
  16.       dns = true;
  17.     } else {
  18.       if (input.split(":").length == 1) {
  19.         t = parseFloat(input);
  20.         dnf = false;
  21.       } else if (input.split(":").length == 2) {
  22.         t = parseFloat(input.split(":")[1]) + 60*parseInt(input.split(":")[0]);
  23.       } else {
  24.         t = 0;
  25.         dnf = true;
  26.       }
  27.     }
  28.   }
  29.   Time duplicate() {
  30.     Time r = new Time("DNF");
  31.     r.dnf = dnf;
  32.     r.dns = dns;
  33.     r.t = t;
  34.     return r;
  35.   }
  36.   String asString() {
  37.     if (dnf) {
  38.       if (dns) {
  39.         return "DNS";
  40.       }
  41.       return "DNF";
  42.     } else {
  43.       if (t < 60) {
  44.         return new DecimalFormat("0.00").format(t);
  45.       } else {
  46.         return floor(t - (t%60))/60 + ":" + new DecimalFormat("00.00").format(t%60);
  47.       }
  48.     }
  49.   }
  50.   boolean isBetterThan(Time _t) {
  51.     if (dnf) return false;
  52.     if (_t.dnf) return true;
  53.     else return t<_t.t;
  54.   }
  55. }
  56. Time average(Time[] times, String mode) {
  57.   if (mode.equals("a") || mode.equals("an")) {
  58.     for(int i = 0; i < times.length - 1; i++) {
  59.       for(int j = 0; j < times.length - 1 - i; j++) {
  60.         if(times[i+j+1].isBetterThan(times[i])) {
  61.           Time a = times[i].duplicate();
  62.           times[i] = times[i+j+1];
  63.           times[i+j+1] = a;
  64.         }
  65.       }
  66.     }
  67.     Time[] temp = new Time[times.length - 2];
  68.     for(int i = 1; i < times.length - 1; i++) {
  69.       temp[i-1] = times[i];
  70.     }
  71.     return average(temp, "m");
  72.   }
  73.   else if (mode.equals("m") || mode.equals("mn")) {
  74.     float sumOfTimes = 0;
  75.     for (int i = 0; i < times.length; i++) {
  76.       if (times[i].dnf) return new Time("DNF");
  77.       else sumOfTimes+=times[i].t;
  78.     }
  79.     return new Time("" + sumOfTimes/times.length);
  80.   }
  81.   else if(mode.equals("s") || mode.equals("sn")) {
  82.     return new Time("DNS");
  83.   }
  84.   else return new Time("DNF");
  85. }
  86. //End generalish API
  87. class Person {
  88.   String WCA, name;
  89.   int competitions;
  90.   Time[] comp1;
  91.   Time[] comp2;
  92.   Time[] comp3;
  93.   float comp1Weight;
  94.   float comp2Weight;
  95.   float comp3Weight;
  96.   Person(String WCA_, String name_) {
  97.     WCA = WCA_;
  98.     name = name_;
  99.   }
  100. }
  101. Person[] competitors = {
  102.   new Person("2013BARK01", "Justin Barker"),
  103.   new Person("2015WEBS01", "Garrett Webster"),
  104.   new Person("2015BUCK03", "Asher Buckner"),
  105.   new Person("2015SPEC01", "Tyler Specht"),
  106.   new Person("2009OLSO01", "Christopher Olson")
  107. };
  108. void setup() {
  109.   for(int i = 0; i < competitors.length; i++) {
  110.     if(loadStrings(competitors[i].WCA + ".txt") == null) {
  111.       saveStrings(competitors[i].WCA + ".txt", new String[]{});
  112.       doExit = true;
  113.     }
  114.   }
  115.   if(doExit) {
  116.     exit();
  117.   }
  118.   for(int i = 0; i < competitors.length; i++) {
  119.     if(loadStrings(competitors[i].WCA + ".txt").length == 0) {
  120.       println("Empty file for " + competitors[i].WCA);
  121.       doExit = true;
  122.     }
  123.     if(loadStrings(competitors[i].WCA + ".txt").length >= 4) {
  124.       println("More than 3 competitions listed for " + competitors[i].WCA);
  125.       doExit = true;
  126.     }
  127.     if(loadStrings(competitors[i].WCA + ".txt").length == 1) {
  128.       competitors[i].competitions = 1;
  129.       competitors[i].comp1 = new Time[loadStrings(competitors[i].WCA + ".txt")[0].split(";")[1].split(",").length];
  130.       for(int j = 0; j < competitors[i].comp1.length; j++) {
  131.         competitors[i].comp1[j] = new Time(loadStrings(competitors[i].WCA + ".txt")[0].split(";")[1].split(",")[j]);
  132.       }
  133.     }
  134.     if(loadStrings(competitors[i].WCA + ".txt").length == 2) {
  135.       competitors[i].competitions = 2;
  136.       competitors[i].comp1 = new Time[loadStrings(competitors[i].WCA + ".txt")[0].split(";")[1].split(",").length];
  137.       competitors[i].comp2 = new Time[loadStrings(competitors[i].WCA + ".txt")[1].split(";")[1].split(",").length];
  138.       for(int j = 0; j < competitors[i].comp1.length; j++) {
  139.         competitors[i].comp1[j] = new Time(loadStrings(competitors[i].WCA + ".txt")[0].split(";")[1].split(",")[j]);
  140.       }
  141.       for(int j = 0; j < competitors[i].comp2.length; j++) {
  142.         competitors[i].comp1[j] = new Time(loadStrings(competitors[i].WCA + ".txt")[1].split(";")[1].split(",")[j]);
  143.       }
  144.     }
  145.     if(loadStrings(competitors[i].WCA + ".txt").length == 3) {
  146.       competitors[i].competitions = 3;
  147.       competitors[i].comp1 = new Time[loadStrings(competitors[i].WCA + ".txt")[0].split(";")[1].split(",").length];
  148.       competitors[i].comp2 = new Time[loadStrings(competitors[i].WCA + ".txt")[1].split(";")[1].split(",").length];
  149.       competitors[i].comp3 = new Time[loadStrings(competitors[i].WCA + ".txt")[2].split(";")[1].split(",").length];
  150.       for(int j = 0; j < competitors[i].comp1.length; j++) {
  151.         competitors[i].comp1[j] = new Time(loadStrings(competitors[i].WCA + ".txt")[0].split(";")[1].split(",")[j]);
  152.       }
  153.       for(int j = 0; j < competitors[i].comp2.length; j++) {
  154.         competitors[i].comp1[j] = new Time(loadStrings(competitors[i].WCA + ".txt")[1].split(";")[1].split(",")[j]);
  155.       }
  156.       for(int j = 0; j < competitors[i].comp3.length; j++) {
  157.         competitors[i].comp1[j] = new Time(loadStrings(competitors[i].WCA + ".txt")[2].split(";")[1].split(",")[j]);
  158.       }
  159.     }
  160.     if(doExit) {
  161.       exit();
  162.     }
  163.   }
  164. }
Advertisement
Add Comment
Please, Sign In to add comment