From 9d37848c7f1619f4acceb269d37f20b819808c9c Mon Sep 17 00:00:00 2001 From: TheCraws Date: Mon, 17 Jun 2019 23:00:16 +0200 Subject: [PATCH] players.json now only saves the starting values of each player's rating. 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. --- PR Tool/GUI/MainWin.cpp | 36 +++++++++++------------------------- 1 file changed, 11 insertions(+), 25 deletions(-) diff --git a/PR Tool/GUI/MainWin.cpp b/PR Tool/GUI/MainWin.cpp index 936d098..62721b4 100644 --- a/PR Tool/GUI/MainWin.cpp +++ b/PR Tool/GUI/MainWin.cpp @@ -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; @@ -708,25 +708,16 @@ bool MainWin::loadWorld() { std::vector 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; @@ -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;