Commit 69ca6728 authored by Le Roux Erwan's avatar Le Roux Erwan
Browse files

[HYPERCUBE] factorize/simplify hypercube code by creating a df_bool method

parent d862d32f
No related merge requests found
Showing with 9 additions and 6 deletions
+9 -6
...@@ -35,13 +35,12 @@ class AltitudeHypercubeVisualizer(AbstractHypercubeVisualizer): ...@@ -35,13 +35,12 @@ class AltitudeHypercubeVisualizer(AbstractHypercubeVisualizer):
# Map each trend type to its serie with percentages # Map each trend type to its serie with percentages
# Define here all the trend type we might need in the results/displays # Define here all the trend type we might need in the results/displays
trend_types_to_process = list(self.display_trend_types) + [AbstractUnivariateTest.SIGNIFICATIVE_ALL_TREND] trend_types_to_process = list(self.display_trend_types) + [AbstractUnivariateTest.SIGNIFICATIVE_ALL_TREND]
return {trend_type: self.trend_type_reduction(reduction_function, trend_type)[0] return {trend_type: self.trend_type_reduction(reduction_function, trend_type)
for trend_type in trend_types_to_process} for trend_type in trend_types_to_process}
def trend_type_reduction(self, reduction_function, display_trend_type): def trend_type_reduction(self, reduction_function, display_trend_type):
# Reduce df_bool df to a serie s_trend_type_percentage # Reduce df_bool df to a serie s_trend_type_percentage
df_bool = self.df_hypercube_trend_type.isin(AbstractUnivariateTest.get_real_trend_types(display_trend_type)) s_trend_type_percentage = reduction_function(self.df_bool(display_trend_type))
s_trend_type_percentage = reduction_function(df_bool)
assert isinstance(s_trend_type_percentage, pd.Series) assert isinstance(s_trend_type_percentage, pd.Series)
assert not isinstance(s_trend_type_percentage.index, pd.MultiIndex) assert not isinstance(s_trend_type_percentage.index, pd.MultiIndex)
s_trend_type_percentage *= 100 s_trend_type_percentage *= 100
...@@ -51,7 +50,10 @@ class AltitudeHypercubeVisualizer(AbstractHypercubeVisualizer): ...@@ -51,7 +50,10 @@ class AltitudeHypercubeVisualizer(AbstractHypercubeVisualizer):
# s_trend_strength = reduction_function(df_strength) # s_trend_strength = reduction_function(df_strength)
# # Group result # # Group result
# series = [s_trend_type_percentage, s_trend_strength] # series = [s_trend_type_percentage, s_trend_strength]
return series, df_bool return series
def df_bool(self, display_trend_type):
return self.df_hypercube_trend_type.isin(AbstractUnivariateTest.get_real_trend_types(display_trend_type))
def subtitle_to_reduction_function(self, reduction_function, level=None, add_detailed_plot=False, subtitle=None): def subtitle_to_reduction_function(self, reduction_function, level=None, add_detailed_plot=False, subtitle=None):
def reduction_function_with_level(df_bool, **kwargs): def reduction_function_with_level(df_bool, **kwargs):
......
...@@ -27,11 +27,12 @@ class Altitude_Hypercube_Year_Visualizer(AltitudeHypercubeVisualizer): ...@@ -27,11 +27,12 @@ class Altitude_Hypercube_Year_Visualizer(AltitudeHypercubeVisualizer):
return df.mean(level=level) return df.mean(level=level)
def trend_type_reduction(self, reduction_function, display_trend_type): def trend_type_reduction(self, reduction_function, display_trend_type):
series, df_bool = super().trend_type_reduction(reduction_function, display_trend_type) series = super().trend_type_reduction(reduction_function, display_trend_type)
# Create df argmax # Create df argmax
df_bool = self.df_bool(display_trend_type)
df = df_bool.copy() df = df_bool.copy()
df = (df * df.columns)[df_bool] df = (df * df.columns)[df_bool]
# Reduce and append # Reduce and append
serie = reduction_function(df, year_visualization=True) serie = reduction_function(df, year_visualization=True)
series.append(serie) series.append(serie)
return series, df_bool return series
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment