diff --git a/src/Modules/General/layout.py b/src/Modules/General/layout.py index 40d3fcafb32abcd0d392a3501f0a7883d1ad1a34..c86af49874439ce1ccaa1b0446231fd791cf5b9e 100644 --- a/src/Modules/General/layout.py +++ b/src/Modules/General/layout.py @@ -131,21 +131,23 @@ class layout(): color="#28a745", style={"marginLeft": "10px"} ), - # Graphs filter - dcc.Dropdown( + # Graphs filter + dcc.Dropdown( id='GeneralGraphFilter', options=[{'label': "Spikes", 'value': "Spikes"}, {'label': "Synapses activity", 'value': "Synapses"}, { 'label': "Neurons potential", 'value': "Potentials"}], value=['Spikes'], multi=True, - style={"minWidth":"20%","marginLeft": "10px", "textAlign": "start"}), - # Layers filter - dcc.Dropdown( + style={"minWidth": "20%", "marginLeft": "10px", "textAlign": "start"}), + # Layers filter + dcc.Dropdown( id='GeneralLayerFilter', - options=[{'label': str(i), 'value': str(i)} for i in (i for i in g.Layer_Neuron if i != "Input")], - value=[str(i) for i in (i for i in g.Layer_Neuron if i != "Input")], + options=[{'label': str(i), 'value': str(i)} for i in ( + i for i in g.Layer_Neuron if i != "Input")], + value=[str(i) for i in ( + i for i in g.Layer_Neuron if i != "Input")], multi=True, - style={"minWidth":"20%","marginLeft": "15px", "textAlign": "start"})], className="row", style={"paddingLeft": "20px",'width': '100%'}) + style={"minWidth": "20%", "marginLeft": "15px", "textAlign": "start"})], className="row", style={"paddingLeft": "20px", 'width': '100%'}) ], className="col-12") ], className="row"), html.Div([dcc.Graph(id='general-graph', animate=False, config={"displaylogo": False})])], className="col-lg-9 col-sm-12 col-xs-12" if(g.labelsExistance) else "col-lg-12 col-sm-12 col-xs-12"), @@ -231,17 +233,21 @@ class layout(): dbc.Button(">", id="btn-next", className="btn btn-default", style={"marginTop": "12px", "marginLeft": "5px", "fontWeight": "500", "backgroundColor": "rgb(68, 71, 99)"})], className="col-md-4 col-sm-12 col-lg-4"), html.Div([ html.Div([ - html.Span("Update Speed (s)",className="input-group-text") - ],className="input-group-prepend"), - dbc.Input(type="number", id="speed", value=1, min=0.25, max=5, step=0.25, style={"width": "30%", "textAlign": "center"}) - ], className="input-group col-md-4 col-sm-7 col-lg-4",style={"height":"38px","paddingTop":"12px"}), + html.Span("Update Speed (s)", + className="input-group-text") + ], className="input-group-prepend"), + dbc.Input(type="number", id="speed", value=1, min=0.25, max=5, step=0.25, style={ + "width": "30%", "textAlign": "center"}) + ], className="input-group col-md-4 col-sm-7 col-lg-4", style={"height": "38px", "paddingTop": "12px"}), html.Div([ html.Div([ - html.Span("Update Interval (s)",className="input-group-text") - ],className="input-group-prepend"), - dbc.Input(type="number", id="interval", value=g.updateInterval, min=0.005, max=180, step=0.005, style={"width": "30%", "textAlign": "center"}) - ], className="input-group col-md-4 col-sm-4 col-lg-4", style={"height":"38px","paddingTop":"12px"}) + html.Span("Update Interval (s)", + className="input-group-text") + ], className="input-group-prepend"), + dbc.Input(type="number", id="interval", value=g.updateInterval, min=0.005, + max=180, step=0.005, style={"width": "30%", "textAlign": "center"}) + ], className="input-group col-md-4 col-sm-4 col-lg-4", style={"height": "38px", "paddingTop": "12px"}) ], className="d-flex justify-content-center"), dbc.Col( [ html.P(id="text", style={"marginLeft": "25px"}), diff --git a/src/Modules/MultiLayer/__init__.py b/src/Modules/MultiLayer/__init__.py new file mode 100755 index 0000000000000000000000000000000000000000..0519ecba6ea913e21689ec692e81e9e4973fbf73 --- /dev/null +++ b/src/Modules/MultiLayer/__init__.py @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/Modules/MultiLayer/callbacks.py b/src/Modules/MultiLayer/callbacks.py new file mode 100644 index 0000000000000000000000000000000000000000..c4f411f90383a583016f5f1f77be549f3585cbbc --- /dev/null +++ b/src/Modules/MultiLayer/callbacks.py @@ -0,0 +1,62 @@ +""" This class contains Dash callbacks + + Dash callbacks are the responsible on updating graphs each step. +""" + + +class callbacks(): + """Callbacks class + """ + + def init(self, super, app, g): + """Initialize the callback . + + Args: + app : Flask app + g (Global_Var): reference to access global variables + """ + # ------------------------------------------------------------ + # Callbacks + # ------------------------------------------------------------ + # to prevent creating duplicate callbacks next use + if not g.checkExistance(app, "name of one element from layout"): + + # Add callbacks here + # Use Input("v-step", "children"),State("interval", + # "value") to keep track of time slider + try: + # @app.callback([Output()], [Input()]) + # def NeuronSelection(input): + # do process here + # return output + print("Add Callbacks here") + + try: + @app.callback([Output("display-Neuron", "children"), Output("clear-Neuron", "children")], + [Input("v-step", "children")], [State("interval", "value"), State("clear", "children"), + State("clear-Neuron", "children"), State("display-Neuron", "children")]) + def display(value, step, clear, localClear, display): + if(localClear != clear): + super.clearData() + + return [display, clear] + except Exception as e: + print("display:"+str(e)) + + except Exception as e: + print("CallbackName:" + str(e)) + + # ---------------------------------------------------------------- + # Callback related Data retreiving functions + # ---------------------------------------------------------------- + try: + + print("Add functions here") + # ------------------------------------------------------------ + # Data gethering (MongoDB operations) + # ------------------------------------------------------------ + + print("Add MongoDB functions here") + + except Exception as e: + print("Data process loading:"+str(e)) \ No newline at end of file diff --git a/src/Modules/MultiLayer/layout.py b/src/Modules/MultiLayer/layout.py new file mode 100644 index 0000000000000000000000000000000000000000..3ef20bf119834c3dec445870cb74c8fd939c32b7 --- /dev/null +++ b/src/Modules/MultiLayer/layout.py @@ -0,0 +1,51 @@ +"""Create a dash layout for the module +""" + +from collections import deque +import dash_html_components as html +import dash_bootstrap_components as dbc +from .callbacks import callbacks + + +class layout(): + """ Layout class + """ + # Needed variables for the graphs -------------------------------- + # + xAxisGraphName = deque(maxlen=100) + # + # ---------------------------------------------------------------- + + def clearData(self): + """ Clear the data when moved forward or backward for more than one step + """ + self.xAxisGraphName.clear() + + def Vis(self, app, g): + """ Create layer components + + Args: + app : Flask app + g (Global_Var): reference to access global variables + + Returns: + Dash app layer + """ + try: + + layer = dbc.Card( + dbc.CardBody( + [ + html.Div(id="neuron-vis", children=[ + # Global show based on selected layer + html.H3("Your Layer here") + ]) + ], style={"textAlign": "center", "padding": "10px"} + ) + ) + # load callbacks + callbacks().init(self, app, g) + # Return the Layer + return layer + except Exception as e: + print("MultiLayer:" + str(e)) \ No newline at end of file diff --git a/src/Modules/MultiLayer/spark.py b/src/Modules/MultiLayer/spark.py new file mode 100644 index 0000000000000000000000000000000000000000..db7d04d8dedb0c60a692fff411f2dea0d3ec88b6 --- /dev/null +++ b/src/Modules/MultiLayer/spark.py @@ -0,0 +1,56 @@ +""" Spark pre-processing operations . +""" + +import traceback + +def process(g): + """ Start processing and reduce module count . + + Args: + g (Global_Var): reference to access global variables + """ + preProcessing(g) + g.modulesNbr = g.modulesNbr - 1 + +# Spark operations and pre-processing -------------------------------- + + +def preProcessing(g): + """Loads the GDD database into BDD . + + Args: + g (Global_Var): reference to access global variables + """ + MODULE_NAME = "" + DOCUMENT_NAME = "" + OUTPUT_DOCUMENT_NAME = "" + MONGODBURL = g.MONGODBURL + try: + if (not (OUTPUT_DOCUMENT_NAME in g.db.list_collection_names())) and (DOCUMENT_NAME in g.db.list_collection_names()): + + # Spark setup -------------------------------------------- + + if g.sparkSession == None: + g.createSparkSession() + + # doing the heavy work ----------------------------------- + + # Save data into Mongo------------------------------------ + + #df.write.format("com.mongodb.spark.sql.DefaultSource") \ + # .option("spark.mongodb.output.uri", + # MONGODBURL + g.name + "."+OUTPUT_DOCUMENT_NAME+"?authSource=admin&#readPreference=primaryPreferred").mode("overwrite").save() + + #print("Saved to BDD") + + # ------------------------------------------------------------ + else: + if(not DOCUMENT_NAME in g.db.list_collection_names()): + print(DOCUMENT_NAME, "not found") + g.modules = [module for module in g.modules if module != MODULE_NAME] + print("done ", MODULE_NAME) + + except Exception as e: + print("Error:" + str(e)) + traceback.print_exc() + pass \ No newline at end of file diff --git a/src/templates/Template Module/layout.py b/src/templates/Template Module/layout.py index fdabbc23e7f97d9538fea74b1f532a730792a6b3..1b932ca2d3fa4d79dc221de9276fc2897e3ec595 100644 --- a/src/templates/Template Module/layout.py +++ b/src/templates/Template Module/layout.py @@ -48,4 +48,4 @@ class layout(): # Return the Layer return layer except Exception as e: - print("Layer:" + str(e)) + print("Layer:" + str(e)) \ No newline at end of file diff --git a/src/templates/Template Module/spark.py b/src/templates/Template Module/spark.py index a1a425cf268c216387bf06abfceae6d33e18fb8b..5432f84913cf1773f14ebe503ccbc97fabc054b7 100644 --- a/src/templates/Template Module/spark.py +++ b/src/templates/Template Module/spark.py @@ -2,8 +2,6 @@ """ import traceback -from config import config - def process(g): """ Start processing and reduce module count . @@ -24,9 +22,9 @@ def preProcessing(g): g (Global_Var): reference to access global variables """ MODULE_NAME = "" - DOCUMENTNAME = "" - OUTPUTDOCUMENTNAME = "" - MONGODBURL = config().MONGODBURL + DOCUMENT_NAME = "" + OUTPUT_DOCUMENT_NAME = "" + MONGODBURL = g.MONGODBURL try: if (not (OUTPUT_DOCUMENT_NAME in g.db.list_collection_names())) and (DOCUMENT_NAME in g.db.list_collection_names()): @@ -39,11 +37,11 @@ def preProcessing(g): # Save data into Mongo------------------------------------ - df.write.format("com.mongodb.spark.sql.DefaultSource") \ - .option("spark.mongodb.output.uri", - MONGODBURL + g.name + "."+OUTPUTDOCUMENTNAME+"?authSource=admin&readPreference=primaryPreferred").mode("overwrite").save() + #df.write.format("com.mongodb.spark.sql.DefaultSource") \ + # .option("spark.mongodb.output.uri", + # MONGODBURL + g.name + "."+OUTPUT_DOCUMENT_NAME+"?authSource=admin&readPreference=primaryPreferred").mode("overwrite").save() - print("Saved to BDD") + #print("Saved to BDD") # ------------------------------------------------------------ else: