Time per move extraction tool

Discussion of chess software programming and technical issues.

Moderators: hgm, Dann Corbit, Harvey Williamson

User avatar
xr_a_y
Posts: 1871
Joined: Sat Nov 25, 2017 2:28 pm
Location: France

Time per move extraction tool

Post by xr_a_y »

Hi,

I'm looking for a tools to build graph of move time in pgn format

Code: Select all

50. Bf3 {-1.51/12 0.15s} Rc4 {+0.57/13 0.12s}
I'd love to by able to plot time per move for one game, or a mean time at move N for many games ... things like this.

Has anyone already script something ?
User avatar
xr_a_y
Posts: 1871
Joined: Sat Nov 25, 2017 2:28 pm
Location: France

Re: Time per move extraction tool

Post by xr_a_y »

I can make sh*t like this

Code: Select all

import chess.pgn
import matplotlib.pyplot as plt

pgn = open("test.pgn")
f = chess.pgn.read_game(pgn)
n = f.variations[0]
tt=[]
while n.variations:
    n = n.variations[0]
    l = n.comment.split(' ')
    if len(l) > 1:
        tt.append(float(l[1].replace('s','').replace(',','')))

print(tt)

plt.plot(tt)
plt.show()
But I guess there are already better things ...
User avatar
xr_a_y
Posts: 1871
Joined: Sat Nov 25, 2017 2:28 pm
Location: France

Re: Time per move extraction tool

Post by xr_a_y »

Or for a mean value

Code: Select all

import chess.pgn
import matplotlib.pyplot as plt

pgn = open("test.pgn")
f = chess.pgn.read_game(pgn)
a=[]
while f:
   n = f.variations[0]
   tt=[]
   while n.variations:
      n = n.variations[0]
      l = n.comment.split(' ')
      if len(l) > 1:
         tt.append(float(l[1].replace('s','').replace(',','')))
   #print(tt)
   a.append(tt)
   f = chess.pgn.read_game(pgn)

#print(a)

times = [0] * 1000
counts = [0] * 1000
for g in a:
    for n,t in enumerate(g):
        #print(n)
        #print(t)
        times[n] += t
        counts[n] += 1

#print(times)
#print(counts)

for n,t in enumerate(times):
    if counts[n]:
       times[n] /= counts[n]

plt.plot([x for x in times if x])
plt.savefig('time.png')
plt.show()

but I'm ashamed of this script ... :oops: :oops:
User avatar
xr_a_y
Posts: 1871
Joined: Sat Nov 25, 2017 2:28 pm
Location: France

Re: Time per move extraction tool

Post by xr_a_y »

This gives this for current Minic
In second for games at TC 30s+0.3 ...

Image
User avatar
xr_a_y
Posts: 1871
Joined: Sat Nov 25, 2017 2:28 pm
Location: France

Re: Time per move extraction tool

Post by xr_a_y »

I'm now able to compare many engine time control, and see that there are more or less all the same, or at least results in the same behaviour

Still very dirty python ... sorry :oops: :oops:

Code: Select all

import chess.pgn
import matplotlib.pyplot as plt

def getData(engine,data):

   print("Engine : " + engine)

   pgn = open("test.pgn")
   f = chess.pgn.read_game(pgn)
   a=[]
   c = 0
   while f:
      if c%100 is 0:
          print('.')
      c+=1
      #print(f.headers["White"])
      #print(f.headers["Black"])
      if e in f.headers["White"]:
         n = f.variations[0]
         tt=[]
         p=0
         while n.variations:
            n = n.variations[0]
            p+=1
            if p%2 is 0:
                continue
            l = n.comment.split(' ')
            if len(l) > 1:
               try:
                  tt.append(float(l[1].replace('s','').replace(',','')))
               except:
                  print("error treating " + ' '.join(l))
         #print(tt)
         a.append(tt)
      if e in f.headers["Black"]:
         n = f.variations[0]
         tt=[]
         p=0
         while n.variations:
            n = n.variations[0]
            p+=1
            if p%2 is 1:
                continue
            l = n.comment.split(' ')
            if len(l) > 1:
               try:
                  tt.append(float(l[1].replace('s','').replace(',','')))
               except:
                  print("error treating " + ' '.join(l))
         #print(tt)
         a.append(tt)         
      f = chess.pgn.read_game(pgn)

   #print(a)

   data[engine] = {}
   data[engine]['times'] = [0] * 1000
   counts = [0] * 1000
   for g in a:
      for n,t in enumerate(g):
         #print(n)
         #print(t)
         data[engine]['times'][n] += t
         counts[n] += 1

   #print(data[engine]['times'])
   #print(counts)

   for n,t in enumerate(data[engine]['times']):
      if counts[n]:
         data[engine]['times'][n] /= counts[n]

   data[engine]['remaining'] = [0] * 1000
   data[engine]['remaining'][0] = 30 

   for n,t in enumerate(data[engine]['times']):
      if n > 0:
         data[engine]['remaining'][n] = data[engine]['remaining'][n-1] - data[engine]['times'][n] + 0.3
      if counts[n] is 0:
         break

data = {}
engines = ["igel", "minic_2.15", "minic_2.12", "texel", "Rubi", "demolito", "Winter", "Topple", "PeSTO", "rodent", "Vajolet"]
for e in engines:
   getData(e, data)
   plt.plot([x for x in data[e]['times'] if x])
plt.legend(engines)   
plt.savefig('time.png')
plt.show()

for e in engines:
   plt.plot([x for x in data[e]['remaining'][:100] if x])
plt.legend(engines)   
plt.savefig('rtime.png')
plt.show()
voffka
Posts: 288
Joined: Sat Jun 30, 2018 10:58 pm
Location: Ukraine
Full name: Volodymyr Shcherbyna

Re: Time per move extraction tool

Post by voffka »

I see Igel is involved :) What's it's time per move? I never tested time really well, just went with a hunch in my formulas.
Terje
Posts: 347
Joined: Tue Nov 19, 2019 4:34 am
Location: https://github.com/TerjeKir/weiss
Full name: Terje Kirstihagen

Re: Time per move extraction tool

Post by Terje »

Any outliers? Graphs could be very cool ;)
User avatar
xr_a_y
Posts: 1871
Joined: Sat Nov 25, 2017 2:28 pm
Location: France

Re: Time per move extraction tool

Post by xr_a_y »

https://ibb.co/ryxTydn
https://ibb.co/bNyyfrM

Everyone is more or less the same ! this is time per move and remaining time for 30+0.3 TC