Esempio n. 1
0
    def start_game(self):
        para = self.merkozesek.currentItem().text().rsplit("\t")
        p1_model = QSqlQueryModel()
        p1_query = QSqlQuery(
            f"select player_id from torna_resztvevok where player_name='{para[2]}'"
        )
        p1_model.setQuery(p1_query)
        p2_model = QSqlQueryModel()
        p2_query = QSqlQuery(
            f"select player_id from torna_resztvevok where player_name='{para[3]}'"
        )
        p2_model.setQuery(p2_query)

        params = []
        params.append(para[2])
        params.append(para[3])
        params.append(int(para[0]))
        self.match_id = int(para[0])
        params.append(int(p1_model.record(0).value(0)))
        params.append(int(p2_model.record(0).value(0)))
        params.append(para[4])
        params.append(int(para[6]))
        params.append(int(para[5]))
        params.append(0)  # hc1
        params.append(0)  # hc2
        params.append(0)  #bets_of...
        self.parent.new_game_window.params = params
        self.parent.new_game_window.refresh()
Esempio n. 2
0
 def load_torna(self):
     torna = QSqlQueryModel()
     query = QSqlQuery("select * from torna_settings where aktiv=2")
     torna.setQuery(query)
     if torna.record(0).value(0):
         for i in range(torna.rowCount()):
             self.tournaments.addItem(
                 torna.record(i).value(1),
                 torna.record(i).value(0))  # a value(0) a torna_id
Esempio n. 3
0
 def load_saved_players(self):
     players = QSqlQueryModel()
     players_query = QSqlQuery("select * from players where aktiv=1")
     players.setQuery(players_query)
     self.saved_players.clear()
     for i in range(players.rowCount()):
         item = QListWidgetItem(players.record(i).value(1))
         item.setData(Qt.UserRole, players.record(i).value(0))
         self.saved_players.addItem(item)
Esempio n. 4
0
 def load_torna_players(self):
     players = QSqlQueryModel()
     players_query = QSqlQuery(
         "select * from torna_resztvevok where 1 group by player_id, player_name"
     )
     players.setQuery(players_query)
     self.torna_players.clear()
     for i in range(players.rowCount()):
         item = QListWidgetItem(players.record(i).value(1))
         item.setData(Qt.UserRole, players.record(i).value(0))
         self.torna_players.addItem(item)
Esempio n. 5
0
 def torna_valasztas(self, i):
     self.torna_id = self.tournaments.itemData(i)
     players = QSqlQueryModel()
     players_query = QSqlQuery(
         f"select * from torna_resztvevok where torna_id={self.torna_id}")
     players.setQuery(players_query)
     self.current_players.clear()
     for i in range(players.rowCount()):
         item = QListWidgetItem(players.record(i).value(1))
         item.setData(Qt.UserRole, players.record(i).value(0))
         self.current_players.addItem(item)
Esempio n. 6
0
    def change_data(self, szum=None):
        self.data = None
        self.data = szum
        self.name1 = self.data[1]
        self.name2 = self.data[3]
        match_id = self.data[6]
        p1_id = self.data[0]
        p2_id = self.data[2]
        # Végeredmény
        self.won1 = 0
        self.won2 = 0
        self.avg1 = self.avg2 = 0
        eredmenyek_model = QSqlQueryModel()
        eredmenyek_query = QSqlQuery(f"select * from matches where match_id={match_id}", db=db)
        eredmenyek_model.setQuery(eredmenyek_query)
        for x in range(1, self.data[8] + 1):
            l1 = l2 = 0
            for i in range(eredmenyek_model.rowCount()):  # csak set-eket összesítünk
                if eredmenyek_model.record(i).value(2) == x:
                    if eredmenyek_model.record(i).value(3) == p1_id:
                        l1 += 1
                    else:
                        l2 += 1
            # print("Set: ", x, "L1: ", l1, "L2: ", l2)
            if self.data[8] == 1:
                self.won1 = l1
                self.won2 = l2
            else:
                if l1 > l2:
                    self.won1 += 1
                else:
                    self.won2 += 1
        # Átlagok
        db1 = db2 = sum1 = sum2 = 0
        for x in range(1, self.data[8] + 1):
            for leg in range(1, self.data[7][x - 1] + 1):
                query = QSqlQuery(f"select max(round_number) as maxround, sum(points) as sumpont from dobas where leg_id={leg} and set_id={x} and match_id={match_id} and player_id={p1_id}")
                query.exec_()
                while query.next():
                    db1 += query.value(0)
                    sum1 += query.value(1)
                query2 = QSqlQuery(f"select max(round_number) as maxround, sum(points) as sumpont from dobas where leg_id={leg} and set_id={x} and match_id={match_id} and player_id={p2_id}")
                query2.exec_()
                while query2.next():
                    db2 += query2.value(0)
                    sum2 += query2.value(1)
        self.avg1 = round(sum1 / db1 * 3, 2)
        self.avg2 = round(sum2 / db2 * 3, 2)

        self.update()
