-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathcartesian
More file actions
executable file
·138 lines (102 loc) · 3.86 KB
/
cartesian
File metadata and controls
executable file
·138 lines (102 loc) · 3.86 KB
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#!/bin/python
import configparser
import argparse
import os
import sys
import json
import time
# Import Button Men utilities.
sys.path.append('lib')
import bmutils
def parse_arguments():
parser = argparse.ArgumentParser(description="Determine and create games for projects of completing certain cartesian products of play counts.")
parser.add_argument("specs",
nargs = "*",
help = "button or set names to include")
parser.add_argument("--limit",
default = 5,
help = "target game count")
parser.add_argument("--mirrors",
default = False,
help = "include mirror matches")
parser.add_argument("--include-active",
default = True,
help = "include active games")
parser.add_argument("--stale-threshold",
default = 14,
help = "days until a game is considered stale")
parser.add_argument('--site',
default = 'www',
help = "site to check ('www' by default)")
parser.add_argument('--config', '-c',
default='~/.bmrc',
help="config file containing site parameters")
return parser.parse_args()
def establish_conn(args):
try:
bmconn = bmutils.BMClientParser(os.path.expanduser(args.config), args.site)
except configparser.NoSectionError as e:
print("ERROR: {0} doesn't seem to have a '{1}' section".format(args.config, args.site))
print("(Exception: {0}: {1})".format(e.__module__, e.message))
sys.exit(1)
if not bmconn.verify_login():
print("ERROR: Could not log in to {0}".format(args.site))
sys.exit(1)
return bmconn
def count(bmconn, args, buttonA, buttonB):
completedCount = bmconn.client.search_game_history({
"buttonNameA": buttonA,
"buttonNameB": buttonB,
"status": "COMPLETE",
"sortColumn": "lastMove",
"sortDirection": "DESC",
"numberOfResults": 0,
"page": 1,
}).data["summary"]["matchesFound"]
if completedCount >= int(args.limit) or not args.include_active:
return completedCount
activeCount = bmconn.client.search_game_history({
"buttonNameA": buttonA,
"buttonNameB": buttonB,
"status": "ACTIVE",
"lastMoveMin": int(time.time() - (60 * 60 * 24 * args.stale_threshold)),
"sortColumn": "lastMove",
"sortDirection": "DESC",
"numberOfResults": 0,
"page": 1,
}).data["summary"]["matchesFound"]
return completedCount + activeCount
def load_buttons(bmconn, args):
allButtons = bmconn.wrap_load_button_names()
buttons = []
for spec in args.specs:
if spec in allButtons:
buttons.append(spec)
else:
data = bmconn.client.load_button_set_data(spec)
if data.status == "ok":
for button in data.data[0]["buttons"]:
buttons.append(button["buttonName"])
else:
raise RuntimeError("Unknown spec: " + spec)
return buttons
def main():
args = parse_arguments()
bmconn = establish_conn(args)
buttons = load_buttons(bmconn, args)
total = 0
for idx, buttonA in enumerate(buttons):
print(buttonA)
print("---")
for buttonB in buttons[idx:]:
if buttonA == buttonB and not args.mirrors:
continue
c = count(bmconn, args, buttonA, buttonB);
if c < int(args.limit):
total += int(args.limit) - c
print(buttonB, c)
print()
print(f"Total: {total}");
# print(json.dumps(bmconn.wrap_load_completed_games()))
if __name__ == "__main__":
main()