|
Revision 236, 1.7 kB
(checked in by ug, 2 years ago)
|
Fixed some issues with creating the frequency db.
|
- Property svn:executable set to
|
| Line | |
|---|
| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
import os |
|---|
| 5 |
import os.path |
|---|
| 6 |
import sys |
|---|
| 7 |
import glob |
|---|
| 8 |
import time |
|---|
| 9 |
from libkombilo import * |
|---|
| 10 |
|
|---|
| 11 |
try: |
|---|
| 12 |
os.system('rm t1.db*') |
|---|
| 13 |
except: |
|---|
| 14 |
pass |
|---|
| 15 |
|
|---|
| 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""" |
|---|
| 19 |
|
|---|
| 20 |
starttime = time.time() |
|---|
| 21 |
try: |
|---|
| 22 |
pop = ProcessOptions() |
|---|
| 23 |
pop.algos = ALGO_FINALPOS | ALGO_MOVELIST | ALGO_HASH_CENTER |
|---|
| 24 |
|
|---|
| 25 |
pop.sgfInDB = False |
|---|
| 26 |
gl = GameList('t1.db', 'id', '', pop, 1000) |
|---|
| 27 |
except DBError: |
|---|
| 28 |
print 'Database error' |
|---|
| 29 |
gl.start_processing() |
|---|
| 30 |
counter = 0 |
|---|
| 31 |
for filename in filenames: |
|---|
| 32 |
|
|---|
| 33 |
counter += 1 |
|---|
| 34 |
try: |
|---|
| 35 |
file = open(filename) |
|---|
| 36 |
sgf = file.read() |
|---|
| 37 |
file.close() |
|---|
| 38 |
except: |
|---|
| 39 |
print 'Unable to read file %s' % filename |
|---|
| 40 |
continue |
|---|
| 41 |
|
|---|
| 42 |
path, fn = os.path.split(filename) |
|---|
| 43 |
gl.process(sgf, path, fn) |
|---|
| 44 |
gl.finalize_processing() |
|---|
| 45 |
print 'Processed %d games in %.2f seconds' % (counter, time.time()-starttime) |
|---|
| 46 |
|
|---|
| 47 |
|
|---|
| 48 |
|
|---|
| 49 |
|
|---|
| 50 |
|
|---|
| 51 |
|
|---|
| 52 |
for path in ['/home/ug/go/gogod06/*/*.sgf', '/home/ug/go/KGS/*/*.sgf']: |
|---|
| 53 |
filelist = glob.glob(path) |
|---|
| 54 |
filelist.sort() |
|---|
| 55 |
process(filelist) |
|---|
| 56 |
|
|---|
| 57 |
gl = GameList("t1.db", "id", "[[filename.]], ") |
|---|
| 58 |
|
|---|
| 59 |
|
|---|
| 60 |
|
|---|
| 61 |
|
|---|
| 62 |
|
|---|
| 63 |
|
|---|
| 64 |
|
|---|
| 65 |
|
|---|
| 66 |
|
|---|
| 67 |
|
|---|
| 68 |
|
|---|