예제 #1
0
    def leerPGN(self, fichero, dlTmp):
        erroneos = duplicados = importados = 0

        # 1.File pgn -> temporal clean
        for n, g in enumerate(PGNreader.readGames(fichero), 1):
            if n % 100 == 0:
                if not dlTmp.actualiza(n, erroneos, duplicados, importados):
                    break
                if n % 10000 == 0:
                    self.dbf.commit()
            if g.erroneo:
                erroneos += 1
                continue
            pv = g.pv()
            if not pv:
                erroneos += 1
                continue
            pgn = g.pgn

            get = g.labels.get
            if get("FEN", None):
                erroneos += 1
                continue

            def get(label):
                if label in g.labels:
                    return g.labels[label]
                return ""

            event = get("EVENT")
            site = get("SITE")
            date = get("DATE")
            white = get("WHITE")
            black = get("BLACK")
            result = get("RESULT")
            eco = get("ECO")
            whiteelo = get("WHITEELO")
            blackelo = get("BLACKELO")

            if self.append(pv, event, site, date, white, black, result, eco,
                           whiteelo, blackelo, pgn, False):
                importados += 1
            else:
                duplicados += 1

        dlTmp.actualiza(n + 1, erroneos, duplicados, importados)

        dlTmp.ponSaving()
        self.dbf.commit()
        dlTmp.ponContinuar()

        return
예제 #2
0
    def leerPGN(self, fichero, dlTmp):
        erroneos = duplicados = importados = 0

        # 1.File pgn -> temporal clean
        for n, g in enumerate(PGNreader.readGames(fichero)):
            if n == 10000:
                break
            if n % 100 == 0:
                if not dlTmp.actualiza(n, erroneos, duplicados, importados):
                    break
            if g.erroneo:
                erroneos += 1
                continue
            pv = g.pv()
            if not pv:
                erroneos += 1
                continue
            pgn = g.pgn

            get = g.labels.get
            if get("FEN", None):
                erroneos += 1
                continue

            def get(label):
                if label in g.labels:
                    return g.labels[label]
                return ""

            event = get("EVENT")
            site = get("SITE")
            date = get("DATE")
            white = get("WHITE")
            black = get("BLACK")
            result = get("RESULT")
            eco = get("ECO")
            whiteelo = get("WHITEELO")
            blackelo = get("BLACKELO")

            if self.append(pv, event, site, date, white, black, result, eco, whiteelo, blackelo, pgn, False):
                importados += 1
            else:
                duplicados += 1

        dlTmp.actualiza(n + 1, erroneos, duplicados, importados)

        dlTmp.ponSaving()
        self.dbf.commit()
        dlTmp.ponContinuar()

        return
예제 #3
0
    def leerPGN(self, fichero, dlTmp):

        erroneos = duplicados = importados = 0

        for n, g in enumerate(PGNreader.readGames(fichero)):

            if n % 100 == 0:
                if not dlTmp.actualiza(n + 1, erroneos, duplicados,
                                       importados):
                    break
            if g.erroneo:
                erroneos += 1
                continue
            pgn = g.pgn
            pv = g.pv()

            get = g.labels.get
            fen = get("FEN", None)
            if not fen:
                erroneos += 1
                continue
            event = get("EVENT", "")
            site = get("SITE", "")
            date = get("DATE", "")
            white = get("WHITE", "")
            black = get("BLACK", "")
            result = get("RESULT", "")

            if self.append(pv, event, site, date, white, black, result, fen,
                           pgn, False):
                importados += 1
            else:
                duplicados += 1

        dlTmp.actualiza(n + 1, erroneos, duplicados, importados)

        dlTmp.ponSaving()
        self.dbf.commit()
        dlTmp.ponContinuar()

        return
