class SearchForm(Form): autojob = TextField( 'Enter Job Title', [validators.Required("Please Select from the Suggested List:")], id='job_autocomplete') autojob2 = TextField( 'Enter Job Title', [validators.Required("Please Select from the Suggested List:")], id='job_autocomplete1') autojob3 = TextField( 'Enter Job Title', [validators.Required("Please Select from the Suggested List:")], id='job_autocomplete2') company = TextField('Enter Company Name:', id="company") compcity = TextField('Enter Company City:', id="compcity") compstate = SelectField('Enter Company State:', choices=states.items(), default='LA') compyears = TextField('Enter Years Worked: (ex: 1985-1888)', id="compyears") company2 = TextField('Enter Company Name:', id="company2") compcity2 = TextField('Enter Company City:', id="compcity2") compstate2 = SelectField('Enter Company State:', choices=states.items(), default='LA') compyears2 = TextField('Enter Years Worked:', id="compyears2") company3 = TextField('Enter Company Name:', id="company3") compcity3 = TextField('Enter Company City:', id="compcity3") compstate3 = SelectField('Enter Company State:', choices=states.items(), default='LA') compyears3 = TextField('Enter Years Worked:', id="compyears3")
def state_election(): for key, value in states.items(): id = key name = value[0] ec = value[1] d_2016_votes = int(value[2]) r_2016_votes = int(value[3]) t_2016_votes = int(value[4]) d_2016_votes_p = (Decimal(value[2]) / Decimal(value[5])) r_2016_votes_p = (Decimal(value[3]) / Decimal(value[5])) t_2016_votes_p = (Decimal(value[4]) / Decimal(value[5])) total_2016_votes = value[5] past_5 = value[6] print(d_2016_votes_p * 100)
'OLD ROUTE': ['OLD RT', 'OLD RTE', 'OLD ROUTE'], 'OLD COUNTY HIGHWAY': ['OLD COUNTY HIGHWAY', 'OLD COUNTY HWY', 'OLD CNTY HWY'], 'OLD COUNTY ROAD': ['OLD COUNTY RD', 'OLD COUNTY ROAD', 'OLD CR', 'OLD CNTY RD'], 'OLD HIGHWAY': ['OLD HIGHWAY', 'OLD HIWAY', 'OLD HWY'], 'OLD': ['OLD'], # 'LOOP' and 'BUSINESS LOOP' are not in docs, but I've seen it in # Columbia MO data. 'LOOP': ['LOOP'], 'BUSINESS LOOP': ['BUSINESS LOOP'], } state_prefixes = {} from states import states for abbr, full in states.items(): # Example: #'KY HIGHWAY': ['KENTUCKY', 'KY HIGHWAY', 'KENTUCKY HIGHWAY', 'KY', 'KY HWY'], key = abbr + ' HIGHWAY' vals = [key, abbr, full, full + ' HIGHWAY', abbr + ' HWY'] state_prefixes[key] = vals # Example: #'KY STATE HIGHWAY': ['KY ST HWY', 'KY STATE HIGHWAY', 'KENTUCKY STATE HIGHWAY'], key = abbr + ' STATE HIGHWAY' vals = [key, abbr + ' ST HWY', full + ' STATE HIGHWAY'] state_prefixes[key] = vals # Example: #'CA COUNTY ROAD': ['CA COUNTY RD', 'CALIFORNIA COUNTY ROAD', 'CA COUNTY ROAD'], key = abbr + ' COUNTY ROAD'
"""Module for defining form classes for use in GolfRecs.""" from flask_wtf import FlaskForm from wtforms import (IntegerField, SelectField, StringField, TextAreaField, HiddenField) from wtforms.validators import EqualTo, InputRequired, Length, Optional from states import states STATE_CHOICES = [('', 'Select State')] + sorted( [(key, value) for key, value in states.items()], key=lambda x: x[1] ) class RegistrationForm(Form): username = StringField( 'Username', validators=[validators.Length(min=3, max=25)] ) email = StringField('Email Address', validators=[validators.Length(min=6, max=35)]) city = StringField('City', validators=[validators.DataRequired()]) state = SelectField( 'State', choices=STATE_CHOICES, validators=[validators.DataRequired()], default='' ) password = StringField('New Password', [ validators.DataRequired(), validators.EqualTo('password_confirm', message='Passwords must match')
def federal_election(): results = {} output = {} wins = [] ec_d = 0 ec_r = 0 simulations = 1000 bar = Bar('Progress', max=simulations) for key, value in states.items(): results[key] = [] for _ in range(simulations): ec_temp_d = 0 ec_temp_r = 0 for key, value in states.items(): n = state_election(int(value[1]), float(value[2]), float(value[3]), random.randint(2,4), float(value[5]), float(value[6]), float(value[7])) results[key].append(n) if n[0] > n[1]: ec_temp_d = ec_temp_d + n[3] ec_d = ec_d + n[3] if n[0] < n[1]: ec_temp_r = ec_temp_r + n[3] ec_r = ec_r + n[3] if n[0] == n[1]: ec_temp_r = ec_temp_r + n[3] ec_r = ec_r + n[3] if ec_temp_d > ec_temp_r: wins.append("D") if ec_temp_d < ec_temp_r: wins.append("R") if ec_temp_d == ec_temp_r: wins.append("T") bar.next() for key, value in results.items(): output[key] = [0,0,0,0,0,0, "T"] for i in results[key]: output[key][0] += i[0] output[key][1] += i[1] output[key][2] += i[2] if i[0] > i[1]: output[key][3] += 1 if i[0] < i[1]: output[key][4] += 1 if i[2] > (i[1] + i[0]): output[key][5] += 1 if i[0] == i[1]: output[key][4] += 1 for i in results[key]: output[key][0] = round(output[key][0], 2) output[key][1] = round(output[key][1], 2) output[key][2] = round(output[key][2], 2) pass se_table_data = [ [colored('STATE'), colored('D VOTES %', 'white', 'on_blue'), colored('R VOTES %', 'white', 'on_red'), colored('T VOTES %', 'grey', 'on_white'), colored('D WINS %', 'white', 'on_blue'), colored('R WINS %', 'white', 'on_red'), colored('T WINS %', 'grey', 'on_white'), "EC"] ] for key, value in output.items(): name = "" if value[0] > value[1]: name = "D" if value[1] >= value[0]: name = "R" se_table_data.append([key, round(value[0]/1000, 2), round(value[1]/1000, 2), round(value[2]/1000, 2), round(value[3]/10, 2), round(value[4]/10, 2), round(value[5]/10, 2), name]) se_table = SingleTable(se_table_data) se_table.title = 'GE Simulation' print('Done') term_table_data = [ [colored('Dem Win %', 'white', 'on_blue'), colored('R Win %', 'white', 'on_red'), colored('Tie %', 'grey', 'on_white'), colored('D Avg ECV', 'white', 'on_blue'), colored('R Avg ECV', 'white', 'on_red')] ] term_table = SingleTable(term_table_data) term_table_data.append([round(wins.count("D")/10, 0), round(wins.count("R")/10, 0), round(wins.count("T")/10, 0), ec_d/1000, ec_r/1000]) print (term_table.table) # print(round(wins.count("D")/10, 0), round(wins.count("R")/10, 0), round(wins.count("T")/10, 0), ec_d/1000, ec_r/1000) today = date.today() with open('results/results-president-' + today.strftime("%m-%d-%Y") + '.csv', 'w') as csvfile: filewriter = csv.writer(csvfile, quotechar='|', quoting=csv.QUOTE_MINIMAL) filewriter.writerow(["id", "name", "ec", "party", "democrat", "republican", "third", "democrat_win", "republican_win", "third_win", "winner"]) for key, value in output.items(): democrat = round(value[0]/1000, 2) republican = round(value[1]/1000, 2) third = round(value[2]/1000, 2) democrat_win = round(value[3]/10, 2) republican_win = round(value[4]/10, 2) third_win = round(value[5]/1000, 2) winner = "" if democrat > republican: party = 3 winner = "D" if democrat - republican > 5: party = 2 if democrat - republican > 10: party = 1 else: pass else: pass if republican > democrat: party = 4 winner = "R" if republican - democrat > 5: party = 5 if republican - democrat > 10: party = 6 else: pass else: pass filewriter.writerow([key, states[key][0], states[key][1], party, democrat, republican, third, democrat_win, republican_win, third_win, name]) print('outputted as results-president-' + today.strftime("%m-%d-%Y") + '.csv')
def federal_election(): results = {} output = {} wins = [] ec_d = 0 ec_r = 0 simulations = 1000 bar = Bar('Progress', max=simulations) for key, value in states.items(): results[key] = [] for _ in range(simulations): ec_temp_d = 35 ec_temp_r = 30 for key, value in states.items(): n = state_election(float(value[1]), float(value[2]), float(value[3]), float(value[4]), float(value[5]), float(value[6])) results[key].append(n) if n[0] > n[1]: ec_temp_d = ec_temp_d + 1 ec_d = ec_d + 1 if n[0] < n[1]: ec_temp_r = ec_temp_r + 1 ec_r = ec_r + 1 if n[0] == n[1]: ec_temp_r = ec_temp_r + 1 ec_r = ec_r + 1 if ec_temp_d > ec_temp_r: wins.append("D") if ec_temp_d < ec_temp_r: wins.append("R") if ec_temp_d == ec_temp_r: wins.append("T") ec_d += 35 ec_r += 30 bar.next() for key, value in results.items(): output[key] = [0, 0, 0, 0, 0, 0] for i in results[key]: output[key][0] += i[0] output[key][1] += i[1] output[key][2] += i[2] if i[0] > i[1]: output[key][3] += 1 if i[0] < i[1]: output[key][4] += 1 if i[2] > (i[1] + i[0]): output[key][5] += 1 if i[0] == i[1]: output[key][4] += 1 for i in results[key]: output[key][0] = round(output[key][0], 2) output[key][1] = round(output[key][1], 2) output[key][2] = round(output[key][2], 2) pass se_table_data = [[ colored('STATE'), colored('D VOTES %', 'white', 'on_blue'), colored('R VOTES %', 'white', 'on_red'), colored('T VOTES %', 'grey', 'on_white'), colored('D WINS %', 'white', 'on_blue'), colored('R WINS %', 'white', 'on_red'), colored('T WINS %', 'grey', 'on_white') ]] for key, value in output.items(): se_table_data.append([ key, round(value[0] / 1000, 2), round(value[1] / 1000, 2), round(value[2] / 1000, 2), round(value[3] / 10, 2), round(value[4] / 10, 2), round(value[5] / 10, 2) ]) se_table = SingleTable(se_table_data) today = date.today() with open('results/results-senate-' + today.strftime("%m-%d-%Y") + '.csv', 'w') as csvfile: filewriter = csv.writer(csvfile, quotechar='|', quoting=csv.QUOTE_MINIMAL) filewriter.writerow([ "id", "name", "democrat", "republican", "third", "democrat_win", "republican_win", "winner" ]) for key, value in output.items(): democrat = round(value[0] / 1000, 2) republican = round(value[1] / 1000, 2) third = round(value[2] / 1000, 2) democrat_win = round(value[3] / 10, 2) republican_win = round(value[4] / 10, 2) third_win = round(value[5] / 1000, 2) winner = "" if democrat > republican: party = 3 winner = "D" if democrat - republican > 5: party = 2 if democrat - republican > 10: party = 1 else: pass else: pass if republican > democrat: party = 4 winner = "R" if republican - democrat > 5: party = 5 if republican - democrat > 10: party = 6 else: pass else: pass filewriter.writerow([ key, states[key][0], str(democrat) + '%', str(republican) + '%', str(third) + '%', str(democrat_win) + '%', str(republican_win) + '%', winner ]) print('outputted as results-senate-' + today.strftime("%m-%d-%Y") + '.csv') se_table.title = 'GE Simulation' print('Done') print(se_table.table) print( wins.count("D") / 10, wins.count("R") / 10, wins.count("T") / 10, ec_d / 1000, ec_r / 1000)