excel_writer
Excel writing functionality for the devices_rap pipeline.
create_excel_reports(output_workbooks, output_directory, use_multiprocessing)
Create the Excel reports based on the processed data. The function will create an Excel file for each region containing the processed worksheets for that region.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output_workbooks
|
dict
|
The processed data for each region |
required |
output_directory
|
Path
|
The path to save the Excel reports to |
required |
use_multiprocessing
|
bool
|
Whether to use multiprocessing for writing the Excel files. |
required |
Returns:
| Type | Description |
|---|---|
None
|
|
Source code in devices_rap/data_io/output/excel_writer.py
process_region(output_directory, region, worksheets, use_multiprocessing)
Process the data for a region and create the Excel report.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output_directory
|
Path
|
The path to save the Excel reports to |
required |
region
|
str
|
The region to process |
required |
worksheets
|
dict
|
The processed data for the region |
required |
use_multiprocessing
|
bool
|
Whether to use multiprocessing for writing the Excel file |
required |
Returns:
| Type | Description |
|---|---|
None
|
|
Source code in devices_rap/data_io/output/excel_writer.py
create_excel_file(output_file, worksheets, use_multiprocessing)
Create an Excel file with the given worksheets.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output_file
|
Path
|
The path to save the Excel file to |
required |
worksheets
|
dict
|
The worksheets to include in the Excel file |
required |
use_multiprocessing
|
bool
|
Whether to use multiprocessing for writing the Excel file |
required |
Returns:
| Type | Description |
|---|---|
None
|
|
Source code in devices_rap/data_io/output/excel_writer.py
create_formats(workbook)
Create the formats for the Excel file. This include the formats for the: - Header rows - Total rows
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
workbook
|
object
|
The workbook object |
required |
Returns:
| Type | Description |
|---|---|
FORMATS_DICT(dict[str, object])
|
A dictionary containing the formats for the Excel file |
Source code in devices_rap/data_io/output/excel_writer.py
apply_excel_formatting(writer, data, formats, sheet_name)
Apply formatting to the Excel worksheet. This includes: - Header formatting - Total row formatting - Column formatting for floats - Autofilter for the header row - Autofit for the columns
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
writer
|
ExcelWriter
|
The Excel writer object |
required |
data
|
DataFrame
|
The data to write to the worksheet |
required |
formats
|
dict
|
The formats to apply to the worksheet |
required |
sheet_name
|
str
|
The name of the worksheet |
required |
Source code in devices_rap/data_io/output/excel_writer.py
write_worksheet(writer, sheet_name, data, formats, output_file)
Write a worksheet to the Excel file with conditional formatting.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
writer
|
ExcelWriter
|
The Excel writer object |
required |
sheet_name
|
str
|
The name of the worksheet |
required |
data
|
DataFrame
|
The data to write to the worksheet |
required |
formats
|
dict
|
The formats to apply to the worksheet |
required |
output_file
|
Path
|
The path to the Excel file that is been written to (only used for logging context) |
required |
Returns:
| Type | Description |
|---|---|
None
|
|
Source code in devices_rap/data_io/output/excel_writer.py
create_excel_zip_reports(output_directory, fin_month, fin_year)
Create a zip file containing all the Excel reports for each region. The zip file will be saved in the output directory with a name that includes the financial year and month.
This function will gather all the Excel files created for each region and compress them into a single zip file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output_directory
|
Path
|
The output directory where the Excel files are saved and where the zip file will be created |
required |
fin_month
|
str
|
The financial month for which the data is being processed |
required |
fin_year
|
str
|
The financial year for which the data is being processed |
required |
Returns:
| Type | Description |
|---|---|
None
|
|