Changeset 197
- Timestamp:
- 02/05/09 17:37:36 (4 years ago)
- Location:
- trunk/src
- Files:
-
- 2 edited
-
statistics.cpp (modified) (5 diffs)
-
statistics.h (modified) (2 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 } -
trunk/src/statistics.h
r193 r197 23 23 24 24 #include "configuration.h" 25 #include <vector> 25 26 namespace statistics { 26 27 … … 52 53 int games_started; 53 54 int games_finished; 55 std::vector<int> score_distribution; 54 56 configuration::Configuration *backend; 55 57 }; 58 59 const int score_distribution_granuality = 50; 60 // anything above the following score will be in the same slot 61 const int score_distribution_max = 500; 62 const int score_distributions_slots = score_distribution_max/score_distribution_granuality+1; 56 63 57 64 } //namespace
Note: See TracChangeset
for help on using the changeset viewer.
