---
header-includes:
- \usepackage{comment}
- \usepackage{url}
lang: en-US
output:
  pdf_document:
     keep_tex: true
  highlight: tango
  fig_caption: yes
  toc: yes
params:
  title: ''
  baselineStartmarkers: !r data.frame(0)
  baselineEndmarkers: !r data.frame(0)
  startActions: !r data.frame(0)
  stopActions: !r data.frame(0)
  startmarkers: !r data.frame(0)
  endmarkers: !r data.frame(0)
  measurementCount: -1
  shortestTestrun: 0
  longestTestrun: 0
  measurementName: '---'
  performanceBaseline: !r data.frame(0)
  performanceMeasurement: !r data.frame(0)
  performanceMeasurementActions: !r data.frame(0)
  allPerformanceMeasurements: !r data.frame(0)
  allPerformanceBaselines: !r data.frame(0)
  powerBaseline: !r data.frame(0)
  powerMeasurement: !r data.frame(0)
  powerMeasurementActions: !r data.frame(0)
  allPowerMeasurements: !r data.frame(0)
  allPowerBaselines: !r data.frame(0)
  watthours: 0
  baselineWatthours: 0
  subtitle: ''
  baselineCount: -1
  whatToPlot: !r list()
  actionNames: !r c("a","b")
  graphicsFolder: "./"
---

---
title: "`r params$title`"
subtitle: "`r params$subtitle`"
---
# Introduction
This report contains the analysis results from the software resource consumption measurement "`r params$measurementName`". The software was executed $n_M = `r params$measurementCount`$ times. The baseline was averaged over $n_B = `r params$baselineCount`$ passes.

## Durations
Table \ref{tab:measurement_durations} describes the measurement and baseline durations (measured in seconds) and table \ref{tab:action_durations} describes the duration for the actions.
```{r echo=FALSE, results='asis'}
library(psych)
library(knitr)
library(reshape2)

baselineTimes <- as.numeric(difftime(time1 = params$baselineEndmarkers$timestamp, time2 = params$baselineStartmarkers$timestamp, units = "secs"))
baselineDescription <- describe(baselineTimes, IQR = T)
measurementTimes <- as.numeric(difftime(params$endmarkers$timestamp, params$startmarkers$timestamp, units = "secs"))
measurementDescription <- describe(measurementTimes, IQR = T)
resultTable <- rbind(baselineDescription[, c("n","mean", "sd", "median", "min", "max", "range", "IQR")], measurementDescription[, c("n","mean", "sd", "median", "min", "max", "range", "IQR")])
rownames(resultTable)<-c("baseline durations", "testrun durations")

actionsDescriptionTable <- list()
actionsTable <- list()
for (action in params$actionNames) {
  actionsTable[[paste(action)]] <- as.numeric(difftime(time1 = params$stopActions$timestamp[which(params$startActions$text == action)], time2 = params$startActions$timestamp[which(params$startActions$text == action)], units = "secs"))
  actionsDescriptionTable[[paste(action)]] <- describe(actionsTable[[paste(action)]], IQR = T)
  actionsDescriptionTable[[paste(action)]] <- actionsDescriptionTable[[paste(action)]][, c("n","mean", "sd", "median", "min", "max", "range", "IQR")]
  rownames(actionsDescriptionTable[[paste(action)]]) <- paste(action)
}
actionsDF <- actionsDescriptionTable[[1]]
for (element in actionsDescriptionTable[2:length(actionsDescriptionTable)]) {
 actionsDF <- rbind(actionsDF, element)
}


kable(resultTable, caption = "Measurement durations\\label{tab:measurement_durations}", digits = 3)
kable(actionsDF, caption = "Action durations\\label{tab:action_durations}", digits = 3)


try(
  boxplot(list("baseline durations" = baselineTimes, "testrun durations" = measurementTimes), main = "Boxplots of the baseline and testrun durations")
)
```

