Commit d7640725 authored by Melanie Bruns's avatar Melanie Bruns
Browse files

Merge branch 'feature-#731-refactor-eval-scripts' into 'master'

Refactor evaluation scripts

See merge request !164
parents aa6422a8 7807a728
Pipeline #17189 passed with stages
in 4 minutes and 47 seconds
......@@ -30,6 +30,29 @@ def findLinesConcerningPriority(all_lines, priority):
nextPriorityLine = findNextLineContaining(all_lines, correctPriorityLine + 1, "prio")
return all_lines[correctPriorityLine:nextPriorityLine]
def parseBroadcastAnalysis(filename, priority):
"""Parses a broadcast analysis file for the specified priority and returns (in that order) the time points, the
minimum number of reached people, and the average number of reached people.
"""
# Read broadcast analysis from file
with open(filename) as analysis_file:
analysis = analysis_file.readlines()
relevantLines = findLinesConcerningPriority(analysis, priority)
# Interpret lines to find minimum and average number of reached people over time
timePoints = []
minimum = []
average = []
for line in relevantLines:
match = re.match("(\d+)\s+(\d+.\d+)\s+(\d+)", line)
if match is None:
continue
timePoints.append(float(match.group(1)) / 60)
average.append(float(match.group(2)))
minimum.append(int(match.group(3)))
return timePoints, minimum, average
# Draws two functions over the same x values.
# Labels are selected as appropriate for broadcast analysis.
def drawPlots(x, y_minimum, y_average, priority):
......@@ -45,40 +68,17 @@ def drawPlots(x, y_minimum, y_average, priority):
axes.set_ylim(ymin = 0)
axes.xaxis.set_major_locator(ticker.IndexLocator(base=60, offset=-5))
def plotAnalysis(lines, priority, figure, plotNumber):
# Interpret lines to find minimum and average number of reached people over time
timePoints = []
minimum = []
average = []
for line in lines:
match = re.match("(\d+)\s+(\d+.\d+)\s+(\d+)", line)
if match is None:
continue
timePoints.append(float(match.group(1)) / 60)
average.append(float(match.group(2)))
minimum.append(int(match.group(3)))
# Draw plots.
figure.add_subplot(1, 3, plotNumber)
drawPlots(timePoints, minimum, average, priority)
# Main function of the script. See script description at the top of the file for further information.
def main(analysisFileName, graphicFileName):
# Read broadcast analysis from file
with open(analysisFileName) as analysis_file:
analysis = analysis_file.readlines()
# Only look at priorities 2, 5 and 9
prio2Analysis = findLinesConcerningPriority(analysis, 2)
prio5Analysis = findLinesConcerningPriority(analysis, 5)
prio9Analysis = findLinesConcerningPriority(analysis, 9)
priorities = [2, 5, 9]
# Draw plots for all those priorities.
fig = plt.figure(figsize=(16, 4))
plotAnalysis(prio2Analysis, 2, fig, 1)
plotAnalysis(prio5Analysis, 5, fig, 2)
plotAnalysis(prio9Analysis, 9, fig, 3)
for idx, priority in enumerate(priorities):
timePoints, minimum, average = parseBroadcastAnalysis(analysisFileName, priority)
fig.add_subplot(1, 3, idx + 1)
drawPlots(timePoints, minimum, average, priority)
# Save to file
plt.tight_layout()
......
......@@ -29,10 +29,13 @@ from readFileUtilities import findNextLineContaining
messageTypeIntro = "Delay distribution for delivered messages of type {}:"
priorityIntro = "For priority {}:"
# Main function of the script. See script description at the top of the file for further information.
def main(analysisFileName, messageType, messagePrio, graphicFileName):
def parseDelayAnalysis(fileName, messageType, messagePrio):
"""Parses a delay analysis file for information about the provided message type and priority and
returns (in that order) the different delay classes (identified by max delay), the percentage of delivered messages
delivered in those intervals, and the cumulative percentages.
"""
# Read delay analysis from file
with open(analysisFileName) as analysis_file:
with open(fileName) as analysis_file:
analysis = analysis_file.readlines()
# Only look at text for correct type
......@@ -46,9 +49,9 @@ def main(analysisFileName, messageType, messagePrio, graphicFileName):
analysis = analysis[correctPriorityLine:nextPriorityLine]
# Find data both for bar chart and cumulative chart
bins = []
vals = []
cumulative = {}
delayClasses = []
percentageDelivered = []
cumulativePercentages = []
sumOfPercentages = 0
for line in analysis:
match = re.match(".*<\s*(\d+):\s*(\d+.\d+)%", line)
......@@ -56,23 +59,25 @@ def main(analysisFileName, messageType, messagePrio, graphicFileName):
continue
maxDelay = int(match.group(1)) / 60
percentage = float(match.group(2))
bins.append(maxDelay)
vals.append(percentage)
delayClasses.append(maxDelay)
percentageDelivered.append(percentage)
sumOfPercentages += percentage
cumulative[maxDelay] = sumOfPercentages
cumulativePercentages.append(sumOfPercentages)
# Plot bar chart
plt.subplot(2,1,1)
plt.title('Delay distribution of delivered {} messages\nPriority {}'.format(messageType, messagePrio))
plt.bar(bins, vals, color='#003a80')
return delayClasses, percentageDelivered, cumulativePercentages
def plotDelayDistribution(title, delayClasses, percentageDelivered):
"""Plots a delay distribution as a bar chart."""
plt.title(title)
plt.bar(delayClasses, percentageDelivered, color='#003a80')
plt.ylabel('Percentage of messages')
plt.grid(True)
axes = plt.gca()
axes.set_xlim(xmin = 0)
# Directly below, plot cumulative chart
plt.subplot(2,1,2)
plt.plot(bins, [cumulative[bin] for bin in bins], color='#003a80')
def plotCumulativeDelay(delayClasses, cumulativePercentages):
"""Plots a cumulative delay chart."""
plt.plot(delayClasses, cumulativePercentages, color='#003a80')
plt.xlabel('Delay in minutes')
plt.ylabel('Cumulative percentage')
plt.grid(True)
......@@ -80,10 +85,27 @@ def main(analysisFileName, messageType, messagePrio, graphicFileName):
axes.set_xlim(xmin = 0)
axes.set_ylim(ymin = 0)
def createDelayGraphicInFile(delayClasses, percentageDelivered, cumulativePercentages, title, fileName):
# Plot bar chart
plt.subplot(2,1,1)
plotDelayDistribution(title, delayClasses, percentageDelivered)
# Directly below, plot cumulative chart
plt.subplot(2,1,2)
plotCumulativeDelay(delayClasses, cumulativePercentages)
# Save to file
plt.savefig(graphicFileName, dpi = 300)
plt.savefig(fileName, dpi = 300)
plt.close()
# Main function of the script. See script description at the top of the file for further information.
def main(analysisFileName, messageType, messagePrio, graphicFileName):
delayClasses, percentageDelivered, cumulativePercentages = parseDelayAnalysis(analysisFileName, messageType, messagePrio)
createDelayGraphicInFile(
delayClasses, percentageDelivered, cumulativePercentages,
title='Delay distribution of delivered {} messages\nPriority {}'.format(messageType, messagePrio),
fileName=graphicFileName)
# Make sure script can be called from command line.
if __name__ == "__main__":
main(sys.argv[1], sys.argv[2], sys.argv[3], sys.argv[4])
\ No newline at end of file
......@@ -15,25 +15,13 @@ import re
# 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, 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 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)
# Main function of the script. See script description at the top of the file for further information.
def main(analysisFileName, graphicFileName):
def parseMulticastAnalysis(filename):
"""Parses a multicast analysis file and returns (in that order) the time points, the minimum delivery rates for
existing messages, the average delivery rates for existing messages, and the average delivery rates over all
messages ever created.
"""
# Read multicast analysis from file
with open(analysisFileName) as analysis_file:
with open(filename) as analysis_file:
analysis = analysis_file.readlines()
# Skip first line which only contains explanation.
analysis = analysis[1:]
......@@ -41,7 +29,6 @@ def main(analysisFileName, graphicFileName):
# Interpret lines to find minimum and average delivery rates over time
timePoints = []
minimum = []
minimumForAll = []
average = []
averageForAll = []
for line in analysis:
......@@ -51,11 +38,26 @@ def main(analysisFileName, graphicFileName):
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, minimumForAll, averageForAll)
return timePoints, minimum, average, averageForAll
# Draws two functions over the same x values.
# Labels are selected as appropiate for multicast analysis.
def drawPlots(x, y_minimum, y_average, y_avgForAll):
plt.title('Multicast delivery rates')
plt.xlabel('Minutes since message creation')
plt.ylabel('Delivery rate')
plt.plot(x, y_minimum, '.-', label='Minimum for existent messages')
plt.plot(x, y_average, '.-', label='Average for existent messages')
plt.plot(x, y_avgForAll, '.-', label='Average for all messages ever created')
plt.legend(loc='upper left')
plt.grid(True)
# Main function of the script. See script description at the top of the file for further information.
def main(analysisFileName, graphicFileName):
timePoints, minimum, average, averageForAll = parseMulticastAnalysis(analysisFileName)
drawPlots(timePoints, minimum, average, averageForAll)
# Save to file
plt.savefig(graphicFileName)
......
......@@ -26,16 +26,21 @@ def getValueFromString(string):
return float(match.group(2))
return int(match.group(2))
# Main function of the script. See script description at the top of the file for further information.
def main(analysisFileName, graphicFileName):
# Read delivery probability from file
with open(analysisFileName) as analysis_file:
def parseDeliveryProbabilityReport(fileName):
"""Parses a delivery probability report file and returns (in that order) the number of created messages,
the number of delivered messages, and the delivery probability.
"""
with open(fileName) as analysis_file:
analysis = analysis_file.readlines()
created = getValueFromString(analysis[2])
delivered = getValueFromString(analysis[3])
delivery_prob = getValueFromString(analysis[4])
return created, delivered, delivery_prob
def createDeliveryPieChart(created, delivered, delivery_prob):
"""Creates a graphical presentation of delivery probability."""
values=[delivery_prob, 1-delivery_prob]
labels=["delivered:\n{p:.1f}% ({t})".format(p=delivery_prob*100, t=delivered),
"not delivered:\n{p:.1f}% ({t})".format(p=(1-delivery_prob)*100, t=(created-delivered))]
......@@ -51,6 +56,11 @@ def main(analysisFileName, graphicFileName):
plt.figtext(0.6, 0.05, 'Total created messages: %d' % created)
plt.title("Message delivery ratio for one-to-one messages")
# Main function of the script. See script description at the top of the file for further information.
def main(analysisFileName, graphicFileName):
created, delivered, delivery_prob = parseDeliveryProbabilityReport(analysisFileName)
createDeliveryPieChart(created, delivered, delivery_prob)
# Save to file
plt.savefig(graphicFileName)
plt.close()
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment