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"
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) + " )"
28 " ORDER BY feetrating DESC LIMIT 1"
29 " ) * 1000 AS max_score FROM tournamentparticipation") );
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);
36 scores->insert(std::make_pair(player, max_score));