예제 #4
0
    def leerPGN(self, fichero, dlTmp):

        erroneos = duplicados = importados = 0

        for n, g in enumerate(PGNreader.readGames(fichero)):

            if n % 100 == 0:
                if not dlTmp.actualiza(n + 1, erroneos, duplicados, importados):
                    break
            if g.erroneo:
                erroneos += 1
                continue
            pgn = g.pgn
            pv = g.pv()

            get = g.labels.get
            fen = get("FEN", None)
            if not fen:
                erroneos += 1
                continue
            event = get("EVENT", "")
            site = get("SITE", "")
            date = get("DATE", "")
            white = get("WHITE", "")
            black = get("BLACK", "")
            result = get("RESULT", "")

            if self.append(pv, event, site, date, white, black, result, fen, pgn, False):
                importados += 1
            else:
                duplicados += 1

        dlTmp.actualiza(n + 1, erroneos, duplicados, importados)

        dlTmp.ponSaving()
        self.dbf.commit()
        dlTmp.ponContinuar()

        return
예제 #5
0
    def importarPGN(self, owner, partidabase, ficheroPGN, maxDepth, variations):

        erroneos = duplicados = importados = 0
        dlTmp = QTVarios.ImportarFicheroPGN(owner)
        dlTmp.hideDuplicados()
        dlTmp.show()

        self.saveHistory(_("Import"), _("PGN with variants"), os.path.basename(ficheroPGN))

        cursor = self._conexion.cursor()

        base = partidabase.pv() if partidabase else self.getconfig("BASEPV")

        sql_insert = "INSERT INTO LINES( XPV ) VALUES( ? )"
        sql_update = "UPDATE LINES SET XPV=? WHERE XPV=?"

        for n, g in enumerate(PGNreader.readGames(ficheroPGN), 1):
            if not dlTmp.actualiza(n, erroneos, duplicados, importados):
                break
            if g.erroneo:
                erroneos += 1
                continue
            if not g.moves:
                erroneos += 1
                continue

            def haz_partida(liMoves):
                njg = len(liMoves)
                if njg > maxDepth:
                    liMoves = liMoves[:maxDepth]
                pv = " ".join([move.pv for move in liMoves])
                partida = Partida.Partida()
                partida.leerPV(pv)
                pv = partida.pv()
                if base and not pv.startswith(base):
                    return
                xpv = LCEngine.pv2xpv(pv)
                updated = False
                for npos, xpv_ant in enumerate(self.li_xpv):
                    if xpv_ant.startswith(xpv):
                        return
                    if xpv.startswith(xpv_ant):
                        cursor.execute(sql_update, (xpv, xpv_ant))
                        self.li_xpv[npos] = xpv
                        updated = True
                        break
                if not updated:
                    cursor.execute(sql_insert, (xpv,))
                    self.li_xpv.append(xpv)

                if variations != "N":  #None
                    for njug, move in enumerate(liMoves):
                        ok = True
                        if variations != "A":
                            if variations == "W":
                                if njug % 2 == 1:
                                    ok = False
                            elif variations == "B":
                                if njug % 2 == 0:
                                    ok = False
                        if ok:
                            for lim in move.variantes:
                                limovnv = [liMoves[j].clona() for j in range(njug)]
                                for move in limovnv:
                                    move.variantes = []
                                limovnv.extend(lim.liMoves)
                                haz_partida(limovnv)

            haz_partida(g.moves.liMoves)
            if n % 50:
                self._conexion.commit()

        cursor.close()
        self.li_xpv.sort()
        self._conexion.commit()

        dlTmp.actualiza(n, erroneos, duplicados, importados)
        dlTmp.ponContinuar()
