data_out
Functionality that handle the output of processed data from the pipeline.
output_data(output_workbooks, pipeline_config)
Handle the output of processed data from the pipeline. This function will create the Excel reports and pickle files based on the processed data for each region. It will check the configuration to determine which outputs to create (Excel, pickle, or both) and will create the output directory if it does not exist.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output_workbooks
|
dict
|
The processed data for each region |
required |
pipeline_config
|
Config
|
The configuration object containing the output directory and other settings |
required |
Returns:
| Type | Description |
|---|---|
None
|
|
Source code in devices_rap/data_out.py
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_out.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_out.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 |
Returns:
| Type | Description |
|---|---|
None
|
|
Source code in devices_rap/data_out.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_out.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_out.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_out.py
create_pickle(output_workbooks, output_directory, fin_month, fin_year)
Create a pickle file containing the processed data for all regions. The pickle file will be saved in the output directory with a name that includes the financial year and month.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output_workbooks
|
dict
|
The processed data for each region |
required |
output_directory
|
Path
|
The path to save the pickle file to |
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
|
|
Source code in devices_rap/data_out.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
|
|