def index(): if os.path.exists('tempstore.txt'): os.remove("tempstore.txt") form = IndividualForm() global batternameone global pitchernameone if form.validate_on_submit(): batternameone=form.battername.data pitchernameone=form.pitchername.data return redirect('/matchup1') return render_template('index.html', form = form)
def individual_submit(request): if request.method == 'POST': print request.POST individual_form = IndividualForm(request.POST, instance=Individual()) req = Individual() req.individual_id = request.POST['individual_id'] req.gender = request.POST['gender'] if individual_form.is_valid(): try: Individual.objects_get(indvidual_id=request.POST['individual_id']) except: individual_form.save(commit=True) ind = Individual.objects.all() context = {'individual': ind} return render(request, 'viewer/individuals/view_individual.html', context) else: individual_form = IndividualForm(instance=Individual()) context = { 'individual_form': individual_form } context.update(csrf(request)) return render(request, 'viewer/individuals/individual_submit.html', context)
def addindividual(): form = IndividualForm() print(session, file=sys.stderr) if request.method == "GET": return render_template('addindividual.html', form=form, session=session) if request.method == "POST": print(session, file=sys.stderr) if form.validate() == True: cursor = mysql.connection.cursor() query = "INSERT INTO customer (customer_id, phone_number, email, street, city, state, postal_code) VALUES (NULL, %s, %s, %s, %s, %s, %s)" variables = [form.phone_number.data, form.email.data, form.street.data, form.city.data, form.state.data, form.postal_code.data] cursor.execute(query, variables) mysql.connection.commit() cursor = mysql.connection.cursor() cursor.execute("SELECT LAST_INSERT_ID()") last_customer_id = cursor.fetchall() query = "INSERT INTO individual (driver_license_number, customer_id, individual_first_name, individual_last_name) VALUES (%s, %s, %s, %s)" variables = [form.driver_license_number.data, last_customer_id, form.individual_first_name.data, form.individual_last_name.data] cursor.execute(query, variables) mysql.connection.commit() # print(previous_page, file=sys.stderr) if session["previous_page"] == "purchase": session["customer"] = { "customer_id": last_customer_id, "customer_type": "Individual", "customer_name": "{} {}".format(form.individual_first_name.data, form.individual_last_name.data) } return redirect(url_for("purchasevehicle")) else: session["customer"] = { "customer_id": last_customer_id, "customer_type": "Individual", "customer_name": "{} {}".format(form.individual_first_name.data, form.individual_last_name.data) } return redirect(url_for("sellvehicle", vin=session["vin"])) else: return render_template('addindividual.html', form=form)
def matchup4(): xoneed = 1 xtwoed = 1 xthreeed = 1 if os.path.exists('tempstore.txt'): with open('tempstore.txt', 'r') as f: read_data = f.read() f.closed read_data = list(read_data) if '1' in read_data: xoneed = 0 if '2' in read_data: xtwoed = 0 if '3' in read_data: xthreeed = 0 form = IndividualForm() bcluster = bclusterlookup(batternamefour) pcluster = pclusterlookup(pitchernamefour) global favratingfour favratingfour = getrating(bcluster, pcluster) global zerofour zerofour = 0 global onefour onefour = 0 global twofour twofour = 0 global threefour threefour = 0 global fourfour fourfour = 0 global fivefour fivefour = 0 global sixfour sixfour = 0 global sevenfour sevenfour = 0 global eightfour eightfour = 0 global ninefour ninefour = 0 global tenfour tenfour = 0 if favratingfour< 5: zerofour = 1 elif favratingfour < 15: onefour = 1 elif favratingfour< 25: twofour = 1 elif favratingfour< 35: threefour = 1 elif favratingfour < 45: fourfour = 1 elif favratingfour< 55: fivefour = 1 elif favratingfour < 65: sixfour = 1 elif favratingfour < 75: sevenfour = 1 elif favratingfour< 85: eightfour = 1 elif favratingfour< 95: ninefour = 1 else: tenfour = 1 walks = pd.read_csv('walks.csv', na_values=[' '], header=None) hits = pd.read_csv('hits.csv', na_values=[' '], header=None) hrs = pd.read_csv('hrs.csv', na_values=[' '], header=None) plateapps = pd.read_csv('plateapps.csv', na_values=[' '], header=None) walks = np.array(walks) hits = np.array(hits) hrs = np.array(hrs) plateapps = np.array(plateapps) if plateapps[bcluster-1, pcluster-1] == 0: plateapps[bcluster-1, pcluster-1] = 1 awalkf = walks[bcluster-1, pcluster-1]/plateapps[bcluster-1, pcluster-1] * 100 global awalkfour if bcluster == 0 or pcluster == 0: awalkfour = 0 else: awalkfour = int(awalkf) ahrf = hrs[bcluster-1, pcluster-1]/plateapps[bcluster-1, pcluster-1] * 100 global ahrfour if bcluster == 0 or pcluster == 0: ahrfour = 0 else: ahrfour = int(ahrf) ahitf = hits[bcluster-1, pcluster-1]/plateapps[bcluster-1, pcluster-1] * 100 global ahitfour if bcluster == 0 or pcluster == 0: ahitfour = 0 else: ahitfour = int(ahitf) if form.validate_on_submit(): return redirect('/index') return render_template('matchup4.html', zeroone = zeroone, oneone = oneone, twoone = twoone, threeone = threeone, fourone = fourone, fiveone = fiveone, sixone = sixone, sevenone = sevenone, eightone = eightone, nineone = nineone, tenone = tenone, batternameone = batternameone, pitchernameone = pitchernameone, favratingone = favratingone, awalkone = awalkone, ahitone = ahitone, ahrone = ahrone, zerotwo = zerotwo, onetwo = onetwo, twotwo = twotwo, threetwo = threetwo, fourtwo = fourtwo, fivetwo = fivetwo, sixtwo = sixtwo, seventwo = seventwo, eighttwo = eighttwo, ninetwo = ninetwo, tentwo = tentwo, batternametwo = batternametwo, pitchernametwo = pitchernametwo, favratingtwo = favratingtwo, awalktwo = awalktwo, ahittwo = ahittwo, ahrtwo = ahrtwo, zerothree = zerothree, onethree = onethree, twothree = twothree, threethree = threethree, fourthree = fourthree, fivethree = fivethree, sixthree = sixthree, seventhree = seventhree, eightthree = eightthree, ninethree = ninethree, tenthree = tenthree, batternamethree = batternamethree, pitchernamethree = pitchernamethree, favratingthree = favratingthree, awalkthree = awalkthree, ahitthree = ahitthree, ahrthree = ahrthree, zerofour = zerofour, onefour = onefour, twofour = twofour, threefour = threefour, fourfour = fourfour, fivefour = fivefour, sixfour = sixfour, sevenfour = sevenfour, eightfour = eightfour, ninefour = ninefour, tenfour = tenfour, batternamefour = batternamefour, pitchernamefour = pitchernamefour, favratingfour = favratingfour, awalkfour = awalkfour, ahitfour = ahitfour, ahrfour = ahrfour, xoneed = xoneed, xtwoed = xtwoed, xthreeed = xthreeed, form = form)
def matchup2(): xoneed = 1 if os.path.exists('tempstore.txt'): with open('tempstore.txt', 'r') as f: read_data = f.read() f.closed read_data = list(read_data) if '1' in read_data: xoneed = 0 form = IndividualForm() bcluster = bclusterlookup(batternametwo) pcluster = pclusterlookup(pitchernametwo) global favratingtwo favratingtwo = getrating(bcluster, pcluster) global zerotwo zerotwo = 0 global onetwo onetwo = 0 global twotwo twotwo = 0 global threetwo threetwo = 0 global fourtwo fourtwo = 0 global fivetwo fivetwo = 0 global sixtwo sixtwo = 0 global seventwo seventwo = 0 global eighttwo eighttwo = 0 global ninetwo ninetwo = 0 global tentwo tentwo = 0 if favratingtwo< 5: zerotwo = 1 elif favratingtwo < 15: onetwo = 1 elif favratingtwo< 25: twotwo = 1 elif favratingtwo< 35: threetwo = 1 elif favratingtwo < 45: fourtwo = 1 elif favratingtwo< 55: fivetwo = 1 elif favratingtwo < 65: sixtwo = 1 elif favratingtwo < 75: seventwo = 1 elif favratingtwo< 85: eighttwo = 1 elif favratingtwo< 95: ninetwo = 1 else: tentwo = 1 walks = pd.read_csv('walks.csv', na_values=[' '], header=None) hits = pd.read_csv('hits.csv', na_values=[' '], header=None) hrs = pd.read_csv('hrs.csv', na_values=[' '], header=None) plateapps = pd.read_csv('plateapps.csv', na_values=[' '], header=None) walks = np.array(walks) hits = np.array(hits) hrs = np.array(hrs) plateapps = np.array(plateapps) if plateapps[bcluster-1, pcluster-1] == 0: plateapps[bcluster-1, pcluster-1] = 1 awalkf = walks[bcluster-1, pcluster-1]/plateapps[bcluster-1, pcluster-1] * 100 global awalktwo if bcluster == 0 or pcluster == 0: awalktwo = 0 else: awalktwo = int(awalkf) ahrf = hrs[bcluster-1, pcluster-1]/plateapps[bcluster-1, pcluster-1] * 100 global ahrtwo if bcluster == 0 or pcluster == 0 : ahrtwo = 0 else: ahrtwo = int(ahrf) ahitf = hits[bcluster-1, pcluster-1]/plateapps[bcluster-1, pcluster-1] * 100 global ahittwo if bcluster == 0 or pcluster == 0: ahittwo = 0 else: ahittwo = int(ahitf) global batternamethree global pitchernamethree if form.validate_on_submit(): batternamethree=form.battername.data pitchernamethree=form.pitchername.data return redirect('/matchup3') return render_template('matchup2.html', zeroone = zeroone, oneone = oneone, twoone = twoone, threeone = threeone, fourone = fourone, fiveone = fiveone, sixone = sixone, sevenone = sevenone, eightone = eightone, nineone = nineone, tenone = tenone, batternameone = batternameone, pitchernameone = pitchernameone, favratingone = favratingone, awalkone = awalkone, ahitone = ahitone, ahrone = ahrone, zerotwo = zerotwo, onetwo = onetwo, twotwo = twotwo, threetwo = threetwo, fourtwo = fourtwo, fivetwo = fivetwo, sixtwo = sixtwo, seventwo = seventwo, eighttwo = eighttwo, ninetwo = ninetwo, tentwo = tentwo, batternametwo = batternametwo, pitchernametwo = pitchernametwo, favratingtwo = favratingtwo, awalktwo = awalktwo, ahittwo = ahittwo, ahrtwo = ahrtwo, xoneed = xoneed, form = form)
def matchup1(): form = IndividualForm() bcluster = bclusterlookup(batternameone) pcluster = pclusterlookup(pitchernameone) global favratingone favratingone = getrating(bcluster, pcluster) global zeroone zeroone = 0 global oneone oneone = 0 global twoone twoone = 0 global threeone threeone = 0 global fourone fourone = 0 global fiveone fiveone = 0 global sixone sixone = 0 global sevenone sevenone = 0 global eightone eightone = 0 global nineone nineone = 0 global tenone tenone = 0 if favratingone< 5: zeroone = 1 elif favratingone < 15: oneone = 1 elif favratingone< 25: twoone = 1 elif favratingone< 35: threeone = 1 elif favratingone < 45: fourone = 1 elif favratingone< 55: fiveone = 1 elif favratingone < 65: sixone = 1 elif favratingone < 75: sevenone = 1 elif favratingone< 85: eightone = 1 elif favratingone< 95: nineone = 1 else: tenone = 1 walks = pd.read_csv('walks.csv', na_values=[' '], header=None) hits = pd.read_csv('hits.csv', na_values=[' '], header=None) hrs = pd.read_csv('hrs.csv', na_values=[' '], header=None) plateapps = pd.read_csv('plateapps.csv', na_values=[' '], header=None) walks = np.array(walks) hits = np.array(hits) hrs = np.array(hrs) plateapps = np.array(plateapps) if plateapps[bcluster-1, pcluster-1] == 0: plateapps[bcluster-1, pcluster-1] = 1 awalkf = walks[bcluster-1, pcluster-1]/plateapps[bcluster-1, pcluster-1] * 100 global awalkone if bcluster == 0 or pcluster == 0: awalkone = 0 else: awalkone = int(awalkf) ahrf = hrs[bcluster-1, pcluster-1]/plateapps[bcluster-1, pcluster-1] * 100 global ahrone if bcluster == 0 or pcluster == 0: ahrone = 0 else: ahrone = int(ahrf) ahitf = hits[bcluster-1, pcluster-1]/plateapps[bcluster-1, pcluster-1] * 100 global ahitone if bcluster == 0 or pcluster == 0: ahitone = 0 else: ahitone = int(ahitf) global batternametwo global pitchernametwo if form.validate_on_submit(): batternametwo=form.battername.data pitchernametwo=form.pitchername.data return redirect('/matchup2') return render_template('matchup1.html', zeroone = zeroone, oneone = oneone, twoone = twoone, threeone = threeone, fourone = fourone, fiveone = fiveone, sixone = sixone, sevenone = sevenone, eightone = eightone, nineone = nineone, tenone = tenone, batternameone = batternameone, pitchernameone = pitchernameone, favratingone = favratingone, awalkone = awalkone, ahitone = ahitone, ahrone = ahrone, form = form)