// Data waiting for insertion into the database.
struct RatingDBTuple {
- string player;
+ int player;
float mu, mu_stddev;
};
struct CovarianceDBTuple {
- string player1, player2;
+ int player1, player2;
float covariance;
};
vector<RatingDBTuple> rating_db_tuples;
map<int, vector<match> > matches_for_player;
vector<match> all_matches;
-void dump_scores(const vector<string> &players, const float *mu, const float *mu_stddev, int num_players)
+void dump_scores(const vector<int> &players, const float *mu, const float *mu_stddev, int num_players)
{
#if USE_DB
for (int i = 0; i < num_players; ++i) {
}
#else
for (int i = 0; i < num_players; ++i) {
- printf("%f %f %s\n", mu[i], mu_stddev[i], players[i].c_str());
+ printf("%f %f %d\n", mu[i], mu_stddev[i], players[i]);
}
#endif
}
// Compute uncertainty (stddev) of mu estimates, which is sqrt((H^-1)_ii),
// where H is the Hessian (see construct_hessian()).
-void compute_mu_uncertainty(const float *mu, const vector<string> &players)
+void compute_mu_uncertainty(const float *mu, const vector<int> &players)
{
// FIXME: Use pseudoinverse if applicable.
Matrix<float, Dynamic, Dynamic> ih = hessian.inverse();
exit(1);
}
- vector<string> players;
- map<string, int> player_map;
+ vector<int> players;
+ map<int, int> player_map;
for (int i = 0; i < num_players; ++i) {
char buf[256];
exit(1);
}
- players.push_back(buf);
- player_map[buf] = i;
+ players.push_back(atoi(buf));
+ player_map[atoi(buf)] = i;
}
int num_matches = 0;
for ( ;; ) {
- char pl1[256], pl2[256];
+ int pl1, pl2;
int score1, score2;
float weight;
- if (fscanf(fp, "%s %s %d %d %f", pl1, pl2, &score1, &score2, &weight) != 5) {
+ if (fscanf(fp, "%d %d %d %d %f", &pl1, &pl2, &score1, &score2, &weight) != 5) {
//fprintf(stderr, "Read %d matches.\n", num_matches);
break;
}
++num_matches;
if (player_map.count(pl1) == 0) {
- fprintf(stderr, "Unknown player '%s'\n", pl1);
+ fprintf(stderr, "Unknown player '%d'\n", pl1);
exit(1);
}
if (player_map.count(pl2) == 0) {
- fprintf(stderr, "Unknown player '%s'\n", pl2);
+ fprintf(stderr, "Unknown player '%d'\n", pl2);
exit(1);
}
txn.exec("TRUNCATE ratings");
pqxx::tablewriter writer(txn, "ratings");
for (unsigned i = 0; i < rating_db_tuples.size(); ++i) {
- char mu_str[128], mu_stddev_str[128];
+ char player_str[128], mu_str[128], mu_stddev_str[128];
+ snprintf(player_str, 128, "%d", rating_db_tuples[i].player);
snprintf(mu_str, 128, "%f", rating_db_tuples[i].mu);
snprintf(mu_stddev_str, 128, "%f", rating_db_tuples[i].mu_stddev);
vector<string> tuple;
- tuple.push_back(rating_db_tuples[i].player);
+ tuple.push_back(player_str);
tuple.push_back(mu_str);
tuple.push_back(mu_stddev_str);
writer.push_back(tuple);
txn.exec("CREATE TABLE new_covariance ( player1 smallint NOT NULL, player2 smallint NOT NULL, cov float NOT NULL )");
pqxx::tablewriter writer(txn, "new_covariance");
for (unsigned i = 0; i < covariance_db_tuples.size(); ++i) {
- char cov_str[128];
+ char player1_str[128], player2_str[128], cov_str[128];
+ snprintf(player1_str, 128, "%d", covariance_db_tuples[i].player1);
+ snprintf(player2_str, 128, "%d", covariance_db_tuples[i].player2);
snprintf(cov_str, 128, "%f", covariance_db_tuples[i].covariance);
vector<string> tuple;
- tuple.push_back(covariance_db_tuples[i].player1);
- tuple.push_back(covariance_db_tuples[i].player2);
+ tuple.push_back(player1_str);
+ tuple.push_back(player2_str);
tuple.push_back(cov_str);
writer.push_back(tuple);
}