<commit_before>import wx
from fitplotter import FitPlotter
#from fitdialog import FitDialog
from  parser.topparser import TopDirParser
from fitlistbox import FitListBox
import pandas as pd
import numpy as np

class FitTopFrame(wx.Frame):
    def __init__(self, parent, id, parsedir, start_date, end_date, title):
        wx.Frame.__init__(self, parent, id, title, wx.DefaultPosition, (750, 450))

        self.SetMinSize((750, 450))
        self.Center(True)

        self.parsedir = parsedir
        self.plotter= dict()

        self.top_dir_parser = self.loadTopData(start_date, end_date)

        self.user_list = self.top_dir_parser.GetItemList('USER')
        self.process_list = self.top_dir_parser.GetItemList('COMMAND')
        self.params_list = ['RES','%CPU']

        if self.user_list == None or self.process_list == None:
            self.showErrorDialog('No User/Process -- Please check directory/Date Range', True)
            return

        self.panel = wx.Panel(self, -1)

        # top level sizer.
        self.main_grid_sizer = wx.GridSizer(2,3,5,10)

        # Static box for each list box
        user_static_box = wx.StaticBox(self.panel, wx.ID_ANY, "User List")
        self.user_static_box_sizer = wx.StaticBoxSizer(user_static_box,wx.VERTICAL)
        process_static_box = wx.StaticBox(self.panel, wx.ID_ANY, label="Process List")
        self.process_listbox_sizer = wx.StaticBoxSizer(process_static_box,wx.VERTICAL)
        param_static_box = wx.StaticBox(self.panel, wx.ID_ANY, label="Param List")
        self.param_listbox_sizer = wx.StaticBoxSizer(param_static_box,wx.VERTICAL)

        # User List Box
        self.user_listbox = FitListBox(self.panel, wx.ID_ANY,
                                       wx.DefaultPosition, (170, 130), self.user_list, wx.LB_MULTIPLE |
                                       wx.LB_SORT)
        self.user_listbox.SetSelection(0)
        # Check Box to select all users
        self.all_user_cb = wx.CheckBox(self.panel, wx.ID_ANY, 'Select All')
        self.all_user_cb.SetValue(False)
        self.all_user_cb.Bind(wx.EVT_CHECKBOX, self.toggleAllUserSelect)

        # Process List Box
        self.process_listbox = FitListBox(self.panel, wx.ID_ANY,
                                          wx.DefaultPosition, (170, 130), self.process_list, wx.LB_MULTIPLE |
                                          wx.LB_SORT)
        self.process_listbox.SetSelection(0)

        # Check Box to select all processes
        self.all_process_cb = wx.CheckBox(self.panel, wx.ID_ANY, 'Select All')
        self.all_process_cb.SetValue(False)
        self.all_process_cb.Bind(wx.EVT_CHECKBOX, self.toggleAllProcessSelect)

        # Param List Box
        self.param_listbox = FitListBox(self.panel, wx.ID_ANY,
                                        wx.DefaultPosition, (170, 130), self.params_list, wx.LB_SINGLE)
        self.param_listbox.SetSelection(0)

        self.user_static_box_sizer.Add(self.user_listbox, proportion = 1,
                                       flag = wx.ALL | wx.EXPAND, border = 10)
        self.user_static_box_sizer.Add(self.all_user_cb, 0, wx.BOTTOM | wx.CENTER)
        self.process_listbox_sizer.Add(self.process_listbox, proportion = 1,
                                       flag = wx.ALL | wx.EXPAND, border = 10)
        self.process_listbox_sizer.Add(self.all_process_cb, 0, wx.BOTTOM | wx.CENTER)
        self.param_listbox_sizer.Add(self.param_listbox, proportion = 1, flag
                                     = wx.ALL | wx.EXPAND, border = 10)

        # Add Each list box to main grid sizer.
        self.main_grid_sizer.Add(self.user_static_box_sizer, proportion = 1,
                                 flag = wx.ALL | wx.EXPAND | wx.ALIGN_TOP)

        self.main_grid_sizer.Add(self.process_listbox_sizer, proportion = 1,
                                 flag = wx.ALL | wx.EXPAND | wx.ALIGN_TOP)

        self.main_grid_sizer.Add(self.param_listbox_sizer, proportion = 1,
                                 flag = wx.ALL | wx.EXPAND | wx.ALIGN_TOP)

        # Static box for each type of plot (Summary,Time plots & Scatter plots)
        summary_plot_static_box = wx.StaticBox(self.panel, wx.ID_ANY, "Summary")
        self.summary_plot_static_box_sizer  = wx.StaticBoxSizer(summary_plot_static_box, wx.VERTICAL)

        time_plot_static_box = wx.StaticBox(self.panel, wx.ID_ANY, "Time")
        self.time_plot_static_box_sizer = wx.StaticBoxSizer(time_plot_static_box,wx.VERTICAL)

        scatter_plot_static_box = wx.StaticBox(self.panel, wx.ID_ANY, "Scatter")
        self.scatter_plot_static_box_sizer = wx.StaticBoxSizer(scatter_plot_static_box,wx.VERTICAL)

        # Buttons for each type of plot.
        self.user_vs_param_summary_btn = wx.Button(self.panel, wx.ID_ANY, 'User(s) vs Param')
        self.user_vs_param_summary_btn.Bind(wx.EVT_BUTTON, self.userVsParamSummary)
        self.process_vs_param_summary_btn = wx.Button(self.panel, wx.ID_ANY, 'Process(s) vs Param')
        self.process_vs_param_summary_btn.Bind(wx.EVT_BUTTON, self.processVsParamSummary)

        self.summary_plot_static_box_sizer.Add(self.user_vs_param_summary_btn, proportion = 1, flag = wx.ALL | wx.EXPAND, border = 10)
        self.summary_plot_static_box_sizer.Add(self.process_vs_param_summary_btn, proportion = 1, flag = wx.ALL | wx.EXPAND, border = 10)

        self.peruserparam_vs_time_btn = wx.Button(self.panel, wx.ID_ANY, 'Time vs per User Param')
        self.peruserparam_vs_time_btn.Bind(wx.EVT_BUTTON, self.perUserParamVsTime)
        self.enable_user_locall_sum = wx.CheckBox(self.panel, wx.ID_ANY, 'Selected Total')
        self.enable_user_locall_sum.SetValue(False)        
        self.perprocessparam_vs_time_btn = wx.Button(self.panel, wx.ID_ANY, 'Time vs per Process Param')
        self.perprocessparam_vs_time_btn.Bind(wx.EVT_BUTTON, self.perProcessParamVsTime)
        self.enable_process_locall_sum = wx.CheckBox(self.panel, wx.ID_ANY, 'Selected Total')
        self.enable_process_locall_sum.SetValue(False)

        self.time_plot_static_box_sizer.Add(self.peruserparam_vs_time_btn, proportion = 1, flag = wx.ALL | wx.EXPAND, border = 10)
        self.time_plot_static_box_sizer.Add(self.enable_user_locall_sum, 0, flag = wx.RIGHT | wx.CENTER)
        self.time_plot_static_box_sizer.Add(self.perprocessparam_vs_time_btn, proportion = 1, flag = wx.ALL | wx.EXPAND, border = 10)
        self.time_plot_static_box_sizer.Add(self.enable_process_locall_sum, 0, flag = wx.RIGHT | wx.CENTER)

        self.user_vs_process_btn = wx.Button(self.panel, wx.ID_ANY, 'User vs Process')

        self.scatter_plot_static_box_sizer.Add(self.user_vs_process_btn, proportion = 1, flag = wx.ALL | wx.EXPAND, border = 10)

        # Add each plot category to the correct grid.
        self.main_grid_sizer.Add(self.summary_plot_static_box_sizer, proportion = 1, flag = wx.ALL | wx.EXPAND | wx.ALIGN_TOP)
        self.main_grid_sizer.Add(self.time_plot_static_box_sizer, proportion = 1, flag = wx.ALL | wx.EXPAND | wx.ALIGN_TOP)
        self.main_grid_sizer.Add(self.scatter_plot_static_box_sizer, proportion = 1, flag = wx.ALL | wx.EXPAND | wx.ALIGN_TOP)

        self.panel.SetSizerAndFit(self.main_grid_sizer)


    def loadTopData(self, start, end):
        if self.parsedir != "":
            self.parsedir = self.parsedir+'/'
            return TopDirParser(start, end, self.parsedir)

    def showErrorDialog(self,message, closeFrame = False):
        dia = wx.MessageDialog(self, message, 'Error', style = wx.OK|wx.ICON_ERROR)
        dia.ShowModal()
        if closeFrame == True:
            self.Destroy()
        else:
            dia.Destroy()

        return

    def checkEmpty(self, obj, message):
        if not obj:
            self.showErrorDialog(message)
            return True
        else:
            return False

    def checkSelectionsEmpty(self):
        if len(self.user_listbox.GetSelections()) == 0:
            self.showErrorDialog("No user selected")
            return True
        elif len(self.process_listbox.GetSelections()) == 0:
            self.showErrorDialog("No process selected")
            return True
        else:
            return False

    def userVsParamSummary(self, event):
        if self.checkSelectionsEmpty() == True:
            return
        preselector={'COMMAND':self.process_listbox.GetSelList(self.process_list)}
        df = self.top_dir_parser.GenDF('USER',False,preselector)
        drop_list = self.param_listbox.GetDropList(self.params_list)
        df = df.drop(drop_list,level=1)<commit_msg>Use df.empty to check if df is emptyU<commit_after>import wx