Esempio n. 7
0
    def jogcim_selected(self):
        napidij_model = QSqlQueryModel()
        query = QSqlQuery(
            "SELECT kulcs, ertek FROM settings WHERE kulcs LIKE '%napidij%'")
        napidij_model.setQuery(query)

        for i in range(napidij_model.rowCount()):
            if (napidij_model.record(i).value(0)
                    == 'ar_ifjusagi_napidij') and (self.jogcim.text()
                                                   == 'Ifjúsági napidíj'):
                self.osszeg.setText(str(napidij_model.record(i).value(1)))
            if (napidij_model.record(i).value(0)
                    == 'ar_napidij') and (self.jogcim.text() == 'Napidíj'):
                self.osszeg.setText(str(napidij_model.record(i).value(1)))
Esempio n. 8
0
    def stat_game(self):
        # Az átvett adatok:
        para = self.merkozesek.currentItem().text().rsplit("\t")
        # Összegyűjtjük egy listába a szükséges infókat
        self.get_adatok(para)
        self.szumma.change_data(self.adatok)
        for x in reversed(range(self.history_layout.count())):
            self.history_layout.itemAt(x).widget().deleteLater()
        # kiszedjük az adott meccs összes set és leg esetére a dobásokat
        sor = 0
        for s in range(1, self.adatok[8] + 1):
            # s: a set-ek száma
            if self.adatok[8] != 1:
                self.history_layout.addWidget(QLabel("Set: " + str(s)), sor, 0, 1, 2)
                sor += 1
            for l in range(1, self.adatok[7][s-1] + 1):
                sl1_model = QSqlQueryModel()
                p1_data_list = []
                p1_data_list.append(self.adatok[4])   # start_score1
                sl1_query = QSqlQuery(f"select * from dobas where match_id ={self.adatok[6]} and set_id={s} and leg_id={l} and player_id='{self.adatok[0]}'", db=db)
                sl1_model.setQuery(sl1_query)
                for i in range(sl1_model.rowCount()):
                    # Itt a model már tartalmazza a p1 összes dobását az adott leg-ben.
                    p1_data_row = []
                    p1_data_row.append(sl1_model.record(i).value(1))
                    p1_data_row.append(sl1_model.record(i).value(2))
                    p1_data_list.append(p1_data_row)
                self.history_layout.addWidget(PlayerLegWidget(self, p1_data_list), sor, 0, Qt.AlignTop)

                sl2_model = QSqlQueryModel()
                p2_data_list = []
                p2_data_list.append(self.adatok[5])  # start_score2
                sl2_query = QSqlQuery(f"select * from dobas where match_id ={self.adatok[6]} and set_id={s} and leg_id={l} and player_id='{self.adatok[2]}'", db=db)
                sl2_model.setQuery(sl2_query)
                for j in range(sl2_model.rowCount()):
                    p2_data_row = []
                    p2_data_row.append(sl2_model.record(j).value(1))
                    p2_data_row.append(sl2_model.record(j).value(2))
                    p2_data_list.append(p2_data_row)
                self.history_layout.addWidget(PlayerLegWidget(self, p2_data_list), sor, 1, Qt.AlignTop)
                sor += 1