예제 #6
0
    def importarPGN(self, owner, partidabase, ficheroPGN, maxDepth):
        erroneos = duplicados = importados = 0
        dlTmp = QTVarios.ImportarFicheroPGN(owner)
        dlTmp.hideDuplicados()
        dlTmp.show()

        cursor = self._conexion.cursor()

        base = self.getconfig("BASEPV")
        njugbase = partidabase.numJugadas()
        n = 0

        sql_insert = "INSERT INTO LINES( XPV, LINE ) VALUES( ?, ? )"
        sql_update = "UPDATE LINES SET XPV=?, LINE=? WHERE XPV=?"
        for n, g in enumerate(PGNreader.readGames(ficheroPGN), 1):
            if not dlTmp.actualiza(n, erroneos, duplicados, importados):
                break
            if g.erroneo:
                erroneos += 1
                continue
            if not g.moves:
                erroneos += 1
                continue

            def haz_partida(partida, liMoves):
                njg = len(partida)
                if len(liMoves) + njg > maxDepth:
                    liMoves = liMoves[:maxDepth - njg]
                pv = " ".join([move.pv for move in liMoves])
                partida.leerPV(pv)
                pv = partida.pv()
                if base and not pv.startswith(base) or partida.numJugadas(
                ) <= njugbase:
                    return
                xpv = LCEngine.pv2xpv(pv)
                if xpv in self.li_xpv:
                    return
                line_blob = partida.save2blob()
                updated = False
                for npos, xpv_ant in enumerate(self.li_xpv):
                    if xpv.startswith(xpv_ant):
                        cursor.execute(sql_update, (xpv, line_blob, xpv_ant))
                        self.li_xpv[npos] = xpv
                        updated = True
                        break
                if not updated:
                    cursor.execute(sql_insert, (xpv, line_blob))
                    self.li_xpv.append(xpv)

                for njug, move in enumerate(liMoves):
                    if move.variantes:
                        for lim in move.variantes:
                            p = partida.copia(
                                njug - 1) if njug > 0 else Partida.Partida()
                            haz_partida(p, lim.liMoves)

            partida = Partida.Partida()
            haz_partida(partida, g.moves.liMoves)
            if n % 50:
                self._conexion.commit()

        cursor.close()
        self.li_xpv.sort()
        self._conexion.commit()

        dlTmp.actualiza(n, erroneos, duplicados, importados)
        dlTmp.ponContinuar()
예제 #7
0
    def grabarPGN(self, ventana, ficheroPGN, maxDepth):

        select = "XPV,PV,COMMENT,NAG,ADV,FEN,POS"
        SQLDBF.DBF(self.conexion, self.tablaDatos, select)

        erroneos = duplicados = importados = 0
        dlTmp = QTVarios.ImportarFicheroPGN(ventana)
        dlTmp.hideDuplicados()
        dlTmp.show()

        select = "XPV,PV,COMMENT,NAG,ADV,FEN,POS"
        dbf = SQLDBF.DBF(self.conexion, self.tablaDatos, select)
        dnag = {"!!": 3, "!": 1, "?": 2, "??": 4, "!?": 5, "?!": 6}

        for n, g in enumerate(PGNreader.readGames(ficheroPGN)):

            if not dlTmp.actualiza(n + 1, erroneos, duplicados, importados):
                break
            if g.erroneo:
                erroneos += 1
                continue
            if not g.moves:
                erroneos += 1
                continue

            liReg = []

            def addMoves(moves, depth, seq):
                for mv in moves.liMoves:
                    if depth > maxDepth:
                        break
                    seqM1 = seq
                    pv = mv.pv
                    seq += LCEngine.pv2xpv(pv)
                    reg = SQLDBF.Almacen()
                    reg.PV = pv
                    reg.XPV = seq
                    reg.COMMENT = "\n".join(mv.comentarios)
                    reg.FEN = mv.fen
                    reg.NAG = 0
                    reg.ADV = 0
                    self.ultPos += 1
                    reg.POS = self.ultPos
                    for critica in mv.criticas:
                        if critica.isdigit():
                            t = int(critica)
                            if t in (4, 2, 1, 3, 5, 6):
                                reg.NAG = t
                            elif t in (11, 14, 15, 16, 17, 18, 19):
                                reg.ADV = t
                        else:
                            if critica in dnag:
                                reg.NAG = dnag[critica]
                    liReg.append(reg)
                    if mv.variantes:
                        for variante in mv.variantes:
                            addMoves(variante, depth, seqM1)
                    depth += 1

            addMoves(g.moves, 1, "")
            if liReg:
                dbf.insertarLista(liReg, None)

        dbf.cerrar()
        dlTmp.actualiza(n, erroneos, duplicados, importados)
        dlTmp.ponContinuar()

        return len(liReg) > 0
