diff --git a/pysollib/app.py b/pysollib/app.py index 9a794c9108..2f45d8a0c1 100644 --- a/pysollib/app.py +++ b/pysollib/app.py @@ -29,6 +29,7 @@ import traceback from pickle import UnpicklingError +from pysollib.app_stat_result import GameStatResult from pysollib.gamedb import GAME_DB, GI, loadGame from pysollib.images import Images, SubsampledImages from pysollib.mfxutil import Struct, destruct @@ -54,7 +55,7 @@ from pysollib.resource import Tile, TileManager from pysollib.settings import DEBUG from pysollib.settings import PACKAGE, VERSION_TUPLE, WIN_SYSTEM -from pysollib.settings import TOOLKIT, TOP_SIZE +from pysollib.settings import TOOLKIT from pysollib.util import CARDSET, IMAGE_EXTENSIONS from pysollib.winsystems import TkSettings if TOOLKIT == 'tk': @@ -71,49 +72,7 @@ # ************************************************************************ # * Statistics # ************************************************************************ - - -class _GameStatResult: - def __init__(self): - self.min = 0 - self.max = 0 - self.top = [] - self.num = 0 - self.total = 0 # sum of all values - self.average = 0 - - def update(self, gameid, value, game_number, game_start_time): - # update min & max - if not self.min or value < self.min: - self.min = value - if not self.max or value > self.max: - self.max = value - # calculate position & update top - position = None - n = 0 - for i in self.top: - if value < i.value: - position = n+1 - v = Struct(gameid=gameid, - value=value, - game_number=game_number, - game_start_time=game_start_time) - self.top.insert(n, v) - del self.top[TOP_SIZE:] - break - n += 1 - if not position and len(self.top) < TOP_SIZE: - v = Struct(gameid=gameid, - value=value, - game_number=game_number, - game_start_time=game_start_time) - self.top.append(v) - position = len(self.top) - # update average - self.total += value - self.num += 1 - self.average = float(self.total)/self.num - return position +_GameStatResult = GameStatResult class GameStat: @@ -126,11 +85,11 @@ def __init__(self, id): self.num_won = 0 self.num_perfect = 0 # - self.time_result = _GameStatResult() - self.moves_result = _GameStatResult() - self.total_moves_result = _GameStatResult() - self.score_result = _GameStatResult() - self.score_casino_result = _GameStatResult() + self.time_result = GameStatResult() + self.moves_result = GameStatResult() + self.total_moves_result = GameStatResult() + self.score_result = GameStatResult() + self.score_casino_result = GameStatResult() def update(self, game, status): # diff --git a/pysollib/app_stat_result.py b/pysollib/app_stat_result.py new file mode 100644 index 0000000000..5fe476f163 --- /dev/null +++ b/pysollib/app_stat_result.py @@ -0,0 +1,62 @@ +# Copyright (C) 1998-2003 Markus Franz Xaver Johannes Oberhumer +# Copyright (C) 2003 Mt. Hood Playing Card Co. +# Copyright (C) 2005-2009 Skomoroh +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +from pysollib.mfxutil import Struct +from pysollib.settings import TOP_SIZE + + +class GameStatResult: + def __init__(self): + self.min = 0 + self.max = 0 + self.top = [] + self.num = 0 + self.total = 0 # sum of all values + self.average = 0 + + def update(self, gameid, value, game_number, game_start_time): + # update min & max + if not self.min or value < self.min: + self.min = value + if not self.max or value > self.max: + self.max = value + # calculate position & update top + position = None + n = 0 + for i in self.top: + if value < i.value: + position = n+1 + v = Struct(gameid=gameid, + value=value, + game_number=game_number, + game_start_time=game_start_time) + self.top.insert(n, v) + del self.top[TOP_SIZE:] + break + n += 1 + if not position and len(self.top) < TOP_SIZE: + v = Struct(gameid=gameid, + value=value, + game_number=game_number, + game_start_time=game_start_time) + self.top.append(v) + position = len(self.top) + # update average + self.total += value + self.num += 1 + self.average = float(self.total)/self.num + return position diff --git a/scripts/gen_individual_importing_tests.py b/scripts/gen_individual_importing_tests.py index 7706703a9f..20d467c469 100644 --- a/scripts/gen_individual_importing_tests.py +++ b/scripts/gen_individual_importing_tests.py @@ -14,6 +14,7 @@ 'pysollib.acard', 'pysollib.actions', 'pysollib.app', + 'pysollib.app_stat_result', 'pysollib.configobj.configobj', 'pysollib.configobj.validate', 'pysollib.customgame',