From 07d8579c7caa32334bf6257415f146b4c6f2ab9c Mon Sep 17 00:00:00 2001
From: mbruns42 <mbruns42@mail.upb.de>
Date: Fri, 8 Sep 2017 11:04:39 +0200
Subject: [PATCH] Add second graph for all messages that ever existed

---
 toolkit/multicastMessageAnalyzer.pl        | 32 ++++++++++++++--------
 toolkit/reportSummary/multicastAnalysis.py | 27 ++++++++++++------
 2 files changed, 39 insertions(+), 20 deletions(-)

diff --git a/toolkit/multicastMessageAnalyzer.pl b/toolkit/multicastMessageAnalyzer.pl
index b938d4d0..b5662acf 100644
--- a/toolkit/multicastMessageAnalyzer.pl
+++ b/toolkit/multicastMessageAnalyzer.pl
@@ -77,7 +77,7 @@ close(INFILE);
 #Map, that stores the last delivery ratio for every message
 my %msgToLastRatio = ();
 
-print "#timeAfterMessageCreation	MinRatio	AvgRatio\n";
+print "#timeAfterMessageCreation	MinRatio	AvgRatio   MinRationForAll AvgRatioForAll\n";
 
 my $lastInterval = 0;
 #Sort intervals numerically and process every interval step by step
@@ -114,28 +114,39 @@ sub getHighestInterval{
 sub printInterval{
     my $interval = shift;
     my $ratioSum = 0;
+    my $ratioSumForAll = 0;
     my $nextMin = 2;
+    my $nextMinForAll = 2;
     my $msgCount = 0;
+    my $msgCountForAll = 0;
     #check every message
     foreach my $msg (keys %msgToLastRatio){
-        #ignore it, if it didn't exist anymore during the current interval
-        if ($msgToMaxInterval{$msg} < $interval){
-            next;
+        #calculate these metrics only for message that still exist during the current interval
+        if ($msgToMaxInterval{$msg} >= $interval){
+            #add it to the min and avg calculation for the current interval
+            $msgCount++;
+            my $msgRatio = $msgToLastRatio{$msg};
+            $ratioSum += $msgRatio;
+            if ($nextMin > $msgRatio){
+                $nextMin = $msgRatio;
+            }
         }
-        #add it to the min and avg calculation for the current interval
-        $msgCount++;
+        #calculate these metrics for all messages ever created
+        $msgCountForAll++;
         my $msgRatio = $msgToLastRatio{$msg};
-        $ratioSum += $msgRatio;
-        if ($nextMin > $msgRatio){
-            $nextMin = $msgRatio;
+        $ratioSumForAll += $msgRatio;
+        if ($nextMinForAll > $msgRatio){
+            $nextMinForAll = $msgRatio;
         }
+
     }
     if ($msgCount > 0) {
         #calculate average
         my $nextAvg = $ratioSum / $msgCount;
+        my $nextAvgForAll = $ratioSumForAll / $msgCountForAll;
         #convert the interval into simulation seconds
         my $seconds = $interval * $timeStep;
-        print "$seconds	$nextMin	$nextAvg\n";
+        print "$seconds	$nextMin	$nextAvg   $nextMinForAll $nextAvgForAll\n";
     }
 }
 
@@ -146,5 +157,4 @@ sub calculateMaxIntervalForAllMsgs {
     foreach my $msgId (keys %msgToCreateTime){
         $msgToMaxInterval{$msgId} = int(($simTime - $msgToCreateTime{$msgId}) / $timeStep );
     }
-
 }
diff --git a/toolkit/reportSummary/multicastAnalysis.py b/toolkit/reportSummary/multicastAnalysis.py
index cc83917a..3f375019 100644
--- a/toolkit/reportSummary/multicastAnalysis.py
+++ b/toolkit/reportSummary/multicastAnalysis.py
@@ -3,25 +3,30 @@ import sys
 import re
 
 # Script that translates multicast analysis into a plot of average and minimum delivery rate over time.
+# The rates are calculated for both messages that exist at that time and all messages that ever existed
 # Takes as arguments
 # (1) a multicast analysis file
 # (2) path to save the graphic to.
 #
 # The multicast analysis file should have a format like:
 #
-# #timeAfterMessageCreation	MinRatio	AvgRatio
-# 300	0.0	0.00444165511837884
-# 600	0.0	0.0164942207497068
-# 900	0.0	0.0340330430435976
+# #timeAfterMessageCreation	MinRatio	AvgRatio   MinRatioForAll AvgRatioForAll
+# 300	0.0	0.00444165511837884 0.0 0.004223002342392
+# 600	0.0	0.0164942207497068  0.0 0.01223002342392
+# 900	0.0	0.0340330430435976  0.0 0.024223002342392
 
 # Draws two functions over the same x values.
 # Labels are selected as appropiate for multicast analysis.
-def drawPlots(x, y_minimum, y_average):
+def drawPlots(x, y_minimum, y_average, y_minForAll, y_avgForAll):
     plt.title('Multicast delivery rates')
     plt.xlabel('Minutes since message creation')
     plt.ylabel('Delivery rate')
-    plt.plot(x, y_minimum, '.-', label='Minimum')
-    plt.plot(x, y_average, '.-',  label='Average')
+    plt.plot(x, y_minimum, '.-', label='Minimum for existent messages')
+    plt.plot(x, y_average, '.-',  label='Average for existent messages')
+    #Currently not plotted as both minima are constantly zero and if the ever get higher it will be more noticably in
+    #the minimum delivery ratio for existent messages, two overlaying graphs make viewers search for the 'missing' one
+    #plt.plot(x, y_minForAll, '.-', label='Minimum for all messages ever created')
+    plt.plot(x, y_avgForAll, '.-',  label='Average for all messages ever created')
     plt.legend(loc='upper left')
     plt.grid(True)
 
@@ -36,17 +41,21 @@ def main(analysisFileName, graphicFileName):
     # Interpret lines to find minimum and average delivery rates over time
     timePoints = []
     minimum = []
+    minimumForAll = []
     average = []
+    averageForAll = []
     for line in analysis:
-        match = re.match("(\d+)\s+(\d+.\d+)\s+(\d+(?:.\d*)?)", line)
+        match = re.match("(\d+)\s+(\d+.\d+)\s+(\d+(?:.\d*)?)\s+(\d+(?:.\d*)?)\s+(\d+(?:.\d*)?)", line)
         if match is None:
             continue
         timePoints.append(float(match.group(1)) / 60)
         minimum.append(float(match.group(2)))
         average.append(float(match.group(3)))
+        minimumForAll.append(float(match.group(4)))
+        averageForAll.append(float(match.group(5)))
 
     # Draw plots.
-    drawPlots(timePoints, minimum, average)
+    drawPlots(timePoints, minimum, average, minimumForAll, averageForAll)
 
     # Save to file
     plt.savefig(graphicFileName)
-- 
GitLab