Python automation × periodic report production

Automated Periodic Reports

Reports produced every week or month use fixed data sources, calculation rules and layouts. This page describes three production tools written in Python: a multi-source weekly report, historical trend curves and a progress summary table. Each tool has a demo that runs on synthetic data.

3 toolsWeekly report / trend curves / summary table
10-year same-week basisComparison range used for weekly ranking
3 output formatsSpreadsheet / document / PDF

Terms

Same-week rank

The rank of this week's value among 11 values: this week and the same week in each of the past ten years, sorted from highest to lowest.

Reduction rate

The assumed percentage decrease from the original consumption rate. 0% means the original rate is kept.

Minimum level

The lowest managed value for the stock level. The date a curve reaches the minimum level is the date that scenario needs replenishment.

Planned and completed

The number of items each division is scheduled to finish and the number finished so far. Completion rate is completed divided by planned.

Regional statistics

Cities are grouped by region, and the mean, maximum and minimum are calculated for each group.

Fixed layout

Columns, order, fonts and page layout are the same in every issue. Only the data changes.

Problem

1. Multi-source weekly report

Before

  • Each week, values for the same week of the past ten years are looked up from several sources and entered one by one.
  • Ranks and statistics are calculated by hand, and the report layout and charts are adjusted manually.

After

  • A program reads each source and calculates the rank of this week's value among the ten-year same-week values.
  • It produces a ranking table, a bar chart and a regional statistics table in the fixed layout.
2. Historical trend curves

Before

  • Each reduction scenario is calculated separately in a spreadsheet, and the chart is pasted over the historical curves.
  • The date each scenario reaches the minimum level is found by scanning columns.

After

  • Starting from the current stock level, it projects the stock level for the coming months at each reduction rate.
  • Scenario curves and actual curves from the same period in past years are drawn on one chart, and the date each scenario reaches the minimum level is calculated.
3. Progress summary table

Before

  • Planned and completed counts reported by each division are entered into the summary table by hand, and percentages and totals are calculated manually.
  • The spreadsheet, document and PDF versions are prepared separately and must share the same layout.

After

  • After the planned and completed counts of each division are entered, a program calculates percentages and totals.
  • It produces the spreadsheet, document and PDF in the fixed layout.

Workflow

1. Multi-source weekly report
1Read source dataReads air quality and temperature data for each city and standardizes dates and units.
2Calculate same-week rankCompares this week's value with the same week of the past ten years to get the rank.
3Compile regional statisticsCalculates the mean, maximum and minimum for each city's region.
4Apply fixed layoutWrites the ranking table, draws the bar chart and adds the report date.
2. Historical trend curves
1Read historical stock levelsLoads daily actual stock levels for past years, aligned to the same start date.
2Set scenariosSpecifies the current stock level, the minimum level and each reduction rate.
3Project day by daySubtracts consumption each day and calculates the date each scenario reaches the minimum level.
4Overlay and outputDraws scenario and historical curves on one chart with a results table.
3. Progress summary table
1Enter reported figuresEnters the planned and completed counts of each division.
2Calculate percentages and totalsWhen planned is 0, no percentage is calculated, which avoids division by 0.
3Apply fixed layoutWrites to the spreadsheet template and document template, with the same layout as the previous issue.
4Convert to PDFExports a PDF from the document for printing and sending.

Interactive demos

Demo 1: Multi-source weekly report

Weekly environmental data reportSynthetic example data; city names are fictional
Select a week and a metric, then select "Generate report".

Demo 2: Historical trend curves

Stock consumption simulationSynthetic example data; start date is July 1
Reduction rate scenarios
Historical years to overlay
Projected stock level (next 180 days)
Scenario results
The consumption rate is a synthetic seasonal value, averaging about 49 units per day without reduction. Historical curves start from the actual stock level on July 1 of each year.

Demo 3: Progress summary table generator

Progress summary tablePre-filled with synthetic data; figures and rows can be edited
After you select "Generate summary table", the formatted table appears here.

Outcome and technology

Consistent layout

Columns, charts and page layout are the same in every issue. Only the data changes.

Fixed calculation rules

Ranks, percentages, totals and the date each scenario reaches the minimum level are calculated by a program. The same data gives the same result on every run.

Scheduled runs

A scheduler reads the data and produces the reports at a fixed time. Output files are named by date.

Pythonpandasopenpyxlpython-pptxmatplotlibSQL ServerScheduling