Questões

Questao 1

MRT_1F <-c(517.1468515630205, 85.13094142168089, 30.333207896694553, 12.694776264558937, 3.3041601673945418, 1.1823111717498882, 1.1892293502386786)

MRT_3F <-c(156.68929936163462, 11.540837783562276, 0.4512835621696538, 0.4509797929766453, 0.4502068233039181, 0.4496185276300172, 0.4543157082191288)

MRT_5F <-c(83.90319666471157, 0.3068151086494968, 0.30522314133037304, 0.3072588968084928, 0.30655265997285697, 0.3055812715727718, 0.3053297166713006)

MRT_10F <-c(29.55430642951759, 0.19832832665772515, 0.1971923924717474, 0.19796648905716516, 0.19615594370806338, 0.2034569237883263, 0.19617420889447737)

MRT_15F <-c(11.317736530583566, 0.167364215666193, 0.16172168266811013, 0.16701085329580515, 0.1598052657153692, 0.1645934043532696, 0.16216563797118075)

MRT_sem_F <-c(11.93430909937736, 0.6095414637034009, 0.6060645101029295, 0.612167181646899, 0.6146761002685637, 0.6096747087200697, 0.6125810476877268)

clock <- c(0.1, 0.5, 1, 1.5, 2, 2.5, 3)
colors <- c("#E6E6E6", "#666666")
plot(clock, MRT_1F, type="o", pch=4, 
     xlab="Time between Things requests (seconds)", 
     ylab="Response time (sec.)", main="Gráfico simples", 
     xlim=c(0,3), ylim=c(0,550))

lines(clock, MRT_3F, type= "o", col="yellow", pch=11)

lines(clock, MRT_5F, type= "o", col="red", pch=1)

lines(clock, MRT_10F, type= "o", col="blue", pch=2)

lines(clock, MRT_15F, type= "o", col="purple", pch=5)

lines(clock, MRT_sem_F, type= "o", col="green", pch=4)

legend("topright", pch=c(4, 11, 1, 2, 5, 4), 
       col=c("black", "yellow", "red", "blue", "purple", "green"), 
       legend=c("1 Fog", "2 Fogs", "3 Fogs",
                "5 Fogs", "10 Fogs", "15 Fogs", "W/o Fog"))

par(mfrow = c(3, 2))

Values<-matrix(c(MRT_sem_F,MRT_1F),nrow= 2,ncol= 7,byrow= TRUE)
names <- c("w/o Fog","1 Fog")

plot1<-barplot(Values,
        names.arg=clock,
        xlab= "Time between Thin requests",
        ylab="Response time (s)",
        col=colors,
        beside= T,
        log="y")

legend("topright",pch=15,col=colors,legend=names)

Values<-matrix(c(MRT_sem_F,MRT_3F),nrow= 2,ncol= 7,byrow= TRUE)
names <- c("w/o Fog","3 Fogs")
plot2<-barplot(Values,
        names.arg=clock,
        xlab= "Time between Thin requests",
        ylab="Response time (s)",
        col=colors,
        beside= T,
        log="y")

legend("topright",pch=15,col=colors,legend=names)

Values<-matrix(c(MRT_sem_F,MRT_5F),nrow= 2,ncol= 7,byrow= TRUE)
names <- c("w/o Fog","5 Fogs")
plot3<-barplot(Values,
        names.arg=clock,
        xlab= "Time between Thin requests",
        ylab="Response time (s)",
        col=colors,
        beside= T,
        log="y")

legend("topright",pch=15,col=colors,legend=names)

Values<-matrix(c(MRT_sem_F,MRT_10F),nrow= 2,ncol= 7,byrow= TRUE)
names <- c("w/o Fog","10 Fogs")
plot4<-barplot(Values,
        names.arg=clock,
        xlab= "Time between Thin requests",
        ylab="Response time (s)",
        col=colors,
        beside= T,
        log="y")

legend("topright",pch=15,col=colors,legend=names)

Values<-matrix(c(MRT_sem_F,MRT_15F),nrow= 2,ncol= 7,byrow= TRUE)
names <- c("w/o Fog","15 Fogs")
plot5<-barplot(Values,
        names.arg=clock,
        xlab= "Time between Thin requests",
        ylab="Response time (s)",
        col=colors,
        beside= T,
        log="y")

legend("topright",pch=15,col=colors,legend=names)

Questao 2

par(mar = c(3, 3, 3, 8), xpd = TRUE)

mealPrice <-c("$10-19", "$20-29", "$30-39", "$40-49")
qualityRating <-c("Good", "Very Good", "Excellent")
good <-c(53.8, 33.9, 2.6, 0)
veryGood <-c(43.6, 54.2, 60.5, 21.4)
excellent <-c(2.6, 11.9, 36.8, 78.6)

Values<-matrix(c(good,veryGood,excellent),nrow= 3,ncol= 4,byrow= TRUE)
colors <- c("yellow","blue", "green")

barplot(Values,
        main="Meal Quality",
        names.arg=mealPrice,
        col = colors)

legend("topright", inset = c(-0.3, 0.1),pch=15,col=colors,legend=qualityRating)

Questao 3

Temperature <- (airquality[airquality$Month==5,4]-32)/1.8

hist(Temperature,col='black',density= 10,freq=F)

densityTemp<-density(Temperature)
lines(densityTemp,col="blue")

