Skip to content
This repository has been archived by the owner on May 4, 2021. It is now read-only.

Commit

Permalink
Version 10.12
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasmonk committed Apr 2, 2017
1 parent e529757 commit 160bbea
Show file tree
Hide file tree
Showing 131 changed files with 5,359 additions and 4,931 deletions.
2 changes: 1 addition & 1 deletion Code/Configuracion.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def __init__(self, user):
self.rivalInicial = "tarrasch"
self.rival = self.buscaRival(self.rivalInicial)

self.tutorInicial = "deepfish"
self.tutorInicial = "mcbrain"
self.tutor = self.buscaRival(self.tutorInicial)
self.tutorMultiPV = 10 # 0: maximo
self.tutorDifPts = 0
Expand Down
85 changes: 85 additions & 0 deletions Code/DBgames.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,9 @@ def __init__(self, nomFichero):

self.rowidReader = Util.RowidReader(self.nomFichero, self.tabla)

def reset_cache(self):
self.cache = {}

def addcache(self, rowid, reg):
if len(self.cache) > self.maxcache:
keys = self.cache.keys()
Expand Down Expand Up @@ -879,9 +882,18 @@ def leeAllRecno(self, recno):
self._cursor.execute("SELECT %s FROM %s WHERE rowid =%d" % (select, self.tabla, rowid))
return self._cursor.fetchone()

def leeRegAllRecno(self, recno):
raw = self.leeAllRecno(recno)
alm = Util.Almacen()
for campo in self.liCamposAll:
setattr(alm, campo, raw[campo])
return alm, raw

def leePartidaRecno(self, recno):
raw = self.leeAllRecno(recno)
return self.leePartidaRaw(raw)

def leePartidaRaw(self, raw):
p = Partida.PartidaCompleta()
xpgn = raw["PGN"]
rtags = None
Expand Down Expand Up @@ -1005,6 +1017,8 @@ def modifica(self, recno, partidaCompleta):
self.dbSTAT.append(pvAnt, resAnt, -1)
self.dbSTAT.append(pvNue, resNue, +1)

del self.cache[rowid]

return True

def inserta(self, partidaCompleta):
Expand Down Expand Up @@ -1038,3 +1052,74 @@ def inserta(self, partidaCompleta):

def guardaPartidaRecno(self, recno, partidaCompleta):
return self.inserta(partidaCompleta) if recno is None else self.modifica(recno, partidaCompleta)

def massive_change_tags(self, li_tags_change, liRegistros, remove, overwrite):
dtag = Util.SymbolDict({tag:val for tag, val in li_tags_change})

def work_tag(tag, alm):
if tag in dtag:
ant = getattr(alm, tag.upper())
if (ant and overwrite) or not ant:
setattr(alm, tag.upper(), dtag[tag])

if remove:
remove = remove.upper()

for recno in liRegistros:
alm, raw = self.leeRegAllRecno(recno)

work_tag("Event", alm)
work_tag("Site", alm)
work_tag("Date", alm)

p = self.leePartidaRaw(raw)
if remove:
for n, (tag, val) in enumerate(p.liTags):
if tag.upper() == remove:
del p.liTags[n]
break
setattr(alm, remove, "")

st_tag_ant_upper = set()
for n, (tag, val) in enumerate(p.liTags):
if overwrite:
if tag in dtag:
p.liTags[n] = [tag, dtag[tag]]
st_tag_ant_upper.add(tag.upper())
setattr(alm, tag.upper(), p.liTags[n][1])

for tag_new in dtag:
if tag_new.upper() not in st_tag_ant_upper:
p.liTags.append([tag_new, dtag[tag_new]])
setattr(alm, tag_new.upper(), dtag[tag_new])

rowid = self.liRowids[recno]
pgn = {"FULLGAME": p.save()}
xpgn = Util.var2blob(pgn)
sql = "UPDATE GAMES SET EVENT=?, SITE=?, DATE=?, WHITE=?, BLACK=?, RESULT=?, " \
"ECO=?, WHITEELO=?, BLACKELO=?, PGN=? WHERE ROWID = %d" % rowid
self._cursor.execute(sql, (alm.EVENT, alm.SITE, alm.DATE, alm.WHITE, alm.BLACK, alm.RESULT,
alm.ECO, alm.WHITEELO, alm.BLACKELO, xpgn))

self._conexion.commit()

self.reset_cache()

def insert_pks(self, path_pks):
f = open(path_pks, "rb")
txt = f.read()
f.close()
dic = Util.txt2dic(txt)
fen = dic.get("FEN")
if fen:
return _("This pks file is not a complete game")

liTags = dic.get("liPGN", [])

partidaCompleta = Partida.PartidaCompleta(liTags=liTags)
partidaCompleta.recuperaDeTexto(dic["PARTIDA"])

if not self.inserta(partidaCompleta):
return _("This game already exists.")

return None
Loading

0 comments on commit 160bbea

Please sign in to comment.