-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path18-getGamesBySystem.py
118 lines (99 loc) · 4.18 KB
/
18-getGamesBySystem.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
113
114
115
116
117
118
# -*- coding: utf-8 -*-
import sys
from datetime import date, datetime, timedelta
import openpyxl
import json
import click
from utils import *
from models import db, objects
dbConnection = db.Database()
breaksDB = dbConnection.connect()
systemsObj = objects.Systems(breaksDB)
@click.command()
@click.option(
'-s', '--system',
help = "System to get games", type = str, default = "New Age IV", show_default = True
)
@click.option(
'-m', '--month',
help = "Month to get system games", type = str, default = date.today().strftime("%Y-%m"), show_default = True
)
def printGamesBySystem(system, month):
# Get system data
with open("parameters.json") as content:
parameters = json.load(content)
systemName = system
period = next(item for item in parameters['periods'] if item['keyword'] == month)
firstRow = period['first-row']
lastRow = period['last-row']
for systemJSON in parameters['systems']:
if systemName in systemJSON['name']:
system = systemJSON
break
# Open Workbook
workbook = openpyxl.load_workbook(filename = "Breaks 1r set.xlsx", read_only = True)
# Get Sheet Object by names
sheet = workbook['Break']
for row in sheet.iter_rows(min_row = firstRow, max_row = lastRow):
rowNumber = row[0].row
if row[0].value is not None:
date = row[0].value
if not rowNumber in parameters['jump']:
valid = True
for criteria in parameters['dismiss']:
column = ord(criteria['col']) - 65
if criteria['operator'] == "=":
if row[column].value == criteria['value']:
valid = False
break
elif criteria['operator'] == "<":
if row[column].value < criteria['value']:
valid = False
break
elif criteria['operator'] == ">":
if row[column].value > criteria['value']:
valid = False
break
elif criteria['operator'] == ">=":
if row[column].value >= criteria['value']:
valid = False
break
elif criteria['operator'] == "<>":
if row[column].value != criteria['value']:
valid = False
break
if valid:
validForSystem = False
for conditionGroup in system['conditions']:
numConditions = len(conditionGroup)
satisfiedConditions = 0
for condition in conditionGroup:
column = ord(condition['col']) - 65
if condition['operator'] == "=":
if row[column].value == condition['value']:
satisfiedConditions += 1
elif condition['operator'] == "<":
if row[column].value < condition['value']:
satisfiedConditions += 1
elif condition['operator'] == ">":
if row[column].value > condition['value']:
satisfiedConditions += 1
elif condition['operator'] == ">=":
if row[column].value >= condition['value']:
satisfiedConditions += 1
elif condition['operator'] == "<>":
if row[column].value != condition['value']:
satisfiedConditions += 1
if numConditions == satisfiedConditions:
validForSystem = True
break
if validForSystem:
game = {}
game['date'] = date
game['player'] = row[4].value
game['opponent'] = row[5].value
game['odd'] = row[10].value
game['result'] = row[14].value
print(game)
if __name__ == '__main__':
printGamesBySystem()