def initData(self): # cmbRegion bd = Bbdd() data = bd.select("region", "name") self.regionIndexToId = {} index = 0 for i in data: id = i[0] name = i[1] self.cmbRegion.addItem(name) self.regionIndexToId[index] = id index += 1 # cmbSport bd = Bbdd() data = bd.select("sport", "name") self.sportIndexToId = {} index = 0 for i in data: id = i[0] name = i[1] self.cmbSport.addItem(name) self.sportIndexToId[index] = id index += 1 bd.close()
def initTree(self): bd = Bbdd() data = bd.select("tipster_month", "year, month") items = [] for i in data: id = i[0] year = i[2] month = numberToMonth(i[1]+1) tipster = bd.getValue(i[3], "tipster") money = i[4] item = QTreeWidgetItem([str(id), str(year), str(month), str(tipster), str(money)]) items.append(item) self.treeMain.addTopLevelItems(items) data = bd.select("conjunta", "year, month") if len(data) < 1: self.lblConjunta.setVisible(False) self.treeConjunta.setVisible(False) else: items = [] for i in data: id = i[0] year = i[3] month = numberToMonth(i[2] + 1) name = i[1] money = i[4] item = QTreeWidgetItem([str(id), str(year), str(month), str(name), str(money)]) items.append(item) self.treeConjunta.addTopLevelItems(items) bd.close()
def initData(self): bd = Bbdd() data = bd.select("tipster_month", None, "id=" + str(self.id))[0] dataCmb = bd.select("tipster", "name") self.tipsterIndexToId = {} index, idCmb = 0, 0 idBd = data[3] for i in dataCmb: id = i[0] if id == idBd: idCmb = index name = i[1] self.cmbTipster.addItem(name) self.tipsterIndexToId[index] = id index += 1 self.cmbTipster.setCurrentIndex(idCmb) self.txtYear.setValue(data[2]) self.cmbMonth.setCurrentIndex(data[1]) self.txtMoney.setValue(data[4]) bd.close()
def initData(self): bd = Bbdd() where = "id=" + str(self.id) # date dataBonus = bd.select("bonus", None, where)[0] date = QDate.fromString(dataBonus[1], "yyyy-MM-dd") self.txtDate.setDate(date) # cmbBookie data = bd.select("bookie", "name") self.bookieIndexToId = {} index, idCmb = 0, 0 for i in data: id = i[0] if dataBonus[2] == id: idCmb = index name = i[1] self.cmbBookie.addItem(name) self.bookieIndexToId[index] = id index += 1 self.cmbBookie.setCurrentIndex(idCmb) self.txtMoney.setValue(dataBonus[3]) self.chkFree.setChecked(str_to_bool(dataBonus[4])) bd.close()
def setRegion(self): self.btnAccept.setDisabled(False) self.cmbRegion.clear() bd = Bbdd() idSport = self.sportIndexToId.get(self.cmbSport.currentIndex()) where = " sport=" + str(idSport) data = bd.select("competition", None, where, "region") dataRegion = "" if len(data) > 0: sData = "(" j = 0 for i in data: if j == len(data) - 1: sData += str(i[0]) + ")" else: sData += str(i[0]) + ", " j += 1 where = " id in " + sData dataRegion = bd.select("region", "name", where) if len(dataRegion) < 1: self.btnAccept.setDisabled(True) bd.close() else: self.regionIndexToId = {} index, idCmb = 0, 0 idBd = bd.getValue(self.id, "bet", "region") for i in dataRegion: id = i[0] if id == idBd: idCmb = index name = i[1] self.cmbRegion.addItem(name) self.regionIndexToId[index] = id index += 1 self.cmbRegion.setCurrentIndex(idCmb) bd.close() self.setCompetition() else: self.btnAccept.setDisabled(True) bd.close() if len(data) == 0 or len(dataRegion) == 0: self.btnAccept.setDisabled(True) else: self.btnAccept.setDisabled(False)
def setRegionComb(self, index_cmb): print(index_cmb) self.btnAccept.setDisabled(False) self.regions[index_cmb].clear() bd = Bbdd() idSport = self.sportIndexToId.get( self.sports[index_cmb].currentIndex()) where = " sport=" + str(idSport) data = bd.select("competition", None, where, "region") dataRegion = "" if len(data) > 0: sData = "(" j = 0 for i in data: if j == len(data) - 1: sData += str(i[0]) + ")" else: sData += str(i[0]) + ", " j += 1 where = " id in " + sData dataRegion = bd.select("region", "name", where) if len(dataRegion) < 1: self.btnAccept.setDisabled(True) bd.close() else: self.regionIndexToIdCmb[index_cmb] = {} index = 0 for i in dataRegion: id = i[0] name = i[1] self.regions[index_cmb].addItem(name) self.regionIndexToIdCmb[index_cmb][index] = id index += 1 bd.close() self.setCompetitionComb(index_cmb) else: self.btnAccept.setDisabled(True) bd.close() if len(data) == 0 or len(dataRegion): self.btnAccept.setDisabled(True) else: self.btnAccept.setDisabled(False)
def initCombined(self): bd = Bbdd() data = bd.select("combined", None, "bet=" + str(self.id)) i = 0 for bet in data: self.addCombined() date = QDateTime.fromString(bet[2], "yyyy-MM-dd hh:mm:ss") self.dates[i].setDateTime(date) sport = key_from_value(self.sportIndexToId, bet[3]) self.sports[i].setCurrentIndex(sport) self.setRegionComb(i) region = key_from_value(self.regionIndexToIdCmb[i], bet[5]) self.regions[i].setCurrentIndex(region) self.setCompetitionComb(i) competition = key_from_value(self.competitionIndexToIdCmb[i], bet[4]) self.competitions[i].setCurrentIndex(competition) self.players1[i].setCurrentText(bet[6]) self.players2[i].setCurrentText(bet[7]) self.picks[i].setText(bet[8]) result = { "Pendiente": 0, "Acertada": 1, "Fallada": 2, "Nula": 3, "Medio Acertada": 4, "Medio Fallada": 5, "Retirada": 6 }[bet[9]] self.results[i].setCurrentIndex(result) i += 1 bd.close()
def accept(self): money = str(self.txtMoney.text()) data = [ self.cmbMonth.currentIndex(), self.txtYear.text(), self.txtName.text(), money ] columns = ["month", "year", "name", "money"] bbdd = Bbdd() bbdd.insert(columns, data, "conjunta") id = bbdd.select("conjunta", None, None, "max(id)")[0][0] for i in self.selected: if i in (0, 1): continue bbdd.insert(["conjunta", "tipster"], [id, i], "conjunta_tipster") bbdd.close() QMessageBox.information(self, _("Added"), _("New joint purchase added.")) self.close()
def initData(self): bd = Bbdd() data = bd.select("tipster", "name") self.listFree.clear() self.listSelected.clear() self.tipsterIndexToId = {} self.selectedIndexToId = {} index, index2 = 0, 0 for i in data: id = i[0] if id == 1: continue name = i[1] if id in self.selected: self.listSelected.addItem(name) self.selectedIndexToId[index2] = id index2 += 1 else: self.listFree.addItem(name) self.tipsterIndexToId[index] = id index += 1 bd.close()
def export(self): bd = Bbdd() file = OrderedDict() data = bd.select("bet") dataOds = [[ "Fecha", "Deporte", "Competicion", "Región", "Local", "Visitante", "Pick", "Casa", "Mercado", "Tipster", "Stake", "Unidad", "Resultado", "Beneficio", "Apuesta", "Cuota", "Gratuita" ]] for i in data: row = [] row.append(i[1]) row.append(bd.getValue(i[2], "sport")) row.append(bd.getValue(i[3], "competition")) row.append(bd.getValue(i[4], "region")) row.append(i[5]) row.append(i[6]) row.append(i[7]) row.append(bd.getValue(i[8], "bookie")) row.append(bd.getValue(i[9], "market")) row.append(bd.getValue(i[10], "tipster")) row.append(i[11]) row.append(i[12]) row.append(i[13]) row.append(i[14]) row.append(i[15]) row.append(i[16]) row.append("No" if i[17] == 0 else "Sí") dataOds.append(row) bd.close() file.update({"Apuestas": dataOds}) save_data(self.directory, file)
def setCompetition(self): self.cmbCompetition.clear() bd = Bbdd() idRegion = self.regionIndexToId.get(self.cmbRegion.currentIndex()) idSport = self.sportIndexToId.get(self.cmbSport.currentIndex()) where = "region=" + str(idRegion) + " AND sport=" + str(idSport) data = bd.select("competition", "name", where) self.competitionIndexToId = {} index = 0 for i in data: id = i[0] name = i[1] self.cmbCompetition.addItem(name) self.competitionIndexToId[index] = id index += 1 if index == 0: self.btnAccept.setDisabled(True) else: self.btnAccept.setDisabled(False) bd.close()
def initCombined(self): bd = Bbdd() data = bd.select("combined", None, "bet=" + str(self.id)) i = 0 for bet in data: self.addCombined() date = QDateTime.fromString(bet[2], "yyyy-MM-dd hh:mm:ss") self.dates[i].setDateTime(date) try: sport = key_from_value(self.sportIndexToId, bet[3]) self.sports[i].setCurrentIndex(sport) self.setRegionComb(i) region = key_from_value(self.regionIndexToIdCmb[i], bet[5]) self.regions[i].setCurrentIndex(region) self.setCompetitionComb(i) competition = key_from_value(self.competitionIndexToIdCmb[i], bet[4]) self.competitions[i].setCurrentIndex(competition) except: print("No data combined") self.players1[i].setCurrentText(bet[6]) self.players2[i].setCurrentText(bet[7]) self.picks[i].setText(bet[8]) self.results[i].setCurrentIndex(int(bet[9])) i += 1 bd.close()
def setCompetitionComb(self, index_cmb): self.competitions[index_cmb].clear() bd = Bbdd() idRegion = self.regionIndexToIdCmb[index_cmb].get( self.regions[index_cmb].currentIndex()) idSport = self.sportIndexToId.get( self.sports[index_cmb].currentIndex()) where = "region=" + str(idRegion) + " AND sport=" + str(idSport) try: data = bd.select("competition", "name", where) index = 0 self.competitionIndexToIdCmb[index_cmb] = {} for i in data: id = i[0] name = i[1] self.competitions[index_cmb].addItem(name) self.competitionIndexToIdCmb[index_cmb][index] = id index += 1 if index == 0: self.btnAccept.setDisabled(True) else: self.btnAccept.setDisabled(False) except: self.btnAccept.setDisabled(True) bd.close()
def initTree(self): year = self.cmbYear.currentText() month = self.cmbMonth.currentText() month = monthToNumber(month) self.treeMain.clear() bd = Bbdd() data = bd.select("bet", "date DESC", "date LIKE '" + year + "-" + month + "%'") index = 0 items = [] for i in data: index += 1 id = i[0] date = i[1][:-3] competition = bd.getValue(i[3], "competition") region = bd.getValue(i[4], "region") player1 = i[5] player2 = i[6] pick = i[7] #bookie = bd.getValue(i[8], "bookie") market = bd.getValue(i[9], "market") # TODO Preload in dictionary tipster = bd.getValue(i[10], "tipster") # TODO Preload in dictionary stake = i[11] one = i[12] result = numberToResult(i[13]) profit = i[14] bet = i[15] quota = i[16] item = QTreeWidgetItem([str(index), str(id), str(date), "", str(competition), str(region), player1, player2, pick, "", market, tipster, str(stake), str(one) + self.coin, str(bet) + self.coin, str(quota), str(result), str(profit) + self.coin]) item = paint_row(item, profit, i[13]) if os.path.isfile(expanduser("~") + "/.betcon/resources/sports/" + str(i[2]) + ".png"): item.setBackground(3, QBrush(QPixmap(expanduser("~") + "/.betcon/resources/sports/" + str(i[2]) + ".png"))) else: if os.path.isfile(directory + "/../resources/sports/" + str(i[2]) + ".png"): item.setBackground(3, QBrush(QPixmap(directory + "/../resources/sports/" + str(i[2]) + ".png"))) else: sport = bd.getValue(i[2], "sport") item.setText(3, sport) if os.path.isfile(expanduser("~") + "/.betcon/resources/bookies/" + str(i[8]) + ".png"): item.setBackground(9, QBrush(QPixmap(expanduser("~") + "/.betcon/resources/bookies/" + str(i[8]) + ".png"))) else: if os.path.isfile(directory + "/../resources/bookies/" + str(i[8]) + ".png"): item.setBackground(9, QBrush(QPixmap(directory + "/../resources/bookies/" + str(i[8]) + ".png"))) else: bookie = bd.getValue(i[8], "bookie") item.setText(9, bookie) items.append(item) self.treeMain.addTopLevelItems(items) bd.close()
def initTree(self): self.treeBookie.clear() data = Bookie.selectAll() items = [] for i in data: bank = Bookie.sumAll("bookie=" + str(i.id)) bank = 0.0 if bank is None else bank bonus = Bookie.sumBonus("bookie=" + str(i.id)) bonus = 0.0 if bonus is None else bonus bank += bonus if 0.01 > bank > -0.01: continue item = QTreeWidgetItem( [i.name, "{0:.2f}".format(bank) + self.coin]) items.append(item) self.treeBookie.addTopLevelItems(items) self.treeMovement.clear() bd = Bbdd() data = bd.select("movement", "date DESC") items = [] for i in data: id = i[0] try: sDate = datetime.strptime(i[1], "%d/%m/%y") except: sDate = datetime.strptime(i[1], "%d/%m/%Y") # Fix for Windows sDate = date.strftime(sDate, "%Y/%m/%d") account = i[2] if account == 1: account = "Banco" elif account == 2: account = "Paypal" elif account == 3: account = "Skrill" bookie = bd.getValue(i[3], "bookie") money = i[4] if money < 0: type = _("Withdrawal to the bank.") else: type = _("Deposit at bookie") item = QTreeWidgetItem([ str(sDate), str(id), bookie, type, str(account), str(money) + self.coin ]) items.append(item) self.treeMovement.addTopLevelItems(items) bd.close()
def initData(self): bd = Bbdd() data = bd.select("conjunta", None, "id=" + str(self.id))[0] self.txtName.setText(data[1]) self.txtYear.setValue(data[3]) self.cmbMonth.setCurrentIndex(data[2]) self.txtMoney.setValue(data[4]) data = bd.select("conjunta_tipster", None, "conjunta=" + str(self.id), "tipster") for i in data: self.selected.append(i[0]) bd.close() self.updateData()
def setId(self, id): self.id = id bd = Bbdd() self.name, self.country = bd.select("bookie", None, "id=" + str(self.id), "name, country")[0] bd.close()
def initTree(self): bd = Bbdd() money = {} data = bd.select("conjunta") for i in data: data2 = bd.select("conjunta_tipster", None, "conjunta=" + str(i[0])) if len(data2) > 1: money_tipster = i[4] / len(data2) for j in data2: try: money[j[1]] += money_tipster except: money[j[1]] = money_tipster data = bd.select("tipster", "name") items = [] for i in data: id = i[0] name = i[1] cost = bd.sum("tipster_month", "money", "tipster=" + str(id)) if id in money.keys(): cost += money[id] profit = bd.sum("bet", "profit", "tipster=" + str(id)) balance = profit - cost if cost == 0: cost = "--" + self.coin else: cost = "{0:.2f}".format(cost) + self.coin profit = "{0:.2f}".format(profit) + self.coin balance = "{0:.2f}".format(balance) + self.coin item = QTreeWidgetItem([name, str(id), cost, profit, balance]) item = paint_row(item, balance) items.append(item) self.treeMain.addTopLevelItems(items) bd.close()
def initData(self): bd = Bbdd() # txtName name = bd.getValue(self.id, "competition") self.txtName.setText(name) # cmbRegion data = bd.select("region", "name") self.regionIndexToId = {} index, idCmb = 0, 0 idBd = bd.getValue(self.id, "competition", "region") for i in data: id = i[0] if id == idBd: idCmb = index name = i[1] self.cmbRegion.addItem(name) self.regionIndexToId[index] = id index += 1 self.cmbRegion.setCurrentIndex(idCmb) # cmbSport bd = Bbdd() data = bd.select("sport", "name") self.sportIndexToId = {} index, idCmb = 0, 0 idBd = bd.getValue(self.id, "competition", "sport") for i in data: id = i[0] if id == idBd: idCmb = index name = i[1] self.cmbSport.addItem(name) self.sportIndexToId[index] = id index += 1 self.cmbSport.setCurrentIndex(idCmb) bd.close()
def initData(self): self.txtDeposit.setText("{0:.2f}".format(Bookie.sumAll("money>0")) + self.coin) self.txtTakeOut.setText("{0:.2f}".format(Bookie.sumAll("money<0")) + self.coin) bookies = Bookie.sumAll() bonus = Bookie.sumBonus() self.txtBonus.setText("{0:.2f}".format(bonus) + self.coin) self.txtBookie.setText("{0:.2f}".format(bookies + bonus) + self.coin) bd = Bbdd() tipsters = bd.sum("tipster_month", "money") conjuntas = bd.sum("conjunta", "money") self.txtTipster.setText("-" + str(tipsters + conjuntas) + self.coin) profits = bd.sum("bet", "profit") + bonus self.txtProfit.setText("{0:.2f}".format(profits - tipsters - conjuntas) + self.coin) bets = bd.sum("bet", "bet") try: yields = "{0:.2f}%".format((profits / bets) * 100) except ZeroDivisionError: yields = "0.0%" self.txtYield.setText(yields) # CC cc = bd.select("bank", None, "id=1", "bank") cc = cc[0][0] self.txtCc.setText("{0:.2f}".format(cc) + self.coin) # Paypal paypal = bd.select("bank", None, "id=2", "bank") paypal = paypal[0][0] self.txtPaypal.setText("{0:.2f}".format(paypal) + self.coin) # SKRILL skrill = bd.select("bank", None, "id=3", "bank") skrill = skrill[0][0] self.txtSkrill.setText("{0:.2f}".format(skrill) + self.coin) total = "{0:.2f}".format(cc + paypal + skrill + bonus + bookies) self.txtTotal.setText(total + self.coin)
def calcBank(self): bd = Bbdd() bookies = Bookie.sumAll() bonus = Bookie.sumBonus() # CC cc = bd.select("bank", None, "id=1", "bank") cc = cc[0][0] # Paypal paypal = bd.select("bank", None, "id=2", "bank") paypal = paypal[0][0] # SKRILL skrill = bd.select("bank", None, "id=3", "bank") skrill = skrill[0][0] total = "{0:.2f}".format(cc + paypal + skrill + bonus + bookies) total = float(total) * (self.txtPercentage.value() * 0.01) self.txtStake.setValue(float(total))
def selectAll(): bd = Bbdd() data = bd.select("bookie", "name") items = [] for i in data: item = Bookie() item.setId(i[0]) items.append(item) bd.close() return items
def initData(self): bd = Bbdd() data = bd.select("tipster", "name") self.tipsterIndexToId = {} index = 0 for i in data: id = i[0] name = i[1] self.cmbTipster.addItem(name) self.tipsterIndexToId[index] = id index += 1 bd.close()
def initTree(self): bd = Bbdd() money = {} data = bd.select("conjunta") for i in data: data2 = bd.select("conjunta_tipster", None, "conjunta=" + str(i[0])) if len(data2) > 1: money_tipster = i[4] / len(data2) for j in data2: try: money[j[1]] += money_tipster except: money[j[1]] = money_tipster data = bd.select("tipster", "name") index = 0 items = [] for i in data: index += 1 id = i[0] name = i[1] cost = bd.sum("tipster_month", "money", "tipster=" + str(id)) if id in money.keys(): cost += money[id] cost = "{0:.2f}".format(cost) profit = bd.sum("bet", "profit", "tipster=" + str(id)) profit = "{0:.2f}".format(profit) item = QTreeWidgetItem([str(index), str(id), name, cost, profit]) items.append(item) self.treeMain.addTopLevelItems(items) bd.close()
def calcStake(self): self.config = LibYaml() if self.config.stake["type"] == 0: bd = Bbdd() bookies = Bookie.sumAll() bonus = Bookie.sumBonus() # CC cc = bd.select("bank", None, "id=1", "bank") cc = cc[0][0] # Paypal paypal = bd.select("bank", None, "id=2", "bank") paypal = paypal[0][0] # SKRILL skrill = bd.select("bank", None, "id=3", "bank") skrill = skrill[0][0] total = "{0:.2f}".format(cc + paypal + skrill + bonus + bookies) total = float(total) * (self.config.stake["percentage"] * 0.01) self.txtOne.setValue(float(total)) else: self.txtOne.setValue(self.config.stake["stake"])
def initTree(self): bd = Bbdd() data = bd.select("market", "name") items = [] for i in data: id = i[0] name = i[1] item = QTreeWidgetItem([name, str(id)]) items.append(item) self.treeMain.addTopLevelItems(items) self.treeMain.sortByColumn(0, QtCore.Qt.AscendingOrder) bd.close()
def initTree(self): bd = Bbdd() data = bd.select("market", "name") index = 0 items = [] for i in data: index += 1 id = i[0] name = i[1] item = QTreeWidgetItem([str(index), str(id), name]) items.append(item) self.treeMain.addTopLevelItems(items) bd.close()
def initTree(self): bd = Bbdd() data = bd.select("sport", "name") items = [] for i in data: id = i[0] name = i[1] competitions = bd.count("competition", "sport=" + str(id)) item = QTreeWidgetItem([name, str(id), str(competitions)]) items.append(item) self.treeMain.addTopLevelItems(items) self.treeMain.sortByColumn(0, QtCore.Qt.AscendingOrder) bd.close()
def initTree(self): bd = Bbdd() data = bd.select("bonus", "date") items = [] for i in data: id = i[0] date = i[1] bookie = bd.getValue(i[2], "bookie") money = i[3] free = _("Yes") if str_to_bool(i[4]) else _("No") item = QTreeWidgetItem([str(date), str(id), str(bookie), str(money) + self.coin, str(free)]) items.append(item) self.treeMain.addTopLevelItems(items) bd.close()
def initTree(self): bd = Bbdd() data = bd.select("competition", "name") items = [] for i in data: id = i[0] name = i[1] region = bd.getValue(i[2], "region") sport = bd.getValue(i[3], "sport") item = QTreeWidgetItem([str(name), str(id), region, str(sport)]) items.append(item) self.treeMain.addTopLevelItems(items) self.treeMain.sortByColumn(0, QtCore.Qt.AscendingOrder) bd.close()