Repository navigation
Expand file tree
/
Copy path08-analyzeBreakData.py
More file actions
122 lines (101 loc) · 5.12 KB
/
Copy path08-analyzeBreakData.py
File metadata and controls
122 lines (101 loc) · 5.12 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
# -*- coding: utf-8 -*-
from __future__ import division
import os
import socket
from datetime import date, datetime, timedelta
import click
import tennisExplorer
from utils import *
from models import db, objects
dbConnection = db.Database()
breaksDB = dbConnection.connect()
playersObj = objects.Players(breaksDB)
gamesObj = objects.Games(breaksDB)
@click.command()
@click.option(
'-d', '--day',
help = "Date to analyze break data", type = str, default = date.today().strftime("%Y-%m-%d"), show_default = True
)
@click.option(
'-s', '--sex',
help = "Sex players to analyze break data", type = str, default = "M", show_default = True
)
def analyzeBreakData(day, sex):
sexKeywords = {'M': 'men', 'W': 'women'}
dailyGames = tennisExplorer.getDailyGames(day, sexKeywords[sex])
gamesToAnalyze = []
gamesObj.delete([{'gameDay': day}, {'sex': sex}])
for game in dailyGames:
print("-> Analyzing game ({} vs {})...".format(game['player1'], game['player2']))
player = playersObj.read(game['player1'])
opponent = playersObj.read(game['player2'])
playerData = {
'totalGames': 0,
'definedGames': 0,
'totalBreaksDone': 0,
'probability': 0.0
}
opponentData = {
'totalGames': 0,
'definedGames': 0,
'totalBreaksReceived': 0,
'probability': 0.0
}
if player is not None and "lastGames" in player:
for previousGame in player['lastGames']:
if playerData['totalGames'] == 5 and playerData['totalBreaksDone'] < 3 or playerData['totalGames'] >= 5 and previousGame['breakDone'] < 1:
break
else:
playerData['totalGames'] += 1
if "breakDone" in previousGame and "breakReceived" in previousGame:
if previousGame['breakDone'] > -1:
playerData['definedGames'] += 1
if previousGame['breakDone'] == 1:
playerData['totalBreaksDone'] += 1
if playerData['totalGames'] > 0:
playerData['probability'] = round(playerData['totalBreaksDone'] * 100 / playerData['totalGames'], 2)
else:
playerData['probability'] = 0.0
#print(playerData['probability'])
if opponent is not None and "lastGames" in opponent:
for previousGame in opponent['lastGames']:
if opponentData['totalGames'] == 5 and opponentData['totalBreaksReceived'] < 3 or opponentData['totalGames'] >= 5 and previousGame['breakReceived'] < 1:
break
else:
opponentData['totalGames'] += 1
if "breakDone" in previousGame and "breakReceived" in previousGame:
if previousGame['breakReceived'] > -1:
opponentData['definedGames'] += 1
if previousGame['breakReceived'] == 1:
opponentData['totalBreaksReceived'] += 1
if opponentData['totalGames'] > 0:
opponentData['probability'] = round(opponentData['totalBreaksReceived'] * 100 / opponentData['totalGames'], 2)
else:
opponentData['probability'] = 0.0
#print(opponentData['probability'])
avgProbability = round((playerData['probability'] + opponentData['probability']) / 2, 2)
#print(avgProbability)
if playerData['totalGames'] >= 5 and opponentData['totalGames'] >= 5 and avgProbability > 70 and playerData['probability'] >= 60 and opponentData['probability'] >= 60:
profitable = True
else:
profitable = False
gameDocument = {'sex': sex, 'tournament': game['tournament'], 'gameDay': day, 'player1ID': player['_id'], 'FS-player1': player['flashScoreName'], 'TE-player1': player['tennisExplorerName'], 'player2ID': opponent['_id'], 'FS-player2': opponent['flashScoreName'], 'TE-player2': opponent['tennisExplorerName'], 'playerData': playerData, 'opponentData': opponentData, 'probability': avgProbability, 'profitable': profitable}
gamesObj.create(gameDocument)
if profitable:
gamesToAnalyze.append(gameDocument)
printCollection(gamesToAnalyze)
currentTime = datetime.now().strftime('%H:%M')
tomorrow = (datetime.now() + timedelta(days=1)).strftime('%Y-%m-%d')
machineName = socket.gethostname()
currentPath = os.path.dirname(os.path.abspath(__file__))
print('Current path: {}'.format(currentPath))
if machineName == 'juxtelab-pc':
pythonPath = 'python'
else:
pythonPath = '/root/.virtualenvs/breaks/bin/python'
if currentTime < '12:00':
os.system('python {}/10-checkOdds.py > /tmp/breaks-10M.log 2>&1'.format(currentPath))
else:
os.system('python {}/10-checkOdds.py -d {} > /tmp/breaks-10M.log 2>&1'.format(currentPath, tomorrow))
if __name__ == '__main__':
analyzeBreakData()