Skip to content

Commit

Permalink
db_dump: include badges in XML stats export
Browse files Browse the repository at this point in the history
I did this by including list of badges in the tables.xml file,
and writing the list of badge assignments to 2 new files,
badge_user.gz (for users) and badge_team.gz (for teams).

I considered including the badges within the <user> and <team> elements.
However, this would require enumerating the badges for a particular user
within the enumeration of users, which doesn't work;
only one enumeration can be active at a time.
Plus it would be less efficient, and db_dump already takes
a half hour on a big project.
  • Loading branch information
davidpanderson committed May 19, 2014
1 parent a2b7161 commit b174558
Show file tree
Hide file tree
Showing 5 changed files with 170 additions and 4 deletions.
42 changes: 42 additions & 0 deletions db/boinc_db.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ void SCHED_TRIGGER_ITEM::clear() {
void FILESET_SCHED_TRIGGER_ITEM::clear() {memset(this, 0, sizeof(*this));}
void VDA_FILE::clear() {memset(this, 0, sizeof(*this));}
void VDA_CHUNK_HOST::clear() {memset(this, 0, sizeof(*this));}
void BADGE::clear() {memset(this, 0, sizeof(*this));}
void BADGE_USER::clear() {memset(this, 0, sizeof(*this));}
void BADGE_TEAM::clear() {memset(this, 0, sizeof(*this));}

DB_PLATFORM::DB_PLATFORM(DB_CONN* dc) :
DB_BASE("platform", dc?dc:&boinc_db){}
Expand Down Expand Up @@ -161,6 +164,12 @@ DB_VDA_FILE::DB_VDA_FILE(DB_CONN* dc) :
DB_BASE("vda_file", dc?dc:&boinc_db){}
DB_VDA_CHUNK_HOST::DB_VDA_CHUNK_HOST(DB_CONN* dc) :
DB_BASE("vda_chunk_host", dc?dc:&boinc_db){}
DB_BADGE::DB_BADGE(DB_CONN* dc) :
DB_BASE("badge", dc?dc:&boinc_db){}
DB_BADGE_USER::DB_BADGE_USER(DB_CONN* dc) :
DB_BASE("badge_user", dc?dc:&boinc_db){}
DB_BADGE_TEAM::DB_BADGE_TEAM(DB_CONN* dc) :
DB_BASE("badge_team", dc?dc:&boinc_db){}

int DB_PLATFORM::get_id() {return id;}
int DB_APP::get_id() {return id;}
Expand Down Expand Up @@ -2600,4 +2609,37 @@ void DB_VDA_CHUNK_HOST::db_parse(MYSQL_ROW &r) {
transfer_send_time = atof(r[i++]);
}

void DB_BADGE::db_parse(MYSQL_ROW &r) {
int i=0;
clear();
id = atoi(r[i++]);
create_time = atof(r[i++]);
type = atoi(r[i++]);
strcpy2(name, r[i++]);
strcpy2(title, r[i++]);
strcpy2(description, r[i++]);
strcpy2(image_url, r[i++]);
strcpy2(level, r[i++]);
strcpy2(tags, r[i++]);
strcpy2(sql_rule, r[i++]);
}

void DB_BADGE_USER::db_parse(MYSQL_ROW &r) {
int i=0;
clear();
badge_id = atoi(r[i++]);
user_id = atoi(r[i++]);
create_time = atof(r[i++]);
reassign_time = atof(r[i++]);
}

void DB_BADGE_TEAM::db_parse(MYSQL_ROW &r) {
int i=0;
clear();
badge_id = atoi(r[i++]);
team_id = atoi(r[i++]);
create_time = atof(r[i++]);
reassign_time = atof(r[i++]);
}

const char *BOINC_RCSID_ac374386c8 = "$Id$";
19 changes: 19 additions & 0 deletions db/boinc_db.h
Original file line number Diff line number Diff line change
Expand Up @@ -509,4 +509,23 @@ struct DB_VDA_CHUNK_HOST : public DB_BASE, public VDA_CHUNK_HOST {
void db_parse(MYSQL_ROW &row);
};

struct DB_BADGE : public DB_BASE, public BADGE {
DB_BADGE(DB_CONN* p=0);
int get_id() {return id;};
void db_print(char*){};
void db_parse(MYSQL_ROW&);
};

struct DB_BADGE_USER : public DB_BASE, public BADGE_USER {
DB_BADGE_USER(DB_CONN* p=0);
void db_print(char*){};
void db_parse(MYSQL_ROW&);
};

struct DB_BADGE_TEAM : public DB_BASE, public BADGE_TEAM {
DB_BADGE_TEAM(DB_CONN* p=0);
void db_print(char*){};
void db_parse(MYSQL_ROW&);
};

#endif
30 changes: 30 additions & 0 deletions db/boinc_db_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -761,4 +761,34 @@ struct VDA_CHUNK_HOST {
void print_status(int level);
};

struct BADGE {
int id;
double create_time;
int type;
char name[256];
char title[256];
char description[256];
char image_url[256];
char level[256];
char tags[256];
char sql_rule[256];
void clear();
};

struct BADGE_USER {
int badge_id;
int user_id;
double create_time;
double reassign_time;
void clear();
};

struct BADGE_TEAM {
int badge_id;
int team_id;
double create_time;
double reassign_time;
void clear();
};

#endif
2 changes: 2 additions & 0 deletions db/db_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,8 @@ int DB_BASE::update_fields_noid(const char* set_clause, const char* where_clause
return 0;
}

// Note: AFAIK, if one enumeration is active you can't do another one
//
int DB_BASE::enumerate(const char* clause, bool use_use_result) {
int x;
char query[MAX_QUERY_LEN];
Expand Down
81 changes: 77 additions & 4 deletions sched/db_dump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@
/// db_dump: dump database views in XML format
// see http://boinc.berkeley.edu/trac/wiki/DbDump

// Note: this program is way more configurable than it needs to be.
// All projects export stats in the same format,
// as described in the default db_dump_spec.xml that is created for you.
// Note:
// 1) this program is way more configurable than it needs to be.
// All projects export stats in the same format,
// as described in the default db_dump_spec.xml that is created for you.
// 2) should scrap this and replace it with a 100 line PHP script.
// I'll get to this someday.

#include "config.h"
#include <cstdio>
Expand Down Expand Up @@ -70,6 +73,7 @@ const char* tag_name[3] = {"users", "teams", "hosts"};

int nusers, nhosts, nteams;
double total_credit;
bool have_badges = false;

struct OUTPUT {
int recs_per_file;
Expand Down Expand Up @@ -462,6 +466,48 @@ void write_user(USER& user, FILE* f, bool /*detail*/) {
);
}

void write_badge_user(char* output_dir) {
DB_BADGE_USER bu;
char path[MAXPATHLEN];
ZFILE* f = new ZFILE("badge_users", COMPRESSION_GZIP);
sprintf(path, "%s/badge_user", output_dir);
f->open(path);
while (!bu.enumerate("")) {
fprintf(f->f,
" <badge_user>\n"
" <user_id>%d</user_id>\n"
" <badge_id>%d</badge_id>\n"
" <create_time>%.0f</create_time>\n"
" </badge_user>\n",
bu.user_id,
bu.badge_id,
bu.create_time
);
}
f->close();
}

void write_badge_team(char* output_dir) {
DB_BADGE_TEAM bt;
char path[MAXPATHLEN];
ZFILE* f = new ZFILE("badge_teams", COMPRESSION_GZIP);
sprintf(path, "%s/badge_team", output_dir);
f->open(path);
while (!bt.enumerate("")) {
fprintf(f->f,
" <badge_team>\n"
" <team_id>%d</team_id>\n"
" <badge_id>%d</badge_id>\n"
" <create_time>%.0f</create_time>\n"
" </badge_team>\n",
bt.team_id,
bt.badge_id,
bt.create_time
);
}
f->close();
}

void write_team(TEAM& team, FILE* f, bool detail) {
DB_USER user;
char buf[256];
Expand Down Expand Up @@ -595,6 +641,27 @@ int print_apps(FILE* f) {
return 0;
}

void print_badges(FILE* f) {
DB_BADGE badge;
fprintf(f, " <badges>\n");
while (!badge.enumerate()) {
have_badges = true;
fprintf(f,
" <badge>\n"
" <id>%d</id>\n"
" <name>%s</name>\n"
" <title>%s</name>\n"
" <image_url>%s</image_url>\n"
" </badge>\n",
badge.id,
badge.name,
badge.title,
badge.image_url
);
}
fprintf(f, " </badges>\n");
}

int tables_file(char* dir) {
char buf[256];

Expand All @@ -610,6 +677,7 @@ int tables_file(char* dir) {
if (nhosts) fprintf(f.f, " <nhosts_total>%d</nhosts_total>\n", nhosts);
if (total_credit) fprintf(f.f, " <total_credit>%lf</total_credit>\n", total_credit);
print_apps(f.f);
print_badges(f.f);
f.close();
return 0;
}
Expand Down Expand Up @@ -857,13 +925,18 @@ int main(int argc, char** argv) {

boinc_mkdir(spec.output_dir);

tables_file(spec.output_dir);

unsigned int j;
for (j=0; j<spec.enumerations.size(); j++) {
ENUMERATION& e = spec.enumerations[j];
e.make_it_happen(spec.output_dir);
}

tables_file(spec.output_dir);
if (have_badges) {
write_badge_user(spec.output_dir);
write_badge_team(spec.output_dir);
}

sprintf(buf, "cp %s %s/db_dump.xml", spec_filename, spec.output_dir);
retval = system(buf);
Expand Down

0 comments on commit b174558

Please sign in to comment.