Skip to content

Commit

Permalink
Reading report details from config.yaml (daxa-ai#148)
Browse files Browse the repository at this point in the history
* Added config changes for pebblo report
  • Loading branch information
KunalJadhav5 authored Feb 15, 2024
1 parent 0c1106f commit a4dbbf6
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 8 deletions.
2 changes: 2 additions & 0 deletions pebblo/app/config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class PortConfig(BaseSettings):
# Report BaseModel
class ReportConfig(BaseSettings):
format: str = Field(default='pdf')
renderer: str = Field(default='weasyprint')
outputDir: str = Field(dir_path)


Expand All @@ -39,6 +40,7 @@ def load_config(path, p_bar=None) -> Config:
),
reports=ReportConfig(
format='pdf',
renderer='weasyprint',
outputDir='~/.pebblo'
),
logging=LoggingConfig(
Expand Down
1 change: 1 addition & 0 deletions pebblo/app/config/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ logging:
level: info
reports:
format: pdf
renderer: weasyprint
outputDir: ~/.pebblo
2 changes: 1 addition & 1 deletion pebblo/app/config/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def __init__(self, config_details):
# Fetching Details from Config File
self.config_details = config_details
self.port = self.config_details.get('daemon', {}).get('port', 8000)
self.host = self.config_details.get('daemon', {}).get('host', '0.0.0.0')
self.host = self.config_details.get('daemon', {}).get('host', 'localhost')
self.log_level = self.config_details.get('logging', {}).get('level', 'info')

async def create_main_api_server(self):
Expand Down
6 changes: 4 additions & 2 deletions pebblo/app/enums/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@
class CacheDir(Enum):
metadata_folder = "/metadata"
metadata_file_path = f"{metadata_folder}/metadata.json"
report_file_name = "report.json"
pdf_report_file_name = "pebblo_report.pdf"
report_data_file_name = "report.json"
report_file_name = f"pebblo_report.{config_details.get('reports', {}).get('format')}"
home_dir = config_details.get('reports', {}).get('outputDir', '~/.pebblo')
renderer = config_details.get('reports', {}).get('renderer')
format = config_details.get('reports', {}).get('format')


class ReportConstants(Enum):
Expand Down
16 changes: 11 additions & 5 deletions pebblo/app/service/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ def process_request(self):
app_name = self.data.get("name")
logger.debug(f"AI Loader Doc, AppName: {app_name}")

report_format = CacheDir.format.value
renderer = CacheDir.renderer.value

# Read metadata file & get current load details
app_metadata_file_path = f"{CacheDir.home_dir.value}/{app_name}/{CacheDir.metadata_file_path.value}"
app_metadata = read_json_file(app_metadata_file_path)
Expand All @@ -97,7 +100,7 @@ def process_request(self):
load_id = self.data['load_id']

# Get current app details from load id
report_file_path = f"{CacheDir.home_dir.value}/{app_name}/{load_id}/{CacheDir.report_file_name.value}"
report_file_path = f"{CacheDir.home_dir.value}/{app_name}/{load_id}/{CacheDir.report_data_file_name.value}"
app_load_metadata_file_path = f"{CacheDir.home_dir.value}/{app_name}/{load_id}/{CacheDir.metadata_file_path.value}"
app_details = read_json_file(app_load_metadata_file_path)
if not app_details:
Expand Down Expand Up @@ -159,15 +162,18 @@ def process_request(self):
# Writing pdf report to current load id directory
load_id = self.data['load_id']
current_load_report_file_path = (f"{CacheDir.home_dir.value}/{app_name}"
f"/{load_id}/{CacheDir.pdf_report_file_name.value}")
f"/{load_id}/{CacheDir.report_file_name.value}")
full_file_path = get_full_path(current_load_report_file_path)
report_obj.generate_report(final_report, full_file_path)
report_obj.generate_report(data=final_report, outputPath=full_file_path, format=report_format,
renderer=renderer)

# Writing pdf report file specific to application name, inside app directory
current_app_report_file_path = (f"{CacheDir.home_dir.value}/{app_name}"
f"/{CacheDir.pdf_report_file_name.value}")
f"/{CacheDir.report_file_name.value}")
full_file_path = get_full_path(current_app_report_file_path)
report_obj.generate_report(final_report, full_file_path)

report_obj.generate_report(data=final_report, outputPath=full_file_path, format=report_format,
renderer=renderer)
logger.info(f"PDF report generated at : {full_file_path}")

logger.info("Loader Doc request Request processed successfully.")
Expand Down

0 comments on commit a4dbbf6

Please sign in to comment.