From be0ce303c6f7f152c0e1b4e5da31d1957ddd02a8 Mon Sep 17 00:00:00 2001 From: Sudipta Basak Date: Mon, 19 Feb 2024 23:20:53 +0100 Subject: [PATCH] Added New Plot 'No. of Repaired Samples by each Node' --- DAS/block.py | 8 ++++++-- DAS/results.py | 2 ++ DAS/validator.py | 7 +++++-- DAS/visualizor.py | 21 +++++++++++++++++++++ 4 files changed, 34 insertions(+), 4 deletions(-) diff --git a/DAS/block.py b/DAS/block.py index ef3f4f5..6d5c1d3 100644 --- a/DAS/block.py +++ b/DAS/block.py @@ -50,12 +50,14 @@ class Block: """ line = self.data[id::self.blockSizeR] success = line.count(1) + repairedSamples = 0 if success >= self.blockSizeCK: ret = ~line self.data[id::self.blockSizeR] = 1 + repairedSamples = len(line) - success else: ret = zeros(self.blockSizeC) - return ret + return ret, repairedSamples def getRow(self, rowID): """It returns the block row corresponding to rowID.""" @@ -71,12 +73,14 @@ class Block: """ line = self.data[id*self.blockSizeR:(id+1)*self.blockSizeR] success = line.count(1) + repairedSamples = 0 if success >= self.blockSizeRK: ret = ~line self.data[id*self.blockSizeR:(id+1)*self.blockSizeR] = 1 + repairedSamples = len(line) - success else: ret = zeros(self.blockSizeR) - return ret + return ret, repairedSamples def print(self): """It prints the block in the terminal (outside of the logger rules)).""" diff --git a/DAS/results.py b/DAS/results.py index 6fbf3a4..2cab701 100644 --- a/DAS/results.py +++ b/DAS/results.py @@ -22,6 +22,7 @@ class Result: self.sampleRecvCount = [0] * shape.numberNodes self.restoreRowCount = [0] * shape.numberNodes self.restoreColumnCount = [0] * shape.numberNodes + self.repairedSampleCount = [0] * shape.numberNodes def copyValidators(self, validators): """Copy information from simulator.validators to result.""" @@ -32,6 +33,7 @@ class Result: self.sampleRecvCount[i] = validators[i].sampleRecvCount self.restoreRowCount[i] = validators[i].restoreRowCount self.restoreColumnCount[i] = validators[i].restoreColumnCount + self.repairedSampleCount[i] = validators[i].repairedSampleCount def populate(self, shape, config, missingVector): """It populates part of the result data inside a vector.""" diff --git a/DAS/validator.py b/DAS/validator.py index ae99d6f..82bb050 100644 --- a/DAS/validator.py +++ b/DAS/validator.py @@ -62,6 +62,7 @@ class Validator: self.sampleRecvCount = 0 self.restoreRowCount = 0 self.restoreColumnCount = 0 + self.repairedSampleCount = 0 self.logger = logger if self.shape.chiR < 1 and self.shape.chiC < 1: self.logger.error("Chi has to be greater than 0", extra=self.format) @@ -518,7 +519,8 @@ class Validator: def restoreRow(self, id): """Restore a given row if repairable.""" - rep = self.block.repairRow(id) + rep, repairedSamples = self.block.repairRow(id) + self.repairedSampleCount += repairedSamples if (rep.any()): # If operation is based on send queues, segments should # be queued after successful repair. @@ -538,7 +540,8 @@ class Validator: def restoreColumn(self, id): """Restore a given column if repairable.""" - rep = self.block.repairColumn(id) + rep, repairedSamples = self.block.repairColumn(id) + self.repairedSampleCount += repairedSamples if (rep.any()): # If operation is based on send queues, segments should # be queued after successful repair. diff --git a/DAS/visualizor.py b/DAS/visualizor.py index fbc62d2..60ddfe3 100644 --- a/DAS/visualizor.py +++ b/DAS/visualizor.py @@ -86,6 +86,7 @@ class Visualizor: self.plotSentData(result, plotPath) self.plotRecvData(result, plotPath) self.plotDupData(result, plotPath) + self.plotSamplesRepaired(result, plotPath) if self.config.saveRCdist: self.plotRowCol(result, plotPath) @@ -380,3 +381,23 @@ class Visualizor: conf["yaxismax"] = maxi plotData(conf) print("Plot %s created." % conf["path"]) + + def plotSamplesRepaired(self, result, plotPath): + """Plots the number of samples repaired 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 Samples Repaired by Nodes" + conf["type"] = "individual_bar" + conf["legLoc"] = 1 + conf["desLoc"] = 1 + conf["xlabel"] = "Nodes" + conf["ylabel"] = "Number of Samples Repaired" + conf["data"] = result.repairedSampleCount + conf["xdots"] = range(result.shape.numberNodes) + conf["path"] = plotPath + "/repairedSampleCount.png" + maxi = max(conf["data"]) + conf["yaxismax"] = maxi + plotData(conf) + print("Plot %s created." % conf["path"])