2021-05-08 21:38:26 +02:00
library ( " tidyverse" )
2021-05-10 10:33:11 +02:00
library ( " knitr" )
2021-05-08 21:38:26 +02:00
2021-05-31 08:16:09 +02:00
data = read_csv ( " results.csv" )
ccgrid = read_csv ( " ccgrid.csv" )
2021-05-08 21:38:26 +02:00
2021-05-12 12:07:00 +02:00
r_ = function ( x ) { round ( x , digits = 2 ) }
2021-05-10 16:03:46 +02:00
finalEnergy = data %>% group_by ( simkey , wireless , wakeupfor ) %>% summarize ( wireless = first ( wireless ) , sd = sd ( energy ) , wakeupfor = first ( wakeupfor ) , energy = mean ( energy ) )
2021-05-14 10:25:51 +02:00
#finalStats=data%>%group_by(simkey,wireless,wakeupfor,seed)%>%
# summarise(success=sum(nSend))%>%
# ungroup()%>%group_by(simkey,wireless,wakeupfor)%>%
# summarise(sd_success=sd(success),success=mean(success))
# Success
finalStats = data %>% filter ( isSender != 0 ) %>% group_by ( simkey , wireless , wakeupfor ) %>% summarise ( sd_success = sd ( nSend ) , success = mean ( nSend ) )
2021-05-11 08:53:11 +02:00
2021-05-20 09:48:32 +02:00
# Hint Added
2021-05-20 14:36:34 +02:00
#hintAdded=data%>%filter(isSender==0)%>%group_by(simkey,wireless,wakeupfor)%>%summarise(hint_added=mean(hint_added))
#finalStats=finalStats%>%left_join(hintAdded,by=c("simkey","wireless","wakeupfor"))
2021-05-20 09:48:32 +02:00
2021-05-11 08:53:11 +02:00
# Sender energy
2021-06-08 09:58:37 +02:00
senderEnergy = data %>% filter ( isSender != 0 ) %>% group_by ( simkey , wireless , wakeupfor ) %>% summarise ( senderEnergy = mean ( energy ) , senderEnergy_sd = sd ( energy ) )
receiverEnergy = data %>% filter ( isSender == 0 ) %>% group_by ( simkey , wireless , wakeupfor ) %>% summarise ( receiverEnergy = mean ( energy ) , receiverEnergy_sd = sd ( energy ) )
2021-05-11 08:53:11 +02:00
finalStats = finalStats %>% left_join ( senderEnergy , by = c ( " simkey" , " wireless" , " wakeupfor" ) )
finalStats = finalStats %>% left_join ( receiverEnergy , by = c ( " simkey" , " wireless" , " wakeupfor" ) )
2021-05-10 10:33:11 +02:00
2021-06-17 10:34:07 +02:00
# J per success
finalStats = finalStats %>% mutate ( senderJPS = senderEnergy / success )
finalStats = finalStats %>% mutate ( receiverJPS = receiverEnergy / success )
2021-05-12 10:05:19 +02:00
# Uptime
senderUptime = data %>% filter ( isSender != 0 ) %>% group_by ( simkey , wireless , wakeupfor ) %>% summarise ( senderUptime = mean ( totalUptime ) )
receiverUptime = data %>% filter ( isSender == 0 ) %>% group_by ( simkey , wireless , wakeupfor ) %>% summarise ( receiverUptime = mean ( totalUptime ) )
finalStats = finalStats %>% left_join ( senderUptime , by = c ( " simkey" , " wireless" , " wakeupfor" ) )
finalStats = finalStats %>% left_join ( receiverUptime , by = c ( " simkey" , " wireless" , " wakeupfor" ) )
2021-06-08 09:58:37 +02:00
# avgTimedataRcv
avgTimeDataRcvData = data %>% filter ( timeDataRcv != -1 ) %>% group_by ( simkey , wireless , wakeupfor ) %>% summarise ( avgTimeDataRcv = mean ( timeDataRcv ) )
finalStats = finalStats %>% left_join ( avgTimeDataRcvData , by = c ( " simkey" , " wireless" , " wakeupfor" ) )
# Uptime Overhead compare to baseline
baseline = finalStats %>% filter ( simkey == " baseline" ) %>% select ( senderUptime , receiverUptime , simkey , wireless , wakeupfor )
keys = unique ( finalStats $ simkey )
baseline = baseline %>% uncount ( length ( keys ) , .id = " id" ) %>% mutate ( simkey = keys [id ] )
finalStats = finalStats %>% left_join ( baseline , by = c ( " simkey" , " wireless" , " wakeupfor" ) , suffix = c ( " " , " _baseline" ) )
finalStats = finalStats %>% mutate ( senderUptimeOverhead = senderUptime - senderUptime_baseline )
finalStats = finalStats %>% mutate ( receiverUptimeOverhead = receiverUptime - receiverUptime_baseline )
# Energy Overhead (percent) compare to baseline
baseline = finalStats %>% filter ( simkey == " baseline" ) %>% select ( senderEnergy , receiverEnergy , simkey , wireless , wakeupfor )
baseline = baseline %>% uncount ( length ( keys ) , .id = " id" ) %>% mutate ( simkey = keys [id ] )
finalStats = finalStats %>% left_join ( baseline , by = c ( " simkey" , " wireless" , " wakeupfor" ) , suffix = c ( " " , " _baseline" ) )
finalStats = finalStats %>% mutate ( senderEnergyOverheadPercent = r_ ( ( senderEnergy - senderEnergy_baseline ) / senderEnergy * 100 ) )
finalStats = finalStats %>% mutate ( receiverEnergyOverheadPercent = r_ ( ( receiverEnergy - receiverEnergy_baseline ) / receiverEnergy * 100 ) )
2021-05-31 08:16:09 +02:00
# Comparison
finalStats = finalStats %>% left_join ( ccgrid , by = c ( " simkey" , " wireless" , " wakeupfor" ) , suffix = c ( " " , " _ccgrid" ) )
finalStats = finalStats %>% mutate ( senderEnergy_err = abs ( r_ ( ( senderEnergy - senderEnergy_ccgrid ) / senderEnergy ) * 100 ) )
finalStats = finalStats %>% mutate ( receiverEnergy_err = abs ( r_ ( ( receiverEnergy - receiverEnergy_ccgrid ) / receiverEnergy ) * 100 ) )
finalStats = finalStats %>% mutate ( senderUptime_err = abs ( r_ ( ( senderUptime - senderUptime_ccgrid ) / senderUptime ) * 100 ) )
finalStats = finalStats %>% mutate ( receiverUptime_err = abs ( r_ ( ( receiverUptime - receiverUptime_ccgrid ) / receiverUptime ) * 100 ) )
2021-05-12 10:05:19 +02:00
2021-05-10 16:03:46 +02:00
# Add nSendFail to stats
sendFail = data %>% filter ( node == " on0" ) %>% group_by ( simkey , wireless , wakeupfor ) %>% summarise ( nSendFail = mean ( nSendFail ) )
finalStats = finalStats %>% left_join ( sendFail , by = c ( " simkey" , " wireless" , " wakeupfor" ) )
2021-06-08 09:58:37 +02:00
# Add nWakeUp to stats
nWakeUpRcv = data %>% filter ( node != " on0" ) %>% group_by ( simkey , wireless , wakeupfor ) %>% summarise ( nWakeUpRcv = mean ( nWakeUp ) )
finalStats = finalStats %>% left_join ( nWakeUpRcv , by = c ( " simkey" , " wireless" , " wakeupfor" ) )
nWakeUpSend = data %>% filter ( node == " on0" ) %>% group_by ( simkey , wireless , wakeupfor ) %>% summarise ( nWakeUpSender = mean ( nWakeUp ) )
finalStats = finalStats %>% left_join ( nWakeUpSend , by = c ( " simkey" , " wireless" , " wakeupfor" ) )
2021-05-31 08:16:09 +02:00
ggplot ( finalStats , aes ( x = simkey , senderEnergy_err , color = wireless , group = wireless ) ) + geom_point ( ) + geom_line ( ) + facet_wrap ( ~ wakeupfor ) + xlab ( " Scenarios" ) + ylab ( " Sender Energy Relative Error (%)" ) + expand_limits ( x = 0 , y = 0 )
ggsave ( " err_sender_energy.png" , width = 7 , height = 5 )
ggplot ( finalStats , aes ( x = simkey , receiverEnergy_err , color = wireless , group = wireless ) ) + geom_point ( ) + geom_line ( ) + facet_wrap ( ~ wakeupfor ) + xlab ( " Scenarios" ) + ylab ( " Receiver Energy Relative Error (%)" ) + expand_limits ( x = 0 , y = 0 )
ggsave ( " err_receiver_energy.png" , width = 7 , height = 5 )
ggplot ( finalStats , aes ( x = simkey , senderUptime_err , color = wireless , group = wireless ) ) + geom_point ( ) + geom_line ( ) + facet_wrap ( ~ wakeupfor ) + xlab ( " Scenarios" ) + ylab ( " Sender AccUptime Energy Relative Error (%)" ) + expand_limits ( x = 0 , y = 0 )
ggsave ( " err_sender_accuptime.png" , width = 7 , height = 5 )
ggplot ( finalStats , aes ( x = simkey , receiverUptime_err , color = wireless , group = wireless ) ) + geom_point ( ) + geom_line ( ) + facet_wrap ( ~ wakeupfor ) + xlab ( " Scenarios" ) + ylab ( " Receiver AccUptime Energy Relative Error (%)" ) + expand_limits ( x = 0 , y = 0 )
ggsave ( " err_rcv_accuptime.png" , width = 7 , height = 5 )
2021-05-10 16:03:46 +02:00
# Generate plots
ggplot ( finalEnergy , aes ( x = simkey , y = energy , fill = wireless ) ) +
2021-05-10 11:35:12 +02:00
geom_bar ( stat = " identity" , position = position_dodge ( ) ) +
2021-05-10 10:33:11 +02:00
xlab ( " Scenarios" ) + ylab ( " Energy (J)" ) +
2021-05-10 11:35:12 +02:00
geom_errorbar ( position = position_dodge ( 0.9 ) , aes ( ymin = energy - sd , ymax = energy + sd ) , width = 0.5 , size = 1.5 , ) +
facet_wrap ( ~ wakeupfor ) +
2021-05-12 12:07:00 +02:00
geom_text ( aes ( label = r_ ( energy + sd ) , y = energy + sd ) , vjust = -0.4 , position = position_dodge ( 0.9 ) ) +
geom_text ( aes ( label = r_ ( energy - sd ) , y = energy - sd ) , vjust = +1.5 , position = position_dodge ( 0.9 ) ) +
geom_text ( aes ( label = r_ ( energy ) , y = energy / 2 ) , fontface = " bold" , colour = " white" , position = position_dodge ( 0.9 ) )
2021-06-08 09:58:37 +02:00
ggsave ( " energy.png" , width = 13 , height = 6 )
2021-05-10 16:03:46 +02:00
ggplot ( finalStats , aes ( x = simkey , y = success , fill = wireless ) ) +
geom_bar ( stat = " identity" , position = position_dodge ( ) ) +
2021-06-08 09:58:37 +02:00
xlab ( " Scenarios" ) + ylab ( " Number of Transmission Success" ) +
2021-05-11 08:53:11 +02:00
geom_errorbar ( position = position_dodge ( 0.9 ) , aes ( ymin = success - sd_success , ymax = success + sd_success ) , width = 0.5 , size = 1.5 , ) +
2021-05-12 12:07:00 +02:00
geom_text ( aes ( label = r_ ( success + sd_success ) , y = success + sd_success ) , vjust = -0.4 , position = position_dodge ( 0.9 ) ) +
geom_text ( aes ( label = r_ ( success - sd_success ) , y = success - sd_success ) , vjust = +1.5 , position = position_dodge ( 0.9 ) ) +
geom_text ( aes ( label = r_ ( success ) , y = success / 2 ) , fontface = " bold" , colour = " white" , position = position_dodge ( 0.9 ) ) +
2021-05-10 16:03:46 +02:00
facet_wrap ( ~ wakeupfor ) +
ggsave ( " success.png" )
2021-05-08 21:38:26 +02:00
2021-06-08 09:58:37 +02:00
ggplot ( finalStats , aes ( x = simkey , y = avgTimeDataRcv , fill = wireless ) ) +
geom_bar ( stat = " identity" , position = position_dodge ( ) ) +
xlab ( " Scenarios" ) + ylab ( " Average Data Received Time" ) +
facet_wrap ( ~ wakeupfor ) +
ggsave ( " avgDataTimeRcv.png" )
ggplot ( finalStats , aes ( x = simkey , y = nWakeUpRcv , fill = wireless ) ) +
geom_bar ( stat = " identity" , position = position_dodge ( ) ) +
xlab ( " Scenarios" ) + ylab ( " Average Number of receiver Wake up" ) +
facet_wrap ( ~ wakeupfor ) +
ggsave ( " nWakeUpRcv.png" )
ggplot ( finalStats , aes ( x = simkey , y = nWakeUpSender , fill = wireless ) ) +
geom_bar ( stat = " identity" , position = position_dodge ( ) ) +
xlab ( " Scenarios" ) + ylab ( " Average Number of sender Wake up" ) +
facet_wrap ( ~ wakeupfor ) +
ggsave ( " nWakeUpSender.png" )
2021-05-31 08:16:09 +02:00
##### Save tables #####
2021-05-10 16:03:46 +02:00
tf = " tables-energy.org"
write ( " " , file = tf )
for ( wake in unique ( data $ wakeupfor ) ) {
write ( kable ( finalEnergy %>% filter ( wireless == " lora" , wakeupfor == wake ) ) , file = tf , append = TRUE )
write ( " \n" , file = tf , append = TRUE )
write ( kable ( finalEnergy %>% filter ( wireless == " nbiot" , wakeupfor == wake ) ) , file = tf , append = TRUE )
write ( " \n" , file = tf , append = TRUE )
}
2021-05-10 11:35:12 +02:00
2021-05-10 16:03:46 +02:00
tf = " tables-stats.org"
2021-05-10 11:35:12 +02:00
write ( " " , file = tf )
2021-05-10 10:33:11 +02:00
for ( wake in unique ( data $ wakeupfor ) ) {
2021-05-10 16:03:46 +02:00
write ( kable ( finalStats %>% filter ( wireless == " lora" , wakeupfor == wake ) ) , file = tf , append = TRUE )
2021-05-10 11:35:12 +02:00
write ( " \n" , file = tf , append = TRUE )
2021-05-10 16:03:46 +02:00
write ( kable ( finalStats %>% filter ( wireless == " nbiot" , wakeupfor == wake ) ) , file = tf , append = TRUE )
2021-05-10 11:35:12 +02:00
write ( " \n" , file = tf , append = TRUE )
2021-05-10 10:33:11 +02:00
}
2021-05-10 11:35:12 +02:00