Skip to content
Snippets Groups Projects
Commit 906e60e7 authored by Nils Weidmann's avatar Nils Weidmann
Browse files

Merge branch 'feature-#645-clarify-multicast-delivery' into 'master'

Feature #645 clarify multicast delivery

See merge request !157
parents 62f99575 ce42fe5c
No related branches found
No related tags found
1 merge request!157Feature #645 clarify multicast delivery
Pipeline #
......@@ -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 );
}
}
......@@ -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)
......
  • 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