```{r echo=FALSE}
try({
  x <- boxplot(actionsTable, main = "Boxplots of the action durations", xaxt = "n", space = 1)
  text(cex=1, x=c(1:length(actionsTable))-.25, y=65, names(actionsTable), xpd=TRUE, srt=45)
})
```

# Energy Consumption
This section presents the energy consumption analysis, based upon the power measurements. The first graph (Fig. \ref{fig:power}) shows the power consumption of the System under Test (SUT) during the measurement scenario. It contains the individual measurements (grey) and the per-second mean (red).

![Graph of the power consumption\label{fig:power}](`r paste(params$graphicsFolder, "power.png", sep="/")`)

In an analogous manner, fig. \ref{fig:powerBaseline} shows the power consumption of the baseline measurement (SUT running only in standard configuration without the software product).

![Graph of the power consumption baseline\label{fig:powerBaseline}](`r paste(params$graphicsFolder, "power_baseline.png", sep="/")`)
```{r results='hide', echo=FALSE}
# Get mean sd for all seconds:
perSecond <- describeBy(as.numeric(params$allPowerMeasurements$Wert.1.avg.W.), group = as.integer(allPowerMeasurements$second))
meanSD <- 0
measurementDuration <- 0
for(e in 1:length(perSecond)){
  if(!is.na(perSecond[[e]]$sd)){
    meanSD <- meanSD + perSecond[[e]]$sd
    measurementDuration <- measurementDuration + 1
  }
}
meanSD <- meanSD/measurementDuration

perSecondBaseline <- describeBy(as.numeric(params$allPowerBaselines$Wert.1.avg.W.), group = as.integer(allPowerBaselines$second))
meanSDBaseline <- 0
measurementDuration <- 0
for(e in 1:length(perSecondBaseline)){
  if(!is.na(perSecondBaseline[[e]]$sd)){
    meanSDBaseline <- meanSDBaseline + perSecondBaseline[[e]]$sd
    measurementDuration <- measurementDuration + 1
  }
}
meanSDBaseline <- meanSDBaseline/measurementDuration
#DEBUG:
#cat("mean sd per second:", meanSD)
```

We now calculate the root mean square deviation for each second of the measurement for the scenario and the baseline to check the accuracy of the automatic load generation. The deviation for the measurements is calculated as $\overline{s} = \frac{1}{`r measurementDuration`}\sum s_n, \text{ with } s_n = s_1, s_2, s_3, ..., s_{`r measurementDuration`}$.

For the testruns, this results to a deviation of `r meanSD` Watts, with a mean value of `r mean(as.numeric(allPowerMeasurements$Wert.1.avg.W.))` Watts. For the baselines, this results to a deviation of `r meanSDBaseline` Watts, with a mean value of `r mean(as.numeric(allPowerBaselines$Wert.1.avg.W.))` Watts.

To evaluate the energy consumption that is caused by the software product, we first calculate the mean energy consumption [Watthours] of the scenario and the baseline measurement as $W_{el} = P\cdot{}t$. Because the measurements of the power usage $P_n$ were recorded with a sampling rate of $F=1 Hz$, the energy can be calculated as
 $$W_{el} = \frac{1}{3600} \sum_{n=1}^{m} P_n, \text{ mit } P_n=P_1, P_2, P_3, ..., P_m$$
Thus, the energy for one testrun or baseline equals the sum of the per-second measurement values (resulting in the unit Wattseconds). It is then divided by $3600\frac{s}{h}$, resulting in the unit Watthours. We then average the energy consumption means over the testruns and baselines, respectively. The results can be found in table \ref{tab:energyResults}.

