Debian Codegraph @

src/statistics.h

raw symbols SCIP
1 /***************************************************************************
2 * Copyright (C) 2006-2009 by Guy Rutenberg *
3 * [email protected] *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
20
21 #ifndef OPENYAHTZEE_STATISTICS_INC
22 #define OPENYAHTZEE_STATISTICS_INC
23
24 #include "configuration.h"
25 #include <vector>
26 #include <exception>
27 namespace statistics {
28
29 class Statistics {
30 public:
31 Statistics(configuration::Configuration *backend);
32 /**
33 * Records that a new game has been started.
34 */
35 void game_started();
36
37 /**
38 * Records that a game was ended.
39 * \param score The score the game ended with.
40 */
41 void game_finished(int score);
42
43 /**
44 * Resets the statistics data.
45 */
46 void reset();
47
48 int games_started() { return _games_started; }
49 int games_finished() { return _games_finished; }
50 time_t last_reset() { return _last_reset; }
51 std::vector<int> score_distribution() { return _score_distribution; }
52
53 private:
54 /**
55 * Saves the current status of the statistics object.
56 */
57 void save();
58
59 /**
60 * Loads data from the backend.
61 */
62 void load_data();
63
64 int _games_started;
65 int _games_finished;
66 time_t _last_reset;
67
68 std::vector<int> _score_distribution;
69 configuration::Configuration *backend;
70 };
71
72 class BadConfiguration : public std::exception {
73 virtual const char* what() const throw()
74 {
75 return "Bad Configuration";
76 }
77 };
78
79 const int score_distribution_granuality = 50;
80 // anything above the following score will be in the same slot
81 const int score_distribution_max = 500;
82 const int score_distributions_slots = score_distribution_max/score_distribution_granuality+1;
83
84 } //namespace
85
86 #endif
87