]> git.sesse.net Git - ccbs/blob - bigscreen/fetch_max_score_for_players.cpp
Put all the auxilliary screens in a rotate 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                 "     )"
22                 "     AND (player,song) NOT IN ("             // not a song the player has chosen before, or is a random song in this round
23                 "       SELECT player,song FROM scores"
24                 "          WHERE tournament=" + pqxx::to_string(tournament) +
25                 "          AND song IS NOT NULL" +
26                 "          AND ( chosen='t' OR round=" + pqxx::to_string(round) + " )"
27                 "       )"
28                 "     ORDER BY feetrating DESC LIMIT 1"      
29                 "  ) * 1000 AS max_score FROM tournamentparticipation") );
30         
31         for (pqxx::result::const_iterator i = res.begin(); i != res.end(); ++i) {
32                 unsigned player, max_score;
33                 player = i["player"].as(player);
34                 max_score = i["max_score"].as(max_score);
35
36                 scores->insert(std::make_pair(player, max_score));
37         }
38 }