def index(): if request.method == 'GET': return render_template('jobs_vs_prices.html') else: #request was a POST jobs_app.vars['profession_key'] = request.form['profession_key'] jobs = load_jobs(jobs_app.vars['profession_key']) prices = get_average_prices_data() scores = get_state_scores(jobs, prices) title = jobs_app.vars['profession_key'].replace('-',' ') title = 'Available ' + title.title() + ' jobs (scaled by average house price)' script, div = choropleth_usa(scores, title) print script return render_template('jobs_vs_prices_graph.html', script=script, div=div)
def counties_map(): criteria_scores = [] if 'jobs' in app.vars['criteria']: scores = get_jobs_scores(load_jobs(app.vars['profession_key'])) criteria_scores.append(scores) if 'houseprices' in app.vars['criteria']: scores = get_houseprices_scores(load_houseprices()) criteria_scores.append(scores) if 'population' in app.vars['criteria']: scores = get_populations_scores(load_populations()) criteria_scores.append(scores) final_scores = get_scores(criteria_scores) svg = choropleth_svg(final_scores) response = make_response(svg) response.headers['Content-Type'] = 'image/svg+xml' return response
import pandas as pd from getdata import load_jobs, get_average_prices_data, get_fips_data from plotchoropleth import choropleth_usa_states profession_keys = ['data-science', 'financial-services', 'information-technology', 'mobile-app'] jobs = None for pk in profession_keys: if jobs is None: jobs = load_jobs(pk) else: new_jobs = load_jobs(pk) jobs = pd.concat((jobs, new_jobs), ignore_index=True) jobs_per_state = jobs.groupby(['state'])['id'].count().to_dict() prices = get_average_prices_data() # Add state abbreviations to prices dataframe fips = get_fips_data() prices = pd.merge(prices, fips.groupby(['state_long','state']).count().reset_index()[['state_long','state']], how='left', on=['state_long']) for p in range(12): max_price = 150000. + float(p)*50000 prices_per_state = prices.loc[prices['average_price'] < max_price, ['state','average_price']].set_index('state').to_dict()['average_price'] if len(prices_per_state) > 0: counts = []
from bs4 import BeautifulSoup from getdata import load_houseprices, load_populations, load_jobs from getscores import get_houseprices_scores, get_populations_scores, get_jobs_scores, get_scores #scores = get_houseprices_scores(load_houseprices()) #scores = get_populations_scores(load_populations()) #scores = get_jobs_scores(load_jobs('information-technology')) scores = get_scores(load_jobs('financial-services'), load_populations(), load_houseprices()) # Load the SVG map svg = open('data/us_counties.svg', 'r').read() soup = BeautifulSoup(svg, 'xml') # Find counties paths = soup.findAll('path') # Map colors colors = ["#F1EEF6", "#D4B9DA", "#C994C7", "#DF65B0", "#DD1C77", "#980043"] path_style = 'font-size:12px;fill-rule:nonzero;stroke:#FFFFFF;stroke-opacity:1;' path_style += 'stroke-width:0.1;stroke-miterlimit:4;stroke-dasharray:none;' path_style += 'stroke-linecap:butt;marker-start:none;stroke-linejoin:bevel;fill:' # Color the counties based on unemployment rate for p in paths: if p['id'] not in ['State_Lines', 'separator']: # pass try: fips = (int(p['id'][:2]), int(p['id'][2:]))
from getdata import load_jobs, get_average_prices_data from getscores import get_state_scores from plotchoropleth import choropleth_usa_states """ Generate (and save) choropleths of available jobs (scaled by house prices) """ prices = get_average_prices_data() profession_keys = ["data-science", "financial-services", "information-technology", "mobile-app"] for pk in profession_keys: jobs = load_jobs(pk) scores = get_state_scores(jobs, prices) choropleth_usa_states(scores, "templates/jobsdata_%s.html" % pk, title="")
import pandas as pd from getdata import load_jobs, get_average_prices_data, get_fips_data from plotchoropleth import choropleth_usa_states profession_keys = [ 'data-science', 'financial-services', 'information-technology', 'mobile-app' ] jobs = None for pk in profession_keys: if jobs is None: jobs = load_jobs(pk) else: new_jobs = load_jobs(pk) jobs = pd.concat((jobs, new_jobs), ignore_index=True) jobs_per_state = jobs.groupby(['state'])['id'].count().to_dict() prices = get_average_prices_data() # Add state abbreviations to prices dataframe fips = get_fips_data() prices = pd.merge( prices, fips.groupby(['state_long', 'state']).count().reset_index()[['state_long', 'state']], how='left', on=['state_long'])