Example #1
0
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
Example #2
0
import xml.etree.ElementTree as et
from getdata import load_houseprices
from getscores import get_houseprices_scores

scores = get_houseprices_scores(load_houseprices())

tree = et.parse('data/us_counties.svg')
root = tree.getroot()

# 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:'

#for p in root.findall('{http://www.w3.org/2000/svg}path'):
#    p.set('style', path_style+'#C994C7')
#    #print p.attrib['style']

for p in root.findall('{http://www.w3.org/2000/svg}path'):
    if p.attrib['id'] not in ['State_Lines', 'separator']:
        # Add tooltip
        #title = et.Element('{http://www.w3.org/2000/svg}title')
        #title.text = p.attrib['{http://www.inkscape.org/namespaces/inkscape}label']
        tooltip = p.attrib[
            '{http://www.inkscape.org/namespaces/inkscape}label']

        try:
            fips = (int(p.attrib['id'][:2]), int(p.attrib['id'][2:]))
            ind = min(int(scores[fips] * 5), 5)
Example #3
0
import xml.etree.ElementTree as et
from getdata import load_houseprices
from getscores import get_houseprices_scores

scores = get_houseprices_scores(load_houseprices())

tree = et.parse('data/us_counties.svg')
root = tree.getroot()

# 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:'

#for p in root.findall('{http://www.w3.org/2000/svg}path'):
#    p.set('style', path_style+'#C994C7')
#    #print p.attrib['style']
    
for p in root.findall('{http://www.w3.org/2000/svg}path'):
    if p.attrib['id'] not in ['State_Lines', 'separator']:
        # Add tooltip
        #title = et.Element('{http://www.w3.org/2000/svg}title')
        #title.text = p.attrib['{http://www.inkscape.org/namespaces/inkscape}label']
        tooltip = p.attrib['{http://www.inkscape.org/namespaces/inkscape}label']
            
        try:
            fips = (int(p.attrib['id'][:2]), int(p.attrib['id'][2:]))
            ind = min(int(scores[fips]*5), 5)
            p.set('style', path_style + colors[ind])