```{r echo=FALSE, results='asis'}
# Calculate Power
powerMeans <- NULL
for(i in 1:length(params$powerMeasurement)){
  powerMeans[i] <- mean(as.numeric(params$powerMeasurement[[i]]$Wert.1.avg.W.))
}
powerMeansTable <- describe(powerMeans, IQR = T)

powerBaselineMeans <- NULL
for(i in 1:length(params$powerBaseline)){
  powerBaselineMeans[i] <- mean(as.numeric(params$powerBaseline[[i]]$Wert.1.avg.W.))
}
powerBaselineMeansTable <- describe(powerBaselineMeans, IQR = T)

# Calculate Watthours
watthours <- NULL
for(i in 1:length(params$powerMeasurement)){
  watthours[i] <- sum(as.numeric(params$powerMeasurement[[i]]$Wert.1.avg.W.))
}
watthours <- watthours/3600
watthoursTable <- describe(watthours, IQR = T)

baselineWatthours <- NULL
for(i in 1:length(params$powerBaseline)){
  baselineWatthours[i] <- sum(as.numeric(params$powerBaseline[[i]]$Wert.1.avg.W.))
}
baselineWatthours <- baselineWatthours/3600
baselineWatthoursTable <- describe(baselineWatthours, IQR = T)

resultTable <- rbind(powerMeansTable[, c("n","mean", "sd", "median", "min", "max", "range", "IQR")], powerBaselineMeansTable[, c("n","mean", "sd", "median", "min", "max", "range", "IQR")], watthoursTable[, c("n","mean", "sd", "median", "min", "max", "range", "IQR")], baselineWatthoursTable[, c("n","mean", "sd", "median", "min", "max", "range", "IQR")])
rownames(resultTable) <- c("testrun power [W]", "baseline power [W]", "testrun energy [Wh]", "baseline energy [Wh]")

adjustedBaselineWatthours <- baselineWatthoursTable$mean / baselineDescription$mean * measurementDescription$mean
softwareWatthours <- watthoursTable$mean - adjustedBaselineWatthours

kable(resultTable, caption = "Power and energy consumption overview\\label{tab:energyResults}", digits = 3)
```

\clearpage

Afterwards, the mean energy for the baselines ($\overline{W}_{el_{Baseline}}$), with the mean duration of $\overline{t}_{Baseline} = `r baselineDescription$mean` s$, is adjusted to the mean duration of the measurements ($\overline{t}_{Testrun} = `r measurementDescription$mean` s$), by dividing the mean baseline energy by the mean baseline duration and multiplying it with the mean measurement duration:
$$\overline{W}_{el_{Adjusted Baseline}} = \frac{\overline{W}_{el_{Baseline}}}{\overline{t}_{Baseline}}\times \overline{t}_{Testrun}$$

This results in a value for the \textbf{mean adjusted baseline energy consumption of `r adjustedBaselineWatthours` Wh}.

Finally, the mean adjusted baseline energy is subtracted from the mean energy of the scenario measurements, which results in the additional energy required to run the software:
$$\overline{W}_{el_{Software}} = \overline{W}_{el_{Testrun}} - \overline{W}_{el_{Adjusted Baseline}}$$

Hence, the \textbf{energy consumption induced by the software product is `r softwareWatthours` Wh}.

Table \ref{tab:testrunResults} contains the results for the individual testruns. Figure \ref{fig:powerWhPlots} shows the resulting energy measurements for each testrun and figure \ref{fig:powerWhBoxplots} shows the boxplots, depicting the measurement results.

```{r echo=FALSE, results='asis'}
resultTable <- as.data.frame(list(c(1:length(powerMeans), "mean"), c(powerMeans, mean(powerMeans)), c(watthours, mean(watthours)), c(watthours - adjustedBaselineWatthours, softwareWatthours)))
names(resultTable)<-c("testrun #", "mean power [W]","energy [Wh]","software induced energy [Wh]")
kable(resultTable, caption="individual measurement results\\label{tab:testrunResults}", digits = 3)
```

```{r echo=FALSE, fig.cap="Plot of the software induced energy consumption per measurement\\label{fig:powerWhPlots}"}
plot(watthours - adjustedBaselineWatthours, type = "h", main = paste("Overview of the energy consumption for the measurements"), xlab = "testrun #", ylab = "Energy [Wh]")
```

