def getNeighborhoodsByAreas(conn, areaids, user): print 'getting votes' (blocks, allVotes) = vote_utils.getVotes(conn, areaids, user) print 'got votes' blocks_by_hoodid = defaultdict(list) id_to_label = {} for block in blocks: votes = allVotes[block['geoid10']] #print block['geoid10'] maxVotes = vote_utils.pickBestVotes(votes) for maxVote in maxVotes: blocks_by_hoodid[maxVote['id']].append(block) id_to_label[maxVote['id']] = maxVote['label'] hoods = {} print 'doing unions' for (id, blocks) in blocks_by_hoodid.iteritems(): geoms = [asShape(eval(block['geojson_geom'])) for block in blocks] blockids = [block['geoid10'] for block in blocks] pop10 = sum([block['pop10'] for block in blocks]) housing10 = sum([block['housing10'] for block in blocks]) geom = cascaded_union(geoms) hoods[id] = NeighborhoodArea(geom, blockids, pop10, housing10) return (hoods, id_to_label)
def makeFeature(row, voteDict, user): return { "type": "Feature", "geometry": eval(row['geojson_geom']), "properties": { "id": row['geoid10'], "votes": vote_utils.pickBestVotes(voteDict[row['geoid10']]) } }
def blockInfo(): apikey = request.args.get('key', '') user = findUserByApiKey(apikey) conn = psycopg2.connect("dbname='gis' user='******' host='localhost' password='******'") blockids = request.args.get('blockid', '').split(',') voteDict = vote_utils.getVotesForBlocks(conn, blockids, user) responseDict = {} for (blockid, votes) in voteDict.iteritems(): responseDict[blockid] = { 'votes': votes, 'bestVotes': vote_utils.pickBestVotes(votes) } return jsonify(responseDict)
def blockInfo(): apikey = request.args.get('key', '') user = findUserByApiKey(conn, apikey) conn = getPostgresConnection() blockids = request.args.get('blockid', '').split(',') voteDict = vote_utils.getVotesForBlocks(conn, blockids, user) responseDict = {} for (blockid, votes) in voteDict.iteritems(): responseDict[blockid] = { 'votes': votes, 'bestVotes': vote_utils.pickBestVotes(votes) } return jsonify(responseDict)
def blockInfo(): apikey = request.args.get('key', '') user = findUserByApiKey(apikey) conn = psycopg2.connect( "dbname='gis' user='******' host='localhost' password='******'") blockids = request.args.get('blockid', '').split(',') voteDict = vote_utils.getVotesForBlocks(conn, blockids, user) responseDict = {} for (blockid, votes) in voteDict.iteritems(): responseDict[blockid] = { 'votes': votes, 'bestVotes': vote_utils.pickBestVotes(votes) } return jsonify(responseDict)
def getNeighborhoodsByArea(conn, areaid, user): (blocks, allVotes) = vote_utils.getVotes(conn, areaid, user) blocks_by_hoodid = defaultdict(list) blockids_by_hoodid = defaultdict(list) id_to_label = {} for block in blocks: geom = asShape(eval(block['geojson_geom'])) votes = allVotes[block['geoid10']] #print block['geoid10'] maxVotes = vote_utils.pickBestVotes(votes) for maxVote in maxVotes: blocks_by_hoodid[maxVote['id']].append(geom) blockids_by_hoodid[maxVote['id']].append(block['geoid10']) id_to_label[maxVote['id']] = maxVote['label'] hoods = {} for (id, geoms) in blocks_by_hoodid.iteritems(): hoods[id] = NeighborhoodArea(cascaded_union(geoms), blockids_by_hoodid[id]) return (hoods, id_to_label)