def create_report(day, filename="tutorial.pdf"): pdf = FPDF() '''First Page''' pdf.add_page() pdf.image("./resources/letterhead_cropped.png", 0, 0, WIDTH) create_title(day, pdf) plot_usa_case_map("usa_cases.png", day=day) pdf.image("usa_cases.png", 5, 90, WIDTH - 20) '''Second Page''' pdf.add_page() states = ["New Hampshire", "Massachusetts"] plot_daily_count_states(states, filename="test.png") pdf.image("test.png", 5, 30, WIDTH / 2 - 5) plot_daily_count_states(states, mode=Mode.DEATHS, filename="test2.png") pdf.image("test2.png", WIDTH / 2 + 5, 30, WIDTH / 2 - 5) pdf.add_page() plot_states(states, days=7, filename="test3.png", end_date=day) pdf.image("test3.png", 5, 110, WIDTH / 2 - 5) plot_states(states, days=7, mode=Mode.DEATHS, filename="test4.png", end_date=day) pdf.image("test4.png", WIDTH / 2 - 5, 110, WIDTH / 2 - 5) pdf.output(filename)
def create_analytics_report(day=TEST_DATE, filename="report.pdf"): pdf = FPDF() # A4 (210 by 297 mm) states = ['Massachusetts', 'New Hampshire'] ''' First Page ''' pdf.add_page() pdf.image("./resources/letterhead_cropped.png", 0, 0, WIDTH) create_title(day, pdf) plot_usa_case_map("./tmp/usa_cases.png", day=day) prev_days = 250 plot_states(states, days=prev_days, filename="./tmp/cases.png", end_date=day) plot_states(states, days=prev_days, mode=Mode.DEATHS, filename="./tmp/deaths.png", end_date=day) pdf.image("./tmp/usa_cases.png", 5, 90, WIDTH-20) pdf.image("./tmp/cases.png", 5, 200, WIDTH/2-10) pdf.image("./tmp/deaths.png", WIDTH/2, 200, WIDTH/2-10) ''' Second Page ''' pdf.add_page() plot_daily_count_states(states, day=day, filename="./tmp/cases_day.png") plot_daily_count_states(states, day=day, mode=Mode.DEATHS, filename="./tmp/deaths_day.png") pdf.image("./tmp/cases_day.png", 5, 20, WIDTH/2-10) pdf.image("./tmp/deaths_day.png", WIDTH/2, 20, WIDTH/2-10) prev_days = 7 plot_states(states, days=prev_days, filename="./tmp/cases2.png", end_date=day) plot_states(states, days=prev_days, mode=Mode.DEATHS, filename="./tmp/deaths2.png", end_date=day) pdf.image("./tmp/cases2.png", 5, 110, WIDTH/2-10) pdf.image("./tmp/deaths2.png", WIDTH/2, 110, WIDTH/2-10) prev_days = 30 plot_states(states, days=prev_days, filename="./tmp/cases3.png", end_date=day) plot_states(states, days=prev_days, mode=Mode.DEATHS, filename="./tmp/deaths3.png", end_date=day) pdf.image("./tmp/cases3.png", 5, 200, WIDTH/2-10) pdf.image("./tmp/deaths3.png", WIDTH/2, 200, WIDTH/2-10) ''' Third Page ''' pdf.add_page() plot_global_case_map("./tmp/global_cases.png", day=day) countries = ['US', 'India', 'Brazil'] prev_days = 7 plot_countries(countries, days=prev_days, filename="./tmp/cases4.png", end_date=day) plot_countries(countries, days=prev_days, mode=Mode.DEATHS, filename="./tmp/deaths4.png", end_date=day) pdf.image("./tmp/global_cases.png", 5, 20, WIDTH-20) pdf.image("./tmp/cases4.png", 5, 130, WIDTH/2-10) pdf.image("./tmp/deaths4.png", WIDTH/2, 130, WIDTH/2-10) pdf.output(filename, 'F')
from fpdf import FPDF from daily_counts import plot_daily_count_states, plot_daily_count_countries WIDTH = 210 HEIGHT = 297 pdf = FPDF() pdf.add_page() pdf.set_font('Arial', 'B', 16) pdf.cell(40, 10, f'Hello World!') plot_daily_count_states(["New Hampshire", "Massachusetts"], filename="test.png") pdf.image("test.png", 0, 30, WIDTH / 2 - 5) plot_daily_count_countries(["US", "India"], filename="test2.png") pdf.image("test2.png", WIDTH / 2, 30, WIDTH / 2 - 5) pdf.output('tutorial.pdf', 'F') print("Done")
@author: Kleogis """ from fpdf import FPDF from daily_counts import plot_daily_count_states, plot_daily_count_countries from time_series_analysis import plot_states, plot_countries from helper import Mode, get_state_names, get_country_names WIDTH = 210 HEIGHT = 297 pdf = FPDF('P', 'mm', 'A4') pdf.add_page() pdf.set_font('Arial', 'B', 16) pdf.cell(40, 10, 'Hello World!') states=["New Hampshire", "Massachusetts"] plot_daily_count_states(states, filename = "test.png") pdf.image("test.png", 5, 30, WIDTH/2-5) plot_daily_count_countries(["US", "Ukraine"], filename="test2.png") pdf.image("test2.png", WIDTH/2+5, 30, WIDTH/2-5) pdf.add_page() plot_states(states, days=7, filename="test3.png") pdf.image("test3.png", 5, 10, WIDTH/2-5) plot_daily_count_states(states, mode=Mode.DEATHS, filename = "test4.png") pdf.image("test4.png", WIDTH/2+5, 10, WIDTH/2-5) pdf.output('tuto1.pdf', 'F')