Esempio n. 9
0
 def check_config(self):
     ip_config = config['DEFAULT'].get('station ip')
     station_id = config['DEFAULT'].get('station id')
     secret = config['DEFAULT'].get('secret key')
     self.ip.setText(ip_config)
     self.station.setText(station_id)
     self.token.setText(secret)
     # todo Ellenőrizni, hogy van-e, és mi van a db-ben
     model2 = QSqlQueryModel()
     query = QSqlQuery(
         f"SELECT * FROM reged_station where secret_key = '{secret}'",
         db=db)
     model2.setQuery(query)
     if model2.record(0).value(0):
         if self.station.text() != model2.record(0).value(
                 1) or self.ip.text() != model2.record(0).value(
                     2) or self.token.text() != model2.record(0).value(3):
             self.valtozott = True
             self.rec_id = model2.record(0).value(0)
     else:
         self.uj_station = True
Esempio n. 10
0
 def torna_valasztas(self, i):
     print(self.tournaments.itemData(i))
     # matches = QSqlRelationalTableModel()
     # matches.setTable("torna_match")
     # matches.setFilter(f'a.torna_id=8889 and a.player1_id=c.player_id and a.player2_id=d.player_id and c.torna_id=a.torna_id and d.torna_id=a.torna_id and a.torna_id=b.torna_id')
     # matches.setFilter(f'torna_name = "{self.tournaments.currentText()}" and torna_resztvevok.torna_id=torna_settings.torna_id and station_id = "{self.station_id}"')
     # matches.setRelation(0, QSqlRelation("torna_settings", "torna_id", "torna_name"))
     # matches.setRelation(2, QSqlRelation("torna_resztvevok", "player_id", "player_name"))
     # matches.setRelation(3, QSqlRelation("torna_resztvevok", "player_id", "player_name"))
     # matches.setRelation(7, QSqlRelation("reged_station", "id", "station_id"))
     # matches.select()
     # print(matches)
     # self.merkozesek.clear()
     # for i in  range(matches.rowCount()):
     #     self.merkozesek.addItem(matches.record(i).value(0) + "\t" +
     #                             str(matches.record(i).value(1)) + "\t" +
     #                             matches.record(i).value(2) + "\t" +
     #                             matches.record(i).value(3) + "\t" +
     #                             matches.record(i).value(4) + "\t" +
     #                             str(matches.record(i).value(5))+ "\t" +
     #                             str(matches.record(i).value(6)))
     matches = QSqlQueryModel()
     # todo itt még nincs táblához kötve a lekérés
     matches_query = QSqlQuery(
         f'SELECT a.match_id,  b.torna_name, c.player_name as nev1, \
     d.player_name as nev2, a.variant, a.sets, a.legsperset FROM `torna_match` a, torna_settings b, torna_resztvevok c, \
     torna_resztvevok d WHERE a.torna_id={self.tournaments.itemData(i)} and a.player1_id=c.player_id and a.player2_id=d.player_id \
     and c.torna_id=a.torna_id and d.torna_id=a.torna_id and a.torna_id=b.torna_id and a.match_status<2'
     )
     matches.setQuery(matches_query)
     self.merkozesek.clear()
     for i in range(matches.rowCount()):
         self.merkozesek.addItem(
             str(matches.record(i).value(0)) + "\t" +
             matches.record(i).value(1) + "\t" +
             matches.record(i).value(2) + "\t" +
             matches.record(i).value(3) + "\t" +
             matches.record(i).value(4) + "\t" +
             str(matches.record(i).value(5)) + "\t" +
             str(matches.record(i).value(6)))
Esempio n. 11
0
    def jogcim_selected(self):
        berlet_model = QSqlQueryModel()
        query = QSqlQuery(
            "SELECT kulcs, ertek FROM settings WHERE kulcs LIKE '%berlet%'")
        berlet_model.setQuery(query)

        for i in range(berlet_model.rowCount()):
            if (berlet_model.record(i).value(0)
                    == 'ar_gyermek_berlet') and (self.jogcim.text()
                                                 == 'Gyermek bérlet'):
                self.osszeg.setText(str(berlet_model.record(i).value(1)))
            if (berlet_model.record(i).value(0)
                    == 'ar_ifjusagi_berlet') and (self.jogcim.text()
                                                  == 'Ifjúsági bérlet'):
                self.osszeg.setText(str(berlet_model.record(i).value(1)))
            if (berlet_model.record(i).value(0)
                    == 'ar_berlet') and (self.jogcim.text() == 'Bérlet'):
                self.osszeg.setText(str(berlet_model.record(i).value(1)))