예제 #8
0
    def creaDB(self, ventana, fichero, uno):

        titulo = os.path.basename(fichero)
        tmpBP = QTUtil2.BarraProgreso(ventana, titulo, _("Working..."),
                                      Util.tamFichero(fichero)).mostrar()

        dClaves = Util.SymbolDict(
        )  # contiene tam maximo de los campos a mostrar

        def iniDB():
            fichDB = uno["PATHDB"]
            Util.borraFichero(fichDB)
            bd = SQLBase.DBBase(fichDB)

            tb = SQLBase.TablaBase("GAMES")
            tb.liCampos = []
            for clave in dClaves:
                tb.liCampos.append(SQLBase.Campo(clave.upper(), 'VARCHAR'))
            if "PLIES" not in dClaves:
                tb.liCampos.append(SQLBase.Campo("PLIES", 'VARCHAR'))
                dClaves["PLIES"] = 4
            if "PGN" not in dClaves:
                tb.liCampos.append(SQLBase.Campo("PGN", 'TEXT'))
            cursor = bd.conexion.cursor()
            tb.crearBase(cursor)
            cursor.close()
            dbf = bd.dbf("GAMES", (",".join(dClaves.keys())) + ",PGN")
            return bd, dbf

        jg = 0
        dbf = None
        for g in PGNreader.readGames(fichero):

            if tmpBP.siCancelado():
                break

            tmpBP.pon(g.nbytes)

            if g.erroneo:
                continue

            if not dbf:
                for clave, valor in g.labels.iteritems():
                    if valor == "?":
                        continue
                    dClaves[clave] = len(valor)
                bd, dbf = iniDB()

            else:
                for clave, valor in g.labels.iteritems():
                    if valor == "?":
                        continue
                    tam = len(valor)
                    if clave not in dClaves:
                        dbf.nuevaColumna(clave.upper(), 'VARCHAR')
                        dClaves[clave] = tam
                    else:
                        if dClaves[clave] < tam:
                            dClaves[clave] = tam

            dic = {}
            for k, v in g.labels.iteritems():
                if v == "?":
                    continue
                dic[k] = v
            dic["PGN"] = g.pgn
            pv = g.pv()
            dic["PLIES"] = pv.count(" ") + 1 if pv else 0
            jg += 1
            dbf.soloGrabar(dic, jg % 10000 == 0)

        if not dbf:
            bd, dbf = iniDB()
        dbf.commit()  # Graba los ultimos
        dbf.cerrar()
        bd.cerrar()

        tmpBP.close()

        uno["DCLAVES"] = dClaves

        return True
