-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
219 lines (176 loc) · 6.72 KB
/
main.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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
# -*- coding: utf-8 -*-
"""
Created on Mon Oct 06 09:16:48 2014
@authors: Gaspard, Thomas
"""
import sys
from utils import *
from tournamentCrawler import *
from matchCrawler import *
from bdd import *
from playerCrawler import *
from tournamentInfoCrawler import *
from seasonCrawler import *
from matchMerger import *
from ATPRankCrawler import *
from ATPRankings import *
from FileSystem import *
infoReader = InfoReader('localurl.txt')
fs = FileSystem(infoReader) # reads 4 lines
yearStart = infoReader.readInt()
yearEnd = infoReader.readInt()
tournamentTypes = infoReader.readIntList()
sleepingTime = infoReader.readInt()
CrawlingSeasons = infoReader.readBool()
CrawlingTournaments = infoReader.readBool()
CrawlPlayers = infoReader.readBool()
CrawlATPRanks = infoReader.readBool()
CrawlMatches = infoReader.readBool()
MergeMatches = infoReader.readBool()
CleaningTournaments = infoReader.readBool()
CleaningPlayers = infoReader.readBool()
CleaningMatches = infoReader.readBool()
AddRankings = infoReader.readBool()
debugMode = infoReader.readBool()
refreshTime = infoReader.readInt()
print "Initialisation: Done."
def mainBody():
debug("Initialisation...")
clock = Clock()
clock.clock()
seasons = Seasons( fs )
tournaments = Tournaments( fs )
players = Players( fs )
matchCrawler= Matches( fs )
matchMerger = MatchMerger( fs )
atpRank = ATPRank( fs )
atpRankings = ATPRankings( fs )
chrono = Chrono()
chrono.periodTime = refreshTime * 0.001
clock.done()
if CrawlingSeasons:
debug("Looking for all tournaments (types " + str(tournamentTypes) +
") from " + str(yearStart) + " to " + str(yearEnd) + "...")
seasons.addTournamentsFromAllTY( tournamentTypes, yearStart, yearEnd )
debug("Saving information...")
seasons.saveCodes( )
else:
debug("Loading all tournaments (types " + str(tournamentTypes) +
") from " + str(yearStart) + " to " + str(yearEnd) + "...")
seasons.loadCodes()
lengthTour = str( len(seasons.codes) )
clock.done()
debug("Found: " + lengthTour + " tournaments")
if tournaments.canLoad():
debug("Loading...")
tournaments.load()
if CrawlingTournaments:
debug("Crawling all tournaments (types " + str(tournamentTypes) +
") from " + str(yearStart) + " to " + str(yearEnd) + "...")
chrono.start( int(lengthTour) )
for code in seasons.codes:
tournaments.addTournamentFromCode(code)
chrono.tick()
if chrono.needPrint():
debugCL("Tournaments " + str(chrono.i) + " / " + lengthTour +
" treated. Players found: " + str(len(tournaments.playerCodes)) +
" Remaining: " + chrono.remaining() )
# chrono.printRemaining()
tournaments.save()
print
clock.done()
numberPlayers = len(tournaments.playerCodes)
debug("Found: " + str(numberPlayers) + " players" )
if players.canLoad():
debug("Loading players...")
players.load()
if CrawlPlayers:
debug("Looking for all " + str(numberPlayers) + " players...")
chrono.start( numberPlayers )
for code in tournaments.playerCodes:
if players.addInfoPlayer(code):
chrono.tick()
if chrono.needPrint(): chrono.printRemaining()
else:
chrono.decTotal()
players.save()
matchCrawler.dicoPlayers = players.dic
clock.done()
if CrawlMatches:
debug("Fetching informations for all matches...")
chrono.start( int(lengthTour) )
for t in tournaments.tournaments:
if matchCrawler.treatTournament( t ):
chrono.tick()
if chrono.needPrint(): chrono.printRemaining()
else:
chrono.decTotal()
debug("All tournaments: Done. " + clock.strClock())
if MergeMatches:
debug("Merging all tournaments...")
matchMerger.startMerging( tournaments.tournaments )
clock.done()
if CrawlATPRanks:
debug("Crawling all " + str(numberPlayers) + " ranking histories...")
chrono.start( numberPlayers )
for i in players.dic:
if atpRank.addATPRank( players.dic[i] ):
chrono.tick()
if chrono.needPrint(): chrono.printRemaining()
else:
chrono.decTotal()
clock.done()
if CleaningTournaments:
debug("Cleaning tournaments...")
tournaments.clean()
clock.done()
if CleaningPlayers:
debug("Cleaning players...")
players.clean()
clock.done()
matchMerger.tournaments = tournaments.tournaments
if CleaningMatches:
debug("Cleaning matches...")
chrono.start(0)
matchMerger.clean( chrono )
clock.done()
# atpRankings.playersNb = players.ID
atpRankings.playersNb = numberPlayers
atpRankings.tournaments = tournaments.tournaments
atpRankings.loadPlayedTournaments()
if AddRankings:
debug("Computing played tournaments...")
atpRankings.startFeedingMatches()
atpRankings.savePlayedTournaments()
clock.done()
debug("Computing rankings...")
atpRankings.startComputingRanks()
clock.done()
debug("Cleaning rankings...")
atpRankings.clean()
clock.done()
return True
clock = Clock()
clock.clock()
with open(fs.debugOut, 'a') as debugout:
setDebugFileOut(debugout)
if debugMode:
mainBody()
else:
keepOn = True
while keepOn:
keepOn = False
try :
mainBody()
except:
err = sys.exc_info()
printError("Error !!! " + str( err[0] ) )
printError("Detail: " + str( err[1] ) )
printError("Network error expected.")
debug("Going to sleep for " + str(sleepingTime) + " seconds...")
time.sleep( sleepingTime )
debug("Waking up !")
keepOn = True
debug("C'est fini !!!")
debug("Duration: " + clock.strClock())
debugPrintTime("End time:")