Questao 4

sales <- read.table("https://training-course-material.com/images/8/8f/Sales.txt",header=TRUE)

pct<-round(sales$SALES/sum(sales$SALES)*100)
lbls<-paste(sales$COUNTRY,pct)
lbls<-paste(lbls,"%",sep="")

pie(sales$SALES,labels=lbls,
    main="Gráfico de Vendas",
    col=rainbow(6))

legend("topleft",col=rainbow(6),pch=15,legend=sales$COUNTRY)

Questao 5

boxplot(InsectSprays$count ~ InsectSprays$spray,
        outline=FALSE,
        main= "Insect Sprays",
        xlab= "Spray type",
        ylab="Spray count",
        col="yellow")

Questao 6

noneWorkload <- read.csv(file = "monitoringCloudData_NONE.csv",
                       header = T,
                       na.strings = "",
                       sep = "," )

data_0.1 <- read.csv(file = "monitoringCloudData_0.1.csv",
                         header = T,
                         na.strings = "",
                         sep = "," )

data_0.5 <- read.csv(file = "monitoringCloudData_0.5.csv",
                     header = T,
                     na.strings = "",
                     sep = "," )

data_1 <- read.csv(file = "monitoringCloudData_1.csv",
                     header = T,
                     na.strings = "",
                     sep = "," )

par(mfrow = c(2, 2))

df <- noneWorkload


x <- difftime(df$currentTime,
              df$currentTime[1],
              units = "hours")

df$usedMemory[grep(pattern = "MB$", df$usedMemory)] <-
  gsub("MB","",grep(pattern = "MB$", df$usedMemory, value= TRUE))

y <- as.numeric(df$usedMemory)

plot(x, y, type="l",
     main="Memory Analysis",
     xlab="Time (hour)",
     ylab="Used Memory (MB)" 
     )

df <- data_0.1

x <- difftime(df$currentTime,
              df$currentTime[1],
              units = "hours")

df$usedMemory[grep(pattern = "GB$", df$usedMemory)] <- 
  as.character(as.numeric(gsub("GB","",grep(pattern = "GB$", df$usedMemory, value= TRUE))) * 1024)

df$usedMemory[grep(pattern = "MB$", df$usedMemory)] <-
  gsub("MB","",grep(pattern = "MB$", df$usedMemory, value= TRUE))

y <- as.numeric(df$usedMemory)

plot(x, y, type="l",
     main="Memory Analysis",
     xlab="Time (hour)",
     ylab="Used Memory (MB)"
     )

df <- data_0.5

x <- difftime(as.Date(df$currentTime),
              as.Date(df$currentTime[1]),
              units = "hours")

df$usedMemory[grep(pattern = "GB$", df$usedMemory)] <- 
  as.character(as.numeric(gsub("GB","",grep(pattern = "GB$", df$usedMemory, value= TRUE))) * 1024)

df$usedMemory[grep(pattern = "MB$", df$usedMemory)] <-
  gsub("MB","",grep(pattern = "MB$", df$usedMemory, value= TRUE))

y <- as.numeric(df$usedMemory)

plot(x, y, type="l",
     main="Memory Analysis",
     xlab="Time (hour)",
     ylab="Used Memory (MB)" 
     )

df <- data_1

x <- difftime(df$currentTime,
              df$currentTime[1],
              units = "hours")

df$usedMemory[grep(pattern = "MB$", df$usedMemory)] <-
  gsub("MB","",grep(pattern = "MB$", df$usedMemory, value= TRUE))

y <- as.numeric(df$usedMemory)

plot(x, y, type="l",
     main="Memory Analysis",
     xlab="Time (hour)",
     ylab="Used Memory (MB)", 
     )

Questao 7

library(dplyr)
## Warning: package 'dplyr' was built under R version 4.3.1
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(plotly)
## Warning: package 'plotly' was built under R version 4.3.1
## Carregando pacotes exigidos: ggplot2
## Warning: package 'ggplot2' was built under R version 4.3.1
## 
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
## 
##     last_plot
## The following object is masked from 'package:stats':
## 
##     filter
## The following object is masked from 'package:graphics':
## 
##     layout
netflix_titles <- read.csv(file = "netflix_titles.csv",
                         header = T,
                         na.strings = "",
                         sep = "," )

filtro <- netflix_titles[grep(pattern = ",", netflix_titles$country,invert = TRUE),]
filtro$country<-as.factor(filtro$country)
df <- data.frame(filtro$country)

df <- df %>%
  filter(complete.cases(.))
55555555555555555555555555555555555555555
## [1] 5.555556e+40
resultado <- df %>%
  group_by(filtro.country) %>%
  summarise(Ocorrencias = n()) %>%
  arrange(desc(Ocorrencias)) %>%
  slice_head(n = 10)

# Crie um gráfico de pizza com o pacote plotly
plot_ly(data = resultado, labels = ~filtro.country, values = ~Ocorrencias, type = "pie")

Questao 8

plot_ly(
  type = "table",
  header = list(
    values = c("País", "Total de conteúdos"),
    align = c("center", "center"),
    fill = list(color = "#666666"),
    font = list(color = "white")
  ),
  cells = list(
    values = rbind(resultado$filtro.country,resultado$Ocorrencias),
    align = c("center", "center"),
    fill = list(color = "#666666"),
    font = list(color = "white")
  )
)