```{r echo=FALSE, fig.cap="Boxplots of the energy consumption of the testruns (l) and software induced consumption (r) \\label{fig:powerWhBoxplots}"}
opar <- par(mfrow=c(1, 3))
par("mar" = par("mar")+1, "cex.axis" = 1.7, "cex.main" = 1.7, "cex.lab" = 1.7)
boxplot(baselineWatthours, main = paste("baselines"), ylab="Energy [Wh]")
boxplot(watthours, main = paste("testruns"), ylab="Energy [Wh]")
boxplot(watthours - adjustedBaselineWatthours, main = paste("software induced"), ylab="Energy [Wh]")
par(opar)
```

##Energy Consumption per Action
This section contains the results for the energy consumption analysis of the individual actions:

```{r results='asis', echo = FALSE}
cat(paste("*", params$actionNames, collapse ="\n"), "\n\n")

cat("The results shown in table \\ref{tab:ActionResultsPower} represent the mean values for the power and energy consumption of the actions, calculated in the same way as the testrun results.")

powerMeansAction <- NULL
  for(i in 1:length(params$powerMeasurementActions)){
    powerMeansAction[i] <- mean(as.numeric(params$powerMeasurementActions[[i]]$Wert.1.avg.W.))
  }

watthoursActions <- NULL
for(i in 1:length(params$powerMeasurementActions)){
  watthoursActions[i] <- sum(as.numeric(params$powerMeasurementActions[[i]]$Wert.1.avg.W.))
}
watthoursActions <- watthoursActions/3600

resultTableActions <- NULL
for(action in actionNames){
  adjustedBaselineWatthoursAction <- baselineWatthoursTable$mean / baselineDescription$mean * actionsDF[action,"mean"]
  softwareWatthoursAction <- mean(watthoursActions[which(startActions$text == action)]) - adjustedBaselineWatthoursAction
  resultTableActions <- rbind(resultTableActions, c(mean(powerMeansAction[which(startActions$text == action)]), mean(watthoursActions[which(startActions$text == action)]), adjustedBaselineWatthoursAction, softwareWatthoursAction))
}
resultTableActions <- data.frame(resultTableActions)
resultTableActions <- cbind(actionNames, resultTableActions)
names(resultTableActions)<-c("action", "mean power [W]", "energy [Wh]", "baseline energy [Wh]", "software induced [Wh]")
kable(resultTableActions, caption="Mean measurement results for the individual actions\\label{tab:ActionResultsPower}", digits = 3)
```

\clearpage

#Hardware Usage
The analysis of the hardware utilization is, for the most part, analogous to the power analysis. The following parameters were analyzed:

* CPU load [%],
* RAM usage [%],
* HDD activity (reading and writing) [kB], and
* Network traffic (sending und receiving) [kB].

##Raw Data Graphs

For each parameter, there is a figure that depicts the raw measurement results:

\begin{tabular}{l|l|l}
parameter & scenario graph & baseline graph \\ \hline
CPU load & figure \ref{fig:hw_cpu} & figure \ref{fig:hw_cpu_bl} \\
RAM usage & figure \ref{fig:hw_ram} & figure \ref{fig:hw_ram_bl} \\
HDD activity & figure \ref{fig:hw_hdd} & figure \ref{fig:hw_hdd_bl} \\
Network traffic & figure \ref{fig:hw_nw} & figure \ref{fig:hw_nw_bl} \\
\end{tabular}

\clearpage

![Graph of the processor load\label{fig:hw_cpu}](`r paste(params$graphicsFolder, "cpu_usage.png", sep="/")`)

![Graph of the baseline processor load\label{fig:hw_cpu_bl}](`r paste(params$graphicsFolder, "cpu_usage_baseline.png", sep="/")`)

