def lambda_handler(event, context): summary_df = hdb.dataframe_from_summary() period = hdb.get_summary_dates(summary_df) clean_summary_df = hdb.remove_zero_values(summary_df) clean_summary_df = hdb.group_by_age(clean_summary_df) clean_summary_df = hdb.group_by_weight(clean_summary_df) # Days on Campus by Age doc_chart_by_age = get_days_on_campus_chart(clean_summary_df, 'age_group', 'age', period, 'Age') tp.write_to_s3(snippets_bucket, 'days_on_campus/days_on_campus_by_age_chart.html', doc_chart_by_age) # Days on Campus by Weight doc_chart_by_weight = get_days_on_campus_chart(clean_summary_df, 'weight_group', 'weight', period, 'Weight') tp.write_to_s3(snippets_bucket, 'days_on_campus/days_on_campus_by_weight_chart.html', doc_chart_by_weight) return { 'statusCode': 200, 'body': json.dumps('Charts created and html pages generated.') }
def lambda_handler(event, context): bucket = event['Records'][0]['s3']['bucket']['name'] file = event['Records'][0]['s3']['object']['key'] s3 = boto3.resource('s3') print(f'Generating shift counts for: {bucket}:{file}') dbs_report = s3.Object(bucket, file) dbs_report_csv = dbs_report.get()['Body'].read().decode('utf-8') shift_counts_df = load_and_summarize_dbs_counts(dbs_report_csv) schedule = get_schedule(shift_counts_df) dbs_assigned = assign_dbs_to_shift(shift_counts_df, schedule) # Temporary during Covid-19 shutdown dbs_assigned = zero_out_dbs_levels(dbs_assigned, ['Green']) # End of temp code dbs_assigned_fmt = format_shift_counts(dbs_assigned) report_time = datetime.now(tz=pytz.timezone('US/Pacific')) thepups.write_to_s3( snippets_bucket, 'dbs_shift_counts_timestamp.html', datetime.strftime(report_time, '%A, %b %d, %Y at %I:%M %p ')) thepups.write_to_s3(snippets_bucket, 'dbs_shift_counts.html', get_shift_counts_as_html(dbs_assigned_fmt)) write_as_csv_to_s3(output_data_bucket, 'shift_counts/shift-counts.csv', dbs_assigned) print( f'Saved html for shift counts in {snippets_bucket} and processed shift counts in {output_data_bucket}' ) return { 'statusCode': 200, 'body': json.dumps( f'HTML snippets created and stored in {snippets_bucket}. Data output to {output_data_bucket}' ) }
def lambda_handler(event, context): dog_history_df = hdb.dataframe_from_history() period = hdb.get_history_dates(dog_history_df) counts_by_date_df = hdb.get_counts_by_date(dog_history_df) count_stats_df = get_dog_count_stats(counts_by_date_df) dog_stats = get_dogs_on_campus_stats(count_stats_df) tp.write_to_s3(snippets_bucket, f'{folder_name}/stats_all_dogs_table.html', get_stats_as_html(dog_stats, 'all_dogs')) dog_stats = get_dogs_on_campus_by_group(count_stats_df) tp.write_to_s3(snippets_bucket, f'{folder_name}/stats_by_group_table.html', get_stats_as_html(dog_stats, 'group')) dog_stats = get_dogs_on_campus_by_dbs_level(count_stats_df) tp.write_to_s3(snippets_bucket, f'{folder_name}/stats_by_dbs_level_table.html', get_stats_as_html(dog_stats, 'dbs')) dog_stats = get_dogs_on_campus_by_staff_level(count_stats_df) tp.write_to_s3(snippets_bucket, f'{folder_name}/stats_by_staff_level_table.html', get_stats_as_html(dog_stats, 'staff')) tp.write_to_s3(snippets_bucket, f'{folder_name}/report_period.html', get_formatted_period(period)) return { 'statusCode': 200, 'body': json.dumps('Stats compiled and html pages generated.') }
def create_needs_output(needs_df): if needs_df.empty: needs_html = get_all_shifts_covered_html() else: formatted_needs_df = format_shift_counts(needs_df) needs_html = get_needs_as_html(formatted_needs_df) thepups.write_to_s3(snippets_bucket, 'dbs_shift_needs.html', needs_html) thepups.write_to_s3('the-pups-info-snippets', 'dbs_shift_needs_timestamp.html', datetime.strftime(datetime.now(), '%A, %b %d, %Y at %I:%M %p '))
def lambda_handler(event, context): summary_df = hdb.dataframe_from_summary() period = hdb.get_summary_dates(summary_df) tp.write_to_s3(snippets_bucket, 'all_dog_info.html', get_dog_info_as_html(summary_df)) tp.write_to_s3(snippets_bucket, 'all_dog_info_report_period.html', get_formatted_period(period)) return { 'statusCode': 200, 'body': json.dumps('Dog history compiled and html pages generated.') }
def write_as_csv_to_s3(bucket: str, file_name: str, assigned_df: pd.DataFrame): all_assigned = pd.DataFrame(assigned_df.to_records()) # print(all_assigned) all_assigned['Start'] = all_assigned['shift'].apply(lambda s: s[0]) all_assigned['End'] = all_assigned['shift'].apply(lambda s: s[1]) all_assigned.drop(columns=['shift'], inplace=True, axis=1) all_assigned = all_assigned.astype({ 'Start': 'datetime64[m]', 'End': 'datetime64[m]', 'Green': int, 'Blue': int, 'Purple': int }) all_assigned = all_assigned[['Start', 'End', 'Green', 'Blue', 'Purple']] all_assigned = all_assigned.set_index('Start') output = StringIO() all_assigned.to_csv(output) thepups.write_to_s3(bucket, file_name, output.getvalue())
def lambda_handler(event, context): dog_history_df = hdb.dataframe_from_history() period = hdb.get_history_dates(dog_history_df) counts_by_date_df = hdb.get_counts_by_date(dog_history_df) # count_stats_df = get_dog_count_stats(counts_by_date_df) chart = get_count_by_group_chart(counts_by_date_df) tp.write_to_s3(snippets_bucket, f'{folder_name}/stats_by_group_chart.html', get_chart_as_html(chart)) chart = get_count_by_dbs_level_chart(counts_by_date_df) tp.write_to_s3(snippets_bucket, f'{folder_name}/stats_by_dbs_level_chart.html', get_chart_as_html(chart)) chart = get_count_by_staff_level_chart(counts_by_date_df) tp.write_to_s3(snippets_bucket, f'{folder_name}/stats_by_staff_level_chart.html', get_chart_as_html(chart)) chart = get_count_by_kc_chart(counts_by_date_df) tp.write_to_s3(snippets_bucket, f'{folder_name}/stats_by_kc_chart.html', get_chart_as_html(chart)) return { 'statusCode': 200, 'body': json.dumps('Charts created and html pages generated.') }
def lambda_handler(event, context): summary_df = hdb.dataframe_from_summary() period = hdb.get_summary_dates(summary_df) clean_summary_df = hdb.remove_zero_values(summary_df) clean_summary_df = hdb.group_by_age(clean_summary_df) clean_summary_df = hdb.group_by_weight(clean_summary_df) doc_stats = get_days_on_campus_stats(clean_summary_df) tp.write_to_s3(snippets_bucket, 'days_on_campus/days_on_campus_table.html', get_stats_as_html(doc_stats)) # Days on Campus by Age doc_stats_by_age = get_days_on_campus_by_age_stats(clean_summary_df) tp.write_to_s3(snippets_bucket, 'days_on_campus/days_on_campus_by_age_table.html', get_stats_as_html(doc_stats_by_age, 'age_group', 'Age Group')) # Days on Campus by Weight doc_stats_by_weight = get_days_on_campus_by_weight_stats(clean_summary_df) tp.write_to_s3(snippets_bucket, 'days_on_campus/days_on_campus_by_weight_table.html', get_stats_as_html(doc_stats_by_weight, 'weight_group', 'Weight Group')) tp.write_to_s3(snippets_bucket, 'days_on_campus/report_period.html', get_formatted_period(period)) return { 'statusCode': 200, 'body': json.dumps('Stats compiled and html pages generated.') }
def lambda_handler(event, context): bucket = event['Records'][0]['s3']['bucket']['name'] file = event['Records'][0]['s3']['object']['key'] s3 = boto3.resource('s3') logger.info(f'Received Event for Bucket: {bucket}, File: {file}') logger.info( f'Output Buckets: Output Data: {output_data_bucket}, Snippets: {snippets_bucket}' ) dog_list = s3.Object(bucket, file) dog_list_csv = dog_list.get()['Body'].read().decode('utf-8') dogs, report_time = get_dogs(dog_list_csv) dogs_df = get_dog_dataframe(dogs) thepups.write_to_s3( snippets_bucket, 'dog_count_timestamp.html', datetime.strftime(report_time, '%A, %b %d, %Y at %I:%M %p ')) thepups.write_to_s3(snippets_bucket, 'dbs_dog_counts.html', get_dog_counts_as_html(filter_for_dbs(dogs_df))) thepups.write_to_s3(snippets_bucket, 'staff_dog_counts.html', get_dog_counts_as_html(filter_for_non_dbs(dogs_df))) thepups.write_to_s3(snippets_bucket, 'dog_info.html', get_dog_info_as_html(dogs_df)) thepups.write_to_s3(output_data_bucket, 'current_dogs/dog-counts.csv', get_dog_counts_dataframe(dogs_df).to_csv()) thepups.write_to_s3(output_data_bucket, 'current_dogs/dogs-on-campus.json', get_dogs_as_json(dogs_df, report_time)) return { 'statusCode': 200, 'body': json.dumps( f'HTML snippets created and stored in {snippets_bucket}. Data output to {output_data_bucket}' ) }