def _gameSetValues(self, game, acItem): seriesItem = self.treeGameExploring.GetItemParent(acItem) tournamentItem = self.treeGameExploring.GetItemParent(seriesItem) self.valTournament.SetLabel( self.treeGameExploring.GetItemText(tournamentItem)) self.valSeries.SetLabel(self.treeGameExploring.GetItemText(seriesItem)) self.valGame.SetLabel(self.treeGameExploring.GetItemText(acItem)) self.valQTYGame.SetLabel("1") #fill measures single game self.lstMeasures.DeleteAllItems() self.txtOverallEvaluation.SetValue('') conn = dataBaseAdapter.getConnection() measures = self.treeGameExploring.GetItemData( acItem).retrieveMeasureList(conn) #fillLst overallValue = 0 index = 0 for m in measures: self.lstMeasures.InsertItem(index, str(m['measurecode'])) self.lstMeasures.SetItem(index, 1, m['measuredescription']) self.lstMeasures.SetItem(index, 2, str(m['measureversion'])) self.lstMeasures.SetItem(index, 3, str(m['measurevalue'])) #byPath-2 uncertainty-3 leadChang-4 if m['measurecode'] == 2 or \ m['measurecode'] == 3 or \ m['measurecode'] == 4: overallValue += m['measurevalue'] index += 1 #self._fillComboGraphType() #overall drama_by_path + uncertainty + lead_change over 3 self.txtOverallEvaluation.SetValue(str(overallValue / 3)) self._fillGraphPanel() dataBaseAdapter.closeConnection(conn)
def _setGameStruct(self): connection = dataBaseAdapter.getConnection() self._players = [] self._gameData = [] gameRounds = sorted(desafio_model.GameRound.retrieveList( self._game, connection), key=lambda gameRound: gameRound.roundOrder) for gameRound in gameRounds: totalScores = sorted(desafio_model.GameRoundResult.retrieveList( gameRound, connection), key=lambda result: result.totalScore, reverse=True) scores = [] for t in totalScores: scores.append( ItemTuple(t.playerCode, t.roundScore, t.totalScore)) if not t.playerCode in self._players: self._players.append(t.playerCode) self._gameData.append((gameRound.roundOrder, scores)) dataBaseAdapter.closeConnection(connection)
def storeUncertainty(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() try: valUncertainty = UncertaintyPDD(game=game_aux, ignored=1, minScore=50).getMeasureValue() except: print('Error:', game.tournamentCode, ' ', game.seriesCode, ' ', game.groupCode) #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(UncertaintyPDD(game=game_aux, ignored=1, minScore=50), conn) dataBaseAdapter.closeConnection(conn) with counter.get_lock(): counter.value += 1 return valUncertainty #(game, valPoints, valPosition, valPath)
#print jogos[:] for jogo in jogos: if not isinstance(jogo, Game): print('error') print(len(jogos)) counter = Value('i', 0) total = Value('i', len(jogos)) p = Process(target=printFollow, args=( counter, total, )) p.start() pool = Pool(processes=3, initargs=(counter, )) r = pool.map(storeUncertainty, (jogos)) drama = sum(r) / total.value print("") print(drama) pool.close() pool.join() dataBaseAdapter.closeConnection(conn) #print " \r", counter.value, " -- ", counter.value / total.value * 100, "%", print("") p.terminate() #print "drama: ", drama," | ", "maior: ", maior.value #gamePlots.GamePlots(desafioGame.DesafioGame(jogos[r.index(max(r))])).byPoints() dataBaseAdapter.closeConnection(conn)
def _fillLstMeasures(self, games): self.lstMeasures.DeleteAllItems() self.txtOverallEvaluation.SetValue('') if not type(games) == list: raise TypeError('First arg has to be a list of games') #get measures #fistMeasure connection = dataBaseAdapter.getConnection() if type(games) == list: measuresControl = self.treeGameExploring.GetItemData( games[0]).retrieveMeasureList(connection) nMeasures = len(measuresControl) # initializing measuresSum measuresValues = {} for m in measuresControl: #measuresValues.append(m['measurecode']) measuresValues[m['measurecode']] = [] #sum values dlg = wx.ProgressDialog("Wait", "Loading Values...", len(games), self) pulseCount = 1 for g in games: if pulseCount % 15 == 0: #dlg.UpdatePulse() dlg.Update(pulseCount) pulseCount += 1 gMeasures = self.treeGameExploring.GetItemData( g).retrieveMeasureList(connection) if not len(gMeasures) == nMeasures: raise Exception('There is an error in measures stored.') for m in gMeasures: measuresValues[m['measurecode']].append(m['measurevalue']) #average measuresAvg = {} for m in measuresControl: #measuresAvg.append(m['measurecode']) measuresAvg[m['measurecode']] = sum( measuresValues[m['measurecode']]) / len(games) #fillLst index = 0 for m in measuresControl: self.lstMeasures.InsertItem(index, str(m['measurecode'])) self.lstMeasures.SetItem(index, 1, m['measuredescription']) self.lstMeasures.SetItem(index, 2, str(m['measureversion'])) self.lstMeasures.SetItem(index, 3, str(measuresAvg[m['measurecode']])) index += 1 #overall drama_by_path + uncertainty + lead_change over 3 overallEvaluation = (measuresAvg[2] + measuresAvg[3] + measuresAvg[4]) / 3 self.txtOverallEvaluation.SetValue(str(overallEvaluation)) dataBaseAdapter.closeConnection(connection) dlg.Destroy() self.treeGameExploring.SetFocus() self.valuesContainer = measuresValues
''' Created on 28/05/2015 @author: mangeli ''' import GameQualityAssessment.code_pac.dataBaseAdapter as db import os,sys sys.path.insert(1, os.path.abspath(os.pardir)) print (sys.path) db.setValues("desafio_simples", "mangeli", "localhost", "agoravai", 5432) conn = db.getConnection() c = db.getCursor(conn) db.cursorExecute(c, "SELECT * FROM tournament;") l = db.fetchAll(c) print (l[:]) for retorno in l : print (retorno["country"]) print (c, conn) db.closeCursor(c) db.closeConnection(conn) print (c, conn)