![Graph of the RAM usage\label{fig:hw_ram}](`r paste(params$graphicsFolder, "ram_usage.png", sep="/")`)

![Graph of the baseline RAM usage\label{fig:hw_ram_bl}](`r paste(params$graphicsFolder, "ram_usage_baseline.png", sep="/")`)

![Graph of the HDD activity\label{fig:hw_hdd}](`r paste(params$graphicsFolder, "hdd_activity.png", sep="/")`)

![Graph of the baseline HDD activity\label{fig:hw_hdd_bl}](`r paste(params$graphicsFolder, "hdd_activity_baseline.png", sep="/")`)

![Graph of the network traffic\label{fig:hw_nw}](`r paste(params$graphicsFolder, "network_traffic.png", sep="/")`)

![Graph of the baseline network traffic\label{fig:hw_nw_bl}](`r paste(params$graphicsFolder, "network_traffic_baseline.png", sep="/")`)

\clearpage

##Analysis Results

It follows the descriptive analysis of each parameter. In all cases the mean software induced usage $\overline{x}(Parameter_{Software})$ is calculated as the mean value of the measurement testruns $\overline{x}(Parameter_{T})$ from which the mean value of the baseline $\overline{x}(Parameter_{B})$ is subtracted. Thus, the average value is calculated as
$$\overline{x}(Parameter_{Software}) = \overline{x}(Parameter_{T}) - \overline{x}(Parameter_{B})$$

Tables \ref{tab:hardwareOverview} and \ref{tab:hardwareResults} list the resulting means for each parameter and baseline.

```{r echo=FALSE, results='asis'}
# Calculate hardware utilization
cpuMeans <- NULL
for(i in 1:length(params$performanceMeasurement)){
  cpuMeans[i] <- mean(as.numeric(params$performanceMeasurement[[i]]$processorTime))
}
cpuMeansTable <- describe(cpuMeans, IQR = T)

ramMeans <- NULL
for(i in 1:length(params$performanceMeasurement)){
  ramMeans[i] <- mean(as.numeric(params$performanceMeasurement[[i]]$ram))
}
ramMeansTable <- describe(ramMeans, IQR = T)

hddMeans <- NULL
for(i in 1:length(params$performanceMeasurement)){
  hddMeans[i] <- mean(as.numeric(params$performanceMeasurement[[i]]$hddActivity))
}
hddMeansTable <- describe(hddMeans, IQR = T)

nwMeans <- NULL
for(i in 1:length(params$performanceMeasurement)){
  nwMeans[i] <- mean(as.numeric(params$performanceMeasurement[[i]]$networkTraffic))
}
nwMeansTable <- describe(nwMeans, IQR = T)

# Calculate baseline hardware utilization
cpuMeansBaseline <- NULL
for(i in 1:length(params$performanceBaseline)){
  cpuMeansBaseline[i] <- mean(as.numeric(params$performanceBaseline[[i]]$processorTime))
}
cpuMeansBaselineTable <- describe(cpuMeansBaseline, IQR = T)

ramMeansBaseline <- NULL
for(i in 1:length(params$performanceBaseline)){
  ramMeansBaseline[i] <- mean(as.numeric(params$performanceBaseline[[i]]$ram))
}
ramMeansBaselineTable <- describe(ramMeansBaseline, IQR = T)

hddMeansBaseline <- NULL
for(i in 1:length(params$performanceBaseline)){
  hddMeansBaseline[i] <- mean(as.numeric(params$performanceBaseline[[i]]$hddActivity))
}
hddMeansBaselineTable <- describe(hddMeansBaseline, IQR = T)

nwMeansBaseline <- NULL
for(i in 1:length(params$performanceBaseline)){
  nwMeansBaseline[i] <- mean(as.numeric(params$performanceBaseline[[i]]$networkTraffic))
}
nwMeansBaselineTable <- describe(nwMeansBaseline, IQR = T)

overviewTable <- rbind(cpuMeansTable[, c("n","mean", "sd", "median", "min", "max", "range", "IQR")], cpuMeansBaselineTable[, c("n","mean", "sd", "median", "min", "max", "range", "IQR")], ramMeansTable[, c("n","mean", "sd", "median", "min", "max", "range", "IQR")], ramMeansBaselineTable[, c("n","mean", "sd", "median", "min", "max", "range", "IQR")],hddMeansTable[, c("n","mean", "sd", "median", "min", "max", "range", "IQR")], hddMeansBaselineTable[, c("n","mean", "sd", "median", "min", "max", "range", "IQR")],nwMeansTable[, c("n","mean", "sd", "median", "min", "max", "range", "IQR")], nwMeansBaselineTable[, c("n","mean", "sd", "median", "min", "max", "range", "IQR")])

rownames(overviewTable) <- c("mean CPU load [%]", "mean baseline CPU load [%]", "mean RAM usage [%]", "mean baseline RAM usage [%]", "mean HDD activity [kB]", "mean baseline HDD activity [kB]", "mean Network traffic [kB]", "mean baseline Network traffic [kB]")

resultTable <- as.data.frame(cbind(c(mean(cpuMeans), mean(ramMeans), mean(hddMeans), mean(nwMeans)),
                     c(mean(cpuMeansBaseline), mean(ramMeansBaseline), mean(hddMeansBaseline), mean(nwMeansBaseline)),
                     c(mean(cpuMeans) - mean(cpuMeansBaseline), mean(ramMeans) - mean(ramMeansBaseline), mean(hddMeans) - mean(hddMeansBaseline), mean(nwMeans) - mean(nwMeansBaseline))))
resultTable <- cbind(c("CPU load [%]", "RAM usage [%]", "HDD activity [kB]", "Network traffic [kB]"), resultTable)
names(resultTable) <- c("parameter", "testruns", "baselines", "software induced")


kable(overviewTable, caption = "Hardware usage measurement overview\\label{tab:hardwareOverview}", digits = 3)
kable(resultTable, caption = "Hardware usage results\\label{tab:hardwareResults}", digits = 3)
```

