Skip to content
Snippets Groups Projects
Commit 07d8579c authored by mbruns42's avatar mbruns42
Browse files

Add second graph for all messages that ever existed

parent 255d13f6
No related branches found
No related tags found
1 merge request!157Feature #645 clarify multicast delivery
Pipeline #
...@@ -77,7 +77,7 @@ close(INFILE); ...@@ -77,7 +77,7 @@ close(INFILE);
#Map, that stores the last delivery ratio for every message #Map, that stores the last delivery ratio for every message
my %msgToLastRatio = (); my %msgToLastRatio = ();
print "#timeAfterMessageCreation MinRatio AvgRatio\n"; print "#timeAfterMessageCreation MinRatio AvgRatio MinRationForAll AvgRatioForAll\n";
my $lastInterval = 0; my $lastInterval = 0;
#Sort intervals numerically and process every interval step by step #Sort intervals numerically and process every interval step by step
...@@ -114,14 +114,15 @@ sub getHighestInterval{ ...@@ -114,14 +114,15 @@ sub getHighestInterval{
sub printInterval{ sub printInterval{
my $interval = shift; my $interval = shift;
my $ratioSum = 0; my $ratioSum = 0;
my $ratioSumForAll = 0;
my $nextMin = 2; my $nextMin = 2;
my $nextMinForAll = 2;
my $msgCount = 0; my $msgCount = 0;
my $msgCountForAll = 0;
#check every message #check every message
foreach my $msg (keys %msgToLastRatio){ foreach my $msg (keys %msgToLastRatio){
#ignore it, if it didn't exist anymore during the current interval #calculate these metrics only for message that still exist during the current interval
if ($msgToMaxInterval{$msg} < $interval){ if ($msgToMaxInterval{$msg} >= $interval){
next;
}
#add it to the min and avg calculation for the current interval #add it to the min and avg calculation for the current interval
$msgCount++; $msgCount++;
my $msgRatio = $msgToLastRatio{$msg}; my $msgRatio = $msgToLastRatio{$msg};
...@@ -130,12 +131,22 @@ sub printInterval{ ...@@ -130,12 +131,22 @@ sub printInterval{
$nextMin = $msgRatio; $nextMin = $msgRatio;
} }
} }
#calculate these metrics for all messages ever created
$msgCountForAll++;
my $msgRatio = $msgToLastRatio{$msg};
$ratioSumForAll += $msgRatio;
if ($nextMinForAll > $msgRatio){
$nextMinForAll = $msgRatio;
}
}
if ($msgCount > 0) { if ($msgCount > 0) {
#calculate average #calculate average
my $nextAvg = $ratioSum / $msgCount; my $nextAvg = $ratioSum / $msgCount;
my $nextAvgForAll = $ratioSumForAll / $msgCountForAll;
#convert the interval into simulation seconds #convert the interval into simulation seconds
my $seconds = $interval * $timeStep; my $seconds = $interval * $timeStep;
print "$seconds $nextMin $nextAvg\n"; print "$seconds $nextMin $nextAvg $nextMinForAll $nextAvgForAll\n";
} }
} }
...@@ -146,5 +157,4 @@ sub calculateMaxIntervalForAllMsgs { ...@@ -146,5 +157,4 @@ sub calculateMaxIntervalForAllMsgs {
foreach my $msgId (keys %msgToCreateTime){ foreach my $msgId (keys %msgToCreateTime){
$msgToMaxInterval{$msgId} = int(($simTime - $msgToCreateTime{$msgId}) / $timeStep ); $msgToMaxInterval{$msgId} = int(($simTime - $msgToCreateTime{$msgId}) / $timeStep );
} }
} }
...@@ -3,25 +3,30 @@ import sys ...@@ -3,25 +3,30 @@ import sys
import re import re
# Script that translates multicast analysis into a plot of average and minimum delivery rate over time. # 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 # Takes as arguments
# (1) a multicast analysis file # (1) a multicast analysis file
# (2) path to save the graphic to. # (2) path to save the graphic to.
# #
# The multicast analysis file should have a format like: # The multicast analysis file should have a format like:
# #
# #timeAfterMessageCreation MinRatio AvgRatio # #timeAfterMessageCreation MinRatio AvgRatio MinRatioForAll AvgRatioForAll
# 300 0.0 0.00444165511837884 # 300 0.0 0.00444165511837884 0.0 0.004223002342392
# 600 0.0 0.0164942207497068 # 600 0.0 0.0164942207497068 0.0 0.01223002342392
# 900 0.0 0.0340330430435976 # 900 0.0 0.0340330430435976 0.0 0.024223002342392
# Draws two functions over the same x values. # Draws two functions over the same x values.
# Labels are selected as appropiate for multicast analysis. # 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.title('Multicast delivery rates')
plt.xlabel('Minutes since message creation') plt.xlabel('Minutes since message creation')
plt.ylabel('Delivery rate') plt.ylabel('Delivery rate')
plt.plot(x, y_minimum, '.-', label='Minimum') plt.plot(x, y_minimum, '.-', label='Minimum for existent messages')
plt.plot(x, y_average, '.-', label='Average') 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.legend(loc='upper left')
plt.grid(True) plt.grid(True)
...@@ -36,17 +41,21 @@ def main(analysisFileName, graphicFileName): ...@@ -36,17 +41,21 @@ def main(analysisFileName, graphicFileName):
# Interpret lines to find minimum and average delivery rates over time # Interpret lines to find minimum and average delivery rates over time
timePoints = [] timePoints = []
minimum = [] minimum = []
minimumForAll = []
average = [] average = []
averageForAll = []
for line in analysis: 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: if match is None:
continue continue
timePoints.append(float(match.group(1)) / 60) timePoints.append(float(match.group(1)) / 60)
minimum.append(float(match.group(2))) minimum.append(float(match.group(2)))
average.append(float(match.group(3))) average.append(float(match.group(3)))
minimumForAll.append(float(match.group(4)))
averageForAll.append(float(match.group(5)))
# Draw plots. # Draw plots.
drawPlots(timePoints, minimum, average) drawPlots(timePoints, minimum, average, minimumForAll, averageForAll)
# Save to file # Save to file
plt.savefig(graphicFileName) plt.savefig(graphicFileName)
......
  • Contributor

    SonarQube analysis reported no issues.

0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment