def __init__(self, file): self.file = file self.db = Base.DBBase(file) self.tabla = "datos" if not self.db.existeTabla(self.tabla): self.crea_tabla() self.dbf = self.db.dbf( self.tabla, "REF,FECHA,SCORE,ENGINE,SEGUNDOS,MIN_MIN,MIN_MAX,LINE", orden="FECHA DESC") if not self.dbf.existe_column("ENGINE"): self.dbf.add_column_varchar("ENGINE") if self.dbf.existe_column("MOTOR"): self.dbf.copy_column("MOTOR", "ENGINE") self.dbf.cerrar() self.dbf = self.db.dbf( self.tabla, "REF,FECHA,SCORE,ENGINE,SEGUNDOS,MIN_MIN,MIN_MAX,LINE", orden="FECHA DESC") self.dbf.leer() self.orden = "FECHA", "DESC" atexit.register(self.close)
def read_id(self, xid): db = Base.DBBase(self._db) dbf = db.dbfT("data", "LEVEL,WHITE,CABS,MOVS", condicion="ROWID=%d" % xid) dbf.leer() dbf.gotop() self.nivel = dbf.LEVEL is_white = dbf.WHITE self.human_side = is_white self.is_engine_side_white = not is_white pv = FasterCode.xpv_pv(dbf.MOVS) self.gameObj = Game.Game() self.gameObj.read_pv(pv) self.posJugadaObj = 0 self.numJugadasObj = self.gameObj.num_moves() li = dbf.CABS.split("\n") for x in li: if x: key, valor = x.split("=") self.game.add_tag(key, valor) dbf.cerrar() db.cerrar()
def __init__(self, nomFichero, segundosBuffer=0.8): self.nomFichero = Util.dirRelativo(nomFichero) self.liCamposBase = [ "EVENT", "SITE", "DATE", "WHITE", "BLACK", "RESULT", "ECO", "WHITEELO", "BLACKELO", "PLIES" ] self.liCamposWork = ["XPV", "PGN"] self.segundosBuffer = segundosBuffer self.db = Base.DBBase(nomFichero) self.tabla = "games" if not self.db.existeTabla(self.tabla): self.creaTabla() liCampos = [] liCampos.extend(self.liCamposWork) liCampos.extend(self.liCamposBase) self.dbf = self.db.dbfCache(self.tabla, ",".join(liCampos)) self.liOrden = [] atexit.register(self.close) self.dbSTAT = TreeSTAT(self.nomFichero + "-stat") self.dbSTATbase = self.dbSTAT self.dbSTATplayer = None
def eligeJuego(self, siCompetitivo, nivel): self.siCompetitivo = siCompetitivo color = self.determinaColor(nivel) db = Base.DBBase(self._db) dbf = db.dbfT("data", "ROWID", condicion="LEVEL=%d AND WHITE=%d" % (nivel, 1 if color else 0)) dbf.leer() reccount = dbf.reccount() # dbf = db.dbfT("data", "ROWID,CABS,MOVS", condicion="LEVEL=%d AND WHITE=%d" % (nivel, 1 if color else 0 )) # dbf.leer() # import Partida # f = open("12001.pgn","wb") # for recno in range(1,reccount+1): # dbf.goto(recno) # pv = LCEngine.xpv2pv(dbf.MOVS) # # if pv.startswith( "d2d4" ) and "RaulJRojel" in dbf.CABS and "tunante" in dbf.CABS: # # break # pv = LCEngine.xpv2pv(dbf.MOVS) # if pv.startswith( "d2d4" ): # p = Partida.Partida() # p.leerPV(pv) # c = "["+dbf.CABS.replace("=", ' "').replace("\n", '"]\n[')+"]\n" # f.write( '[ID "%d"]\n'%dbf.ROWID) # f.write( c ) # f.write(p.pgnBase()) # f.write("\n\n") # f.close() recno = random.randint(1, reccount) dbf.goto(recno) xid = dbf.ROWID dbf.cerrar() db.cerrar() return xid
def readID(self, xid): db = Base.DBBase(self._db) dbf = db.dbfT("data", "LEVEL,WHITE,CABS,MOVS", condicion="ROWID=%d" % xid) dbf.leer() dbf.gotop() self.nivel = dbf.LEVEL siBlancas = dbf.WHITE self.siJugamosConBlancas = siBlancas self.siRivalConBlancas = not siBlancas pv = LCEngine.xpv2pv(dbf.MOVS) self.partidaObj = Partida.Partida() self.partidaObj.leerPV(pv) self.posJugadaObj = 0 self.numJugadasObj = self.partidaObj.numJugadas() self.cabs = collections.OrderedDict() li = dbf.CABS.split("\n") for x in li: if x: clave, valor = x.split('=') self.cabs[clave] = valor dbf.cerrar() db.cerrar()
def __init__(self, configuration): self.configuration = configuration nom_fichero = configuration.ficheroExpeditions self.db = Base.DBBase(nom_fichero) self.tabla = "Expeditions" if not self.db.existeTabla(self.tabla): self.creaTabla() li_fields = ( "DATE_INIT", "NAME", "DATE_END", "TIMES", "NUM_GAMES", "NEXT_GAME", "TRIES_USED", "DISTRIBUTION", "TOLERANCE", "TRIES", "COLOR", ) # , "GAMES" Games no se lee en cache, leeOtroCampo, # o al escribir un reg self.dbf = self.db.dbf(self.tabla, ",".join(li_fields), orden="DATE_INIT DESC") self.dbf.leer()
def creaTabla(self): tb = Base.TablaBase(self.tabla) tb.nuevoCampo("FECHA", "VARCHAR", notNull=True, primaryKey=True) tb.nuevoCampo("MOVES", "INTEGER") tb.nuevoCampo("SECONDS", "INTEGER") tb.nuevoCampo("HINTS", "INTEGER") self.db.generarTabla(tb)
def creaTabla(self): tb = Base.TablaBase(self.tabla) tb.nuevoCampo("XPV", "VARCHAR", notNull=True, primaryKey=True) for campo in self.liCamposBase: tb.nuevoCampo(campo, "VARCHAR") tb.nuevoCampo("PGN", "BLOB") self.db.generarTabla(tb)
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
def crea_tabla(self): tb = Base.TablaBase(self.tabla) tb.nuevoCampo("FECHA", "VARCHAR", notNull=True, primaryKey=True) tb.nuevoCampo("REF", "INTEGER") tb.nuevoCampo("SCORE", "INTEGER") tb.nuevoCampo("MOTOR", "VARCHAR") tb.nuevoCampo("SEGUNDOS", "INTEGER") tb.nuevoCampo("MIN_MIN", "INTEGER") tb.nuevoCampo("MIN_MAX", "INTEGER") tb.nuevoCampo("LINE", "TEXT") tb.nuevoIndice("IND_SCORE", "SCORE") self.db.generarTabla(tb)
def __init__(self, fichero, test): self.fichero = fichero self.db = Base.DBBase(fichero) self.tabla = test if not self.db.existeTabla(self.tabla): self.creaTabla() self.dbf = self.db.dbf(self.tabla, "FECHA,MOVES,SECONDS,HINTS", orden="FECHA DESC") self.dbf.leer() self.orden = "FECHA", "DESC" atexit.register(self.close)
def __init__(self, file): self.file = file self.db = Base.DBBase(file) self.tabla = "datos" if not self.db.existeTabla(self.tabla): self.crea_tabla() self.dbf = self.db.dbf(self.tabla, "REF,FECHA,SCORE,MOTOR,SEGUNDOS,MIN_MIN,MIN_MAX,LINE", orden="FECHA DESC") self.dbf.leer() self.orden = "FECHA", "DESC" atexit.register(self.close)
def creaTabla(self): tb = Base.TablaBase(self.tabla) tb.nuevoCampo("DATE_INIT", "VARCHAR", notNull=True, primaryKey=True) tb.nuevoCampo("NAME", "VARCHAR") tb.nuevoCampo("DATE_END", "VARCHAR") tb.nuevoCampo("TIMES", "VARCHAR") tb.nuevoCampo("NUM_GAMES", "INTEGER") tb.nuevoCampo("NEXT_GAME", "INTEGER") tb.nuevoCampo("TRIES_USED", "INTEGER") tb.nuevoCampo("DISTRIBUTION", "VARCHAR") tb.nuevoCampo("TOLERANCE", "VARCHAR") tb.nuevoCampo("TRIES", "VARCHAR") tb.nuevoCampo("COLOR", "VARCHAR") tb.nuevoCampo("GAMES", "BLOB") self.db.generarTabla(tb)
def elige_juego(self, nivel): color = self.determinaColor(nivel) db = Base.DBBase(self._db) dbf = db.dbfT("data", "ROWID", condicion="LEVEL=%d AND WHITE=%d" % (nivel, 1 if color else 0)) dbf.leer() reccount = dbf.reccount() recno = random.randint(1, reccount) dbf.goto(recno) xid = dbf.ROWID dbf.cerrar() db.cerrar() return xid
def __init__(self, fichero, nivel): self.fichero = fichero self.nivel = nivel self.db = Base.DBBase(fichero) self.tabla = "Nivel%d" % self.nivel if not self.db.existeTabla(self.tabla): self.creaTabla() self.dbf = self.db.dbf(self.tabla, "FECHA,SEGUNDOS", orden="FECHA DESC") self.dbf.leer() self.calculaMedia() self.orden = "FECHA", "DESC" atexit.register(self.close)
def __init__(self, nomFichero, segundosBuffer=0.8): self.nomFichero = nomFichero self.liCamposBase = [ "FEN", "EVENT", "SITE", "DATE", "WHITE", "BLACK", "RESULT", "PLIES" ] self.liCamposWork = ["XPV", "PGN"] self.segundosBuffer = segundosBuffer self.db = Base.DBBase(nomFichero) self.tabla = "games" if not self.db.existeTabla(self.tabla): self.creaTabla() liCampos = [] liCampos.extend(self.liCamposWork) liCampos.extend(self.liCamposBase) self.dbf = self.db.dbfCache(self.tabla, ",".join(liCampos)) self.liOrden = [] atexit.register(self.close) self.miraReccountTotal()
def ficheroMostrar(self, dicDB, siRepite, siAnterior=False, siSiguiente=False): bd = SQLBase.DBBase(dicDB["PATHDB"]) if (not siRepite) and self.siFicheroNuestro: orden = "ROWID DESC" else: orden = "" dClavesTam = dicDB["DCLAVES"] dbf = bd.dbf( "GAMES", ",".join(dClavesTam.keys()), orden=orden ) # La lectura se hace en la pantalla, para que la haga en el mismo sitio tanto siRepite como si no estadoWpgn = dicDB["ESTADOWPGN"] if siRepite else None if siAnterior or siSiguiente: siSeguir = True siSeHaBorradoAlgo = False dbf.leer() recno = estadoWpgn.recno if siAnterior: if recno > 0: recno -= 1 elif siSiguiente: if recno < dbf.reccount() - 1: recno += 1 dbf.goto(recno) estadoWpgn.recno = recno else: siSeguir, estadoWpgn, siSeHaBorradoAlgo = PantallaPGN.elegirPGN( self.pantalla, dbf, dClavesTam, self, estadoWpgn) if siSeguir: self.pensando(True) rid = dbf.rowid(dbf.recno) self.dicDB = dicDB dicDB["ESTADOWPGN"] = estadoWpgn dbf.cerrar() dbf = bd.dbfT("GAMES", ",".join(dClavesTam.keys()) + ",PGN", condicion="ROWID=%d" % rid) dbf.leer() dbf.gotop() dicDatos = dbf.dicValores() self.pgnPaste = dicDatos["PGN"] dbf.cerrar() pgn = PGN.UnPGN() pgn.leeTexto(self.pgnPaste) siMostrar = not pgn.siError self.pensando(False) if not siMostrar: QTUtil2.mensError(self.pantalla, _("This is not a valid PGN file")) else: siMostrar = False bd.cerrar() if siSeHaBorradoAlgo: fpgn = PGN.PGN() fpgn.borraReferenciaA(dicDB["FICHERO"]) if siMostrar: self.mostrar(pgn, True) elif self.muestraInicial or self.finExit: self.finPartida()
def mas(self): path = QTVarios.select_pgn(self) if not path: return fpgn = PGN.PGN() dicDB = fpgn.leeFichero(self, path) if dicDB is None: return bd = SQLBase.DBBase(dicDB["PATHDB"]) dClavesTam = dicDB["DCLAVES"] dbf = bd.dbf("GAMES", ",".join(dClavesTam.keys())) dbf.leer() nreccount = dbf.reccount() plant = "" shuffle = False reverse = False todos = range(1, nreccount + 1) li_regs = None while True: sep = FormLayout.separador liGen = [] liGen.append((None, "%s: %d" % (_("Total games"), nreccount))) liGen.append(sep) config = FormLayout.Editbox(_("Select games") + "<br>" + _("By example:") + " -5,7-9,14,19-" + "<br>" + _("Empty means all games"), rx="[0-9,\-,\,]*") liGen.append((config, plant)) liGen.append(sep) liGen.append((_("Shuffle") + ":", shuffle)) liGen.append(sep) liGen.append((_("Reverse") + ":", reverse)) liGen.append(sep) config = FormLayout.Spinbox(_("Max moves"), 0, 999, 50) liGen.append((config, 0)) resultado = FormLayout.fedit(liGen, title=_("Select games"), parent=self, anchoMinimo=200, icon=Iconos.Opciones()) if resultado: accion, liResp = resultado plant, shuffle, reverse, max_moves = liResp if plant: ln = Util.ListaNumerosImpresion(plant) li_regs = ln.selected(todos) else: li_regs = todos nregs = len(li_regs) if 12 <= nregs <= 500: break else: QTUtil2.mensError( self, "%s (%d)" % (_("Number of games must be in range 12-500"), nregs)) li_regs = None else: break if li_regs: if shuffle: random.shuffle(li_regs) if reverse: li_regs.sort(reverse=True) li_regs = [x - 1 for x in li_regs] # 0 init dic = {} dic["TOURNEY"] = os.path.basename(path)[:-4] games = dic["GAMES"] = [] for recno in li_regs: pgn = dbf.leeOtroCampo(recno, "PGN") g = PGNReader.read1Game(pgn) pv = g.pv() if max_moves: lipv = pv.strip().split(" ") if len(lipv) > max_moves: pv = " ".join(lipv[:max_moves]) dt = { "LABELS": [(k, v) for k, v in g.labels.items()], "XPV": LCEngine.pv2xpv(pv) } games.append(dt) self.litourneys.append(dic) li = [("%s (%d)" % (tourney["TOURNEY"], len(tourney["GAMES"])), tourney) for tourney in self.litourneys] self.cbtourney.rehacer(li, dic) dbf.cerrar() bd.cerrar()
def creaTabla(self): tb = Base.TablaBase(self.tabla) tb.nuevoCampo("FECHA", "VARCHAR", notNull=True, primaryKey=True) tb.nuevoCampo("SEGUNDOS", "FLOAT") tb.nuevoIndice("IND_SEGUNDOS%d" % self.nivel, "SEGUNDOS") self.db.generarTabla(tb)