From 11afac03b993cd9c83cc11f8dabafe6fa29e7881 Mon Sep 17 00:00:00 2001 From: Sudipta Basak Date: Wed, 21 Feb 2024 12:26:38 +0100 Subject: [PATCH] Added box plot for messages received & samples received by nodes --- DAS/results.py | 2 ++ DAS/visualizor.py | 56 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) diff --git a/DAS/results.py b/DAS/results.py index 2cab701..f679702 100644 --- a/DAS/results.py +++ b/DAS/results.py @@ -23,6 +23,8 @@ class Result: self.restoreRowCount = [0] * shape.numberNodes self.restoreColumnCount = [0] * shape.numberNodes self.repairedSampleCount = [0] * shape.numberNodes + self.numberNodes = shape.numberNodes + self.class1ratio = shape.class1ratio def copyValidators(self, validators): """Copy information from simulator.validators to result.""" diff --git a/DAS/visualizor.py b/DAS/visualizor.py index 60ddfe3..8ab83a0 100644 --- a/DAS/visualizor.py +++ b/DAS/visualizor.py @@ -34,6 +34,20 @@ def plotData(conf): plt.legend(loc=conf["legLoc"]) plt.savefig(conf["path"], bbox_inches="tight") +def plotBoxData(conf): + plt.clf() + plt.grid(True) + props = dict(boxstyle='round', facecolor='wheat', alpha=0.5) + num_boxes = len(conf["data"]) + positions = np.arange(num_boxes) + plt.text(0.05, 0.05, conf["textBox"], fontsize=10, verticalalignment='bottom', transform=plt.gca().transAxes, bbox=props) + plt.boxplot(conf["data"], patch_artist=True, showmeans=True, meanline=True, positions=positions) + plt.title(conf["title"], fontsize=14) + plt.ylabel(conf["ylabel"], fontsize=12) + plt.xlabel(conf["xlabel"], fontsize=12) + plt.xticks(fontsize=10) + plt.yticks(fontsize=10) + plt.savefig(conf["path"], bbox_inches="tight") class Visualizor: """This class helps the visualization of the results""" @@ -80,7 +94,9 @@ class Visualizor: self.plotRestoreColumnCount(result, plotPath) self.plotMessagesSent(result, plotPath) self.plotMessagesRecv(result, plotPath) + self.plotBoxMessagesRecv(result, plotPath) self.plotSampleRecv(result, plotPath) + self.plotBoxSampleRecv(result, plotPath) self.plotMissingSamples(result, plotPath) self.plotProgress(result, plotPath) self.plotSentData(result, plotPath) @@ -163,6 +179,25 @@ class Visualizor: plotData(conf) print("Plot %s created." % conf["path"]) + def plotBoxSampleRecv(self, result, plotPath): + """Box Plot of the sampleRecv for each node""" + conf = {} + text = str(result.shape).split("-") + conf["textBox"] = "Row Size: "+text[2]+"\nColumn Size: "+text[6]+"\nNumber of nodes: "+text[10]\ + +"\nFailure rate: "+text[14]+"%"+"\nNetwork degree: "+text[32]+"\nMalicious Nodes: "+text[36]+"%" + conf["title"] = "Number of Samples Received by Nodes" + conf["type"] = "individual_bar_with_2line" + conf["legLoc"] = 1 + conf["desLoc"] = 1 + conf["xlabel"] = "Node Type" + conf["ylabel"] = "Number of samples received (%)" + n1 = int(result.numberNodes * result.class1ratio) + conf["data"] = [result.sampleRecvCount[1: n1], result.sampleRecvCount[n1: ]] + conf["xdots"] = range(result.shape.numberNodes) + conf["path"] = plotPath + "/box_sampleRecv.png" + plotBoxData(conf) + print("Plot %s created." % conf["path"]) + def plotMissingSamples(self, result, plotPath): """Plots the missing samples in the network""" conf = {} @@ -381,6 +416,27 @@ class Visualizor: conf["yaxismax"] = maxi plotData(conf) print("Plot %s created." % conf["path"]) + + def plotBoxMessagesRecv(self, result, plotPath): + """Plots the number of messages received by all nodes""" + conf = {} + text = str(result.shape).split("-") + conf["textBox"] = "Row Size: "+text[2]+"\nColumn Size: "+text[6]+"\nNumber of nodes: "+text[10]\ + +"\nFailure rate: "+text[14]+"%"+"\nNetwork degree: "+text[32]+"\nMalicious Nodes: "+text[36]+"%" + conf["title"] = "Number of Messages Received by Nodes" + conf["type"] = "individual_bar" + conf["legLoc"] = 1 + conf["desLoc"] = 1 + conf["xlabel"] = "Node Type" + conf["ylabel"] = "Number of Messages Received" + n1 = int(result.numberNodes * result.class1ratio) + conf["data"] = [result.msgRecvCount[1: n1], result.msgRecvCount[n1: ]] + conf["xdots"] = range(result.shape.numberNodes) + conf["path"] = plotPath + "/box_messagesRecv.png" + maxi = max(conf["data"]) + conf["yaxismax"] = maxi + plotBoxData(conf) + print("Plot %s created." % conf["path"]) def plotSamplesRepaired(self, result, plotPath): """Plots the number of samples repaired by all nodes"""