Questões
Questão 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)
layout(matrix(c(1, 1,
2, 3,
4, 5,
6, 0),
nrow = 4, byrow = TRUE))
par(mar = c(4, 4, 3, 1))
plot(clock, MRT_1F, type = "o", pch = 16, col = "gray30",
ylim = c(0, max(MRT_1F)),
xlab = "Time between Things requests (seconds)",
ylab = "Response Time (secs)",
main = "Response Time by Workload")
lines(clock, MRT_3F, type = "o", pch = 16, col = "yellow")
lines(clock, MRT_5F, type = "o", pch = 16, col = "pink")
lines(clock, MRT_10F, type = "o", pch = 16, col = "blue")
lines(clock, MRT_15F, type = "o", pch = 16, col = "green")
lines(clock, MRT_sem_F, type = "o", pch = 16, col = "purple")
legend("topright",
legend = c("1 Fog", "3 Fogs", "5 Fogs", "10 Fogs", "15 Fogs", "w/o Fog"),
col = c("gray30", "yellow", "pink", "blue", "green", "purple"),
pch = 16,
lty = 1,
cex = 0.7)
grafico_barras <- function(com_fog, titulo) {
dados <- rbind(MRT_sem_F, com_fog)
barplot(dados,
beside = TRUE,
log = "y",
col = c("#E6E6E6", "#666666"),
names.arg = clock,
xlab = "Time between Things requests",
ylab = "Response Time (s)",
main = titulo,
cex.names = 0.7)
legend("topright",
legend = c("w/o Fog", titulo),
fill = c("#E6E6E6", "#666666"),
cex = 0.6)
}
grafico_barras(MRT_1F, "1 Fog")
grafico_barras(MRT_3F, "3 Fogs")
grafico_barras(MRT_5F, "5 Fogs")
grafico_barras(MRT_10F, "10 Fogs")
grafico_barras(MRT_15F, "15 Fogs")

Questão 2
precos <- c("$10-19", "$20-29", "$30-39", "$40-49")
qualidade <- matrix(c(
53.8, 33.9, 2.6, 0.0,
43.6, 54.2, 60.5, 21.4,
2.6, 11.9, 36.8, 78.6
),
nrow = 3,
byrow = TRUE)
rownames(qualidade) <- c("Good", "Very Good", "Excellent")
colnames(qualidade) <- precos
barplot(qualidade,
col = c("lightblue", "lightgreen", "orange"),
main = "Qualidade da refeição por faixa de preço",
xlab = "Preço da refeição",
ylab = "Porcentagem (%)",
legend.text = rownames(qualidade),
args.legend = list(x = "topright", cex = 0.8),
ylim = c(0, 100))

Questão 3
dados_maio <- subset(airquality, Month == 5)
temperatura_celsius <- (dados_maio$Temp - 32) / 1.8
hist(temperatura_celsius,
probability = TRUE,
col = "lightblue",
border = "white",
main = "Histograma das temperaturas de maio",
xlab = "Temperatura em Celsius",
ylab = "Densidade")
lines(density(temperatura_celsius),
col = "red",
lwd = 2)

Questão 4
sales <- read.table(
"https://training-course-material.com/images/8/8f/Sales.txt",
header = TRUE
)
pais <- sales[[1]]
vendas <- sales[[2]]
total_por_pais <- tapply(vendas, pais, sum)
porcentagens <- round(100 * total_por_pais / sum(total_por_pais), 1)
rotulos <- paste(names(total_por_pais), porcentagens, "%")
cores <- rainbow(length(total_por_pais))
pie(total_por_pais,
labels = rotulos,
col = cores,
main = "Porcentagem do total de vendas por país")
legend("topright",
legend = names(total_por_pais),
fill = cores,
cex = 0.8)

Questão 5
boxplot(count ~ spray,
data = InsectSprays,
outline = FALSE,
col = "yellow",
main = "Contagem de insetos por tipo de inseticida",
xlab = "Tipo de inseticida",
ylab = "Contagem de insetos")

