def __init__(self, scheduleFileName, registrationFileName, numLanes=4): self.numLanes = numLanes self.numCars = 40 self.fileName = scheduleFileName if path.exists(self.fileName): self.prevSched = CsvReader.CSVReader(self.fileName) self.reg = CsvReader.CSVReader(registrationFileName)
def __init__(self, fileName): self.fileName = fileName self.loc = Lock() #the csv file has to use these column names as the first row. self.cols = ['regId', 'name', 'displayName', 'carNum', 'den'] #make sure no one else is using the file at the same time with self.loc: savedReg = CsvReader.CSVReader(fileName) self.regData = [] self.regIDDict = {} self.carNumDict = {} for i in range(len(savedReg.getRows())): r = savedReg.getRows()[i] participant = {} self.regIDDict[int(r[savedReg.nameToIndex('regId')])] = i self.carNumDict[r[savedReg.nameToIndex('carNum')]] = i for c in self.cols: index = savedReg.nameToIndex(c) if index >= 0: participant[c] = r[index] if 'regId' in c: participant[ 'edit'] = '<a href="/register?lookupRegId=' + participant[ 'regId'] + '">edit</a>' self.regData.append(participant)
def cars(): data = [] # other column settings -> http://bootstrap-table.wenzhixin.net.cn/documentation/#column-options raceSchedule = CsvReader.CSVReader('csv/raceSchedule.csv') columns = [ getTableColSettingsWithCookie('cars', 'car#', 'car#'), getTableColSettingsWithCookie('cars', 'name', 'name'), getTableColSettingsWithCookie('cars', 'den', 'den'), getTableColSettingsWithCookie('cars', 'min', 'min'), getTableColSettingsWithCookie('cars', 'avg', 'avg'), getTableColSettingsWithCookie('cars', 'totalPoints', 'totalPoints'), getTableColSettingsWithCookie('cars', 'totalTime', 'totalTime'), getTableColSettingsWithCookie('cars', 'stdev', 'stdev') ] columnsDen = [ getTableColSettingsWithCookie('cars', 'den', 'den'), getTableColSettingsWithCookie('cars', 'avg', 'avg') ] count = 0 for h in raceSchedule.getHeader(): if 'car' in h: count = count + 1 columns.append( getTableColSettingsWithCookie('cars', 'heat#' + str(count), 'heat#')) columns.append( getTableColSettingsWithCookie('cars', 'pos' + str(count), 'pos')) columns.append( getTableColSettingsWithCookie('cars', 'time' + str(count), 'time')) return render_template("cars.html", columns=columns, columnsDen=columnsDen, title='Welcome to the Pinewood Derby!')
def initLanes(self, updateExisting=False): self.lanes = [] for i in range(0, self.numLanes): self.lanes.append([]) cars = [] if path.exists(self.fileName) and updateExisting: prevSched = CsvReader.CSVReader(self.fileName) carHeaders = ['car1#', 'car2#', 'car3#', 'car4#'] for r in prevSched.rows: if len(r[prevSched.headerToIndex['timestamp']]) > 2: for i in range(1, self.numLanes + 1): h = 'car' + str(i) + '#' if h in prevSched.headerToIndex: carNum = int(r[prevSched.headerToIndex[h]]) cars.append(carNum) self.lanes[i - 1].append(carNum) return cars
def __init__(self, fileName): self.raceSchedule = CsvReader.CSVReader(fileName)
def get_schedule(): raceSchedule = CsvReader.CSVReader('csv/raceSchedule.csv') timeIndex = [] fastestTimes = [] i = 0 for col in raceSchedule.getHeader(): if 'time' in col and not 'timestamp' in col: timeIndex.append(i) fastestTimes.append(999999) i += 1 for heat in raceSchedule.getRows(): for i in range(len(timeIndex)): try: fastestTimes[i] = min(fastestTimes[i], float(heat[timeIndex[i]])) except: pass data = [] columns = [] colCount = {} for col in raceSchedule.getHeader(): if 'car' in col: if not 'name' in colCount: colCount['name'] = 0 else: colCount['name'] += 1 columns.append( getTableColSettingsWithCookie( 'index', str(colCount['name'] + 1), '<b>' + str(colCount['name'] + 1) + '</b>')) columns.append( getTableColSettingsWithCookie('index', 'name' + str(colCount['name']), 'name')) columns.append( getTableColSettingsWithCookie('index', 'result' + str(colCount['name']), 'result')) if not col in colCount: colCount[col] = 0 else: colCount[col] += 1 columns.append( getTableColSettingsWithCookie('index', col + str(colCount[col]), col)) for heat in raceSchedule.getRows(): heatInfo = {} colCount = {} curLane = 0 curPos = "" for i in range(len(heat)): col = raceSchedule.getColumnName(i) if not col in colCount: colCount[col] = 0 else: colCount[col] += 1 heatInfo.update({col + str(colCount[col]): heat[i]}) if 'car' in col: if not 'name' in colCount: colCount['name'] = 0 else: colCount['name'] += 1 curLane = colCount['name'] + 1 heatInfo[str(curLane)] = '<b>' + str(curLane) + '</b>' participant = registration.getParticipantFromCar(heat[i]) if len(participant) > 0: heatInfo['name' + str(colCount['name'])] = participant[ 'name'] + ' (' + participant['carNum'] + ')' else: heatInfo[ 'name' + str(colCount['name'])] = '?' + ' (' + heat[i] + ')' if 'pos' in col: curPos = heat[i] if 'time' == col: if '-' in curPos or curPos == ' ' or curPos == '': result = '-' else: result = curPos + ' <i>(' + heat[i] + ')</i>' heatInfo['result' + str(curLane - 1)] = result data.append(heatInfo) return jsonify(data)
def homepage(): raceSchedule = CsvReader.CSVReader('csv/raceSchedule.csv') timeIndexes = [] fastestTimes = [] for i in range(0, len(raceSchedule.getHeader())): if 'time' in raceSchedule.getHeader( )[i] and not 'timestamp' in raceSchedule.getHeader()[i]: timeIndexes.append(i) fastestTimes.append(999999) for heat in raceSchedule.getRows(): for i in range(len(timeIndexes)): try: fastestTimes[i] = min(fastestTimes[i], float(heat[timeIndexes[i]])) except: pass fastestTimesStr = 'Fastest times: ' for f in range(len(fastestTimes)): if fastestTimes[f] < 999: fastestTimesStr = fastestTimesStr + ' Lane ' + str( f + 1) + ': ' + "{:.3f}".format(fastestTimes[f]) columns = [] colCount = {} for col in raceSchedule.getHeader(): if 'car' in col: if not 'name' in colCount: colCount['name'] = 0 else: colCount['name'] += 1 columns.append( getTableColSettingsWithCookie( 'index', str(colCount['name'] + 1), '<b>' + str(colCount['name'] + 1) + '</b>')) columns.append( getTableColSettingsWithCookie('index', 'name' + str(colCount['name']), 'name')) columns.append( getTableColSettingsWithCookie('index', 'result' + str(colCount['name']), 'result')) if not col in colCount: colCount[col] = 0 else: colCount[col] += 1 columns.append( getTableColSettingsWithCookie('index', col + str(colCount[col]), col)) return render_template("index.html", title="Pinewood Derby", columns=columns, fastestTime=fastestTimesStr)