-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjuniors-dic.py
executable file
·185 lines (146 loc) · 5.61 KB
/
juniors-dic.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
#!/usr/bin/python
# Python version of RaceImport
# Restarted 8/23/15
# Steve
# opens defined file
# fills dictionary with run data
import os
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('-i', dest='infile', help="input file", metavar='INPUT_FILE')
parser.add_argument('-o', dest='outdir', help="output directory", metavar='OUTPUT_DIR')
args = parser.parse_args()
def Export_Left(rundata,outputfile):
with open(outputfile, 'a') as out:
out.write("insert into RunDetailJuniors (RaceNum, RaceDateTime, Class, RunType, ")
out.write("Lane, CarNo, DriverName, DialIn, Reaction, ")
out.write("60ft, MPH, Margin, OffDial, Result, ET) Values ")
out.write("('%s', '%s', '%s', '%s', " % (rundata['Num'].strip(),rundata['DateTime'].strip(),rundata['RaceClass'].strip(),rundata['Type'].strip()) )
out.write("'%s', '%s', '%s', '%s', '%s', " % ('L', rundata['LeftNum'].strip(), rundata['LeftName'].strip(), rundata['LeftDial'].strip(), rundata['LeftReaction'].strip()) )
out.write("'%s', '%s', '%s', " % (rundata['Left60FT'].strip(), rundata['LeftMPH'].strip(),rundata['LeftMargin'].strip()))
out.write("'%s', '%s', '%s')\n" % (rundata['LeftOffDial'].strip(), rundata['LeftResult'].strip(), rundata['LeftET'].strip()) )
out.close()
def Export_Right(rundata,outputfile):
with open(outputfile, 'a') as out:
out.write("insert into RunDetailJuniors (RaceNum, RaceDateTime, Class, RunType, ")
out.write("Lane, CarNo, DriverName, DialIn, Reaction, ")
out.write("60ft, MPH, Margin, OffDial, Result, ET) Values ")
out.write("('%s', '%s', '%s', '%s', " % (rundata['Num'].strip(),rundata['DateTime'].strip(),rundata['RaceClass'].strip(),rundata['Type'].strip()) )
out.write("'%s', '%s', '%s', '%s', '%s', " % ('R', rundata['RightNum'].strip(":"), rundata['RightName'].strip(), rundata['RightDial'].strip(), rundata['RightReaction'].strip()) )
out.write("'%s', '%s', '%s', " % (rundata['Right60FT'].strip(), rundata['RightMPH'].strip(),rundata['RightMargin'].strip()))
out.write("'%s', '%s', '%s')\n" % (rundata['RightOffDial'].strip(), rundata['RightResult'].strip(), rundata['RightET'].strip()) )
out.close()
def ProcessRun(rundata,outputfileLeft,outputfileRight):
Export_Left(rundata,outputfileLeft)
Export_Right(rundata,outputfileRight)
WriteLastRunNum(LastRunFile,rundata['Num'])
run.clear()
def LastRunNumFile(infilename,outdir):
logfile=os.path.basename(infilename)
RunNumFile=os.path.splitext(logfile)[0]
RunNumFile = outdir + RunNumFile + '.last'
return RunNumFile
def WriteLastRunNum(outfile,runnum):
with open(outfile,"w") as out:
out.write(runnum + '\n')
out.close()
def ReadLastRunNum(runfile):
if os.path.exists(runfile):
with open(runfile,"r") as runin:
lastrun = runin.read()
return int(lastrun)
else:
return 0
run={}
LastRunFile=LastRunNumFile(args.infile,args.outdir)
LastRun=ReadLastRunNum(LastRunFile)
print(LastRun)
with open(args.infile,"r") as infile:
for line in infile:
# Run Number
if line.find("RUN:",0) > -1:
run['Num']=line[4:9]
run['DateTime']=line[13:36]
outfileLeft = args.outdir + run['Num'].strip() + 'L.sql'
outfileRight = args.outdir + run['Num'].strip() + 'R.sql'
# Round, Class, and Type
if line.find("RD#",0) > -1:
run['RaceClass']=line[0:19]
run['Round']=line[28:36]
run['Type']=line[19:27]
# Car Numbers. Advances line and takes names
if line.find("LEFT:",0) > -1:
run['LeftNum']=line[5:17]
run['RightNum']=line[33:36]
line = next(infile)
run['LeftName']=line[0:17]
run['RightName']=line[18:36]
# Dial Ins
if line.find("DIAL IN",0) > -1:
run['LeftDial']=line[0:7]
run['RightDial']=line[28:36]
# Reaction
if line.find("REACTION",0) > -1:
run['LeftReaction']=line[0:7]
run['RightReaction']=line[28:36]
# 60 Ft
if line.find("60 FT",0) > -1:
run['Left60FT']=line[0:7]
run['Right60FT']=line[28:36]
# ET
if line.find("300 ET",0) > -1:
run['LeftET']=line[0:7]
run['RightET']=line[28:36]
# MPH
if line.find("300 MPH",0) > -1:
run['LeftMPH']=line[0:7]
run['RightMPH']=line[28:36]
# Margin and Result
if line.find("FINISH MARGIN",0) > -1:
run['LeftMargin']=line[0:7]
run['RightMargin']=line[28:36]
line = next(infile)
if line.find("OFF DIAL",0) > -1:
run['LeftOffDial']=line[0:7]
run['RightOffDial']=line[28:36]
line = next(infile)
run['LeftResult']=line[0:17]
run['RightResult']=line[18:36]
if int(run['Num']) > LastRun:
ProcessRun(run,outfileLeft,outfileRight)
else:
run['LeftOffDial']='0'
run['RightOffDial']='0'
run['LeftResult']=line[0:17]
run['RightResult']=line[18:36]
if int(run['Num']) > LastRun:
ProcessRun(run,outfileLeft,outfileRight)
# Export_Left(run,outfileLeft)
# Export_Right(run,outfileRight)
#print(run['RaceClass'])
#run.clear()
# Section to print contents of dictionary
# really only here for testing
# with open(outfilename,'a') as outfile:
# for key in run:
# if key == 'RightNum':
# outfile.write(key + '=' + run[key].strip(':') + '\n')
# elif key == 'Round':
# outfile.write(key + '=' + run[key].strip('RD# ') + '\n')
# else:
# outfile.write(key + '=' + run[key].strip() + '\n')
# with open(outfilename,'a') as outfile:
# print run['RaceCls']
# Empty this run from dictionary
# print outfilename
# print run['Num'].strip()
# print run['DateTime'].strip()
# print run['Class'].strip()
# print run['Round'].strip('RD# ')
# print run['Type'].strip()
# print run['LeftNum']
# print run['RightNum'].strip(':')
# print run['LeftName'].strip()
# print run['RightName'].strip()
# Close log file
infile.close()