Questão 6
converter_memoria_mb <- function(x) {
x <- trimws(as.character(x))
valor <- as.numeric(gsub("[^0-9.]", "", x))
unidade <- gsub("[0-9.]", "", x)
unidade <- trimws(unidade)
memoria_mb <- ifelse(unidade == "TB", valor * 1000000,
ifelse(unidade == "GB", valor * 1024,
ifelse(unidade == "MB", valor,
ifelse(unidade == "KB", valor / 1024,
ifelse(unidade == "B", valor / (1024^2), NA)))))
return(memoria_mb)
}
preparar_dados <- function(nome_arquivo) {
caminho <- arquivo(nome_arquivo)
dados <- read.csv(caminho, stringsAsFactors = FALSE)
dados$currentTime <- as.POSIXct(dados$currentTime,
format = "%Y-%m-%d %H:%M:%OS")
if (all(is.na(dados$currentTime))) {
dados$currentTime <- as.POSIXct(dados$currentTime)
}
dados$tempo_horas <- as.numeric(
difftime(dados$currentTime, min(dados$currentTime, na.rm = TRUE), units = "hours")
)
dados$usedMemory_MB <- converter_memoria_mb(dados$usedMemory)
return(dados)
}
dados_none <- preparar_dados("monitoringCloudData_NONE.csv")
dados_01 <- preparar_dados("monitoringCloudData_0.1.csv")
dados_05 <- preparar_dados("monitoringCloudData_0.5.csv")
dados_1 <- preparar_dados("monitoringCloudData_1.csv")
layout(matrix(c(1, 2, 3, 4), nrow = 2, byrow = TRUE))
par(mar = c(4, 4, 3, 1))
plot(dados_none$tempo_horas, dados_none$usedMemory_MB,
type = "l",
main = "Memory Analysis (None Workload)",
xlab = "Time (hour)",
ylab = "Used Memory (MB)")
plot(dados_01$tempo_horas, dados_01$usedMemory_MB,
type = "l",
main = "Memory Analysis (Workload of 0.1)",
xlab = "Time (hour)",
ylab = "Used Memory (MB)")
plot(dados_05$tempo_horas, dados_05$usedMemory_MB,
type = "l",
main = "Memory Analysis (Workload of 0.5)",
xlab = "Time (hour)",
ylab = "Used Memory (MB)")
plot(dados_1$tempo_horas, dados_1$usedMemory_MB,
type = "l",
main = "Memory Analysis (Workload of 1.0)",
xlab = "Time (hour)",
ylab = "Used Memory (MB)")

Questão 7
netflix <- read.csv(arquivo("netflix_titles.csv"), stringsAsFactors = FALSE)
netflix_um_pais <- netflix %>%
filter(!is.na(country),
country != "",
!str_detect(country, ","))
top10_paises <- netflix_um_pais %>%
count(country, name = "total") %>%
arrange(desc(total)) %>%
slice_head(n = 10)
plot_ly(top10_paises,
labels = ~country,
values = ~total,
type = "pie") %>%
layout(title = "Top 10 países com mais conteúdos na Netflix")
Questão 8
tabela_paises <- top10_paises %>%
rename(
País = country,
`Total de conteúdos` = total
)
plot_ly(
type = "table",
header = list(
values = names(tabela_paises),
fill = list(color = "gray"),
font = list(color = "white"),
align = "center"
),
cells = list(
values = list(tabela_paises$País, tabela_paises$`Total de conteúdos`),
align = "center"
)
)
Questão 9
netflix_decadas <- netflix %>%
mutate(decada = floor(release_year / 10) * 10) %>%
group_by(decada, type) %>%
summarise(total = n(), .groups = "drop")
series <- netflix_decadas %>%
filter(type == "TV Show")
filmes <- netflix_decadas %>%
filter(type == "Movie")
plot_ly() %>%
add_trace(data = series,
x = ~decada,
y = ~total,
type = "scatter",
mode = "lines+markers",
name = "TV Series",
line = list(color = "blue")) %>%
add_trace(data = filmes,
x = ~decada,
y = ~total,
type = "scatter",
mode = "lines+markers",
name = "Movies",
line = list(color = "yellow")) %>%
layout(title = "Quantidade de conteúdos por década",
xaxis = list(title = "Década"),
yaxis = list(title = "Qtd. Conteúdos"))
Questão 10
filmes_generos <- netflix %>%
filter(type == "Movie",
release_year >= 2000,
release_year <= 2010) %>%
mutate(genero_principal = str_trim(str_extract(listed_in, "^[^,]+"))) %>%
filter(genero_principal %in% c("Dramas", "Action & Adventure", "Comedies")) %>%
count(release_year, genero_principal, name = "total")
plot_ly(filmes_generos,
x = ~release_year,
y = ~total,
color = ~genero_principal,
type = "bar") %>%
layout(title = "Filmes por gênero entre 2000 e 2010",
xaxis = list(title = "Ano de lançamento"),
yaxis = list(title = "Qtd. de lançamentos"),
barmode = "group")