Esempio n. 12
0
def new_settings(parent):
    m_id = p1_id = p2_id = set = leg = 0
    var = ""
    # manage_settings_window = GameSettingsDialog()
    # manage_settings_window.show()
    if manage_settings_window.exec_():
        player1 = manage_settings_window.input_player1_name.text()
        player2 = manage_settings_window.input_player2_name.text()
        # A MATCH_ID-T AZ AUTOINCREMENTBŐL KELLENE VISSZAKÉRNI ÉS NEM IMPLICIT RANDOMBÓL GENERÁLNI
        m_id = random.randint(10, 1000000)
        # print(m_id)
        set = manage_settings_window.spin_legs.value()
        leg = manage_settings_window.spin_sets.value()
        if manage_settings_window.gomb_301.isChecked():
            var = "301"
        elif manage_settings_window.gomb_401.isChecked():
            var = "401"
        elif manage_settings_window.gomb_501.isChecked():
            var = "501"
        else:
            var = "701"
        # print(var)
        player1_id_model = QSqlQueryModel()
        query1 = QSqlQuery(
            f"SELECT player_id FROM players where player_name = '{player1}'",
            db=db)
        player1_id_model.setQuery(query1)
        if player1_id_model.record(0).value(0):
            p1_id = int(player1_id_model.record(0).value(0))
        else:
            player_model1 = QSqlTableModel()
            player_model1.setTable("players")
            rec_play1 = player_model1.record()
            rec_play1.remove(0)
            rec_play1.setValue(0, player1)
            if player_model1.insertRecord(-1, rec_play1):
                player_model1.submitAll()
            else:
                db.rollback()
            query1 = QSqlQuery(
                f"SELECT player_id FROM players where player_name = '{player1}'",
                db=db)
            player1_id_model.setQuery(query1)
            p1_id = int(player1_id_model.record(0).value(0))

        player2_id_model = QSqlQueryModel()
        query2 = QSqlQuery(
            f"SELECT player_id FROM players where player_name = '{player2}'",
            db=db)
        player2_id_model.setQuery(query2)
        if player2_id_model.record(0).value(0):
            p2_id = int(player2_id_model.record(0).value(0))
        else:
            player_model2 = QSqlTableModel()
            player_model2.setTable("players")
            rec_play2 = player_model2.record()
            rec_play2.remove(0)
            rec_play2.setValue(0, player2)
            if player_model2.insertRecord(-1, rec_play2):
                player_model2.submitAll()
            else:
                db.rollback()
            query2 = QSqlQuery(
                f"SELECT player_id FROM players where player_name = '{player2}'",
                db=db)
            player2_id_model.setQuery(query2)
            p2_id = int(player2_id_model.record(0).value(0))

        # Match paremeterek rögzítése
        match_model = QSqlTableModel()
        match_model.setTable("match_settings")
        record = match_model.record()
        record.setValue(0, m_id)
        record.setValue(1, p1_id)
        record.setValue(2, p2_id)
        record.setValue(3, var)
        record.setValue(4, set)
        record.setValue(5, leg)
        if match_model.insertRecord(-1, record):
            match_model.submitAll()
        else:
            db.rollback()
        # parent.main_layout.addLayout(parent.match_layout)
        # parent.match_layout.addWidget(parent.cimke)
        # parent.main_layout.addWidget(parent.GameWindow)
        parent.gomb1.setText("OK")
    else:
        # parent.gomb1.setText("Cancel")
        parent.close()
