From 2e5a3ca100d88edaf1b76f4eff4bd16b0106cc45 Mon Sep 17 00:00:00 2001
From: Hammouda Elbez <hammouda.elbez@univ-lille.fr>
Date: Thu, 6 Apr 2023 11:02:06 +0200
Subject: [PATCH] Prints moved to debug mode

---
 src/Global_Var.py                | 12 ++++++++----
 src/Modules/General/callbacks.py |  8 ++++----
 src/Modules/General/spark.py     |  3 ++-
 src/Modules/Neuron/layout.py     |  7 ++++---
 src/Modules/Neuron/spark.py      |  3 ++-
 src/Modules/Synapse/spark.py     |  5 +++--
 6 files changed, 23 insertions(+), 15 deletions(-)

diff --git a/src/Global_Var.py b/src/Global_Var.py
index 879ce06..2c0a2d8 100755
--- a/src/Global_Var.py
+++ b/src/Global_Var.py
@@ -118,21 +118,24 @@ class Global_Var():
         if ('labels' in self.db.list_collection_names()):
             col = pymongo.collection.Collection(self.db, 'labels')
             col.create_index([("T", 1)])
-            print("Labels index done")
+            if self.config.DEBUG:
+                print("Labels index done")
 
         if ('spikes' in self.db.list_collection_names()):
             col = pymongo.collection.Collection(self.db, 'spikes')
             col.create_index([("T", 1)])
             col.create_index([("i.L", 1)])
             col.create_index([("i.N", 1)])
-            print("Spikes index done")
+            if self.config.DEBUG:
+                print("Spikes index done")
         
         if ('potential' in self.db.list_collection_names()):
             col = pymongo.collection.Collection(self.db, 'potential')
             col.create_index([("T", 1)])
             col.create_index([("L", 1)])
             col.create_index([("N", 1)])
-            print("Potential index done")
+            if self.config.DEBUG:
+                print("Potential index done")
         
         if ('synapseWeight' in self.db.list_collection_names()):
             col = pymongo.collection.Collection(self.db, 'synapseWeight')
@@ -140,7 +143,8 @@ class Global_Var():
             col.create_index([("C", 1)])
             col.create_index([("L", 1)])
             col.create_index([("To", 1)])
