diff --git a/results/180sec.pdf b/results/180sec.pdf index 38aabdc..2cf3a79 100644 Binary files a/results/180sec.pdf and b/results/180sec.pdf differ diff --git a/results/60sec.pdf b/results/60sec.pdf index 3308a18..f8bfdb3 100644 Binary files a/results/60sec.pdf and b/results/60sec.pdf differ diff --git a/results/analysis2.R b/results/analysis2.R index 6fa7219..4af75ed 100644 --- a/results/analysis2.R +++ b/results/analysis2.R @@ -1,35 +1,64 @@ library("tidyverse") library("gridExtra") +library("patchwork") +library(RColorBrewer) data=read_csv("results.csv") r_=function(x){round(x,digits=1)} color=function(){scale_fill_manual(values = c("#00AFBB", "#E7B800", "#FC4E07"))} +color2=function(){scale_fill_brewer(palette = "Dark2")} +nolegend=function(){theme(legend.position="none")} simkeys=unique(data$simkey) nsimkeys=length(simkeys) s_=function(x){if(x<0){return("")}else{return("+")}} +simkey_rename=function(key){ + if(key=="hint") + return("Hints") + if(key=="baseline") + return("Baseline") + if(key=="extended") + return("Extended") + if(key=="hintandextended") + return("Hints+Extended") + return(key) +} +dformat=function(data){ + data%>%rowwise()%>%mutate(simkey=simkey_rename(simkey))%>%mutate(wireless=ifelse(wireless=="lora","LoRa","NbIoT")) +} +g_legend <- function(a.gplot){ + tmp <- ggplot_gtable(ggplot_build(a.gplot)) + leg <- which(sapply(tmp$grobs, function(x) x$name) == "guide-box") + legend <- tmp$grobs[[leg]] + legend +} energy60=data%>%filter(wakeupfor==60) energy60Snd=energy60%>%filter(isSender==1)%>%group_by(simkey,wireless)%>%summarise(sd=sd(energy),energy=mean(energy),type="Sender") energy60Rcv=energy60%>%filter(isSender==0)%>%group_by(simkey,wireless)%>%summarise(sd=sd(energy),energy=mean(energy),type="Receiver") -energy60=energy60Snd%>%ungroup()%>%rbind(energy60Rcv)%>%mutate(type=factor(type,levels = c("Sender","Receiver"))) +energy60=energy60Snd%>%ungroup()%>%rbind(energy60Rcv) energy60=energy60%>%mutate(sd_min=energy-sd,sd_max=energy+sd)%>%mutate(sd_min_txt=paste0("-",r_(sd_min)))%>%mutate(sd_max_txt=paste0("+",r_(sd_max))) energy60Baseline=energy60%>%filter(simkey=="baseline")%>%uncount(nsimkeys,.id="id")%>%mutate(simkey=simkeys[id]) energy60=energy60%>%left_join(energy60Baseline,by=c("simkey","wireless","type"),suffix = c("","_baseline")) energy60=energy60%>%mutate(ovhd=energy*100/energy_baseline-100) energy60=energy60%>%rowwise()%>%mutate(ovhd_txt=paste0("(",s_(ovhd),r_(ovhd),"%)")) -success60=data%>%filter(wakeupfor==60)%>%filter(isSender!=0)%>%group_by(simkey,wireless,wakeupfor)%>%summarise(success=r_(mean(nSend)),type="Sender") +success60Snd=data%>%filter(wakeupfor==60)%>%filter(isSender!=0)%>%group_by(simkey,wireless,wakeupfor)%>%summarise(success_orig=mean(nSend),success=r_(mean(nSend)),type="Sender") +success60Rcv=data%>%filter(wakeupfor==60)%>%filter(isSender!=0)%>%group_by(simkey,wireless,wakeupfor)%>%summarise(success_orig=mean(nSend),success=r_(mean(nSend)),type="Receiver") +success60=rbind(success60Snd,success60Rcv) success60=success60%>%rowwise()%>%mutate(success_txt=paste0("[",success,"]")) +energy60=energy60%>%left_join(success60)%>%rowwise()%>%mutate(infos=paste0(ovhd_txt,"\n{",r_(energy/success_orig),"}")) +energy60=energy60%>%mutate(type=factor(type,levels = c("Sender","Receiver"))) -energy60P=ggplot(energy60,aes(x=simkey,y=energy,fill=type))+ + +energy60P=ggplot(energy60%>%dformat,aes(x=simkey,y=energy,fill=type))+ geom_bar(colour="black", stat="identity",position=position_dodge())+ geom_errorbar(position=position_dodge(0.9),aes(ymin=energy-sd, ymax=energy+sd),width=0.3,size=1)+ geom_text(aes(label = r_(sd_max), y= sd_max),vjust=-0.4,position=position_dodge(0.9))+ geom_text(aes(label = r_(sd_min), y= sd_min),vjust=+1.5,position=position_dodge(0.9))+ - geom_text(aes(label = paste0(r_(energy),"\n",ovhd_txt), y= min(energy)/2),fontface="bold",colour="white",position=position_dodge(0.9))+ - geom_label(data=success60,aes(label = success_txt, y=80),label.padding=unit(0.3,"lines"),label.r=unit(0.09,"lines"),fill="white",label.size=0,fontface="bold",colour="black",position=position_dodge(0.9))+ + geom_text(aes(label = paste0(r_(energy),"\n",infos), y= min(energy)/2),fontface="bold",colour="white",position=position_dodge(0.9))+ + geom_label(data=success60%>%dformat(),aes(label = success_txt, y=35),label.padding=unit(0.35,"lines"),label.r=unit(0.09,"lines"),fill="#f0f0f0",label.size=0.5,fontface="bold",colour="black",position=position_dodge(0.9))+ facet_wrap(~wireless)+ - xlab("Policy")+ylab("Energy Consumption (J)")+ - labs(fill="Node type")+theme(legend.position="top")+color()+coord_cartesian(ylim=c(0,1200)) + xlab(element_blank())+ylab("Energy consumption (J)")+ + labs(fill="Energy:")+theme(legend.position="top")+color()+coord_cartesian(ylim=c(0,1200)) #ggsave("energy-60sec.png",width = 12,height=4.8) energy180=data%>%filter(wakeupfor==180) @@ -41,20 +70,23 @@ energy180Baseline=energy180%>%filter(simkey=="baseline")%>%uncount(nsimkeys,.id= energy180=energy180%>%left_join(energy180Baseline,by=c("simkey","wireless","type"),suffix = c("","_baseline")) energy180=energy180%>%mutate(ovhd=energy*100/energy_baseline-100) energy180=energy180%>%rowwise()%>%mutate(ovhd_txt=paste0("(",s_(ovhd),r_(ovhd),"%)")) -success180=data%>%filter(wakeupfor==180)%>%filter(isSender!=0)%>%group_by(simkey,wireless,wakeupfor)%>%summarise(success=r_(mean(nSend)),type="Sender") +success180Snd=data%>%filter(wakeupfor==180)%>%filter(isSender!=0)%>%group_by(simkey,wireless,wakeupfor)%>%summarise(success_orig=mean(nSend),success=r_(mean(nSend)),type="Sender") +success180Rcv=data%>%filter(wakeupfor==180)%>%filter(isSender!=0)%>%group_by(simkey,wireless,wakeupfor)%>%summarise(success_orig=mean(nSend),success=r_(mean(nSend)),type="Receiver") +success180=rbind(success180Snd,success180Rcv) success180=success180%>%rowwise()%>%mutate(success_txt=paste0("[",success,"]")) +energy180=energy180%>%left_join(success180)%>%rowwise()%>%mutate(infos=paste0(ovhd_txt,"\n{",r_(energy/success_orig),"}")) +energy180=energy180%>%mutate(type=factor(type,levels = c("Sender","Receiver"))) - -energy180P=ggplot(energy180,aes(x=simkey,y=energy,fill=type))+ +energy180P=ggplot(energy180%>%dformat,aes(x=simkey,y=energy,fill=type))+ geom_bar(colour="black",stat="identity",position=position_dodge())+ geom_errorbar(position=position_dodge(0.9),aes(ymin=energy-sd, ymax=energy+sd),width=0.3,size=1)+ geom_text(aes(label = r_(sd_max), y= sd_max),vjust=-0.4,position=position_dodge(0.9))+ geom_text(aes(label = r_(sd_min), y= sd_min),vjust=+1.5,position=position_dodge(0.9))+ - geom_text(aes(label = paste0(r_(energy),"\n",ovhd_txt), y= min(energy)/2),fontface="bold",colour="white",position=position_dodge(0.9))+ - geom_label(data=success180,aes(label = success_txt, y=210),label.padding=unit(0.3,"lines"),label.r=unit(0.09,"lines"),fill="white",label.size=0,fontface="bold",colour="black",position=position_dodge(0.9))+ + geom_text(aes(label = paste0(r_(energy),"\n",infos), y= min(energy)/2),fontface="bold",colour="white",position=position_dodge(0.9))+ + geom_label(data=success180%>%dformat(),aes(label = success_txt, y=100),label.padding=unit(0.35,"lines"),label.r=unit(0.09,"lines"),fill="#f0f0f0",label.size=0.5,fontface="bold",colour="black",position=position_dodge(0.9))+ facet_wrap(~wireless)+ - xlab("Policy")+ylab("Energy Consumption (J)")+ - labs(fill="Node type")+theme(legend.position="top")+color()+coord_cartesian(ylim=c(0,2600)) + xlab(element_blank())+ylab("Energy consumption (J)")+ + labs(fill="Energy:")+theme(legend.position="top")+color()+coord_cartesian(ylim=c(0,2600)) #ggsave("energy-180sec.png",width = 12,height=4.8) totalUptime60=data%>%filter(wakeupfor==60) @@ -66,17 +98,17 @@ totalUptime60Baseline=totalUptime60%>%filter(simkey=="baseline")%>%uncount(nsimk totalUptime60=totalUptime60%>%left_join(totalUptime60Baseline,by=c("simkey","wireless","type"),suffix = c("","_baseline")) totalUptime60=totalUptime60%>%mutate(ovhd=totalUptime-totalUptime_baseline) totalUptime60=totalUptime60%>%rowwise()%>%mutate(ovhd_txt=paste0("(",s_(ovhd),r_(ovhd),")")) +totalUptime60=totalUptime60%>%mutate(type=factor(type,levels = c("Sender","Receiver"))) - -totalUptime60P=ggplot(totalUptime60,aes(x=simkey,y=totalUptime,fill=type))+ - geom_bar(colour="black", linetype="dashed", stat="identity",position=position_dodge())+ +totalUptime60P=ggplot(totalUptime60%>%dformat,aes(x=simkey,y=totalUptime,fill=type))+ + geom_bar(colour="black", stat="identity",position=position_dodge())+ geom_errorbar(position=position_dodge(0.9),aes(ymin=totalUptime-sd, ymax=totalUptime+sd),width=0.3,size=1)+ geom_text(aes(label = r_(sd_max), y= sd_max),vjust=-0.4,position=position_dodge(0.9))+ geom_text(aes(label = r_(sd_min), y= sd_min),vjust=+1.5,position=position_dodge(0.9))+ geom_text(aes(label = paste0(r_(totalUptime),"\n",ovhd_txt), y= min(totalUptime)/2),fontface="bold",colour="white",position=position_dodge(0.9))+ facet_wrap(~wireless)+ - xlab("Policy")+ylab("Accumulated Uptime Consumption (s)")+ - labs(fill="Node type")+theme(legend.position="none")+color()+coord_cartesian(ylim=c(0,2500)) + xlab("Policy")+ylab("Accumulated uptime (s)")+ + labs(fill="Total uptime:")+color2()+theme(legend.position="top")+coord_cartesian(ylim=c(0,2500)) totalUptime180=data%>%filter(wakeupfor==180) totalUptime180Snd=totalUptime180%>%filter(isSender==1)%>%group_by(simkey,wireless)%>%summarise(sd=sd(totalUptime),totalUptime=mean(totalUptime),type="Sender") @@ -87,24 +119,23 @@ totalUptime180Baseline=totalUptime180%>%filter(simkey=="baseline")%>%uncount(nsi totalUptime180=totalUptime180%>%left_join(totalUptime180Baseline,by=c("simkey","wireless","type"),suffix = c("","_baseline")) totalUptime180=totalUptime180%>%mutate(ovhd=totalUptime-totalUptime_baseline) totalUptime180=totalUptime180%>%rowwise()%>%mutate(ovhd_txt=paste0("(",s_(ovhd),r_(ovhd),")")) +totalUptime180=totalUptime180%>%mutate(type=factor(type,levels = c("Sender","Receiver"))) -totalUptime180P=ggplot(totalUptime180,aes(x=simkey,y=totalUptime,fill=type))+ - geom_bar(colour="black", linetype="dashed",stat="identity",position=position_dodge())+ +totalUptime180P=ggplot(totalUptime180%>%dformat,aes(x=simkey,y=totalUptime,fill=type))+ + geom_bar(colour="black",stat="identity",position=position_dodge())+ geom_errorbar(position=position_dodge(0.9),aes(ymin=totalUptime-sd, ymax=totalUptime+sd),width=0.3,size=1)+ geom_text(aes(label = r_(sd_max), y= sd_max),vjust=-0.4,position=position_dodge(0.9))+ geom_text(aes(label = r_(sd_min), y= sd_min),vjust=+1.5,position=position_dodge(0.9))+ geom_text(aes(label = paste0(r_(totalUptime),"\n",ovhd_txt), y= min(totalUptime)/2),fontface="bold",colour="white",position=position_dodge(0.9))+ facet_wrap(~wireless)+ - xlab("Policy")+ylab("Accumulated Uptime Consumption (s)")+ - labs(fill="Node type")+theme(legend.position="none")+color()+coord_cartesian(ylim=c(0,5600)) - - + xlab("Policy")+ylab("Accumulated uptime (s)")+ + labs(fill="Total uptime:")+theme(legend.position="top")+color2()+coord_cartesian(ylim=c(0,5600)) success60=data%>%filter(wakeupfor==60) success60=success60%>%filter(isSender==1)%>%group_by(simkey,wireless)%>%summarise(sd=sd(nSend),success=mean(nSend)) success60=success60%>%mutate(sd_min=success-sd,sd_max=success+sd) -success60P=ggplot(success60,aes(x=simkey,y=success))+ +success60P=ggplot(success60%>%dformat,aes(x=simkey,y=success))+ geom_bar(stat="identity",position=position_dodge(),fill="gray50")+ geom_errorbar(position=position_dodge(0.9),aes(ymin=success-sd, ymax=success+sd),width=0.2,size=1)+ geom_text(aes(label = r_(sd_max), y= sd_max),vjust=-0.4,position=position_dodge(0.9))+ @@ -119,7 +150,7 @@ success180=data%>%filter(wakeupfor==180) success180=success180%>%filter(isSender==1)%>%group_by(simkey,wireless)%>%summarise(sd=sd(nSend),success=mean(nSend)) success180=success180%>%mutate(sd_min=success-sd,sd_max=success+sd) -success180P=ggplot(success180,aes(x=simkey,y=success))+ +success180P=ggplot(success180%>%dformat,aes(x=simkey,y=success))+ geom_bar(stat="identity",position=position_dodge(),fill="gray50")+ geom_errorbar(position=position_dodge(0.9),aes(ymin=success-sd, ymax=success+sd),width=0.2,size=1)+ geom_text(aes(label = r_(sd_max), y= sd_max),vjust=-0.4,position=position_dodge(0.9))+ @@ -130,9 +161,7 @@ success180P=ggplot(success180,aes(x=simkey,y=success))+ labs(fill="Node type")+theme(legend.position="none")+color()+coord_cartesian(ylim=c(0,13)) #ggsave("success-180sec.png",width = 5.8,height=4.2) -sec60P=grid.arrange(energy60P,totalUptime60P,heights=c(1.3,1),widths=1,ncol=1) -ggsave("60sec.pdf",plot=sec60P,width=12,height=7) -sec180P=grid.arrange(energy180P,totalUptime180P,heights=c(1,1),widths=1,ncol=1) -ggsave("180sec.pdf",plot=sec180P,width=12,height=7) +ggsave("60sec.pdf",plot=(energy60P)/(totalUptime60P)+ plot_layout(guides = "collect")&theme(legend.position = "top"),width=12,height=7) +ggsave("180sec.pdf",plot=(energy180P)/(totalUptime180P)+ plot_layout(guides = "collect")&theme(legend.position = "top"),width=12,height=7)