]> git.sesse.net Git - ccbs/commitdiff
Hit the group-fetching code so it compiles.
authorSteinar H. Gunderson <sesse@samfundet.no>
Sat, 19 Feb 2005 16:01:57 +0000 (16:01 +0000)
committerSteinar H. Gunderson <sesse@samfundet.no>
Sat, 19 Feb 2005 16:01:57 +0000 (16:01 +0000)
bigscreen/Makefile
bigscreen/ccbs_bigscreen.cpp
bigscreen/fetch_group.cpp
bigscreen/fetch_list_of_active_groups.cpp
bigscreen/fetch_list_of_active_groups.h
bigscreen/group.h

index 76d280d015570f81e4ce32653a11a6c8723a26d5..aca82435744f11cee59cff18b48a0daec02ff992 100644 (file)
@@ -4,7 +4,7 @@ CPPFLAGS=-I/usr/include/postgresql $(shell freetype-config --cflags) -Itinyptc/
 CXXFLAGS=-g -Wall
 LDFLAGS=-L/usr/X11R6/lib
 LIBS=$(shell freetype-config --libs) $(shell libpq3-config) -lpqxx tinyptc/libtinyptc.a -lX11
-CCBS_BIGSCREEN_OBJS=ccbs_bigscreen.o flagtrigger.o widestring.o fetch_current_tournament.o fetch_list_of_active_groups.o fonts.o
+CCBS_BIGSCREEN_OBJS=ccbs_bigscreen.o flagtrigger.o widestring.o fetch_current_tournament.o fetch_list_of_active_groups.o fetch_group.o fonts.o
 
 all: ccbs-bigscreen
 
index 9db87c8f9be0f9024c344ef2ea502a2b1ca2adab..f50991212b4257bc323c01b3413b81f98ea2992f 100644 (file)
@@ -8,10 +8,11 @@
 #include "widestring.h"
 #include "fetch_current_tournament.h"
 #include "fetch_list_of_active_groups.h"
+#include "fetch_group.h"
 #include "fonts.h"
 
 Tournament active_tournament;
-std::vector<Group> active_groups;
+std::vector<SkeletonGroup> active_groups;
 unsigned char framebuf[800 * 600 * 4];
 
 void init(pqxx::connection &conn)
@@ -24,9 +25,13 @@ void init(pqxx::connection &conn)
        } else {
                std::fprintf(stderr, "Current tournament is %d\n", active_tournament.id);
 
-               for (std::vector<Group>::const_iterator i = active_groups.begin(); i != active_groups.end(); ++i) {
+               for (std::vector<SkeletonGroup>::const_iterator i = active_groups.begin(); i != active_groups.end(); ++i) {
                        std::fprintf(stderr, "tourn: %u  round: %u   parallel: %u\n",
                                i->tournament, i->round, i->parallel);
+
+                       Group gr;
+                       conn.perform(FetchGroup(i->tournament, i->round, i->parallel, &gr));
+                       std::fprintf(stderr, "%u players in group\n", gr.players.size());
                }
        }
 }
