#NEWLINE# def load_energy( ) : #NEWLINE# #INDENT# 'Loads an energy related dataset to use with sankey and graphs' #NEWLINE# tbl_name = 'energy_usage' #NEWLINE# with gzip . open ( os . path . join ( DATA_FOLDER , 'energy.json.gz' ) ) as f : #NEWLINE# #INDENT# pdf = pd . read_json ( tbl ) #NEWLINE# #UNINDENT# pdf . to_sql ( tbl_name , db . engine , if_exists = 'replace' , chunksize = 500 , dtype = { #NEWLINE# #INDENT# 'source' : String ( 255 ) , #NEWLINE# 'target' : String ( 255 ) , #NEWLINE# 'value' : Float ( ) , #NEWLINE# #UNINDENT# } , index = False ) #NEWLINE# print ( 'Creating table [wb_health_population] reference' ) #NEWLINE# tbl = db . session . query ( TBL ) . filter_by ( table_name = tbl_name ) . first ( ) #NEWLINE# if ( not tbl ) : #NEWLINE# #INDENT# tbl = TBL ( table_name = tbl_name ) #NEWLINE# #UNINDENT# tbl . description = 'Energy consumption' #NEWLINE# tbl . is_featured = True #NEWLINE# tbl . database = get_or_create_db ( db . session ) #NEWLINE# db . session . merge ( tbl ) #NEWLINE# db . session . commit ( ) #NEWLINE# tbl . fetch_metadata ( ) #NEWLINE# merge_slice ( Slice ( slice_name = 'Energy Sankey' , viz_type = 'sankey' , datasource_type = 'table' , table = tbl , params = textwrap . dedent ( '            {\n                "collapsed_fieldsets": "",\n                "datasource_id": "3",\n                "datasource_name": "energy_usage",\n                "datasource_type": "table",\n                "flt_col_0": "source",\n                "flt_eq_0": "",\n                "flt_op_0": "in",\n                "groupby": [\n                    "source",\n                    "target"\n                ],\n                "having": "",\n                "metric": "sum__value",\n                "row_limit": "5000",\n                "slice_id": "",\n                "slice_name": "Energy Sankey",\n                "viz_type": "sankey",\n                "where": ""\n            }\n            ' ) ) ) #NEWLINE# merge_slice ( Slice ( slice_name = 'Energy Force Layout' , viz_type = 'directed_force' , datasource_type = 'table' , table = tbl , params = textwrap . dedent ( '            {\n                "charge": "-500",\n                "collapsed_fieldsets": "",\n                "datasource_id": "1",\n                "datasource_name": "energy_usage",\n                "datasource_type": "table",\n                "flt_col_0": "source",\n                "flt_eq_0": "",\n                "flt_op_0": "in",\n                "groupby": [\n                    "source",\n                    "target"\n                ],\n                "having": "",\n                "link_length": "200",\n                "metric": "sum__value",\n                "row_limit": "5000",\n                "slice_id": "229",\n                "slice_name": "Force",\n                "viz_type": "directed_force",\n                "where": ""\n            }\n            ' ) ) ) #NEWLINE# merge_slice ( Slice ( slice_name = 'Heatmap' , viz_type = 'heatmap' , datasource_type = 'table' , table = tbl , params = textwrap . dedent ( '            {\n                "all_columns_x": "source",\n                "all_columns_y": "target",\n                "canvas_image_rendering": "pixelated",\n                "collapsed_fieldsets": "",\n                "datasource_id": "1",\n                "datasource_name": "energy_usage",\n                "datasource_type": "table",\n                "flt_col_0": "source",\n                "flt_eq_0": "",\n                "flt_op_0": "in",\n                "having": "",\n                "linear_color_scheme": "blue_white_yellow",\n                "metric": "sum__value",\n                "normalize_across": "heatmap",\n                "slice_id": "229",\n                "slice_name": "Heatmap",\n                "viz_type": "heatmap",\n                "where": "",\n                "xscale_interval": "1",\n                "yscale_interval": "1"\n            }\n            ' ) ) )