Skip to content

Commit

Permalink
monior changes
Browse files Browse the repository at this point in the history
  • Loading branch information
boazhaim committed Nov 17, 2024
1 parent 35cca1c commit 97b0dbb
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ def create_analyzer(parsed_args, full_extracted_logs_list,
in the full report.
Returns the created analyzer
"""
# Checking the base name since some logs in the list are with a directory name
if any(os.path.basename(log) == log_name for log in full_extracted_logs_list):
log_csvs = get_files_in_dest_by_type(parsed_args.destination,
log_name,
Expand Down Expand Up @@ -372,7 +373,6 @@ def create_analyzer(parsed_args, full_extracted_logs_list,
text_to_show_in_pdf = f"Used ufm version in console log {used_ufm_version}{os.linesep}"

pdf = PDFCreator(pdf_path, pdf_header, png_images, text_to_show_in_pdf)
# Adding telemetry stats to the PDF
dataframes_for_pdf = []
fabric_info = ibdiagnet_analyzer.get_fabric_size() \
if ibdiagnet_analyzer else "No Fabric Info found"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@ def plot_iteration_time_over_time(self):

self._iteration_time_data.set_index('timestamp', inplace=True)

# Plot the data using the existing method
with warnings.catch_warnings():
warnings.filterwarnings("ignore", ".*Locator attempting to generate.*")
self._save_data_based_on_timestamp(
Expand Down
18 changes: 2 additions & 16 deletions plugins/ufm_log_analyzer_plugin/src/loganalyze/pdf_creator.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import os
from io import StringIO
from fpdf import FPDF
from tabulate import tabulate # Import FPDF from fpdf module
from tabulate import tabulate


class PDFCreator(FPDF):
Expand Down Expand Up @@ -66,22 +66,16 @@ def add_list_of_dicts_as_text(self, data_list, title=None, headers=None):
if not data_list or not isinstance(data_list, list):
return

# Add title if provided
if title:
self.set_font("Arial", "B", 12)
self.cell(0, 10, title, 0, 1, 'C')
self.ln(5)

# Set font size for the content
self.set_font("Arial", "", 10)

# Prepare data for tabulate
table_data = [[str(item.get(header, '')) for header in headers] for item in data_list]

# Convert the list of dictionaries to a formatted string using `tabulate`
table_str = tabulate(table_data, headers=headers, tablefmt='plain')

# Print the formatted text as plain text
self.multi_cell(0, 10, table_str)
self.ln(10)

Expand All @@ -90,13 +84,11 @@ def add_dataframe_as_text(self, data_frame, title=None):
if data_frame is None or data_frame.empty:
return

# Add title if provided
if title:
self.set_font("Arial", "B", 12)
self.cell(0, 10, title, 0, 1, 'C')
self.ln(5)

# Adjust font size based on the number of columns
num_columns = len(data_frame.columns)
if num_columns > 10:
self.set_font("Arial", "", 8) # Smaller font for many columns
Expand All @@ -105,30 +97,24 @@ def add_dataframe_as_text(self, data_frame, title=None):
else:
self.set_font("Arial", "", 12)

# Convert DataFrame to a formatted string using `tabulate` without row numbers
# Converting and removing the row number as it is not needed
table_str = tabulate(data_frame.values, headers=data_frame.columns, tablefmt='plain')

# Print the formatted table as plain text
self.multi_cell(0, 10, table_str)
self.ln(10)

def create_pdf(self, data_frames_with_titles, lists_to_add):
"""Generates the PDF with images, text, and multiple tables."""
self.set_display_mode("fullpage")
self.add_page()

# Add images section
self.add_images()

# Add multiple DataFrames with titles
for title, df in data_frames_with_titles:
self.add_dataframe_as_text(data_frame=df, title=title)

for data_list, title, headers in lists_to_add:
self.add_list_of_dicts_as_text(data_list, title, headers)

# Output the final PDF
# Add text section
self.add_text()

self.output(self._pdf_path)

0 comments on commit 97b0dbb

Please sign in to comment.