def positions(inputGame, panel, ignored=0): obj = BrasileiroGame(inputGame) players = obj.getPlayers() gameObj = obj.getGameStruct() panel.figure.clf() graphical = panel.figure.gca() len_gameRounds = obj.getNumberRounds() for player in players: x = list(range(1+ignored,len_gameRounds+1)) y = [] for index in range(0+ignored,len_gameRounds): round = obj.getRound(index+1) count = 0 for item_tuple in round[1]: count = count + 1 if item_tuple.playerCode == player: y.append(count) pass graphical.plot(x,y,'o-',lineWidth=2) #print(player,y,"<----") graphical.set_yticks(list(range(0,len(players)+1))) graphical.set_ylabel("Position") graphical.set_xlabel("Round") graphical.invert_yaxis() panel.draw()
def points(inputGame, panel, ignored=0): obj = BrasileiroGame(inputGame) players = obj.getPlayers() gameObj = obj.getGameStruct() panel.figure.clf() graphical = panel.figure.gca() len_gameRounds = obj.getNumberRounds() for player in players: x = list(range(1+ignored,len_gameRounds+1)) y = [] for index in range(0+ignored,len_gameRounds): round = obj.getRound(index+1) for item_tuple in round[1]: if item_tuple.playerCode == player: y.append(item_tuple.totalScore) pass graphical.plot(x,y,'o-',lineWidth=2) #print(player,y,"<----") graphical.set_ylabel('Points') graphical.set_xlabel('Round') panel.draw()
''' from GameQualityAssessment.code_pac.brasileiro.model.game import Game from GameQualityAssessment.code_pac.model import BrasileiroGame import matplotlib.pyplot as plt import numpy as np from openpyxl import Workbook from GameQualityAssessment.project_path import make_absolute_path as abspath from GameQualityAssessment.code_pac.measures import DramaByPaths, DramaByPositionUp2First, DramaByPointsUp2First if __name__ == '__main__': wb = Workbook() planilha = wb.active planilha.append(['ano','Drama by Path', 'Drama by Points', 'Drama by position']) games = Game.retrieveList() for game in games: genGame = BrasileiroGame(game) dramaPath = DramaByPaths(game=genGame, ignored=0).getMeasureValue() dramaPoints = DramaByPointsUp2First(game=genGame, ignored=0, normScores=True).getMeasureValue() dramaPosition = DramaByPositionUp2First(game=genGame, ignored=0).getMeasureValue() planilha.append([game.year, dramaPath, dramaPoints, dramaPosition]) winner = genGame.getWinner() nPlayers = len(genGame.getPlayers()) nRounds = genGame.getNumberRounds() winnerPath = [] for i in range(1, nRounds + 1): gameRound = genGame.getRound(i)[1] for r in gameRound: if r.playerCode == winner:
if __name__ == '__main__': #anos = xrange(2003, 2015) f = open(abspath('code_pac/brasileiro/tabela_resultados_full.csv'), 'w') #f2 = open('tabela_resultados.csv', 'w') arq = UnicodeWriter(f) arq_r = UnicodeWriter(f) fString = '{0:.4f}' valuesW = [[ 'Edition', 'Drama by Points', 'Drama by Position', 'Drama by Path' ]] valuesC = [] games = Game.retrieveList() for game in games: genGame = BrasileiroGame(game) dramaPath = DramaByPaths(game=genGame, ignored=0).getMeasureValue() dramaPoints = DramaByPointsUp2First(game=genGame, ignored=0, normScores=True).getMeasureValue() dramaPosition = DramaByPositionUp2First(game=genGame, ignored=0).getMeasureValue() valuesW.append([ game.year, fString.format(dramaPoints), fString.format(dramaPosition), fString.format(dramaPath) ]) valuesC.append([dramaPoints, dramaPosition, dramaPath])
def __setData(self, event): selected = self.gameExplorer.GetSelection() games = None if selected.IsOk(): games = self.gameExplorer.GetItemData(selected) if games == None: games = self.gamesList else: games = [games] else: games = self.gamesList dramas = [] uncerts = [] leadChgs = [] for game in games: brgame = BrasileiroGame(game) dramas.append(Drama(game=brgame, ignored=0).getMeasureValue()) uncerts.append( Uncertainty(game=brgame, ignored=0).getMeasureValue()) leadChgs.append( LeadChange(game=brgame, ignored=0).getMeasureValue()) self.dataGrid.SetCellValue(0, 0, str(sum(dramas) / len(dramas))) self.dataGrid.SetCellValue(1, 0, str(sum(uncerts) / len(uncerts))) self.dataGrid.SetCellValue(2, 0, str(sum(leadChgs) / len(leadChgs))) # avg(avg_drama,avg_uncert,avg_leadChg) # avg(sum_drama/num_games,sum_uncert/num_games,sum_leadChg/num_games) # avg(sum_drama,sum_uncert,sum_leadChg)/num_games # (sum_drama+sum_uncert+sum_leadChg)/3/num_games # (sum_drama+sum_uncert+sum_leadChg)/3*num_games self.dataGrid.SetCellValue( 3, 0, str((sum(dramas) + sum(uncerts) + sum(leadChgs)) / (3 * len(dramas)))) for i in range(0, self.graphShow.GetPageCount()): page = self.graphShow.GetPage(0) self.graphShow.RemovePage(0) self.graphShow.RemoveChild(page) page.Destroy() if len(dramas) > 1: overall_evals = [(dramas[i] + uncerts[i] + leadChgs[i]) / 3 for i in range(0, len(dramas))] panel_drama = PanelPlot(self.graphShow) panel_uncert = PanelPlot(self.graphShow) panel_leadChg = PanelPlot(self.graphShow) panel_evals = PanelPlot(self.graphShow) bp.values_histogram(dramas, panel_drama, 'Drama') bp.values_histogram(uncerts, panel_uncert, 'Uncertainty') bp.values_histogram(leadChgs, panel_leadChg, 'Lead Change') bp.values_histogram(overall_evals, panel_evals, 'Overall Eval.') self.graphShow.AddPage(panel_drama, "Histogram - Drama") self.graphShow.AddPage(panel_uncert, "Histogram - Uncertainty") self.graphShow.AddPage(panel_leadChg, "Histogram - Lead Change") self.graphShow.AddPage(panel_evals, "Histogram - Overall Eval.") panel_drama.draw() panel_drama.set_size() panel_uncert.draw() panel_uncert.set_size() panel_leadChg.draw() panel_leadChg.set_size() panel_evals.draw() panel_evals.set_size() else: panel_points = PanelPlot(self.graphShow) panel_positions = PanelPlot(self.graphShow) bp.points(games[0], panel_points) bp.positions(games[0], panel_positions) self.graphShow.AddPage(panel_points, "History by Points") self.graphShow.AddPage(panel_positions, "History by Positions") panel_points.draw() panel_points.set_size() panel_positions.draw() panel_positions.set_size() pass