1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
|
* Logs Analysis
** R Scripts
*** Generate all plots script
#+BEGIN_SRC R :results graphics :file second-try/plot.png :noweb yes
<<RUtils>>
data=loadData("./second-try/data.csv")
data=data%>%filter(simKey=="nbSensors")%>%filter(nbSensors==20)
ggplot(data,aes(x=time,y=energy))+geom_point(position="jitter")+xlab(getLabel("time"))+expand_limits(y=0)#+geom_hline(aes(group=nbSensors,color=nbSensors,yintercept=mean(energy)))
ggsave("./second-try/plot.png",dpi=80)
#+END_SRC
#+RESULTS:
[[file:second-try/plot.png]]
*** R Utils
RUtils is intended to load logs (data.csv) and providing
simple plot function for them.
#+NAME: RUtils
#+BEGIN_SRC R :eval never
library("tidyverse")
# Fell free to update the following
labels=c(time="Time (s)")
loadData=function(path){
data=read_csv(path)
}
# Get label according to varName
getLabel=function(varName){
if(is.na(labels[varName])){
return(varName)
}
return(labels[varName])
}
#+END_SRC
** Plots -> PDF
Merge all plots in plots/ folder into a pdf file.
#+NAME: plotToPDF
#+BEGIN_SRC bash :results output :noweb yes
orgFile="plots/plots.org"
<<singleRun>> # To get all default arguments
# Write helper function
function write {
echo "$1" >> $orgFile
}
echo "#+TITLE: Analysis" > $orgFile
write "#+LATEX_HEADER: \usepackage{fullpage}"
write "#+OPTIONS: toc:nil"
# Default arguments
write '\begin{center}'
write '\begin{tabular}{lr}'
write 'Parameters & Values\\'
write '\hline'
write "sensorsPktSize & ${sensorsPktSize} bytes\\\\"
write "sensorsSendInterval & ${sensorsSendInterval}s\\\\"
write "sensorsNumber & ${sensorsNumber}\\\\"
write "nbHop & ${nbHop}\\\\"
write "linksBandwidth & ${linksBandwidth}Mbps\\\\"
write "linksLatency & ${linksLatency}ms\\\\"
write '\end{tabular}'
write '\newline'
write '\end{center}'
for plot in $(find plots/ -type f -name "*.png")
do
write "\includegraphics[width=0.5\linewidth]{$(basename ${plot})}"
done
# Export to pdf
emacs $orgFile --batch -f org-latex-export-to-pdf --kill
#+END_SRC
** CSVs -> CSV
Merge all energy file into one (and add additional fields).
#+NAME: mergeCSV
#+BEGIN_SRC sh
#!/bin/bash
whichLog="second-try"
logFile="$(dirname $(readlink -f $0))"/$whichLog/simLogs.txt
dataFile=$(dirname "$logFile")/data.csv
getValue () {
line=$(echo "$1" | grep "Simulation para"|sed "s/Simulation parameters: //g")
key=$2
echo "$line"|awk 'BEGIN{RS=" ";FS=":"}"'$key'"==$1{gsub("\n","",$0);print $2}'
}
##### Add extract info to energy #####
IFS=$'\n'
for cmd in $(cat $logFile|grep "Simulation parameters")
do
nodeName=$(getValue $cmd serverNodeName)
from=$(getValue $cmd simStart)
to=$(getValue $cmd simEnd)
vmSize=$(getValue $cmd vmSize)
nbSensors=$(getValue $cmd nbSensors)
simKey=$(getValue $cmd simKey)
csvFile="$whichLog/${simKey}_${vmSize}VMSIZE_${nbSensors}NBSENSORS_${from}${to}.csv"
tmpFile=${csvFile}_tmp
echo ts,energy,simKey,vmSize,nbSensors,time > $tmpFile
minEnergy=$(tail -n+2 $csvFile|awk -F"," 'BEGIN{min=0}$1<min||min==0{min=$1}END{print(min)}') # To compute ts field
tail -n+2 ${csvFile} | awk -F"," '{print $0",'$simKey','$vmSize','$nbSensors',"$1-'$minEnergy'}' >> $tmpFile
done
##### File dataFile #####
echo ts,energy,simKey,vmSize,nbSensors,time > $dataFile
for tmpFile in $(find ${whichLog}/*_tmp -type f)
do
tail -n+2 $tmpFile >> $dataFile
rm $tmpFile # Pay attention to this line :D
done
#+END_SRC
#+RESULTS: mergeCSV
** Custom Plots
#+NAME: ssiNet
#+BEGIN_SRC R :noweb yes :results graphics :file plots/sensorsSendInterval-net.png
<<RUtils>>
data%>%filter(simKey=="SENDINTERVAL",sensorsNumber==20) %>% ggplot(aes(x=sensorsSendInterval,y=networkEnergy))+xlab(getLabel("sensorsSendInterval"))+ylab(getLabel("networkEnergy"))+
geom_line()+labs(title="For 20 sensors")
ggsave("plots/sensorsSendInterval-net.png",dpi=80)
#+END_SRC
#+RESULTS:
[[file:plots/sensorsSendInterval-net.png]]
#+NAME: ssiWifi
#+BEGIN_SRC R :noweb yes :results graphics :file plots/sensorsSendInterval-wifi.png
<<RUtils>>
data%>%filter(simKey=="SENDINTERVAL",sensorsNumber==20) %>% ggplot(aes(x=sensorsSendInterval,y=sensorsEnergy))+xlab(getLabel("sensorsSendInterval"))+ylab(getLabel("sensorsEnergy"))+
geom_line() + geom_line()+labs(title="For 20 sensors")
ggsave("plots/sensorsSendInterval-wifi.png",dpi=80)
#+END_SRC
#+RESULTS: ssiWifi
[[file:plots/sensorsSendInterval-wifi.png]]
#+RESULTS:
[[file:plots/sensorsSendInterval.png]]
|