# AUTOGENERATED! DO NOT EDIT! File to edit: notebooks/05_Create_Acs_Indicators.ipynb (unless otherwise specified).

__all__ = ['createAcsIndicator']

# Cell
#@title Run This Cell: Create createIndicator()
import geopandas as gpd
import numpy as np
import pandas as pd
def createAcsIndicator(state, county, tract, year, tableId, saveAcs,
                    cwUrl, cw_left_col, cw_right_col, merge_how,
                    saveCrosswalked, saveCrosswalkedFileName, groupBy,
                    aggMethod, method, columnsToInclude, finalFileName=False):

  # Pull the data
  df = retrieve_acs_data(state, county, tract, tableId, year, saveAcs)
  print('Table: ' + tableId + ', Year: ' + year + ' imported.')

  # Get the crosswalk
  if cwUrl:
    right_ds = pd.read_csv( cwUrl )
    print('Tract-ACS Crosswalk file imported')
    # Merge crosswalk with the data
    df = mergeDatasets( left_ds=df, right_ds=right_ds,
                  left_col=cw_left_col, right_col=cw_right_col,
                  merge_how=merge_how, interactive=False )

    print('Both are now merged.')

  # Group and Aggregate
  if groupBy:
    df = df.groupby(groupBy)
    print('Aggregating...')
    if aggMethod == 'sum':
      df = sumInts(df)
    else:
      df = sumInts(df)
    print('Aggregated')

  # Create the indicator
  print('Creating Indicator')
  resp = method( df, columnsToInclude)
  print('Indicator Created')
  if finalFileName:
    resp.to_csv(finalFileName, quoting=csv.QUOTE_ALL)
    print('Indicator Saved')



  return resp