##Testrun Results

Finally, the results for the individual testruns are presented as tables and figures:
\begin{tabular}{l|l|l|l}
parameter & overview table & overview graph & boxplots \\ \hline
CPU load & table \ref{tab:hw_cpu} & figure \ref{fig:hw_cpu_overview} & figure \ref{fig:hw_cpu_boxplots}\\
RAM usage & table \ref{tab:hw_ram} & figure \ref{fig:hw_ram_overview} & figure \ref{fig:hw_ram_boxplots}\\
HDD activity & table \ref{tab:hw_hdd} & figure \ref{fig:hw_hdd_overview} & figure \ref{fig:hw_hdd_boxplots}\\
Network traffic & table \ref{tab:hw_nw} & figure \ref{fig:hw_nw_overview} & figure \ref{fig:hw_nw_boxplots}\\
\end{tabular}

\clearpage

###CPU

```{r echo=FALSE, results='asis'}
#CPU
resultTable <- as.data.frame(list(c(1:length(cpuMeans), "mean"), c(cpuMeans, mean(cpuMeans)), c(cpuMeans - mean(cpuMeansBaseline), mean(cpuMeans) - mean(cpuMeansBaseline))))
names(resultTable)<-c("testrun #", "mean CPU load [%]","software induced CPU load [%]")
kable(resultTable, caption="individual CPU measurement results\\label{tab:hw_cpu}", digits = 3)
```

```{r echo=FALSE, fig.cap="Plot of the software induced CPU load per measurement\\label{fig:hw_cpu_overview}"}
plot(cpuMeans - mean(cpuMeansBaseline), type = "h", main = paste("Overview of the CPU load for the measurements"), xlab = "testrun #", ylab = "CPU load [%]")
```

