Skip to content

Commit

Permalink
issue #383 add logging to replace printing to stdout
Browse files Browse the repository at this point in the history
  • Loading branch information
bikegeek committed Mar 7, 2024
1 parent 375c429 commit df9bd8b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 8 deletions.
16 changes: 14 additions & 2 deletions metplotpy/plots/tcmpr_plots/box/tcmpr_box.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
import os
from datetime import datetime

import plotly.graph_objects as go

from metplotpy.plots.tcmpr_plots.box.tcmpr_box_point import TcmprBoxPoint
from metplotpy.plots.tcmpr_plots.tcmpr_series import TcmprSeries
import metplotpy.plots.util as util


class TcmprBox(TcmprBoxPoint):
def __init__(self, config_obj, column_info, col, case_data, input_df, baseline_data, stat_name):
super().__init__(config_obj, column_info, col, case_data, input_df, baseline_data, stat_name)

print("--------------------------------------------------------")
print(f"Plotting BOXPLOT time series by {self.config_obj.series_val_names[0]}")
# Set up Logging
self.box_logger = util.get_common_logger(self.config_obj.log_level, self.config_obj.log_filename)

self.box_logger.info(f"--------------------------------------------------------\n")
self.box_logger.info(f"Plotting BOXPLOT time series by {self.config_obj.series_val_names[0]}")
self._adjust_titles(stat_name)
self.series_list = self._create_series(self.input_df, stat_name)
self.case_data = None
Expand All @@ -24,6 +29,8 @@ def __init__(self, config_obj, column_info, col, case_data, input_df, baseline_d
else:
self.plot_filename = f"{self.config_obj.plot_dir}{os.path.sep}{self.config_obj.prefix}_{stat_name}_boxplot.png"

self.box_logger.info(f"Plot will be saved as {self.plot_filename}")

# remove the old file if it exists
if os.path.exists(self.plot_filename):
os.remove(self.plot_filename)
Expand All @@ -47,6 +54,7 @@ def _draw_series(self, series: TcmprSeries) -> None:
:param series: Line series object with data and parameters
"""

start_time = datetime.now()
# defaults markers and colors for the regular box plot
line_color = dict(color='rgb(0,0,0)')
marker_color = series.color
Expand Down Expand Up @@ -89,3 +97,7 @@ def _draw_series(self, series: TcmprSeries) -> None:
),
secondary_y=series.y_axis != 1
)

end_time = datetime.now()
total_time = end_time - start_time
self.box_logger.debug(f"Drawing series points took {total_time} millisecs")
22 changes: 16 additions & 6 deletions metplotpy/plots/tcmpr_plots/box/tcmpr_box_point.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,30 @@
import datetime

from metplotpy.plots.tcmpr_plots.tcmpr import Tcmpr
from metplotpy.plots.tcmpr_plots.tcmpr_series import TcmprSeries

import metplotpy.plots.util as util

class TcmprBoxPoint(Tcmpr):
def __init__(self, config_obj, column_info, col, case_data, input_df, baseline_data, stat_name):
super().__init__(config_obj, column_info, col, case_data, input_df)
super().__init__(config_obj, column_info, col, case_data, input_df, stat_name)
# Set up Logging
self.box_point_logger = util.get_common_logger(self.config_obj.log_level, self.config_obj.log_filename)
self.series_len = len(config_obj.get_series_y(1)) + len(config_obj.get_config_value('derived_series_1'))


def _init_hfip_baseline_for_plot(self):
if 'Water Only' in self.config_obj.title or self.cur_baseline == 'no':
print("Plot HFIP Baseline:" + self.cur_baseline)
self.box_point_logger.info(f"Plot HFIP Baseline: {self.cur_baseline}")
else:
self.cur_baseline_data = self.cur_baseline_data[(self.cur_baseline_data['TYPE'] == 'CONS')]
print('Plot HFIP Baseline:' + self.cur_baseline.replace('Error ', ''))
self.box_point_logger.info(f"Plot HFIP Baseline: {self.cur_baseline.replace('Error ', '')}")

def _draw_series(self, series: TcmprSeries) -> None:
pass

def _create_figure(self):
""" Create a box plot from default and custom parameters"""

start_time = datetime.datetime.now()
self.figure = self._create_layout()
self._add_xaxis()
self._add_yaxis()
Expand Down Expand Up @@ -48,7 +54,7 @@ def _create_figure(self):
yaxis_min, yaxis_max = self.find_min_max(series, yaxis_min, yaxis_max)
self._draw_series(series)

print(f'Range of {self.config_obj.list_stat_1[0]}: {yaxis_min}, {yaxis_max}')
self.box_point_logger.info(f'Range of {self.config_obj.list_stat_1[0]}: {yaxis_min}, {yaxis_max}')
self._add_hfip_baseline()

self.figure.update_layout(shapes=[dict(
Expand All @@ -73,3 +79,7 @@ def _create_figure(self):

# add x2 axis
self._add_x2axis(self.config_obj.indy_vals)
end_time = datetime.datetime.now()
total_time = end_time - start_time
self.box_point_logger.info(f"Took {total_time} millisecs to create a boxplot")

0 comments on commit df9bd8b

Please sign in to comment.