]> git.sesse.net Git - ccbs/blob - bigscreen/fetch_max_score_for_songs.cpp
Write the machine number (if any) in the header.
[ccbs] / bigscreen / fetch_max_score_for_songs.cpp
1 #include "fetch_max_score_for_songs.h"
2
3 FetchMaxScoreForSongs::FetchMaxScoreForSongs(unsigned tournament, std::map<unsigned, unsigned> *score)
4         : tournament(tournament), score(score) {}
5         
6 void FetchMaxScoreForSongs::operator() (pqxx::transaction<> &t)
7 {
8         score->erase(score->begin(), score->end());
9         
10         pqxx::result res( t.exec("SELECT song,MAX(feetrating)*1000 AS max_score FROM songratings WHERE " 
11                 " machine=( SELECT machine FROM tournaments WHERE tournament=" + pqxx::to_string(tournament) + ") GROUP BY song") );
12         
13         for (pqxx::result::const_iterator i = res.begin(); i != res.end(); ++i) {
14                 unsigned song, max_score;
15                 song = i["song"].as(song);
16                 max_score = i["max_score"].as(max_score);
17                 
18                 score->insert(std::make_pair(song, max_score));
19         }
20 }