From: Steinar H. Gunderson Date: Sat, 19 Feb 2005 15:57:10 +0000 (+0000) Subject: Add beginning code for fetching groups. X-Git-Url: https://git.sesse.net/?p=ccbs;a=commitdiff_plain;h=8970b43d021e65f07ed4d279185c5062b4f9ee4a Add beginning code for fetching groups. --- diff --git a/bigscreen/fetch_group.cpp b/bigscreen/fetch_group.cpp new file mode 100644 index 0000000..7e131c4 --- /dev/null +++ b/bigscreen/fetch_group.cpp @@ -0,0 +1,53 @@ +#include "fetch_group.h" + +FetchGroup::FetchGroup(unsigned tournament, unsigned round, unsigned parallel, Group *group) : + tournament(tournament), round(round), parallel(parallel), dest_group(group) {} + +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 " + + "tournament=" + pqxx::to_string(tournament) + " AND " + + "round=" + pqxx::to_string(round) + " AND " + + "parallel=" + pqxx::to_string(parallel) + " " + + "ORDER BY position,songnumber") ); + + curr_group.tournament = tournament; + curr_group.round = round; + curr_group.parallel = parallel; + + // 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) { + Player p; + + p.id = i["player"]; + p.nick = i["nick"].as(p.nick); + p.total = 0; + p.rank = 1; + curr_group.players.push_back(p); + + curr_player = i["player"]; + } + + // note: we _will_ get some duplication here (multiple identical Song + // objects), but it isn't the end of the world + Score sc; + Song so; + + so.id = i["song"].as(so.id); + so.title = i["song"].as(so.title); + so.artist = i["song"].as(so.artist); + + sc.song = so; + sc.chosen = i["chosen"].as(s.chosen); + sc.score = i["score"].as(s.score); + + curr_group.players[curr.group.players.size() - 1].scores.push_back(sc); + } +} + +void FetchGroup::OnCommit() +{ + *dest_group = curr_group; +} diff --git a/bigscreen/fetch_group.h b/bigscreen/fetch_group.h new file mode 100644 index 0000000..78b943e --- /dev/null +++ b/bigscreen/fetch_group.h @@ -0,0 +1,20 @@ +#ifndef _FETCH_GROUP_H +#define _FETCH_GROUP_H 1 + +#include +#include "group.h" + +/* A transactor that fetches a group, all its scores etc. */ +class FetchGroup : public pqxx::transactor<> { +private: + unsigned tournament, round, parallel; + Group *dest_group; + Group curr_group; + +public: + FetchGroup(unsigned tournament, unsigned round, unsigned parallel, Group *group); + void operator() (pqxx::transaction<> &t); + void OnCommit(); +}; + +#endif /* !defined(_FETCH_CURRENT_TOURNAMENT_H) */ diff --git a/bigscreen/group.h b/bigscreen/group.h new file mode 100644 index 0000000..6961a90 --- /dev/null +++ b/bigscreen/group.h @@ -0,0 +1,30 @@ +#ifndef _GROUP_H +#define _GROUP_H 1 + +#include +#include "widestring.h" + +/* This more or less mimics the structures from show-tournament.pl */ +struct Song { + unsigned id; + widestring title, artist; +}; +struct Score { + Song song; + bool chosen; + unsigned score; +}: +struct Player { + unsigned id; + widestring nick; + unsigned score, rank; + + std::vector scores; +}; + +struct Group { + unsigned tournament, round, parallel; + std::vector players; +}; + +#endif /* !defined(_GROUPSCREEN_H) */ diff --git a/bigscreen/groupscreen.h b/bigscreen/groupscreen.h new file mode 100644 index 0000000..c794f60 --- /dev/null +++ b/bigscreen/groupscreen.h @@ -0,0 +1,21 @@ +#ifndef _GROUPSCREEN_H +#define _GROUPSCREEN_H 1 + +#include "flagtrigger.h" +#include "group.h" + +/* A screen class showing a group in the tournament */ +class GroupScreen : public Screen { +private: + unsigned tournament; + FlagTrigger scores_changed; + + +public: + Screen(unsigned tournament); + + bool check_invalidated(); + void draw(unsigned char *buf); +}; + +#endif /* !defined(_GROUPSCREEN_H) */