reporting_funcs documentation#

class reporting_funcs.Report(report_functions, engine_settings, start_date, end_date, report_type='Queries', interval=None, group_by_interval=False)#

Bases: object

__init__(report_functions, engine_settings, start_date, end_date, report_type='Queries', interval=None, group_by_interval=False)#

Creates an object that runs a report and stores its outputs

Parameters:
  • report_functions (Dict) – A dictionary of functions to run. Value is

  • engine_settings (Dict) – A dictionary of preferences to initialize a suave_sql object

  • start_date (Str) – The start date of the report period, formatted as ‘YYYY-MM-DD’

  • end_date (Str) – The end date of the report period, formatted as ‘YYYY-MM-DD’

  • report_type – The sql_funcs object to use. Options include Audits, IDHS, ReferralAsks, Queries. Defaults to Queries

  • interval – (optional) The date intervals within the time period to run the report over. ‘MS’ for month, ‘3MS’ for quarter, ‘YS’ for year. Defaults to None

  • group_by_interval (Bool) – (optional) True groups a series of reports by time interval, False groups by each query. Defaults to False

Examples

Sample report_functions:

funcz = {"highest cases by team": ("highest_cases", (False,)),
        "highest cases by atty": ("highest_cases", (True,)),
        "all client neighborhoods":("dem_address",(False, 'region',)),
        "custody status counts":("custody_status",(True,)),
        "services missing staff":("service_lacks_staff",())
            }

Sample engine settings:

engine = create_engine('mysql+pymysql://eli:password@LCLCN001/neon', isolation_level="AUTOCOMMIT")
full_engine_settings = {
    'engine': engine,
    'print_SQL': True,
    'clipboard': False,
    'mycase': True,
    'default_table': 'stints.neon_chd'
}

Create a report for all clients between January and August:

r = Report(funcz, full_engine_settings, '2024-01-01', '2024-08-31', interval = None, report_type = 'Queries')

See reports for each month between January and August side-by-side:

r = Report(funcz, full_engine_settings, '2024-01-01', '2024-08-31', report_type = 'Queries', interval = 'MS')

See reports for each quarter between January and August one at a time:

r = Report(funcz, full_engine_settings, '2024-01-01', '2024-08-31', report_type = 'Queries', interval = '3MS', group_by_interval = True)
run_a_report()#

Runs the report using sql_funcs’ Tables.run_report() and saves it as a dictionary. Done automatically when using the Report object.

Example

To access the full dictionary of outputs:

r.report_outputs

To access a single query:

r.report_outputs["all client neighborhoods"]
report_to_excel(file_path, query_tabs=False, spacer_rows=1)#

Saves the report outputs to an excel file

Parameters:
  • file_path – The new file path for the excel document

  • query_tabs (Bool) – Whether each function should get its own tab in the file. Must be False if report_functions has multiple levels. Defaults to False

  • spacer_rows (Int) – The number of empty rows to put between each query if not on separate tabs. Defaults to 1

Examples

Save each query on separate tabs:

r.report_to_excel(file_path="C:/Users/eli/Downloads/test.xlsx", query_tabs=True)

Put two spaces between each query on the same sheet:

r.report_to_excel(file_path="C:/Users/eli/Downloads/test.xlsx", spaces = True)
make_date_dict(interval)#

Makes a dictionary of dates to pass to an sql_funcs object

Parameters:

interval – the time interval to subset the dates. “MS” for month, “3MS” for quarter, “YS” for year

generate_reports()#

Generates reports for each time interval within the report and saves them to self.report_outputs.

consolidate_query_outputs(query_dict)#

Consolidates outputs for a given query over multiple intervals into one df

Parameters:

query_dict – the dictionary of report outputs