OJD database committing support
[eidogo-ojd.git] / kombilo / process.py
blob1bc1ffd87dd3beb8ead98d91cf872bbc1a5cdd3d
1 #! /usr/bin/env python2.4
3 # from pysqlite2 import dbapi2
4 import os
5 import os.path
6 import sys
7 import glob
8 import time
9 from libkombilo import *
11 try:
12 os.system('rm t1.db*')
13 except:
14 pass
16 def process(filenames):
17 """Process a list of sgf files, put the game info into "table" of the database
18 given by con, and call the relevant processing functions for the algorithms in algos"""
20 starttime = time.time()
21 try:
22 pop = ProcessOptions()
23 # pop.algos = 0
24 # pop.rootNodeTags = 'PW,PB,RE,DT'
25 pop.sgfInDB = False
26 pop.algos = ALGO_FINALPOS | ALGO_MOVELIST
27 gl = GameList('t1.db', 'id', '', pop, 100)
28 except DBError:
29 print 'Database error'
30 gl.start_processing()
31 counter = 0
32 i = 0;
33 for filename in filenames:
34 i += 1
35 if i % 4 != 0:
36 continue
37 # print filename
38 try:
39 file = open(filename)
40 sgf = file.read()
41 file.close()
42 except:
43 print 'Unable to read file %s' % filename
44 continue
46 path, fn = os.path.split(filename)
47 if gl.process(sgf, path, fn, '', CHECK_FOR_DUPLICATES_STRICT):
48 if gl.process_results() & IS_DUPLICATE:
49 print 'duplicate', counter
50 else: print 'SGF error'
51 counter += 1
53 gl.finalize_processing()
54 print 'Processed %d games in %.2f seconds' % (counter, time.time()-starttime)
56 # filelist = glob.glob('./*.sgf')
57 # filelist = glob.glob('/home/ug/go/KGS2005/*.sgf')
58 # filelist = glob.glob('/Users/tin/Sites/eidogo/sgf/downloaded/Honinbo/*.sgf')
59 filelist = glob.glob('/Users/tin/Sites/eidogo/sgf/games/*.sgf')
61 filelist.sort()
62 process(filelist)
64 gl = GameList("t1.db", "id", "")
66 # .X.
67 # .OX
68 # .OX
69 # .OX
70 # OXO
71 p = Pattern(CENTER_PATTERN, 19, 3, 5, ".X..OX.OX.OXOXO")
72 so = SearchOptions()
74 gl.reset()
75 gl.search(p, so)
77 for i in range(gl.size())[-10:]:
78 print gl.currentEntryAsString(i)