Changeset 197 for trunk/src/statistics.cpp
- Timestamp:
- 05/02/2009 05:37:36 PM (3 years ago)
- File:
-
- 1 edited
-
trunk/src/statistics.cpp (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/statistics.cpp
r193 r197 21 21 #include <string> 22 22 #include <cstdlib> 23 #include <boost/algorithm/string/split.hpp> 24 #include <boost/algorithm/string/classification.hpp> 23 25 #include "statistics.h" 24 26 #include "utility.h" … … 26 28 using namespace std; 27 29 using namespace statistics; 30 using namespace boost; 28 31 29 32 Statistics::Statistics(configuration::Configuration *backend) 30 33 { 31 34 string tmp; 35 vector<string> tmp_vec; 32 36 this->backend = backend; 33 37 … … 37 41 tmp = backend->get("statistics_games_finished"); 38 42 games_finished = atoi(tmp.c_str()); 43 44 tmp = backend->get("statistics_score_distribution"); 45 split(tmp_vec, tmp, is_any_of(",")); 46 if (tmp_vec.size() != score_distributions_slots) { 47 reset(); 48 return; 49 } 50 51 for (vector<string>::iterator iter = tmp_vec.begin(); 52 iter != tmp_vec.end(); iter++) { 53 score_distribution.push_back(atoi(iter->c_str())); 54 } 39 55 40 56 } … … 48 64 void Statistics::game_finished(int score) 49 65 { 66 int score_slot; 50 67 games_finished++; 68 69 score_slot = score/score_distribution_granuality; 70 score_slot = score_slot<score_distributions_slots ? score_slot : score_slot; 71 score_distribution[score_slot]++; 51 72 save(); 52 73 } 53 74 54 75 void Statistics::save() { 76 string tmp; 55 77 backend->set("statistics_games_started", stringify(games_started)); 56 78 backend->set("statistics_games_finished", stringify(games_finished)); 79 80 tmp = ""; 81 for (vector<int>::iterator iter = score_distribution.begin(); 82 iter != score_distribution.end(); iter++) { 83 tmp += stringify(*iter) + ","; 84 } 85 //delete trailing comma 86 tmp = tmp.substr(0, tmp.size()-1); 87 backend->set("statistics_score_distribution", tmp); 57 88 58 89 backend->save(); … … 60 91 61 92 void Statistics::reset() { 62 backend->set("statistics_games_started", 0);63 backend->set("statistics_games_finished", 0);93 games_started = 0; 94 games_finished = 0; 64 95 65 backend->save(); 96 score_distribution = vector<int>(score_distributions_slots, 0); 97 98 save(); 66 99 }
Note: See TracChangeset
for help on using the changeset viewer.
