summaryrefslogtreecommitdiff
path: root/g5k/logs/analysis.org
diff options
context:
space:
mode:
authorLoic Guegan <manzerberdes@gmx.com>2019-05-17 11:08:57 +0200
committerLoic Guegan <manzerberdes@gmx.com>2019-05-17 11:08:57 +0200
commit7c9410246fc64f2638de7779b11070d95e7756e3 (patch)
tree2cd99dbd0241bcf3209b3bf09b2f27ad64cc6af6 /g5k/logs/analysis.org
parent1ab4a6a97aab850aa496fccc8c26293c57561620 (diff)
Add analysis script
Diffstat (limited to 'g5k/logs/analysis.org')
-rw-r--r--g5k/logs/analysis.org164
1 files changed, 164 insertions, 0 deletions
diff --git a/g5k/logs/analysis.org b/g5k/logs/analysis.org
new file mode 100644
index 0000000..a476cb2
--- /dev/null
+++ b/g5k/logs/analysis.org
@@ -0,0 +1,164 @@
+
+
+
+
+* Logs Analysis
+** R Scripts
+*** Generate all plots script
+ #+BEGIN_SRC R
+ #<<RUtils>>
+
+
+ energy=loadEnergy
+ #+END_SRC
+
+
+*** 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(nbNodes="Number of nodes",sensorsNumber="Number of sensors",totalEnergy="Total Energy (J)",
+ nbHop="Number of hop (AP to Cloud)", linksBandwidth="Links Bandwidth (Mbps)", avgDelay="Average Application Delay (s)",
+ linksLatency="Links Latency (ms)", sensorsSendInterval="Sensors Send Interval (s)", positionSeed="Position Seed",
+ sensorsEnergy="Sensors Wifi Energy Consumption (J)", networkEnergy="Network Energy Consumption (J)")
+
+ # Load Data
+ data=read_csv("logs/data.csv")
+
+ loadData=function(path){
+ data=read_csv(path)
+ data%>%mutate(time=ts-min(ts))
+ }
+
+ # 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
+
+ #+RESULTS:
+
+
+
+** CSVs -> CSV
+
+ #+NAME: mergeCSV
+ #+BEGIN_SRC sh :results output
+ #!/bin/bash
+
+ whichLog="first-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 > $tmpFile
+ tail -n+2 ${csvFile} | awk '{print $0",'$simKey','$vmSize','$nbSensors'"}' >> $tmpFile
+ done
+
+
+ ##### File dataFile #####
+ echo ts,energy,simKey,vmSize,nbSensors > $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:
+
+** 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]]