예제 #1
0
 public void initComponents() {
   competitors =
       DB.getCompetitors(turniej.getId())
           .stream()
           .filter(c -> c.getGoesFinal())
           .collect(Collectors.toList());
   competitorMap = competitors.stream().collect(Collectors.toMap(c -> c.getId(), c -> c));
   singleGames =
       DB.getSingleGames(turniej.getId(), true)
           .stream()
           .filter(
               sg ->
                   competitorMap.containsKey(sg.getCompetitorW())
                       && competitorMap.containsKey(sg.getCompetitorB()))
           .collect(Collectors.toList());
   // filtrowanie powyżej, bo baza zwraca również gry,
   // gdzie grali (dostał się do finałów) vs (nie dostał się)
   // można to naprawić w bazie
   for (Competitor c : competitors) {
     competitorGames.put(c, new LinkedList<>());
   }
   for (SingleGame sg : singleGames) {
     competitorGames.get(competitorMap.get(sg.getCompetitorW())).add(sg);
     competitorGames.get(competitorMap.get(sg.getCompetitorB())).add(sg);
   }
   removeAll();
   table = new JTable(new MyTableModel());
   add(new JScrollPane(table));
   updateTables();
 }
예제 #2
0
  void updateTables() {
    for (Competitor c : competitors) {
      competitorWon.put(c, 0);
      competitorLost.put(c, 0);
      competitorTie.put(c, 0);
      for (SingleGame sg : competitorGames.get(c)) {
        Competitor c1 = competitorMap.get(sg.getCompetitorW()); // gra białymi
        Competitor c2 = competitorMap.get(sg.getCompetitorB()); // gra czarnymi
        int score = sg.getScore(); // 1 - wygrały białe, 2 - czarne, 3 - remis;
        if (score == 1 && c.equals(c1)) competitorWon.put(c, competitorWon.get(c) + 1);
        if (score == 2 && c.equals(c2)) competitorWon.put(c, competitorWon.get(c) + 1);

        if (score == 1 && c.equals(c2)) competitorLost.put(c, competitorLost.get(c) + 1);
        if (score == 2 && c.equals(c1)) competitorLost.put(c, competitorLost.get(c) + 1);

        if (score == 3) competitorTie.put(c, competitorTie.get(c) + 1);
      }
      float points = 1.0f * competitorWon.get(c) + 0.5f * competitorTie.get(c);
      competitorPoints.put(c, points);
    }
    for (Competitor c : competitors) {
      float SBPoints = 0.0f;
      for (SingleGame sg : competitorGames.get(c)) {
        Competitor c1 = competitorMap.get(sg.getCompetitorW()); // gra białymi
        Competitor c2 = competitorMap.get(sg.getCompetitorB()); // gra czarnymi
        int score = sg.getScore(); // 1 - wygrały białe, 2 - czarne, 3 - remis;
        if (score == 1 && c.equals(c1)) SBPoints += competitorPoints.get(c2);
        if (score == 2 && c.equals(c2)) SBPoints += competitorPoints.get(c1);
        if (score == 3 && c.equals(c1)) SBPoints += 0.5f * competitorPoints.get(c2);
        if (score == 3 && c.equals(c2)) SBPoints += 0.5f * competitorPoints.get(c1);
      }
      competitorSBPoints.put(c, SBPoints);
    }
    competitors.sort(
        (c1, c2) -> (int) (4. * (competitorSBPoints.get(c2) - competitorSBPoints.get(c1))));
    competitors.sort(
        (c1, c2) -> (int) (2. * (competitorPoints.get(c2) - competitorPoints.get(c1))));
    ((AbstractTableModel) table.getModel()).fireTableDataChanged();
  }