From 57cab8b854cd87d1708213aedfecd943186bae4a Mon Sep 17 00:00:00 2001 From: "Steve L. Nyemba -- The Architect" Date: Thu, 15 Nov 2018 16:19:12 -0600 Subject: [PATCH] formalizing models --- src/models/__init__.py | 0 src/models/basic.py | 80 ++++++++++++++++++------------------- src/models/free/apps.py | 70 ++++++++++++++++++++++++++++++++ src/models/free/folders.py | 0 src/models/paid/__init__.py | 10 +++++ 5 files changed, 119 insertions(+), 41 deletions(-) create mode 100644 src/models/__init__.py create mode 100644 src/models/free/apps.py create mode 100644 src/models/free/folders.py create mode 100644 src/models/paid/__init__.py diff --git a/src/models/__init__.py b/src/models/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/models/basic.py b/src/models/basic.py index f8a41be..6c542c0 100644 --- a/src/models/basic.py +++ b/src/models/basic.py @@ -19,45 +19,43 @@ class model : self.cache[key] = value def get(self,key): return self.cache[key] -class simple: - class app_status(model): - """ - This model will perform a simple count of application status - The intent is to quickly inform the user if there's a crash - """ - def __init(self,**args): - model.__init__(self,**args) - def compute(self): - """ - This function performs the actual counts associated with the status of an application - """ - df = self.data[df.name.str.contains('other',na=False)==False] - x_crash = df.status.str.contains('X').sum() - x_idle = df.status.str.contains('S').sum() - x_run = df.shape[0] - x_crash - x_idle - odf = pd.DataFrame({"labels":['crash','idle','running'],"counts":[x_crash,x_idle,x_run]}) - self.set("type","doughnut") - # self.set("labels",["crash","idle","running"]) - # self.set("data",{"data":[x_crash,x_idle,x_run]}) - self.set('data',odf) - if x_crash > 0 : - self.set("analysis"," ".join([x_crash,"applications found out of ",str(df.shape[0]),"monitored" ])) - class app_ranking(model): - """ - This model will group the applications that are monitored and the rest of the system to guage resource consumption (CPU,RAM) - """ - def __init__(self,**args): - model.__init__(self,**args) - def compute(self): - N = self.data.shape[0] - 1 +# class simple: +# class app_status(model): +# """ +# This model will perform a simple count of application status +# The intent is to quickly inform the user if there's a crash +# """ +# def __init(self,**args): +# model.__init__(self,**args) +# def compute(self): +# """ +# This function performs the actual counts associated with the status of an application +# """ +# df = self.data[df.name.str.contains('other',na=False)==False] +# x_crash = df.status.str.contains('X').sum() +# x_idle = df.status.str.contains('S').sum() +# x_run = df.shape[0] - x_crash - x_idle +# odf = pd.DataFrame({"labels":['crash','idle','running'],"counts":[x_crash,x_idle,x_run]}) +# self.set("type","doughnut") +# # self.set("labels",["crash","idle","running"]) +# # self.set("data",{"data":[x_crash,x_idle,x_run]}) +# self.set('data',odf) +# if x_crash > 0 : +# self.set("analysis"," ".join([x_crash,"applications found out of ",str(df.shape[0]),"monitored" ])) +# class app_resource(model): +# """ +# This model will group the applications that are monitored and the rest of the system to guage resource consumption (CPU,RAM) +# """ +# def __init__(self,**args): +# model.__init__(self,**args) +# def compute(self): +# N = self.data.shape[0] - 1 - df = pd.DataFrame(self.data[self.data.name == 'other'].sum()[['cpu','mem']] ) .T - df = df.append(pd.DataFrame( self.data[self.data.name != 'other'].sum()[['cpu','mem']] ).T) - df['labels'] = ['other','monitored'] - # other_df = pd.DataFrame(self.data[self.data.name.str.contains('other',na=False)]) - # watch_df = pd.DataFrame(self.data[self.data.name.str.contains('other',na=False)==False]) - # datasets = [[other_df.cpu.sum(),watch_df.cpu.sum()],[other_df.mem.sum(),watch_df.mem.sum()]] - self.set("data",odf) - self.set("type","bar") - - \ No newline at end of file +# df = pd.DataFrame(self.data[self.data.name == 'other'].sum()[['cpu','mem']] ) .T +# df = df.append(pd.DataFrame( self.data[self.data.name != 'other'].sum()[['cpu','mem']] ).T) +# df['labels'] = ['other','monitored'] +# # other_df = pd.DataFrame(self.data[self.data.name.str.contains('other',na=False)]) +# # watch_df = pd.DataFrame(self.data[self.data.name.str.contains('other',na=False)==False]) +# # datasets = [[other_df.cpu.sum(),watch_df.cpu.sum()],[other_df.mem.sum(),watch_df.mem.sum()]] +# self.set("data",df) +# self.set("type","bar") diff --git a/src/models/free/apps.py b/src/models/free/apps.py new file mode 100644 index 0000000..f6bb62f --- /dev/null +++ b/src/models/free/apps.py @@ -0,0 +1,70 @@ + +""" + (c) 2018 Smart Top - Free Models + Steve L. Nyemba, steve@the-phi.com + + This file contains free models for smart-top, these are basic models that will serve as data visualization + The most we will do here is a basic regression (basis for prediction). + + @TODO: Include process counts in the equation so as to add another variable (good for ml) +""" +from models.basic import model + +class status(model): + """ + This model will perform a simple count of application status + The intent is to quickly inform the user if there's a crash + """ + def __init(self,**args): + model.__init__(self,**args) + def compute(self): + """ + This function performs the actual counts associated with the status of an application + """ + df = self.data[df.name.str.contains('other',na=False)==False] + x_crash = df.status.str.contains('X').sum() + x_idle = df.status.str.contains('S').sum() + x_run = df.shape[0] - x_crash - x_idle + odf = pd.DataFrame({"labels":['crash','idle','running'],"counts":[x_crash,x_idle,x_run]}) + self.set("type","doughnut") + # self.set("labels",["crash","idle","running"]) + # self.set("data",{"data":[x_crash,x_idle,x_run]}) + self.set('data',odf) + if x_crash > 0 : + self.set("analysis"," ".join([x_crash,"applications found out of ",str(df.shape[0]),"monitored" ])) +class resource(model): + """ + This model will group the applications that are monitored and the rest of the system to guage resource consumption (CPU,RAM) + The intent of this model is to see how resource intensive the selected applications are relative to the rest of the system + """ + def __init__(self,**args): + model.__init__(self,**args) + def compute(self): + N = self.data.shape[0] - 1 + + df = pd.DataFrame(self.data[self.data.name == 'other'].sum()[['cpu','mem']] ) .T + df = df.append(pd.DataFrame( self.data[self.data.name != 'other'].sum()[['cpu','mem']] ).T) + df['labels'] = ['other','monitored'] + self.set("data",df) + self.set("type","bar") + +class trend(model): + """ + This model is designed to display the trends for a given attribute over a period of time + Additionally there will be a regression line associated with it + """ + def __init__(self,**args): + model.__init__(self,**args) + self.attr_name = args['name'] + self.attr_values= args['values'] + def compute(self): + df = self.data[self.data[self.attr_name].isin(self.attr_values)] + cols = ['cpu','mem'] + pass + + +model = keras.Sequential([keras.layers.Dense(2, activation=tf.nn.relu,input_shape=(x.shape[1],)),keras.layers.Dense(2, activation=tf.nn.relu),keras.layers.Dense(1)]) + +optimizer = tf.train.RMSPropOptimizer(0.001) + +model.compile(loss='mse', optimizer=optimizer,metrics=['mae']) \ No newline at end of file diff --git a/src/models/free/folders.py b/src/models/free/folders.py new file mode 100644 index 0000000..e69de29 diff --git a/src/models/paid/__init__.py b/src/models/paid/__init__.py new file mode 100644 index 0000000..69d7c7e --- /dev/null +++ b/src/models/paid/__init__.py @@ -0,0 +1,10 @@ +""" + (c) 2018 Smart-Top, Paid Models + Steve L. Nyemba + + + The Paid models are largely based around machine learning and will deliver insights into : + - Anomaly detection + - Clustering + - And Crash Prediction (regression) +""" \ No newline at end of file