Skip to content

Commit

Permalink
feat: add method to unify process values
Browse files Browse the repository at this point in the history
  • Loading branch information
rafabailon committed Jun 14, 2024
1 parent 3cd69e3 commit a21ace0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ def get_script_arguments():
help=f'Base name for the images. Default {None}.')
parser.add_argument('-c', '--columns', dest='columns', default=None,
help=f'Path to Json with Columns to Plot. Default {None}.')
parser.add_argument('-u', '--unify', dest='unify', default=False,
help=f'Unify process values. Default {False}.')

return parser.parse_args()

Expand All @@ -32,7 +34,7 @@ def main():
makedirs(destination)
dv = DataVisualizer(dataframes=options.csv_list, target=options.visualization_target,
compare=False, store_path=options.destination, base_name=options.name,
columns_path=options.columns)
columns_path=options.columns, unify=options.unify)
dv.plot()


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class DataVisualizer:
base_name (str, optional): base name used to store the images.
"""
def __init__(self, dataframes, target, compare=False, store_path=gettempdir(), x_ticks_granularity='minutes',
x_ticks_interval=1, base_name=None, columns_path=None):
x_ticks_interval=1, base_name=None, columns_path=None, unify=False):
self.dataframes_paths = dataframes
self.dataframe = None
self.compare = compare
Expand All @@ -48,6 +48,9 @@ def __init__(self, dataframes, target, compare=False, store_path=gettempdir(), x
if target in ['binary', 'analysis', 'remote', 'agent', 'logcollector', 'wazuhdb']:
self.columns_to_plot = self._load_columns_to_plot(columns_path)

if unify:
self._unify_dataframes()

@staticmethod
def _color_palette(size):
"""Create a list of different colors.
Expand Down Expand Up @@ -87,6 +90,17 @@ def _load_dataframes(self):
new_csv = pd.read_csv(df_path, index_col="Timestamp", parse_dates=True)
self.dataframe = pd.concat([self.dataframe, new_csv])

def _unify_dataframes(self):
"""Unify dataframe values."""
df_row = self.dataframe.iloc[0]
df_names = [df_row['Daemon'], df_row['Version'], df_row['PID']]
columns_to_drop = ['Daemon', 'Version', 'PID']
columns_to_sum = self.dataframe.columns.drop(columns_to_drop)
self.dataframe = self.dataframe.groupby('Timestamp')[columns_to_sum].sum().reset_index(drop=False)

for index, value in enumerate(df_names):
self.dataframe.insert(index, columns_to_drop[index], value)

def _set_x_ticks_interval(self, ax):
"""Set the number of labels that will appear in the X axis and their format.
Expand Down

0 comments on commit a21ace0

Please sign in to comment.