Beispiel #1
0
def dramaAnalizerLocal(game):
    conn = dataBaseAdapter.getConnection()
    game_aux = DesafioGame(game)

    #valPoints = DramaByPointsUp2First(game=game_aux, ignored=1).getMeasureValue()
    #valPosition = DramaByPositionUp2First(game=game_aux, ignored=1).setIgnored(1).getMeasureValue()
    #valPath = DramaByPaths(game=game_aux, ignored=1).getMeasureValue()
    valLeadChange = LeadChange(game=game_aux, ignored=1).getMeasureValue()
    #game.storeMeasure(DramaByPointsUp2First(game=game_aux, ignored=1), conn)
    #game.storeMeasure(DramaByPositionUp2First(game=game_aux, ignored=1),conn)
    #game.storeMeasure(DramaByPaths(game=game_aux, ignored=1),conn)
    game.storeMeasure(LeadChange(game=game_aux, ignored=1), conn)
    dataBaseAdapter.closeConnection(conn)
    with counter.get_lock():
        counter.value += 1
    return valLeadChange  #(game, valPoints, valPosition, valPath)
Beispiel #2
0
def calculaMudancasLideranca(game):
    obj = model.DiceGame(game)
    value = LeadChange(game=obj, ignored=0)
    return value.getMeasureValue()  
Beispiel #3
0
    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:
            plgame = PremierLeagueGame(game)
            dramas.append(Drama(game=plgame, ignored=0).getMeasureValue())
            uncerts.append(
                Uncertainty(game=plgame, ignored=0).getMeasureValue())
            leadChgs.append(
                LeadChange(game=plgame, 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)
            plp.values_histogram(dramas, panel_drama, 'Drama')
            plp.values_histogram(uncerts, panel_uncert, 'Uncertainty')
            plp.values_histogram(leadChgs, panel_leadChg, 'Lead Change')
            plp.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)
            plp.points(games[0], panel_points)
            plp.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
if __name__ == '__main__':
    games = Game.retrieveList()
    ano = '2003'
    game = None
    for g in games:
        if g.year == ano:
            game = g
            break

    genGame = BrasileiroGame(game)
    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:
                winnerPath.append(gameRound.index(r) + 1)
                break
    dramaPath = DramaByPaths(game=genGame, ignored=0).getMeasureValue()
    dramaPoints = DramaByPointsUp2First(game=genGame,
                                        ignored=0,
                                        normScores=True).getMeasureValue()
    dramaPosition = DramaByPositionUp2First(game=genGame,
                                            ignored=0).getMeasureValue()
    leadChange = LeadChange(game=genGame, ignored=0).getMeasureValue()
    dValues = (dramaPath, dramaPoints, dramaPosition, leadChange)

    plotPath(nPlayers, nRounds, ano, winnerPath, dValues)
    plt.show()