1# Copyright (C) 1998-2003 Markus Franz Xaver Johannes Oberhumer 2# Copyright (C) 2003 Mt. Hood Playing Card Co. 3# Copyright (C) 2005-2009 Skomoroh 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 3 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, see <http://www.gnu.org/licenses/>. 17 18 19from pysollib.app_stat_result import GameStatResult 20 21 22class GameStat: 23 def __init__(self, id): 24 self.gameid = id 25 # 26 self.num_total = 0 27 # self.num_not_won = 0 28 self.num_lost = 0 29 self.num_won = 0 30 self.num_perfect = 0 31 # 32 self.time_result = GameStatResult() 33 self.moves_result = GameStatResult() 34 self.total_moves_result = GameStatResult() 35 self.score_result = GameStatResult() 36 self.score_casino_result = GameStatResult() 37 38 def update(self, game, status): 39 # 40 game_number = game.getGameNumber(format=0) 41 game_start_time = game.gstats.start_time 42 # update number of games 43 # status: 44 # -1 - NOT WON (not played) 45 # 0 - LOST 46 # 1 - WON 47 # 2 - PERFECT 48 self.num_total += 1 49 assert status in (0, 1, 2) 50 if status == 0: 51 self.num_lost += 1 52 return 53 elif status == 1: 54 self.num_won += 1 55 else: # status == 2 56 self.num_perfect += 1 57 58 score = game.getGameScore() 59 # print 'GameScore:', score 60 score_p = None 61 if score is not None: 62 score_p = self.score_result.update( 63 game.id, score, game_number, game_start_time) 64 score = game.getGameScoreCasino() 65 # print 'GameScoreCasino:', score 66 score_casino_p = None 67 if score is not None: 68 score_casino_p = self.score_casino_result.update( 69 game.id, score, game_number, game_start_time) 70 71 if status == 0: 72 return 73 74 game.updateTime() 75 time_p = self.time_result.update( 76 game.id, game.stats.elapsed_time, game_number, game_start_time) 77 moves_p = self.moves_result.update( 78 game.id, game.moves.index, game_number, game_start_time) 79 total_moves_p = self.total_moves_result.update( 80 game.id, game.stats.total_moves, game_number, game_start_time) 81 82 return time_p, moves_p, total_moves_p, score_p, score_casino_p 83