-            print("Synapses index done")
+            if self.config.DEBUG:
+                print("Synapses index done")
 
     def getLabelTime(self, step, value):
         """ Return a string that represent time .
diff --git a/src/Modules/General/callbacks.py b/src/Modules/General/callbacks.py
index ffb7308..61c1ebb 100755
--- a/src/Modules/General/callbacks.py
+++ b/src/Modules/General/callbacks.py
@@ -609,9 +609,9 @@ class callbacks(callbacksOp):
                                         matrix[layer] = []
                                         indices[layer] = []
 
-                            heatmaps = [{"data":[go.Heatmap(z = matrix[layer], colorscale= 'Reds', customdata = indices[layer], hovertemplate=('Neuron: %{customdata} <br>Spikes: %{z} <extra></extra>'))],"layout":{"xaxis":dict(showgrid = False, zeroline = False),"yaxis":dict(autorange = 'reversed',scaleanchor = 'x',showgrid = False, zeroline = False),"margin":{'l': 0, 'r': 0, 't': 5, 'b': 0},"uirevision":'no reset of zoom', "hoverlabel_align": 'right'}} for layer in super.AccumulatedSpikes2D]
+                            heatmaps = [{"data":[go.Heatmap(z = matrix[layer], colorscale= 'Reds', customdata = indices[layer], hovertemplate=('Neuron: %{customdata} <br>Spikes: %{z} <extra></extra>'),xgap=4,ygap=4)],"layout":{"xaxis":dict(showgrid = False, zeroline = False),"yaxis":dict(autorange = 'reversed',scaleanchor = 'x',showgrid = False, zeroline = False),"margin":{'l': 0, 'r': 0, 't': 5, 'b': 0},"uirevision":'no reset of zoom', "hoverlabel_align": 'right'}} for layer in super.AccumulatedSpikes2D]
 
-                            SpikesActivityPerInput = [{"data":[go.Heatmap(z=super.SpikesActivityPerInput[layer], colorscale= 'Reds',hovertemplate=('Class: %{x} <br>Neuron: %{y} <br>Spikes: %{z} <extra></extra>'))],"layout":{"xaxis":dict(title="Class",tickmode="array",tickvals=[i for i in range(g.nbrClasses+1)]),"yaxis":dict(title="Neuron"),"margin":{'r': 0,'t': 0},"uirevision":'no reset of zoom'}} for layer in super.SpikesActivityPerInput]
+                            SpikesActivityPerInput = [{"data":[go.Heatmap(z=super.SpikesActivityPerInput[layer], colorscale= 'Reds',hovertemplate=('Class: %{x} <br>Neuron: %{y} <br>Spikes: %{z} <extra></extra>'),xgap=4,ygap=4)],"layout":{"xaxis":dict(title="Class",tickmode="array",zeroline = False,tickvals=[i for i in range(g.nbrClasses+1)]),"yaxis":dict(title="Neuron",zeroline = False),"margin":{'r': 0,'t': 0},"uirevision":'no reset of zoom'}} for layer in super.SpikesActivityPerInput]
                             return [elements,[],heatmaps,SpikesActivityPerInput]
                         else:
                             
@@ -626,9 +626,9 @@ class callbacks(callbacksOp):
                                             matrix[layer] = []
                                             indices[layer] = []
 
-                                heatmaps = [{"data":[go.Heatmap(z = matrix[layer], colorscale= 'Reds', customdata = indices[layer], hovertemplate=('Neuron: %{customdata} <br>Spikes: %{z} <extra></extra>'))],"layout":{"xaxis":dict(showgrid = False, zeroline = False),"yaxis":dict(autorange = 'reversed',scaleanchor = 'x',showgrid = False, zeroline = False),"margin":{'l': 0, 'r': 0, 't': 5, 'b': 0},"uirevision":'no reset of zoom', "hoverlabel_align": 'right'}} for layer in super.AccumulatedSpikes2D]
+                                heatmaps = [{"data":[go.Heatmap(z = matrix[layer], colorscale= 'Reds', customdata = indices[layer], hovertemplate=('Neuron: %{customdata} <br>Spikes: %{z} <extra></extra>'),xgap=4,ygap=4)],"layout":{"xaxis":dict(showgrid = False, zeroline = False),"yaxis":dict(autorange = 'reversed',scaleanchor = 'x',showgrid = False, zeroline = False),"margin":{'l': 0, 'r': 0, 't': 5, 'b': 0},"uirevision":'no reset of zoom', "hoverlabel_align": 'right'}} for layer in super.AccumulatedSpikes2D]
 
-                                SpikesActivityPerInput = [{"data":[go.Heatmap(z=super.SpikesActivityPerInput[layer], colorscale= 'Reds',hovertemplate=('Class: %{x} <br>Neuron: %{y} <br>Spikes: %{z} <extra></extra>'))],"layout":{"xaxis":dict(title="Class",tickmode="array",tickvals=[i for i in range(g.nbrClasses+1)]),"yaxis":dict(title="Neuron"),"margin":{'r': 0,'t': 0},"uirevision":'no reset of zoom'}} for layer in super.SpikesActivityPerInput]
+                                SpikesActivityPerInput = [{"data":[go.Heatmap(z=super.SpikesActivityPerInput[layer], colorscale= 'Reds',hovertemplate=('Class: %{x} <br>Neuron: %{y} <br>Spikes: %{z} <extra></extra>'),xgap=4,ygap=4)],"layout":{"xaxis":dict(title="Class",tickmode="array",zeroline = False,tickvals=[i for i in range(g.nbrClasses+1)]),"yaxis":dict(title="Neuron",zeroline = False),"margin":{'r': 0,'t': 0},"uirevision":'no reset of zoom'}} for layer in super.SpikesActivityPerInput]
                                 return [elements,f"Neuron {mouseOverNodeData['label']} : {mouseOverNodeData['spikes']}" if 'spikes' in mouseOverNodeData else "", heatmaps,SpikesActivityPerInput]
                             except Exception:
                                 print("OnHover:"+traceback.format_exc())
diff --git a/src/Modules/General/spark.py b/src/Modules/General/spark.py
index 063d31f..eb175ab 100755
--- a/src/Modules/General/spark.py
+++ b/src/Modules/General/spark.py
@@ -93,7 +93,8 @@ class spark(sparkOp):
                 pass
 
             # ------------------------------------------------------------
-            print("done ", self.MODULE_NAME)
+            if self.g.config.DEBUG:
+                print("done ", self.MODULE_NAME)
 
         except Exception:
             print("GlobalSpark:" + traceback.format_exc())
diff --git a/src/Modules/Neuron/layout.py b/src/Modules/Neuron/layout.py
index 81c30ab..603cab5 100755
--- a/src/Modules/Neuron/layout.py
+++ b/src/Modules/Neuron/layout.py
@@ -57,7 +57,8 @@ class layout(layoutOp):
         """
         try:
             self.clearData([])
