1 #include "fetch_max_score_for_players.h"
3 FetchMaxScoreForPlayers::FetchMaxScoreForPlayers(unsigned tournament, unsigned round, std::map<unsigned, unsigned> *scores)
4 : tournament(tournament), round(round), scores(scores) {}
6 void FetchMaxScoreForPlayers::operator() (pqxx::transaction<> &t)
8 scores->erase(scores->begin(), scores->end());
10 pqxx::result res( t.exec(
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"
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) + " )"
29 " AND playmode='single'"
30 " ORDER BY feetrating DESC LIMIT 1"
31 " ) * 1000 AS max_score FROM tournamentparticipation") );
33 for (pqxx::result::const_iterator i = res.begin(); i != res.end(); ++i) {
34 unsigned player, max_score;
35 player = i["player"].as(player);
36 max_score = i["max_score"].as(max_score);
38 scores->insert(std::make_pair(player, max_score));