index 7e131c437951a4022e7a04017e2373cc6cc2db5b..e1d0112160f2fa6f9e85d692e731f5f0e32fd9d1 100644 (file)
@@ -5,7 +5,7 @@ FetchGroup::FetchGroup(unsigned tournament, unsigned round, unsigned parallel, G
        
 void FetchGroup::operator() (pqxx::transaction<> &t)
 {
-       pqxx::result res( t.exec("SELECT round,parallel,position,playmode,difficulty,songnumber,player,nick,song,title,artist,chosen,score FROM roundparticipation NATURAL JOIN players NATURAL JOIN scores NATURAL LEFT JOIN songs WHERE " +
+       pqxx::result res( t.exec("SELECT round,parallel,position,playmode,difficulty,songnumber,player,nick,song,title,artist,chosen,score FROM roundparticipation NATURAL JOIN players NATURAL JOIN scores NATURAL LEFT JOIN songs WHERE " 
                "tournament=" + pqxx::to_string(tournament) + " AND " +
                "round=" + pqxx::to_string(round) + " AND " +
                "parallel=" + pqxx::to_string(parallel) + " " +
@@ -18,16 +18,16 @@ void FetchGroup::operator() (pqxx::transaction<> &t)
        // massage the data we get back into a Group object and children
        int curr_player = -1;
        for (pqxx::result::const_iterator i = res.begin(); i != res.end(); ++i) {
-               if (i["player"] != curr_player) {
+               if (i["player"].as(curr_player) != curr_player) {
                        Player p;
 
-                       p.id = i["player"];
+                       p.id = i["player"].as(p.id);
                        p.nick = i["nick"].as(p.nick);
                        p.total = 0;
                        p.rank = 1;
                        curr_group.players.push_back(p);
                        
-                       curr_player = i["player"];
+                       curr_player = i["player"].as(curr_player);
                }
 
                // note: we _will_ get some duplication here (multiple identical Song
@@ -40,10 +40,10 @@ void FetchGroup::operator() (pqxx::transaction<> &t)
                so.artist = i["song"].as(so.artist);
        
                sc.song = so;
-               sc.chosen = i["chosen"].as(s.chosen);
-               sc.score = i["score"].as(s.score);
+               sc.chosen = i["chosen"].as(sc.chosen);
+               sc.score = i["score"].as(sc.score);
                
-               curr_group.players[curr.group.players.size() - 1].scores.push_back(sc);
+               curr_group.players[curr_group.players.size() - 1].scores.push_back(sc);
        }
 }
 
index 1df67585ce55c94d15816dde7dc3226445173d4d..c2d587b1a395dd758d4f50207edc5389390594f6 100644 (file)
@@ -1,6 +1,6 @@
 #include "fetch_list_of_active_groups.h"
 
-FetchListOfActiveGroups::FetchListOfActiveGroups(std::vector<Group> *active) : active(active) {}
+FetchListOfActiveGroups::FetchListOfActiveGroups(std::vector<SkeletonGroup> *active) : active(active) {}
 void FetchListOfActiveGroups::operator() (pqxx::transaction<> &t)
 {
        // make sure we start with an empty list
@@ -8,7 +8,7 @@ void FetchListOfActiveGroups::operator() (pqxx::transaction<> &t)
        
        pqxx::result res( t.exec("SELECT * FROM bigscreen.active_groups") );
        for (pqxx::result::const_iterator i = res.begin(); i != res.end(); ++i) {
-               Group g;
+               SkeletonGroup g;
 
                g.tournament = i["tournament"].as(g.tournament);
                g.round = i["round"].as(g.round);
index 113160d85f5b69f21357e132a11946e8dc9b0f05..b1039d384f2aa12a2061f92618894a8efff03b69 100644 (file)
@@ -4,17 +4,17 @@
 #include <pqxx/transactor>
 #include <vector>
 
-struct Group {
+struct SkeletonGroup {
        unsigned tournament, round, parallel;
 };
 
 /* A transactor that fetches the current list of active groups. */
 class FetchListOfActiveGroups : public pqxx::transactor<> {
 private:
-       std::vector<Group> *active;
+       std::vector<SkeletonGroup> *active;
 
 public:
-       FetchListOfActiveGroups(std::vector<Group> *active);
+       FetchListOfActiveGroups(std::vector<SkeletonGroup> *active);
        void operator() (pqxx::transaction<> &t);
 };
 
index 6961a90b5b2636a1e71213ebec91cc8801c6e3ba..f6348c0cab71576d49ddcd26700586164e24a4c3 100644 (file)
@@ -13,11 +13,11 @@ struct Score {
        Song song;
        bool chosen;
        unsigned score;
-}:
+};
 struct Player {
        unsigned id;
        widestring nick;
-       unsigned score, rank;
+       unsigned total, rank;
        
        std::vector<Score> scores;
 };