```{r echo=FALSE, fig.cap="Boxplots of the CPU load of the testruns (l) and software induced load (r) \\label{fig:hw_cpu_boxplots}"}
opar <- par(mfrow=c(1, 3))
par("mar" = par("mar")+1, "cex.axis" = 1.7, "cex.main" = 1.7, "cex.lab" = 1.7)
boxplot(cpuMeansBaseline, main = paste("baselines"), ylab="CPU load [%]")
boxplot(cpuMeans, main = paste("testruns"), ylab="CPU load [%]")
boxplot(cpuMeans - mean(cpuMeansBaseline), main = paste("software induced"), ylab="CPU load [%]")
par(opar)
```

\clearpage

###RAM

```{r echo=FALSE, results='asis'}
#RAM
resultTable <- as.data.frame(list(c(1:length(ramMeans), "mean"), c(ramMeans, mean(ramMeans)), c(ramMeans - mean(ramMeansBaseline), mean(ramMeans) - mean(ramMeansBaseline))))
names(resultTable)<-c("testrun #", "mean RAM usage [%]","software induced RAM usage [%]")
kable(resultTable, caption="individual RAM measurement results\\label{tab:hw_ram}", digits = 3)
```

```{r echo=FALSE, fig.cap="Plot of the software induced RAM usage per measurement\\label{fig:hw_ram_overview}"}
plot(ramMeans - mean(ramMeansBaseline), type = "h", main = paste("Overview of the RAM usage for the measurements"), xlab = "testrun #", ylab = "RAM usage [%]")
```

```{r echo=FALSE, fig.cap="Boxplots of the RAM usage of the testruns (l) and software induced load (r) \\label{fig:hw_ram_boxplots}"}
opar <- par(mfrow=c(1, 3))
par("mar" = par("mar")+1, "cex.axis" = 1.7, "cex.main" = 1.7, "cex.lab" = 1.7)
boxplot(ramMeansBaseline, main = paste("baselines"), ylab="RAM usage [%]")
boxplot(ramMeans, main = paste("testruns"), ylab="RAM usage [%]")
boxplot(ramMeans - mean(ramMeansBaseline), main = paste("software induced"), ylab="RAM usage [%]")
par(opar)
```

\clearpage

###HDD

```{r echo=FALSE, results='asis'}
#HDD
resultTable <- as.data.frame(list(c(1:length(hddMeans), "mean"), c(hddMeans, mean(hddMeans)), c(hddMeans - mean(hddMeansBaseline), mean(hddMeans) - mean(hddMeansBaseline))))
names(resultTable)<-c("testrun #", "mean HDD activity [kB]","software induced HDD activity [kB]")
kable(resultTable, caption="individual HDD measurement results\\label{tab:hw_hdd}", digits = 3)
```

```{r echo=FALSE, fig.cap="Plot of the software induced HDD activity per measurement\\label{fig:hw_hdd_overview}"}
plot(hddMeans - mean(hddMeansBaseline), type = "h", main = paste("Overview of the HDD activity for the measurements"), xlab = "testrun #", ylab = "HDD activity [kB]")
```

```{r echo=FALSE, fig.cap="Boxplots of the HDD activity of the testruns (l) and software induced load (r) \\label{fig:hw_hdd_boxplots}"}
opar <- par(mfrow=c(1, 3))
par("mar" = par("mar")+1, "cex.axis" = 1.7, "cex.main" = 1.7, "cex.lab" = 1.7)
boxplot(hddMeansBaseline, main = paste("baselines"), ylab="HDD activity [kB]")
boxplot(hddMeans, main = paste("testruns"), ylab="HDD activity [kB]")
boxplot(hddMeans - mean(hddMeansBaseline), main = paste("software induced"), ylab="HDD activity [kB]")
par(opar)
```

\clearpage

###Network

