summaryrefslogtreecommitdiff
path: root/extract.sh
blob: 60e01f9d7ca4b7c980134c5229452e7ab26dab74 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/bin/bash

db_file=games_anon.db

query() {
		echo "SELECT $1 FROM games WHERE (size == $2) \
and (result != '1-0') and (result != '0-1') and (result != '0-0')\
and (result != '1/2-1/2');"
}

extract() {
		cd data
		if [ ! -f "$db_file" ]; then
				wget "https://www.playtak.com/games_anon.db"
		fi
		for size in 5 6; do
				echo Extracing games of size "$size"...
				sqlite3 "$db_file" "$(query $1 $size)" | shuf > "playtak-$size"
		done
}

process() {
		echo -e "Beginning to process data\n"
		for i in 5 6; do
				echo "Size $i..."
				./pptdb "$i" "data/playtak-$i" > "data/check-$i"
				tail -n21 "data/check-$i"
				echo Stripping overflows and illegal games...
				grep -Fvxf "data/check-$i" "data/playtak-$i" > "data/good-playtak-$i"
				echo -n "Generating training data... "
				./pptdb "$i" "data/good-playtak-$i" generate
				echo "Shuffling data..."
				shuf "data/training-$i.csv" > "data/shuf-$i.csv"
				mv "data/shuf-$i.csv" "data/training-$i.csv"
				echo
		done
}

# extract notation,result
if [ ! -f "pptdb" ]; then
		echo Preparing pptdb
		make pptdb
fi

# process

make pptdb
shuf -n10000 data/good-playtak-5 > data/smalltak-5 && ./pptdb 5 data/smalltak-5 generate && \
head -n1 data/training-5.csv > t && tail -n+2 data/training-5.csv > data/train5.csv && shuf data/train5.csv >> t && mv t data/train5.csv