Esempio n. 13
0
    def accept(self):
        params = []
        m_id = p1_id = p2_id = set = leg = hc1 = hc2 = 0
        var = ""
        player1 = self.input_player1_name.text()
        player2 = self.input_player2_name.text()
        # todo A MATCH_ID-T VALAMI EGYEDI MÓDON KELL GENERÁLNI(pl. az időbélyeg bizonyos részével)
        m_id = random.randint(10, 1000000)
        leg = self.spin_legs.value()
        set = self.spin_sets.value()
        hc1 = self.handi1.value()
        hc2 = self.handi2.value()
        if self.gomb_301.isChecked():
            var = "301"
        elif self.gomb_401.isChecked():
            var = "401"
        elif self.gomb_501.isChecked():
            var = "501"
        else:
            var = "701"

        if self.best_of.isChecked():
            bestof = 1
        else:
            bestof = 0

        if len(player1) == 0:
            p1_id = 1
            player1 = "Player 1"
        else:
            player1_id_model = QSqlQueryModel()
            query1 = QSqlQuery(
                f"SELECT player_id FROM players where player_name = '{player1}' and type='local' and aktiv=1",
                db=db)
            player1_id_model.setQuery(query1)
            # todo megnézni, hogy sima query.exec_ -el hogyan működik, lehet-e ellenőrizni, hogy üres vagy nem
            if player1_id_model.record(0).value(0):
                p1_id = int(player1_id_model.record(0).value(0))
            else:
                # todo beszúrás előtt ellenőritni, hogy egyedi-e. Létezhet versenyen felvitt ugyanolyan név
                player_model1 = QSqlTableModel()
                player_model1.setTable("players")
                rec_play1 = player_model1.record()
                rec_play1.remove(0)
                rec_play1.setValue(0, player1)
                rec_play1.setValue(1, 'local')
                rec_play1.setValue(2, 1)
                if player_model1.insertRecord(-1, rec_play1):
                    player_model1.submitAll()
                else:
                    db.rollback()
                query1 = QSqlQuery(
                    f"SELECT player_id FROM players where player_name = '{player1}' and type='local' and aktiv=1",
                    db=db)
                player1_id_model.setQuery(query1)
                # todo megnézni, hogy sima query.exec_ -el hogyan működik, lehet-e ellenőrizni, hogy üres vagy nem
                p1_id = int(player1_id_model.record(0).value(0))

        if len(player2) == 0:
            p2_id = 2
            player2 = "Player 2"
        else:
            player2_id_model = QSqlQueryModel()
            query2 = QSqlQuery(
                f"SELECT player_id FROM players where player_name = '{player2}' and type='local' and aktiv=1",
                db=db)
            player2_id_model.setQuery(query2)
            # todo megnézni, hogy sima query.exec_ -el hogyan működik, lehet-e ellenőrizni, hogy üres vagy nem
            if player2_id_model.record(0).value(0):
                p2_id = int(player2_id_model.record(0).value(0))
            else:
                player_model2 = QSqlTableModel()
                player_model2.setTable("players")
                rec_play2 = player_model2.record()
                rec_play2.remove(0)
                rec_play2.setValue(0, player2)
                rec_play2.setValue(1, 'local')
                rec_play2.setValue(2, 1)
                if player_model2.insertRecord(-1, rec_play2):
                    player_model2.submitAll()
                else:
                    db.rollback()
                query2 = QSqlQuery(
                    f"SELECT player_id FROM players where player_name = '{player2}' and type='local' and aktiv=1",
                    db=db)
                player2_id_model.setQuery(query2)
                # todo megnézni, hogy sima query.exec_ -el hogyan működik, lehet-e ellenőrizni, hogy üres vagy nem
                p2_id = int(player2_id_model.record(0).value(0))

        # Match paremeterek rögzítése
        now = QDateTime.currentDateTime()
        match_model = QSqlTableModel()
        match_model.setTable("match_settings")
        # todo Best Of... nincs db-ben tárolva
        record = match_model.record()
        record.setValue(0, m_id)
        record.setValue(1, p1_id)
        record.setValue(2, p2_id)
        record.setValue(3, var)
        record.setValue(4, leg)
        record.setValue(5, set)
        record.setValue(6, hc1)
        record.setValue(7, hc2)
        record.setValue(8, now)
        if match_model.insertRecord(-1, record):
            match_model.submitAll()
        else:
            db.rollback()
        params.append(player1)
        params.append(player2)
        params.append(m_id)
        params.append(p1_id)
        params.append(p2_id)
        params.append(var)
        params.append(leg)
        params.append(set)
        params.append(hc1)
        params.append(hc2)
        params.append(bestof)
        self.parent.new_game_window.params = params
        self.parent.new_game_window.refresh()
        super().accept()