```{r echo=FALSE, results='asis'}
#Network
resultTable <- as.data.frame(list(c(1:length(nwMeans), "mean"), c(nwMeans, mean(nwMeans)), c(nwMeans - mean(nwMeansBaseline), mean(nwMeans) - mean(nwMeansBaseline))))
names(resultTable)<-c("testrun #", "mean network traffic [kB]","software induced network traffic [kB]")
kable(resultTable, caption="individual network measurement results\\label{tab:hw_nw}", digits = 3)
```

```{r echo=FALSE, fig.cap="Plot of the software induced network traffic per measurement\\label{fig:hw_nw_overview}"}
plot(nwMeans - mean(nwMeansBaseline), type = "h", main = paste("Overview of the network traffic for the measurements"), xlab = "testrun #", ylab = "network traffic [kB]")
```

```{r echo=FALSE, fig.cap="Boxplots of the network traffic of the testruns (l) and software induced load (r) \\label{fig:hw_nw_boxplots}"}
opar <- par(mfrow=c(1, 3))
par("mar" = par("mar")+1, "cex.axis" = 1.7, "cex.main" = 1.7, "cex.lab" = 1.7)
boxplot(nwMeansBaseline, main = paste("baselines"), ylab="network traffic [kB]")
boxplot(nwMeans, main = paste("testruns"), ylab="network traffic [kB]")
boxplot(nwMeans - mean(nwMeansBaseline), main = paste("software induced"), ylab="network traffic [kB]")
par(opar)
```

\clearpage

##Hardware Usage per Action
This section contains the results for the hardware consumption analysis of the individual actions:

```{r results='asis', echo = FALSE}
cat(paste("*", params$actionNames, collapse ="\n"), "\n\n")

actionResultTableLables <- NULL
for(action in actionNames){
actionResultTableLables <- c(actionResultTableLables, paste0("\\label{tab:", action,"ResultsPerformance}"))
}

cat(paste0("The results shown in tables below represent the mean values for the hardware usage of the actions, calculated in the same way as the testrun results.\n\n"))

performanceMeansAction <- NULL
  for(i in 1:length(params$performanceMeasurementActions)){
    performanceMeansAction <- rbind(performanceMeansAction,
      c(mean(as.numeric(params$performanceMeasurementActions[[i]]$processorTime)),
      mean(as.numeric(params$performanceMeasurementActions[[i]]$ram)),
      mean(as.numeric(params$performanceMeasurementActions[[i]]$hddActivity)),
      mean(as.numeric(params$performanceMeasurementActions[[i]]$networkTraffic))))
  }
performanceMeansAction <- as.data.frame(performanceMeansAction)
names(performanceMeansAction) <- c("processorTime", "ram", "hddActivity", "networkTraffic")

for(action in actionNames){
  cat("###", action, "\n\n")
  resultTableActions <- data.frame(c(
    mean(performanceMeansAction[which(startActions$text == action), "processorTime"]),
    mean(performanceMeansAction[which(startActions$text == action), "ram"]),
    mean(performanceMeansAction[which(startActions$text == action), "hddActivity"]),
    mean(performanceMeansAction[which(startActions$text == action), "networkTraffic"]))
  )
  names(resultTableActions) <- "means"
  resultTableActions <- cbind(resultTableActions,
    c(mean(cpuMeansBaseline), mean(ramMeansBaseline), mean(hddMeansBaseline), mean(nwMeansBaseline)),
    resultTableActions$means - c(mean(cpuMeansBaseline), mean(ramMeansBaseline), mean(hddMeansBaseline), mean(nwMeansBaseline))
  )
  names(resultTableActions) <- c("mean value", "mean value of baseline", "software induced")
  rownames(resultTableActions) <- c("CPU load [%]", "RAM usage [%]", "HDD activity [kB]", "Network traffic [kB]")
  
  print(kable(resultTableActions, caption=paste("Mean measurement results for action \"", action, "\"", sep=""), digits = 3))
  cat("\n")
}
```