-
Notifications
You must be signed in to change notification settings - Fork 1
/
matchMerger.py
90 lines (67 loc) · 2.75 KB
/
matchMerger.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
# -*- coding: utf-8 -*-
"""
Created on Mon Oct 20 15:03:09 2014
@author: Gaspard
"""
import re
from bdd import *
from utils import *
from ForexCrawler import *
class MatchMerger:
def __init__(self,fs):
self.matchesFolder = fs.matchesFolder
self.targetPath = fs.matchesPath
self.cleanMatchesPath= fs.cleanMatchesPath
self.tournaments = None
self.ID = 0
def startMerging(self, tournaments):
chrono = Chrono()
size = len(tournaments)
with open( self.targetPath , 'wb') as f:
w = getMatchWriter(f)
chrono.start(size)
for t in tournaments:
writeTournament(w, self.load( int(t['e']) , int(t['y'])))
chrono.tick()
if chrono.i % 20 == 0:
printLine("Tournaments " + str(chrono.i) + " / " + str(size) +
chrono.getBar() + " Remaining: " + chrono.remaining() )
self.ID += 1
print # New line after loading bar
def getPath(self, e, y):
return self.matchesFolder + "y" + str(y) + "e" + str(e)
def load(self, e, y):
r = []
try:
with open( self.getPath(e, y)+".csv", 'rb') as f:
r = getReader(f)
except:
printError("Missing tournament: y " + str(y) + " | e " + str(e) )
return r
def clean(self, chrono):
self.ID = 0
with open( self.cleanMatchesPath + "id" , 'wb') as f:
w = getWriter(f, match_field_names_clean)
with open(self.targetPath, 'rb') as f2:
for e in csv.DictReader(f2, restval='?', delimiter='|'):
w.writerow( self.defaultMatchCleanFunction(e) )
chrono.tick()
if chrono.needPrint():
debugCL("Matches " + str(chrono.i) + " Elapsed: " + chrono.elapsed() )
def defaultMatchCleanFunction(self, entry):
e = self.tournaments[ int(entry['IDTournament']) ]['e']
cat = int( entry['TournamentCategory'] )
entry['TournamentCategory'] = updateCategory(e,cat)
a = re.findall('([^0-9]+)([0-9]*)', entry['TournamentPrize'] )
currency = currencyName[a[0][0]]
entry['TournamentPrize'] = int( a[0][1] )
entry['TournamentCurrency'] = currency
conversion = forexDate( entry['TournamentStart'], currency)
entry['TournamentPrizeUSD'] = int( float(entry['TournamentPrize']) / conversion )
nullStats = 0
for s in match_stats_field_names:
nullStats += int( int(entry[s]) == 0 )
entry['NullStats'] = nullStats
entry['IDMatch'] = self.ID // 2
self.ID += 1
return entry