Пример #1
0
 /** Rebuilds the team statistics. */
 public synchronized void validate() {
   statsValid = false;
   Iterator<Comment> it = comments.iterator();
   Comment item;
   // clean up the comments list - remove dead matches
   while (it.hasNext()) {
     item = it.next();
     if (item.getMatch() != null
         && !matches.containsKey(new SecondTime(item.getMatch().getTime()))) {
       AppLib.printDebug("Stripping comment from " + getNumber());
       it.remove();
     }
   }
   // init
   it = comments.iterator();
   if (data == null) data = new ArrayList<Integer>(numUDFs);
   int total = 0, num = 0, udf = 0;
   int[] totalUDFs = new int[numUDFs];
   int[] countUDFs = new int[numUDFs];
   while (it.hasNext()) {
     item = it.next();
     // run up rating and UDFs
     if (item.getRating() > 0.) {
       num++;
       total += item.getRating();
     }
     for (int i = 0; i < item.getUDFs().size(); i++) {
       udf = item.getUDFs().get(i);
       if (udf != 0) {
         totalUDFs[i] += udf;
         countUDFs[i]++;
       }
     }
   }
   // total and save
   data.clear();
   for (int i = 0; i < countUDFs.length; i++) {
     if (countUDFs[i] == 0) data.add(0);
     else data.add((int) Math.round((double) totalUDFs[i] / countUDFs[i]));
   }
   if (num == 0) cachedRating = 0;
   else cachedRating = round1((double) total / num);
   scores = new ArrayList<Integer>();
   // match stats
   Iterator<ScheduleItem> sit = matches.values().iterator();
   ScheduleItem match;
   List<Score> sc;
   Score myScore;
   int index, diff;
   boolean side;
   points = teamPoints = enPoints = wins = ties = losses = rp = 0;
   while (sit.hasNext()) {
     match = sit.next();
     index = match.getTeams().indexOf(getNumber());
     // sp, rp, record
     if (index >= 0
         && match.getStatus() == ScheduleItem.COMPLETE
         && match.counts()
         && !match.getSurrogate().get(index)) {
       side = index < ScheduleItem.TPA; // true is red, false is blue
       diff = match.getBlueScore() - match.getRedScore();
       if ((!side && diff > 0) || (side && diff < 0)) wins++;
       else if (diff == 0) ties++;
       else losses++;
       sc = match.getScores();
       myScore = null;
       if (sc != null) {
         myScore = sc.get(index);
         points += myScore.totalScore();
         // accumulate
         if (scores.size() < 1) {
           scores = new ArrayList<Integer>(myScore.size());
           for (int i = 0; i < myScore.size(); i++) scores.add(0);
         }
         // add it up!
         for (int i = 0; i < myScore.size() && i < scores.size(); i++)
           scores.set(i, scores.get(i) + myScore.getScoreAt(i));
       }
       if (side) {
         teamPoints += match.getRedScore();
         enPoints += match.getBlueScore();
       } else {
         teamPoints += match.getBlueScore();
         enPoints += match.getRedScore();
       }
       rp += Math.min(match.getBlueScore(), match.getRedScore());
       if (myScore != null && ((!side && diff > 0) || (side && diff < 0))) {
         // penalty points for RP
         for (int i = 0; i < ScheduleItem.TPA; i++)
           rp += 10 * sc.get(i + (side ? ScheduleItem.TPA : 0)).getPenaltyCount();
       }
     }
   }
   statsValid = true;
 }