loosely-coupled-dss-extended/analysis/scalability_datasize.R

135 lines
8 KiB
R

library("tidyverse")
library("ggthemes")
library("gridExtra")
library("patchwork")
library(RColorBrewer)
data=read_csv("../results/scalability_datasize.csv")
r_=function(x){round(x,digits=1)}
color=function(){scale_fill_brewer(palette = "Accent")}
color2=function(){scale_fill_brewer(palette = "Set2")}
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","Nb-IoT"))
}
dsformat=function(data){
data=data%>%mutate(datasize=ifelse(datasize==1000,"1KB",as.character(datasize)))
data=data%>%mutate(datasize=ifelse(datasize==10000,"10KB",as.character(datasize)))
data=data%>%mutate(datasize=ifelse(datasize==100000,"100KB",as.character(datasize)))
data=data%>%mutate(datasize=ifelse(datasize==500000,"500KB",as.character(datasize)))
data=data%>%mutate(datasize=ifelse(datasize==1000000,"1MB",as.character(datasize)))
data=data%>%mutate(datasize=ifelse(datasize==2000000,"2MB",as.character(datasize)))
data=data%>%mutate(datasize=ifelse(datasize==10000000,"10MB",as.character(datasize)))
data=data%>%mutate(datasize=ifelse(datasize==50000000,"50MB",as.character(datasize)))
data=data%>%mutate(datasize=ifelse(datasize==100000000,"100MB",as.character(datasize)))
data=data%>%mutate(datasize=ifelse(datasize==500000000,"500MB",as.character(datasize)))
data=data%>%mutate(datasize=ifelse(datasize==1000000000,"1GB",as.character(datasize)))
data$datasize=factor(data$datasize,levels=c("1KB","10KB","100KB","500KB","1MB","2MB","10MB","50MB","100MB","500MB","1GB"))
return(data)
}
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
}
custom_theme=function(){theme_clean()+ theme(plot.background=element_blank())}
data=data%>%dformat()
# Compute delivery success
statsSuccess=data%>%filter(isSender!=0)%>%group_by(wireless,wakeupfor,datasize,seed,simkey)%>%summarize(success=mean(nSend))%>%ungroup()
data=data%>%left_join(statsSuccess,by=c("wireless","wakeupfor","datasize","seed","simkey"))
# Computer stats senders
statsSender=data%>%filter(isSender!=0)%>%group_by(wireless,wakeupfor,datasize,seed,simkey)%>%summarize(success=mean(success),energy=mean(energy))%>%ungroup()
statsSender=statsSender%>%group_by(wireless,wakeupfor,datasize,simkey)%>%summarize(success_sd=sd(success),success=mean(success),energy_sd=sd(energy),energy=mean(energy))%>%ungroup()
# Computer stats receiver
statsReceiver=data%>%filter(isSender==0)%>%group_by(wireless,wakeupfor,datasize,seed,simkey)%>%summarize(success=mean(success),energy=mean(energy))%>%ungroup()
statsReceiver=statsReceiver%>%group_by(wireless,wakeupfor,datasize,simkey)%>%summarize(success_sd=sd(success),success=mean(success),energy_sd=sd(energy),energy=mean(energy))%>%ungroup()
# Energy
sender60sPlotEnergy=ggplot(statsSender%>%filter(wakeupfor==60)%>%dsformat(),aes(datasize,energy,color=simkey,group=simkey))+
geom_ribbon(aes(ymin=energy-energy_sd, ymax=energy+energy_sd,fill=simkey),linetype=1,alpha=0.4)+
geom_point()+geom_line()+
facet_wrap(~wireless)+xlab("Data size")+ylab("Energy consumption (J)")+labs(colour="Policy")+custom_theme()+theme(legend.position="top")+ggtitle("Sender")+
guides(colour=FALSE,fill=guide_legend(title="Policy"))
sender180sPlotEnergy=ggplot(statsSender%>%filter(wakeupfor==180)%>%dsformat(),aes(datasize,energy,color=simkey,group=simkey))+
geom_ribbon(aes(ymin=energy-energy_sd, ymax=energy+energy_sd,fill=simkey),linetype=1,alpha=0.4)+
geom_point()+geom_line()+
facet_wrap(~wireless)+xlab("Data size")+ylab("Energy consumption (J)")+labs(colour="Policy")+custom_theme()+theme(legend.position="top")+ggtitle("Sender")+
guides(colour=FALSE,fill=guide_legend(title="Policy"))
receiver60sPlotEnergy=ggplot(statsReceiver%>%filter(wakeupfor==60)%>%dsformat(),aes(datasize,energy,color=simkey,group=simkey))+
geom_ribbon(aes(ymin=energy-energy_sd, ymax=energy+energy_sd,,fill=simkey),linetype=1,alpha=0.4)+
geom_point()+geom_line()+
facet_wrap(~wireless)+xlab("Data size")+ylab("Energy consumption (J)")+labs(colour="Policy") + custom_theme()+theme(legend.position="top")+ggtitle("Receiver")+
guides(colour=FALSE,fill=guide_legend(title="Policy"))
receiver180sPlotEnergy=ggplot(statsReceiver%>%filter(wakeupfor==180)%>%dsformat(),aes(datasize,energy,color=simkey,group=simkey))+
geom_ribbon(aes(ymin=energy-energy_sd, ymax=energy+energy_sd,fill=simkey),linetype=1,alpha=0.4)+
geom_point()+geom_line()+
facet_wrap(~wireless)+xlab("Data size")+ylab("Energy consumption (J)")+labs(colour="Policy")+custom_theme()+theme(legend.position="top")+ggtitle("Receiver")+
guides(colour=FALSE,fill=guide_legend(title="Policy"))
# Success
sender60sPlotSuccess=ggplot(statsSender%>%filter(wakeupfor==60)%>%dsformat(),aes(datasize,success,color=simkey,group=simkey))+
geom_ribbon(aes(ymin=success-success_sd, ymax=success+success_sd,fill=simkey),linetype=1,alpha=0.4)+
geom_point()+geom_line()+
facet_wrap(~wireless)+xlab("Data size")+ylab("Number of delivery success")+labs(colour="Policy")+custom_theme()+theme(legend.position="top")+
theme(panel.background = element_rect(fill = '#EFEFEF', color=NA))+guides(colour=FALSE,fill=guide_legend(title="Policy"))
sender180sPlotSuccess=ggplot(statsSender%>%filter(wakeupfor==180)%>%dsformat(),aes(datasize,success,color=simkey,group=simkey))+
geom_ribbon(aes(ymin=success-success_sd, ymax=success+success_sd,fill=simkey),linetype=1,alpha=0.4)+
geom_point()+geom_line()+
facet_wrap(~wireless)+xlab("Data size")+ylab("Number of delivery success")+labs(colour="Policy")+custom_theme()+theme(legend.position="top")+
theme(panel.background = element_rect(fill = '#EFEFEF', color=NA))+guides(colour=FALSE,fill=guide_legend(title="Policy"))
receiver60sPlotSuccess=ggplot(statsReceiver%>%filter(wakeupfor==60)%>%dsformat(),aes(datasize,success,color=simkey,group=simkey))+
geom_ribbon(aes(ymin=success-success_sd, ymax=success+success_sd,fill=simkey),linetype=1,alpha=0.4)+
geom_point()+geom_line()+
facet_wrap(~wireless)+xlab("Data size")+ylab("Number of delivery success")+labs(colour="Policy") + custom_theme()+theme(legend.position="top")+
theme(panel.background = element_rect(fill = '#EFEFEF', color=NA))+guides(colour=FALSE,fill=guide_legend(title="Policy"))
receiver180sPlotSuccess=ggplot(statsReceiver%>%filter(wakeupfor==180)%>%dsformat(),aes(datasize,success,color=simkey,group=simkey))+
geom_ribbon(aes(ymin=success-success_sd, ymax=success+success_sd,fill=simkey),linetype=1,alpha=0.4)+
geom_point()+geom_line()+
facet_wrap(~wireless)+xlab("Data size")+ylab("Number of delivery success")+labs(colour="Policy")+custom_theme()+theme(legend.position="top")+
theme(panel.background = element_rect(fill = '#EFEFEF', color=NA))+guides(colour=FALSE,fill=guide_legend(title="Policy"))
w1=10
h1=4
w2=15
h2=4
ggsave("figures/scalability_datasize_60s_sender_energy.pdf",plot=sender60sPlotEnergy+guides(fill = FALSE, color = FALSE),width=w1,height=h1)
ggsave("figures/scalability_datasize_60s_receiver_energy.pdf",plot=receiver60sPlotEnergy+guides(fill = FALSE, color = FALSE),width=w1,height=h1)
ggsave("figures/scalability_datasize_60s_success.pdf",plot=sender60sPlotSuccess,width=w2,height=h2)
ggsave("figures/scalability_datasize_180s_sender_energy.pdf",plot=sender180sPlotEnergy+guides(fill = FALSE, color = FALSE),width=w1,height=h1)
ggsave("figures/scalability_datasize_180s_receiver_energy.pdf",plot=receiver180sPlotEnergy+guides(fill = FALSE, color = FALSE),width=w1,height=h1)
ggsave("figures/scalability_datasize_180s_success.pdf",plot=sender180sPlotSuccess,width=w2,height=h2)