Respostas
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)
graphics::layout(matrix(c(1, 1,
2, 3,
4, 5,
6, 0), nrow = 4, byrow = TRUE),
heights = c(1.4, 1, 1, 1))
par(mar = c(4.5, 4.5, 2, 1))
cores <- c("black", "yellow", "red", "blue", "purple", "green")
simbolos <- c(4, 0, 1, 2, 5, 4)
plot(clock, MRT_1F, type = "b", col = cores[1], pch = simbolos[1],
ylim = c(0, max(MRT_1F)),
xlab = "Time between Things requests (seconds)",
ylab = "Response Time (sec.)")
lines(clock, MRT_3F, type = "b", col = cores[2], pch = simbolos[2])
lines(clock, MRT_5F, type = "b", col = cores[3], pch = simbolos[3])
lines(clock, MRT_10F, type = "b", col = cores[4], pch = simbolos[4])
lines(clock, MRT_15F, type = "b", col = cores[5], pch = simbolos[5])
lines(clock, MRT_sem_F, type = "b", col = cores[6], pch = simbolos[6])
legend("topright",
legend = c("1 Fog", "3 Fogs", "5 Fogs", "10 Fogs", "15 Fogs", "w/o Fog"),
col = cores, pch = simbolos, lty = 1, cex = 0.8)
cores_barra <- c("#E6E6E6", "#666666")
grafico_barras <- function(dados_fog, rotulo) {
barplot(rbind(MRT_sem_F, dados_fog), beside = TRUE, log = "y",
col = cores_barra, names.arg = clock,
xlab = "Time between Things requests",
ylab = "Response time (s)",
legend.text = c("w/o Fog", rotulo),
args.legend = list(x = "topright", cex = 0.7))
}
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")

graphics::layout(1)
Questão 2
tabela <- matrix(c(53.8, 43.6, 2.6,
33.9, 54.2, 11.9,
2.6, 60.5, 36.8,
0.0, 21.4, 78.6),
nrow = 3,
dimnames = list(c("Good", "Very Good", "Excellent"),
c("$10-19", "$20-29", "$30-39", "$40-49")))
barplot(tabela,
col = c("#FDAE61", "#ABDDA4", "#2B83ba"),
main = "Qualidade da refeição por faixa de preço",
xlab = "Preço da refeição (Meal Price)",
ylab = "Porcentagem (%)",
xlim = c(0, 6.5),
legend.text = TRUE,
args.legend = list(x = "topright", title = "Quality Rating"))

Questão 3
maio <- subset(airquality, Month == 5)
temp_c <- (maio$Temp - 32) / 1.8
hist(temp_c,
freq = FALSE,
col = "lightblue", border = "white",
main = "Temperaturas de maio (airquality)",
xlab = "Temperatura (°C)",
ylab = "Densidade")
lines(density(temp_c), col = "red", lwd = 2)

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

Questão 6
preparar_dados <- function(arquivo) {
d <- read.csv(arquivo, stringsAsFactors = FALSE)
tempo <- as.POSIXct(d$currentTime, tz = "UTC")
if (all(is.na(tempo))) {
tempo <- as.POSIXct(paste("2000-01-01", d$currentTime), tz = "UTC")
tempo <- tempo + 86400 * cumsum(c(0, diff(as.numeric(tempo)) < 0))
}
d$horas <- as.numeric(difftime(tempo, tempo[1], units = "hours"))
texto <- trimws(as.character(d$usedMemory))
valor <- as.numeric(sub("^([0-9.]+).*$", "\\1", texto))
unidade <- toupper(gsub("[^A-Za-z]", "", texto))
fator <- ifelse(unidade %in% c("TB", "T"), 1000000,
ifelse(unidade %in% c("GB", "G"), 1024,
ifelse(unidade %in% c("KB", "K"), 1/1024, 1))) # MB = 1
d$memoria_mb <- valor * fator
d
}
arquivos <- c("None" = "monitoringCloudData_NONE.csv",
"0.1" = "monitoringCloudData_0.1.csv",
"0.5" = "monitoringCloudData_0.5.csv",
"1.0" = "monitoringCloudData_1.csv")
graphics::layout(matrix(1:4, nrow = 2, byrow = TRUE))
par(mar = c(4.5, 4.5, 3, 1))
for (nome in names(arquivos)) {
d <- preparar_dados(arquivos[[nome]])
titulo <- ifelse(nome == "None",
"Memory Analysis (None Workload)",
paste0("Memory Analysis (Workload of ", nome, ")"))
plot(d$horas, d$memoria_mb, type = "l",
main = titulo, xlab = "Time (hour)", ylab = "Used Memory (MB)")
}

graphics::layout(1)
Questão 7
netflix <- read.csv("netflix_titles.csv", stringsAsFactors = FALSE)
um_pais <- netflix %>%
mutate(country = trimws(country)) %>%
filter(country != "", !grepl(",", country))
top10 <- um_pais %>%
count(country, name = "total", sort = TRUE) %>%
slice_head(n = 10)
plot_ly(top10, labels = ~country, values = ~total, type = "pie",
textinfo = "label+percent") %>%
layout(title = "10 países com mais conteúdo na Netflix")
Questão 8
plot_ly(
type = "table",
header = list(
values = c("País", "Total de conteúdos"),
fill = list(color = "gray"),
font = list(color = "white"),
align = "center"
),
cells = list(
values = list(top10$country, top10$total),
align = "center"
)
)
Questão 9
por_decada <- netflix %>%
mutate(decada = floor(release_year / 10) * 10) %>%
count(decada, type)
series <- filter(por_decada, type == "TV Show")
filmes <- filter(por_decada, type == "Movie")
plot_ly() %>%
add_trace(data = series, x = ~decada, y = ~n, type = "scatter",
mode = "lines+markers", name = "TV Series",
line = list(color = "blue"), marker = list(color = "blue")) %>%
add_trace(data = filmes, x = ~decada, y = ~n, type = "scatter",
mode = "lines+markers", name = "Movies",
line = list(color = "gold"), marker = list(color = "gold")) %>%
layout(title = "Quantidade de conteúdo por década",
xaxis = list(title = "Década"),
yaxis = list(title = "Qtd. Conteúdo"))
Questão 10
generos <- c("Dramas", "Action & Adventure", "Comedies")
filmes_gen <- netflix %>%
filter(type == "Movie", release_year >= 2000, release_year <= 2010) %>%
mutate(genero = trimws(sub(",.*$", "", listed_in))) %>% # só o 1º gênero
filter(genero %in% generos) %>%
count(release_year, genero) %>%
complete(release_year = 2000:2010, genero = generos, fill = list(n = 0))
nomes <- c("Dramas" = "Drama",
"Action & Adventure" = "Ação e Aventura",
"Comedies" = "Comédia")
plot_ly(filmes_gen, x = ~release_year, y = ~n, color = ~nomes[genero],
type = "bar") %>%
layout(barmode = "group",
title = "Filmes lançados por gênero (2000–2010)",
xaxis = list(title = "Ano de Lançamento"),
yaxis = list(title = "Qtd. de Lançamentos"))