<s> from pipehtml import * <EOL> from pipegeojson import * <EOL> from pipegeohash import * <EOL> import pandas as pd <EOL> import numpy as np <EOL> import itertools <EOL> def map_axis_unique ( dataframe , uniqueaxis , ** kwargs ) : <EOL> return_filenames = False <EOL> return_spark = False <EOL> for key , value in kwargs . iteritems ( ) : <EOL> if key == '<STR_LIT>' : <EOL> if value == True : <EOL> return_filenames = True <EOL> uniques = np . unique ( dataframe [ str ( uniqueaxis ) ] ) . tolist ( ) <EOL> colors = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:default>' ] <EOL> filenames = [ ] <EOL> for a , b in itertools . izip ( uniques , colors ) : <EOL> temp = dataframe [ dataframe [ uniqueaxis ] == a ] <EOL> temp [ '<STR_LIT>' ] = b <EOL> templines = make_points ( temp , list = True ) <EOL> filename = b + '<STR_LIT>' <EOL> parselist ( templines , filename ) <EOL> filenames . append ( filename ) <EOL> if not return_filenames == True : <EOL> loadparsehtml ( filenames , colorkey = '<STR_LIT>' ) <EOL> else : <EOL> return filenames <EOL> def heatmap ( data , precision , ** kwargs ) : <EOL> return_filenames = False <EOL> return_spark = False <EOL> return_both = False <EOL> for key , value in kwargs . iteritems ( ) : <EOL> if key == '<STR_LIT>' : <EOL> if value == True : <EOL> return_filenames = True <EOL> elif key == '<STR_LIT>' : <EOL> if value == True : <EOL> return_spark = True <EOL> elif key == '<STR_LIT>' : <EOL> if value == True : <EOL> return_both = True <EOL> map_table ( data , precision , list = True ) <EOL> data = pd . read_csv ( '<STR_LIT>' + str ( precision ) + '<STR_LIT>' ) <EOL> maxvalue = data [ '<STR_LIT>' ] . max ( ) <EOL> factor = maxvalue / <NUM_LIT:5> <EOL> factors = [ <NUM_LIT:0> , factor * <NUM_LIT> , factor * <NUM_LIT:1> , factor * <NUM_LIT:2> , factor * <NUM_LIT:3> , factor * <NUM_LIT:6> ] <EOL> colors = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> filenames = [ ] <EOL> sparks = [ ] <EOL> count = <NUM_LIT:0> <EOL> for a , b in itertools . izip ( factors , colors ) : <EOL> if count == <NUM_LIT:0> : <EOL> count = <NUM_LIT:1> <EOL> oldrow = a <EOL> else : <EOL> temp = data [ ( data . COUNT >= oldrow ) & ( data . COUNT < a ) ] <EOL> count += <NUM_LIT:1> <EOL> oldrow = a <EOL> temp [ '<STR_LIT>' ] = b <EOL> if len ( temp ) == <NUM_LIT:0> : <EOL> temp = [ temp . columns . values . tolist ( ) ] <EOL> add = [ ] <EOL> count2 = <NUM_LIT:0> <EOL> while not count2 == len ( temp [ <NUM_LIT:0> ] ) : <EOL> count2 += <NUM_LIT:1> <EOL> add . append ( <NUM_LIT:0> ) <EOL> temp = temp + [ add ] <EOL> temp = list2df ( temp ) <EOL> filenames . append ( str ( b ) + '<STR_LIT>' ) <EOL> sparks . append ( [ temp , '<STR_LIT>' , str ( b ) + '<STR_LIT>' ] ) <EOL> if return_filenames == True : <EOL> return filenames <EOL> if return_spark == True : <EOL> return sparks <EOL> if return_both == True : <EOL> return [ filenames , sparks ] <EOL> def make_dummy_lines ( header ) : <EOL> newlist = [ header ] <EOL> linestring = '<STR_LIT>' <EOL> count = <NUM_LIT:0> <EOL> ind = <NUM_LIT:0> <EOL> while not count == <NUM_LIT:5> : <EOL> values = [ ] <EOL> count += <NUM_LIT:1> <EOL> for row in header : <EOL> if row == '<STR_LIT>' : <EOL> values . append ( linestring ) <EOL> elif ind == <NUM_LIT:0> : <EOL> ind = <NUM_LIT:1> <EOL> values . append ( count ) <EOL> else : <EOL> values . append ( '<STR_LIT:null>' ) <EOL> ind = <NUM_LIT:0> <EOL> newlist . append ( values ) <EOL> return list2df ( newlist ) <EOL> def make_dummy_polygons ( header ) : <EOL> newlist = [ header ] <EOL> linestring = '<STR_LIT>' <EOL> count = <NUM_LIT:0> <EOL> ind = <NUM_LIT:0> <EOL> while not count == <NUM_LIT:5> : <EOL> values = [ ] <EOL> count += <NUM_LIT:1> <EOL> for row in header : <EOL> if row == '<STR_LIT>' : <EOL> values . append ( linestring ) <EOL> elif ind == <NUM_LIT:0> : <EOL> ind = <NUM_LIT:1> <EOL> values . append ( count ) <EOL> else : <EOL> values . append ( '<STR_LIT:null>' ) <EOL> ind = <NUM_LIT:0> <EOL> newlist . append ( values ) <EOL> return list2df ( newlist ) <EOL> def make_dummy_points ( header ) : <EOL> newlist = [ header ] <EOL> ind = <NUM_LIT:0> <EOL> count = <NUM_LIT:0> <EOL> while not count == <NUM_LIT:5> : <EOL> values = [ ] <EOL> count += <NUM_LIT:1> <EOL> for row in header : <EOL> if '<STR_LIT>' in str ( row ) . lower ( ) or '<STR_LIT>' in str ( row ) . lower ( ) : <EOL> values . append ( <NUM_LIT:0> ) <EOL> elif ind == <NUM_LIT:0> : <EOL> ind = <NUM_LIT:1> <EOL> values . append ( count ) <EOL> else : <EOL> values . append ( '<STR_LIT:null>' ) <EOL> ind = <NUM_LIT:0> <EOL> newlist . append ( values ) <EOL> return list2df ( newlist ) <EOL> def make_dummy_blocks ( header ) : <EOL> newlist = [ header ] <EOL> ind = <NUM_LIT:0> <EOL> count = <NUM_LIT:0> <EOL> while not count == <NUM_LIT:5> : <EOL> values = [ ] <EOL> count += <NUM_LIT:1> <EOL> for row in header : <EOL> if '<STR_LIT>' in str ( row ) . lower ( ) or '<STR_LIT>' in str ( row ) . lower ( ) : <EOL> values . append ( <NUM_LIT:0> ) <EOL> elif ind == <NUM_LIT:0> : <EOL> ind = <NUM_LIT:1> <EOL> values . append ( count ) <EOL> else : <EOL> values . append ( '<STR_LIT:null>' ) <EOL> ind = <NUM_LIT:0> <EOL> newlist . append ( values ) <EOL> return list2df ( newlist ) <EOL> def make_dummy ( header , type ) : <EOL> if type == '<STR_LIT>' : <EOL> dummy = make_dummy_lines ( header ) <EOL> elif type == '<STR_LIT>' : <EOL> dummy = make_dummy_polygons ( header ) <EOL> elif type == '<STR_LIT>' : <EOL> dummy = make_dummy_points ( header ) <EOL> elif type == '<STR_LIT>' : <EOL> dummy = make_dummy_blocks ( header ) <EOL> return dummy <EOL> def yieldgen ( list ) : <EOL> for row in list : <EOL> yield row <EOL> def df2list ( df ) : <EOL> df = [ df . columns . values . tolist ( ) ] + df . values . tolist ( ) <EOL> return df <EOL> def list2df ( df ) : <EOL> df = pd . DataFrame ( df [ <NUM_LIT:1> : ] , columns = df [ <NUM_LIT:0> ] ) <EOL> return df <EOL> def get_range ( table , headercolumn , min , max ) : <EOL> temp = table [ ( table [ headercolumn ] > min ) & ( table [ headercolumn ] <= max ) ] <EOL> return temp <EOL> def make_type ( table , filename , type ) : <EOL> if type == '<STR_LIT>' : <EOL> make_points ( table , list = True , filename = filename ) <EOL> elif type == '<STR_LIT>' : <EOL> make_blocks ( table , list = True , filename = filename ) <EOL> elif type == '<STR_LIT>' : <EOL> make_postgis_lines ( table , filename ) <EOL> elif type == '<STR_LIT>' : <EOL> make_postgis_polygons ( table , filename ) <EOL> def make_object_map ( table , headercolumn , ranges , colors , type , ** kwargs ) : <EOL> filenames = False <EOL> for key , value in kwargs . iteritems ( ) : <EOL> if '<STR_LIT>' == key : <EOL> filenames = value <EOL> count = <NUM_LIT:0> <EOL> dummy = make_dummy ( table . columns . values . tolist ( ) , type ) <EOL> for row in ranges : <EOL> if count == <NUM_LIT:0> : <EOL> count = <NUM_LIT:1> <EOL> oldrow = row <EOL> colorgenerator = yieldgen ( colors ) <EOL> colordict = { } <EOL> else : <EOL> temp = get_range ( table , headercolumn , oldrow , row ) <EOL> color = next ( colorgenerator ) <EOL> if filenames == True : <EOL> filename = color + '<STR_LIT>' <EOL> else : <EOL> filename = color + '<STR_LIT>' <EOL> try : <EOL> if not len ( temp ) == <NUM_LIT:0> : <EOL> make_type ( temp , filename , type ) <EOL> colordict [ filename ] = color <EOL> else : <EOL> make_type ( dummy , filename , type ) <EOL> colordict [ filename ] = color <EOL> except Exception : <EOL> make_type ( dummy , filename , type ) <EOL> colordict [ filename ] = color <EOL> oldrow = row <EOL> return colordict </s>
