]> git.sesse.net Git - ccbs/blob - bigscreen/fetch_max_score_for_players.cpp
Make more room for the players in the "top 10 scores" screen.
[ccbs] / bigscreen / fetch_max_score_for_players.cpp
1 #include "fetch_max_score_for_players.h"
2
3 FetchMaxScoreForPlayers::FetchMaxScoreForPlayers(unsigned tournament, unsigned round, std::map<unsigned, unsigned> *scores)
4         : tournament(tournament), round(round), scores(scores) {}
5         
6 void FetchMaxScoreForPlayers::operator() (pqxx::transaction<> &t)
7 {
8         scores->erase(scores->begin(), scores->end());
9         
10         pqxx::result res( t.exec(
11                 "SELECT player,"
12                 "  ("
13                 "     SELECT feetrating"
14                 "     FROM songratings"
15                 "     WHERE machine=( SELECT machine FROM tournaments WHERE tournament=" + pqxx::to_string(tournament) + " ) " // only find songs on the machine we use
16                 "     AND song NOT IN ("                      // not a song that has been in elimination or seeding
17                 "       SELECT song FROM scores "
18                 "         WHERE tournament=" + pqxx::to_string(tournament) +
19                 "         AND song IS NOT NULL"
20                 "         AND parallel=0"
21                 "         AND chosen='f'"
22                 "     )"
23                 "     AND (player,song) NOT IN ("             // not a song the player has chosen before, or is a random song in this round
24                 "       SELECT player,song FROM scores"
25                 "          WHERE tournament=" + pqxx::to_string(tournament) +
26                 "          AND song IS NOT NULL" +
27                 "          AND ( chosen='t' OR round=" + pqxx::to_string(round) + " )"
28                 "       )"
29                 "     ORDER BY feetrating DESC LIMIT 1"      
30                 "  ) * 1000 AS max_score FROM tournamentparticipation") );
31         
32         for (pqxx::result::const_iterator i = res.begin(); i != res.end(); ++i) {
33                 unsigned player, max_score;
34                 player = i["player"].as(player);
35                 max_score = i["max_score"].as(max_score);
36
37                 scores->insert(std::make_pair(player, max_score));
38         }
39 }