from fitplotter import FitPlotter
#from fitdialog import FitDialog
from  parser.topparser import TopDirParser
from fitlistbox import FitListBox
import pandas as pd
import numpy as np

class FitTopFrame(wx.Frame):
    def __init__(self, parent, id, parsedir, start_date, end_date, title):
        wx.Frame.__init__(self, parent, id, title, wx.DefaultPosition, (750, 450))

        self.SetMinSize((750, 450))
        self.Center(True)

        self.parsedir = parsedir
        self.plotter= dict()

        self.top_dir_parser = self.loadTopData(start_date, end_date)

        self.user_list = self.top_dir_parser.GetItemList('USER')
        self.process_list = self.top_dir_parser.GetItemList('COMMAND')
        self.params_list = ['RES','%CPU']

        if self.user_list == None or self.process_list == None:
            self.showErrorDialog('No User/Process -- Please check directory/Date Range', True)
            return

        self.panel = wx.Panel(self, -1)

        # top level sizer.
        self.main_grid_sizer = wx.GridSizer(2,3,5,10)

        # Static box for each list box
        user_static_box = wx.StaticBox(self.panel, wx.ID_ANY, "User List")
        self.user_static_box_sizer = wx.StaticBoxSizer(user_static_box,wx.VERTICAL)
        process_static_box = wx.StaticBox(self.panel, wx.ID_ANY, label="Process List")
        self.process_listbox_sizer = wx.StaticBoxSizer(process_static_box,wx.VERTICAL)
        param_static_box = wx.StaticBox(self.panel, wx.ID_ANY, label="Param List")
        self.param_listbox_sizer = wx.StaticBoxSizer(param_static_box,wx.VERTICAL)

        # User List Box
        self.user_listbox = FitListBox(self.panel, wx.ID_ANY,
                                       wx.DefaultPosition, (170, 130), self.user_list, wx.LB_MULTIPLE |
                                       wx.LB_SORT)
        self.user_listbox.SetSelection(0)
        # Check Box to select all users
        self.all_user_cb = wx.CheckBox(self.panel, wx.ID_ANY, 'Select All')
        self.all_user_cb.SetValue(False)
        self.all_user_cb.Bind(wx.EVT_CHECKBOX, self.toggleAllUserSelect)

        # Process List Box
        self.process_listbox = FitListBox(self.panel, wx.ID_ANY,
                                          wx.DefaultPosition, (170, 130), self.process_list, wx.LB_MULTIPLE |
                                          wx.LB_SORT)
        self.process_listbox.SetSelection(0)

        # Check Box to select all processes
        self.all_process_cb = wx.CheckBox(self.panel, wx.ID_ANY, 'Select All')
        self.all_process_cb.SetValue(False)
        self.all_process_cb.Bind(wx.EVT_CHECKBOX, self.toggleAllProcessSelect)

        # Param List Box
        self.param_listbox = FitListBox(self.panel, wx.ID_ANY,
                                        wx.DefaultPosition, (170, 130), self.params_list, wx.LB_SINGLE)
        self.param_listbox.SetSelection(0)

        self.user_static_box_sizer.Add(self.user_listbox, proportion = 1,
                                       flag = wx.ALL | wx.EXPAND, border = 10)
        self.user_static_box_sizer.Add(self.all_user_cb, 0, wx.BOTTOM | wx.CENTER)
        self.process_listbox_sizer.Add(self.process_listbox, proportion = 1,
                                       flag = wx.ALL | wx.EXPAND, border = 10)
        self.process_listbox_sizer.Add(self.all_process_cb, 0, wx.BOTTOM | wx.CENTER)
        self.param_listbox_sizer.Add(self.param_listbox, proportion = 1, flag
                                     = wx.ALL | wx.EXPAND, border = 10)

        # Add Each list box to main grid sizer.
        self.main_grid_sizer.Add(self.user_static_box_sizer, proportion = 1,
                                 flag = wx.ALL | wx.EXPAND | wx.ALIGN_TOP)

        self.main_grid_sizer.Add(self.process_listbox_sizer, proportion = 1,
                                 flag = wx.ALL | wx.EXPAND | wx.ALIGN_TOP)

        self.main_grid_sizer.Add(self.param_listbox_sizer, proportion = 1,
                                 flag = wx.ALL | wx.EXPAND | wx.ALIGN_TOP)

        # Static box for each type of plot (Summary,Time plots & Scatter plots)
        summary_plot_static_box = wx.StaticBox(self.panel, wx.ID_ANY, "Summary")
        self.summary_plot_static_box_sizer  = wx.StaticBoxSizer(summary_plot_static_box, wx.VERTICAL)

        time_plot_static_box = wx.StaticBox(self.panel, wx.ID_ANY, "Time")
        self.time_plot_static_box_sizer = wx.StaticBoxSizer(time_plot_static_box,wx.VERTICAL)

        scatter_plot_static_box = wx.StaticBox(self.panel, wx.ID_ANY, "Scatter")
        self.scatter_plot_static_box_sizer = wx.StaticBoxSizer(scatter_plot_static_box,wx.VERTICAL)

        # Buttons for each type of plot.
        self.user_vs_param_summary_btn = wx.Button(self.panel, wx.ID_ANY, 'User(s) vs Param')
        self.user_vs_param_summary_btn.Bind(wx.EVT_BUTTON, self.userVsParamSummary)
        self.process_vs_param_summary_btn = wx.Button(self.panel, wx.ID_ANY, 'Process(s) vs Param')
        self.process_vs_param_summary_btn.Bind(wx.EVT_BUTTON, self.processVsParamSummary)

        self.summary_plot_static_box_sizer.Add(self.user_vs_param_summary_btn, proportion = 1, flag = wx.ALL | wx.EXPAND, border = 10)
        self.summary_plot_static_box_sizer.Add(self.process_vs_param_summary_btn, proportion = 1, flag = wx.ALL | wx.EXPAND, border = 10)

        self.peruserparam_vs_time_btn = wx.Button(self.panel, wx.ID_ANY, 'Time vs per User Param')
        self.peruserparam_vs_time_btn.Bind(wx.EVT_BUTTON, self.perUserParamVsTime)
        self.enable_user_locall_sum = wx.CheckBox(self.panel, wx.ID_ANY, 'Selected Total')
        self.enable_user_locall_sum.SetValue(False)        
        self.perprocessparam_vs_time_btn = wx.Button(self.panel, wx.ID_ANY, 'Time vs per Process Param')
        self.perprocessparam_vs_time_btn.Bind(wx.EVT_BUTTON, self.perProcessParamVsTime)
        self.enable_process_locall_sum = wx.CheckBox(self.panel, wx.ID_ANY, 'Selected Total')
        self.enable_process_locall_sum.SetValue(False)

        self.time_plot_static_box_sizer.Add(self.peruserparam_vs_time_btn, proportion = 1, flag = wx.ALL | wx.EXPAND, border = 10)
        self.time_plot_static_box_sizer.Add(self.enable_user_locall_sum, 0, flag = wx.RIGHT | wx.CENTER)
        self.time_plot_static_box_sizer.Add(self.perprocessparam_vs_time_btn, proportion = 1, flag = wx.ALL | wx.EXPAND, border = 10)
        self.time_plot_static_box_sizer.Add(self.enable_process_locall_sum, 0, flag = wx.RIGHT | wx.CENTER)

        self.user_vs_process_btn = wx.Button(self.panel, wx.ID_ANY, 'User vs Process')

        self.scatter_plot_static_box_sizer.Add(self.user_vs_process_btn, proportion = 1, flag = wx.ALL | wx.EXPAND, border = 10)

        # Add each plot category to the correct grid.
        self.main_grid_sizer.Add(self.summary_plot_static_box_sizer, proportion = 1, flag = wx.ALL | wx.EXPAND | wx.ALIGN_TOP)
        self.main_grid_sizer.Add(self.time_plot_static_box_sizer, proportion = 1, flag = wx.ALL | wx.EXPAND | wx.ALIGN_TOP)
        self.main_grid_sizer.Add(self.scatter_plot_static_box_sizer, proportion = 1, flag = wx.ALL | wx.EXPAND | wx.ALIGN_TOP)

        self.panel.SetSizerAndFit(self.main_grid_sizer)


    def loadTopData(self, start, end):
        if self.parsedir != "":
            self.parsedir = self.parsedir+'/'
            return TopDirParser(start, end, self.parsedir)

    def showErrorDialog(self,message, closeFrame = False):
        dia = wx.MessageDialog(self, message, 'Error', style = wx.OK|wx.ICON_ERROR)
        dia.ShowModal()
        if closeFrame == True:
            self.Destroy()
        else:
            dia.Destroy()

        return

    def checkEmpty(self, obj, message):
        if obj.empty:
            self.showErrorDialog(message)
            return True
        else:
            return False

    def checkSelectionsEmpty(self):
        if len(self.user_listbox.GetSelections()) == 0:
            self.showErrorDialog("No user selected")
            return True
        elif len(self.process_listbox.GetSelections()) == 0:
            self.showErrorDialog("No process selected")
            return True
        else:
            return False

    def userVsParamSummary(self, event):
        if self.checkSelectionsEmpty() == True:
            return
        preselector={'COMMAND':self.process_listbox.GetSelList(self.process_list)}
        df = self.top_dir_parser.GenDF('USER',False,preselector)
        drop_list = self.param_listbox.GetDropList(self.params_list)
        df = df.drop(drop_list,level=1)
{'fraction_non_alphanumeric': 0.09842565597667638, 'fraction_numerical': 0.008862973760932945, 'mean_word_length': 2.6875940657923025, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 30, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6392907', 'n_tokens_mistral': 5756, 'n_tokens_neox': 5544, 'n_words': 971}