Skip to content

Commit

Permalink
players.json now only saves the starting values of each player's rating.
Browse files Browse the repository at this point in the history
Since the calculation of the players' rating values is done by only using the results and starting values, there's no need to save the rating values for every rating period.
  • Loading branch information
ThatCraws committed Jun 17, 2019
1 parent 2941dac commit 9d37848
Showing 1 changed file with 11 additions and 25 deletions.
36 changes: 11 additions & 25 deletions PR Tool/GUI/MainWin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -682,7 +682,7 @@ bool MainWin::loadWorld() {

const Json::Value& players = obj["players"]; // array of players

// load rating periods before players so the number of rating values per player can be corrected if neccessary
// load rating periods before players so the size of the rating value can be set accordingly
const Json::Value& periods = obj["rating periods"]; // array of start and end dates of all rating periods

wxDateTime start;
Expand All @@ -708,25 +708,16 @@ bool MainWin::loadWorld() {

std::vector<Rating> ratingVector; // vector containing the start-rating of the player and entries for each rating period (start values -> current)

const Json::Value& ratingVals = players[i]["rating values"]; // array of current players' rating values (or rather rating values-objects)
const Json::Value& ratingVals = players[i]["start rating values"]; // current player's starting rating values

// loading and storing the players' start rating values and inserting items into the ratingVal-vector per rating period

Rating toAdd;
toAdd.rating = ratingVals[0]["rating"].asDouble();
toAdd.deviation = ratingVals[0]["deviation"].asDouble();
toAdd.volatility = ratingVals[0]["volatility"].asDouble();
toAdd.rating = ratingVals["rating"].asDouble();
toAdd.deviation = ratingVals["deviation"].asDouble();
toAdd.volatility = ratingVals["volatility"].asDouble();

ratingVector.resize(ratingVals.size(), toAdd);

/*for (unsigned int j = 0; j < ratingVals.size(); j++) {
Rating toAdd;
toAdd.rating = ratingVals[j]["rating"].asDouble();
toAdd.deviation = ratingVals[j]["deviation"].asDouble();
toAdd.volatility = ratingVals[j]["volatility"].asDouble();
ratingVector.push_back(toAdd);
}*/
ratingVector.resize(ratingPeriods.size() + 1, toAdd);

// could use the default values of addPlayer, but this spares us the ifception
unsigned int wins = 0;
Expand Down Expand Up @@ -777,17 +768,12 @@ bool MainWin::saveWorld() {
currAliases.append(Json::Value(*currAlias)); // filling the aliases section with the aliases of the current player
}

Json::Value currPlayerRatings(Json::arrayValue); // equal to the "rating values" in players.json (to save all rating values for every period)

for (auto currRating = currPlayerBasePlayer->ratings.begin(); currRating != currPlayerBasePlayer->ratings.end(); currRating++) {
Json::Value ratingValsToAdd; // Contains the rating values of the currently saved period
ratingValsToAdd["rating"] = currRating->rating;
ratingValsToAdd["deviation"] = currRating->deviation;
ratingValsToAdd["volatility"] = currRating->volatility;
currPlayerRatings.append(ratingValsToAdd);
}
Json::Value startValues; // The player's starting (rating) values
startValues["rating"] = currPlayerBasePlayer->ratings.at(0).rating;
startValues["deviation"] = currPlayerBasePlayer->ratings.at(0).deviation;
startValues["volatility"] = currPlayerBasePlayer->ratings.at(0).volatility;

currEntry["rating values"] = currPlayerRatings;
currEntry["start rating values"] = startValues;
currEntry["wins"] = currPlayerBasePlayer->wins;
currEntry["losses"] = currPlayerBasePlayer->losses;
currEntry["ties"] = currPlayerBasePlayer->ties;
Expand Down

0 comments on commit 9d37848

Please sign in to comment.