Esempio n. 14
0
    def insert_torna_settings(self):
        van_ilyen_nev = False
        if len(self.torna_name.text()) != 0:
            torna_id_model = QSqlQueryModel()
            query = QSqlQuery(
                "select torna_id, torna_name from torna_settings", db=db)
            torna_id_model.setQuery(query)
            for i in range(torna_id_model.rowCount()):
                if torna_id_model.record(i).value(1) == self.torna_name.text():
                    msg = QMessageBox(self)
                    msg.setStyleSheet("fonz-size: 20px")
                    msg.setWindowTitle("Név ütközés!")
                    msg.setText(
                        '<html style="font-size: 14px; color: red">Már van ilyen nevű verseny!<br></html>'
                        +
                        '<html style="font-size: 16px">Kérem adjon a versenynek egyedi nevet!</html>'
                    )
                    msg.exec_()
                    van_ilyen_nev = True
            if not van_ilyen_nev:
                torna_settings_model = QSqlTableModel(
                    db=db
                )  # !!!!!!! Ha több db van, akkor itt konkrétan meg kell adni
                torna_settings_model.setTable("torna_settings")
                record = torna_settings_model.record()

                record.setValue(1, self.torna_name.text())
                if self.is_roundrobin.isChecked():
                    record.setValue(2, 1)
                else:
                    record.setValue(2, 0)
                record.setValue(3, self.csoport_number.value())
                record.setValue(4, self.jatekos_per_csoport.value())
                record.setValue(5, self.variant.value())
                if self.is_sets.isChecked():
                    record.setValue(6, 1)
                else:
                    record.setValue(6, 0)
                record.setValue(7, self.sets_number.value())
                record.setValue(8, self.legs_number.value())
                # print(record.value(2))
                if self.is_best.isChecked():
                    record.setValue(9, 1)
                else:
                    record.setValue(9, 0)
                if self.is_draw.isChecked():
                    record.setValue(10, 1)
                else:
                    record.setValue(10, 0)
                record.setValue(11, self.pont_win.value())
                record.setValue(12, self.pont_draw.value())
                record.setValue(13, self.pont_lost.value())
                if self.is_single_elim.isChecked():
                    record.setValue(14, 1)
                else:
                    record.setValue(14, 0)
                record.setValue(15, self.num_single.value())
                if self.is_3place.isChecked():
                    record.setValue(16, 1)
                else:
                    record.setValue(16, 0)
                record.setValue(17, self.leg_num_single.value())
                record.setValue(18, self.leg_num_semifinal.value())
                record.setValue(19, self.leg_num_3place.value())
                record.setValue(20, self.leg_num_final.value())
                record.setValue(21, 2)
                # aktiv flag:  0: vége, 1: folyamatban, 2: szerkesztés alatt
                # print(record)
                if torna_settings_model.insertRecord(-1, record):
                    torna_settings_model.submitAll()
                else:
                    db.rollback()

                torna_id_model2 = QSqlQueryModel()
                query2 = QSqlQuery(
                    f"select torna_id from torna_settings where torna_name='{self.torna_name.text()}'",
                    db=db)
                torna_id_model2.setQuery(query2)
                self.torna_id = int(torna_id_model2.record(0).value(0))
                self.gomb_members.setDisabled(False)
        else:
            msg = QMessageBox(self)
            msg.setStyleSheet("fonz-size: 20px")
            msg.setWindowTitle("Hiányzik a verseny neve!")
            msg.setText(
                '<html style="font-size: 14px; color: red">A létrehozott versenynek kell egy elnevezés!<br></html>'
                +
                '<html style="font-size: 16px">Kérem adja meg a verseny nevét!</html>'
            )
            msg.exec_()