예제 #9
0
파일: PGN.py 프로젝트: JERUKA9/lucaschess
    def creaDB(self, ventana, fichero, uno):

        titulo = os.path.basename(fichero)
        tmpBP = QTUtil2.BarraProgreso(ventana, titulo, _("Working..."), Util.tamFichero(fichero)).mostrar()

        dClaves = Util.SymbolDict()  # contiene tama_o maximo de los campos a mostrar

        def iniDB():
            fichDB = uno["PATHDB"]
            Util.borraFichero(fichDB)
            bd = SQLBase.DBBase(fichDB)

            tb = SQLBase.TablaBase("GAMES")
            tb.liCampos = []
            for clave in dClaves:
                tb.liCampos.append(SQLBase.Campo(clave.upper(), 'VARCHAR'))
            if "PLIES" not in dClaves:
                tb.liCampos.append(SQLBase.Campo("PLIES", 'VARCHAR'))
                dClaves["PLIES"] = 4
            if "PGN" not in dClaves:
                tb.liCampos.append(SQLBase.Campo("PGN", 'TEXT'))
            cursor = bd.conexion.cursor()
            tb.crearBase(cursor)
            cursor.close()
            dbf = bd.dbf("GAMES", (",".join(dClaves.keys())) + ",PGN")
            return bd, dbf

        jg = 0
        dbf = None
        for g in PGNreader.readGames(fichero):

            if tmpBP.siCancelado():
                break

            tmpBP.pon(g.nbytes)

            if g.erroneo:
                continue

            if not dbf:
                for clave, valor in g.labels.iteritems():
                    if valor == "?":
                        continue
                    dClaves[clave] = len(valor)
                bd, dbf = iniDB()

            else:
                for clave, valor in g.labels.iteritems():
                    if valor == "?":
                        continue
                    tam = len(valor)
                    if clave not in dClaves:
                        dbf.nuevaColumna(clave.upper(), 'VARCHAR')
                        dClaves[clave] = tam
                    else:
                        if dClaves[clave] < tam:
                            dClaves[clave] = tam

            dic = {}
            for k, v in g.labels.iteritems():
                if v == "?":
                    continue
                dic[k] = v
            dic["PGN"] = g.pgn
            pv = g.pv()
            dic["PLIES"] = pv.count(" ") + 1 if pv else 0
            jg += 1
            dbf.soloGrabar(dic, jg % 10000 == 0)

        if not dbf:
            bd, dbf = iniDB()
        dbf.commit()  # Graba los ultimos
        dbf.cerrar()
        bd.cerrar()

        tmpBP.close()

        uno["DCLAVES"] = dClaves

        return True
예제 #10
0
    def grabarPGN(self, ventana, ficheroPGN, maxDepth):

        select = "XPV,PV,COMMENT,NAG,ADV,FEN,POS"
        SQLDBF.DBF(self.conexion, self.tablaDatos, select)

        erroneos = duplicados = importados = 0
        dlTmp = QTVarios.ImportarFicheroPGN(ventana)
        dlTmp.hideDuplicados()
        dlTmp.show()

        select = "XPV,PV,COMMENT,NAG,ADV,FEN,POS"
        dbf = SQLDBF.DBF(self.conexion, self.tablaDatos, select)
        dnag = {"!!": 3, "!": 1, "?": 2, "??": 4, "!?": 5, "?!": 6}

        for n, g in enumerate(PGNreader.readGames(ficheroPGN, siFast=False)):

            if not dlTmp.actualiza(n + 1, erroneos, duplicados, importados):
                break
            if g.erroneo:
                erroneos += 1
                continue
            if not g.moves:
                erroneos += 1
                continue

            liReg = []

            def addMoves(moves, depth, seq):
                for mv in moves.liMoves:
                    if depth > maxDepth:
                        break
                    seqM1 = seq
                    pv = mv.pv
                    seq += Movimientos.pv2xpv(pv)
                    reg = SQLDBF.Almacen()
                    reg.PV = pv
                    reg.XPV = seq
                    reg.COMMENT = "\n".join(mv.comentarios)
                    reg.FEN = mv.fen
                    reg.NAG = 0
                    reg.ADV = 0
                    self.ultPos += 1
                    reg.POS = self.ultPos
                    for critica in mv.criticas:
                        if critica.isdigit():
                            t = int(critica)
                            if t in (4, 2, 1, 3, 5, 6):
                                reg.NAG = t
                            elif t in (11, 14, 15, 16, 17, 18, 19):
                                reg.ADV = t
                        else:
                            if critica in dnag:
                                reg.NAG = dnag[critica]
                    liReg.append(reg)
                    if mv.variantes:
                        for variante in mv.variantes:
                            addMoves(variante, depth, seqM1)
                    depth += 1

            addMoves(g.moves, 1, "")
            if liReg:
                dbf.insertarLista(liReg, None)

        dbf.cerrar()
        dlTmp.actualiza(n, erroneos, duplicados, importados)
        dlTmp.ponContinuar()

        return len(liReg) > 0