-            print("neuron-vis")
+            if self.g.config.DEBUG:
+                print("neuron-vis")
             self.SpikePerNeuron = self.getSpikePerNeuron(self.g)
             layer = dbc.Card(
                 dbc.CardBody(
@@ -181,11 +182,11 @@ class layout(layoutOp):
                     'layout': {'margin': {'l': 0, 'r': 0, 't': 30, 'b': 0}}}
         else:
             data = self.SpikePerNeuron
-
+            print(data)
             data = [d for d, l in product(data, g.finalLabels) if (
                 int(l["N"]) == d['i']['N'] and int(l["Label"]) == filteredClass["z"])]
             xx = [N["i"]["N"] for N in data]
-            yy = [(count["count"]) for count in data]
+            yy = [count["count"] for count in data]
 
             graph = {'data': [go.Bar(
                 x=[x for x in range(len(xx))],
diff --git a/src/Modules/Neuron/spark.py b/src/Modules/Neuron/spark.py
index 02c4dec..54dafba 100755
--- a/src/Modules/Neuron/spark.py
+++ b/src/Modules/Neuron/spark.py
@@ -53,7 +53,8 @@ class spark(sparkOp):
                 if(not self.DOCUMENT_NAME in self.g.db.list_collection_names()):
                     print(self.DOCUMENT_NAME, "not found")
                     self.g.modules = [module for module in self.g.modules if module != self.MODULE_NAME]
-            print("done ", self.MODULE_NAME)
+            if self.g.config.DEBUG:
+                print("done ", self.MODULE_NAME)
 
         except Exception:
             print("Error:" + traceback.format_exc())
diff --git a/src/Modules/Synapse/spark.py b/src/Modules/Synapse/spark.py
index 70e9a8f..89cce7a 100755
--- a/src/Modules/Synapse/spark.py
+++ b/src/Modules/Synapse/spark.py
@@ -61,8 +61,9 @@ class spark(sparkOp):
             col = pymongo.collection.Collection(self.g.db, 'synapseWeightFinal')
             globalSynapseWeights = pd.DataFrame(list(col.aggregate([{"$group": {"_id":None, "x":{"$max":"$_id.index.x"}, "y":{"$max":"$_id.index.y"}}}])))
             self.g.NeuronsSize = {"x":globalSynapseWeights["x"].max(),"y":globalSynapseWeights["y"].max()}
-                
-            print("done", self.MODULE_NAME)
+
+            if self.g.config.DEBUG:
+                print("done", self.MODULE_NAME)
 
         except Exception:
             print("Error:" + traceback.format_exc())
-- 
GitLab