-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtag.py
112 lines (93 loc) · 3.36 KB
/
tag.py
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
import logging, os, sys
import common as gc
import gamerep as gamerep
LOGGER = logging.getLogger(__name__)
def is_opening(matchid):
pips_pair = gamerep.position_id_to_pips(matchid)
if all(pips > 145 for pips in pips_pair):
return True
def is_closing(matchid):
pips_pair = gamerep.position_id_to_pips(matchid)
if all(pips < 70 for pips in pips_pair):
return True
def is_midgame(matchid):
pips_pair = gamerep.position_id_to_pips(matchid)
if all(100 < pips < 120 for pips in pips_pair):
return True
def is_backgame(matchid):
if gc.is_nocontact(matchid):
return False
points = gamerep.position_id_to_points(matchid)[25:]
opp_pips, player_pips = gamerep.position_id_to_pips(matchid)
board = points[-7:-1]
if (sum(1 for point in board if point >= 2) >= 2
and player_pips - opp_pips >= 55):
return True
def is_backgameopp(matchid):
if gc.is_nocontact(matchid):
return False
points = gamerep.position_id_to_points(matchid)[:25]
opp_pips, player_pips = gamerep.position_id_to_pips(matchid)
board = points[-7:-1]
if (sum(1 for point in board if point >= 2) >= 2
and opp_pips - player_pips >= 55):
return True
def is_holding(matchid):
if gc.is_nocontact(matchid):
return False
points = gamerep.position_id_to_points(matchid)[25:]
opp_pips, player_pips = gamerep.position_id_to_pips(matchid)
board = points[-8:-3]
if (sum(1 for point in board if point >= 2) == 1
and player_pips - opp_pips >= 55):
return True
def is_holdingopp(matchid):
if gc.is_nocontact(matchid):
return False
points = gamerep.position_id_to_points(matchid)[:25]
opp_pips, player_pips = gamerep.position_id_to_pips(matchid)
board = points[-8:-3]
if (sum(1 for point in board if point >= 2) == 1
and opp_pips - player_pips >= 55):
return True
if __name__ == '__main__':
with gc.get_conn() as conn:
def add_tag(matchid, tag):
print('Called add_tag with %s and %s' % (matchid, tag))
insert_tag_sql = '''
insert into postags
(posmatchid, tag, createdat)
values
(%s, %s, current_timestamp)
'''
conn.execute(insert_tag_sql, [matchid, tag])
TAG_SQL = '''
select tag, donetagging
from tags
order by tag
'''
tags_to_process = [
tag
for tag, donetagging
in conn.execute(TAG_SQL)
if donetagging != '1'
]
if len(tags_to_process) == 0:
sys.exit()
SQL = '''
select
posmatchid
from posmatchids
where 1=1
'''
rs = conn.execute(SQL)
for rowi, row in enumerate(rs):
posmatchid = row[0]
for tag in tags_to_process:
func = globals()['is_' + tag]
if func(posmatchid):
add_tag(posmatchid, tag)
if rowi % 500 == 0:
print(rowi)
conn.commit()
conn.execute('update tags set donetagging = 1')