1º Questão
Dados
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)
Gráfico de Linhas
plot(clock, MRT_1F, type = "b", col = "blue", pch = 16,
xlab = "Time between Things requests (seconds)",
ylab = "Response time (s)",
ylim = c(0, max(MRT_1F) + 50),
las = 1,
main = "Response Time vs Time Between Requests")
lines(clock, MRT_3F, type = "b", col = "red", pch = 16)
lines(clock, MRT_5F, type = "b", col = "green", pch = 16)
lines(clock, MRT_10F, type = "b", col = "purple", pch = 16)
lines(clock, MRT_15F, type = "b", col = "orange", pch = 16)
lines(clock, MRT_sem_F, type = "b", col = "brown", pch = 16)
legend("topright", legend = c("1 fog", "3 fogs", "5 fogs", "10 fogs", "15 fogs", "w/o fog"),
col = c("blue", "red", "green", "purple", "orange", "brown"),
lty = 1, pch = 16, cex = 0.8)

Gráficos de Barras
cores <- c("#E6E6E6", "#666666")
# Comparar w/o fog (sem_F) com 1F
dados_1f <- rbind(MRT_sem_F, MRT_1F)
barplot(dados_1f, beside = TRUE, col = cores,
names.arg = clock,
log = "y",
xlab = "Time between Things requests",
ylab = "Response time (s)",
las = 1)
legend("topright", legend = c("w/o fog", "1 fog"), fill = cores, cex = 0.7)

dados_3f <- rbind(MRT_sem_F, MRT_3F)
barplot(dados_3f, beside = TRUE, col = cores,
names.arg = clock,
log = "y",
xlab = "Time between Things requests",
ylab = "Response time (s)",
las = 1,
ylim = c(0.1, 200))
legend("topright", legend = c("w/o fog", "3 fogs"), fill = cores, cex = 0.7)

dados_5f <- rbind(MRT_sem_F, MRT_5F)
barplot(dados_5f, beside = TRUE, col = cores,
names.arg = clock,
log = "y",
xlab = "Time between Things requests",
ylab = "Response time (s)",
las = 1)
legend("topright", legend = c("w/o fog", "5 fogs"), fill = cores, cex = 0.7)

dados_10f <- rbind(MRT_sem_F, MRT_10F)
barplot(dados_10f, beside = TRUE, col = cores,
names.arg = clock,
log = "y",
xlab = "Time between Things requests",
ylab = "Response time (s)",
las = 1)
legend("topright", legend = c("w/o fog", "10 fogs"), fill = cores, cex = 0.7)

dados_15f <- rbind(MRT_sem_F, MRT_15F)
barplot(dados_15f, beside = TRUE, col = cores,
names.arg = clock,
log = "y",
xlab = "Time between Things requests",
ylab = "Response time (s)",
las = 1)
legend("topright", legend = c("w/o fog", "15 fogs"), fill = cores, cex = 0.7)

2º Questão
Dados
dados2 <- matrix(c(53.8, 33.9, 2.6, 0.0,
43.6, 54.2, 11.9, 0.0,
0.0, 66.5, 36.8, 0.0,
0.0, 21.4, 78.6, 0.0),
nrow = 4, byrow = TRUE)
# Nomes das linhas (categorias de qualidade) e colunas (faixas de preço)
rownames(dados2) <- c("Good", "Very Good", "Excellent", "Total")
colnames(dados2) <- c("$10-19", "$20-29", "$30-39", "$40-49")
# Remover a linha "Total" para o gráfico
dados_grafico <- dados2[1:3, ]
Gráfico de Barras Empilhadas
# Cores para cada categoria de qualidade
cores <- c("#8B4513", "#DAA520", "#FFD700")
# Criar gráfico de barras empilhadas
barplot(dados_grafico,
col = cores,
main = "Quality Rating by Meal Price Category",
xlab = "Meal Price Range",
ylab = "Percentage (%)",
legend.text = rownames(dados_grafico),
args.legend = list(x = "topright",
title = "Quality Rating",
cex = 0.8),
ylim = c(0, 120),
las = 1)
# Adicionar grid horizontal para facilitar leitura
grid(nx = NA, ny = NULL, col = "lightgray", lty = "dotted")

6º Questão
Dados
# Carregar bibliotecas necessárias
library(ggplot2)
library(stringr)
# Função para converter memória para MB
convert_to_mb <- function(memory_str) {
# Extrair o número e a unidade
number <- as.numeric(str_extract(memory_str, "[0-9.]+"))
unit <- str_extract(memory_str, "[A-Za-z]+")
# Converter para MB baseado na unidade
mb_value <- ifelse(unit == "TB", number * 1000000,
ifelse(unit == "GB", number * 1024,
ifelse(unit == "MB", number, NA)))
return(mb_value)
}
# Função para processar cada arquivo
process_data <- function(filename) {
# Ler o arquivo CSV
data <- read.csv(filename, stringsAsFactors = FALSE)
# Converter currentTime para formato de data/hora
data$currentTime <- as.POSIXct(data$currentTime, format = "%Y-%m-%d %H:%M:%S")
# Calcular tempo em horas desde o início
start_time <- min(data$currentTime)
data$time_hours <- as.numeric(difftime(data$currentTime, start_time, units = "hours"))
# Converter usedMemory para MB
data$usedMemory_MB <- sapply(data$usedMemory, convert_to_mb)
return(data)
}
# Processar todos os arquivos
data_none <- process_data("monitoringCloudData_NONE.csv")
data_01 <- process_data("monitoringCloudData_0.1.csv")
data_05 <- process_data("monitoringCloudData_0.5.csv")
data_10 <- process_data("monitoringCloudData_1.csv")
Gráfico de Linhas
# Configurar layout para 4 gráficos (2x2)
par(mfrow = c(2, 2))
# Gráfico 1: None Workload
plot(data_none$time_hours, data_none$usedMemory_MB,
type = "l",
xlab = "Time (hour)",
ylab = "Used Memory (MB)",
main = "Memory Analysis (None Workload)",
xlim = c(0, 70),
ylim = c(min(data_none$usedMemory_MB, na.rm = TRUE),
max(data_none$usedMemory_MB, na.rm = TRUE)),
las = 1)
# Gráfico 2: Workload 0.1
plot(data_01$time_hours, data_01$usedMemory_MB,
type = "l",
xlab = "Time (hour)",
ylab = "Used Memory (MB)",
main = "Memory Analysis (Workload of 0.1)",
xlim = c(0, 70),
ylim = c(min(data_01$usedMemory_MB, na.rm = TRUE),
max(data_01$usedMemory_MB, na.rm = TRUE)),
las = 1)
# Gráfico 3: Workload 0.5
plot(data_05$time_hours, data_05$usedMemory_MB,
type = "l",
xlab = "Time (hour)",
ylab = "Used Memory (MB)",
main = "Memory Analysis (Workload of 0.5)",
xlim = c(0, 70),
las = 1)
# Gráfico 4: Workload 1.0
plot(data_10$time_hours, data_10$usedMemory_MB,
type = "l",
xlab = "Time (hour)",
ylab = "Used Memory (MB)",
main = "Memory Analysis (Workload of 1.0)",
xlim = c(0, 70),
ylim = c(min(data_10$usedMemory_MB, na.rm = TRUE),
max(data_10$usedMemory_MB, na.rm = TRUE)),
las = 1)

7º Questão
Dados
# Instalar pacotes necessários se não estiverem instalados
if (!require("dplyr")) install.packages("dplyr", repos = "http://cran.us.r-project.org")
if (!require("plotly")) install.packages("plotly", repos = "http://cran.us.r-project.org")
if (!require("tidyr")) install.packages("tidyr", repos = "http://cran.us.r-project.org")
library(dplyr)
library(plotly)
library(tidyr)
# Carregar o dataset
df <- read.csv("netflix_titles.csv", stringsAsFactors = FALSE)
# Filtrar apenas países únicos (sem múltiplos países)
df_single_country <- df %>%
filter(!grepl(",", country)) %>%
filter(!is.na(country) & country != "")
# Contar conteúdos por país e pegar top 10
top10_paises <- df_single_country %>%
count(country, name = "total") %>%
arrange(desc(total)) %>%
head(10)
Gráfico de Pizza
# Criar gráfico de pizza
fig1 <- plot_ly(
data = top10_paises,
labels = ~country,
values = ~total,
type = 'pie',
textposition = 'inside',
textinfo = 'label+percent',
hoverinfo = 'label+value+percent',
marker = list(
line = list(color = '#FFFFFF', width = 2)
)
) %>%
layout(
title = "Top 10 Países com Mais Conteúdo na Netflix",
showlegend = TRUE,
xaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE),
yaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE)
)
fig1
8º Questão
Dados
# Preparar dados para a tabela
tabela_dados <- top10_paises %>%
rename("País" = country, "Total de conteúdos" = total)
Tabela
# Criar tabela com Plotly
fig2 <- plot_ly(
type = 'table',
header = list(
values = c("País", "Total de conteúdos"),
align = c('center', 'center'),
line = list(width = 1, color = 'black'),
fill = list(color = 'grey'),
font = list(family = "Arial", size = 14, color = "white")
),
cells = list(
values = rbind(tabela_dados$`País`, tabela_dados$`Total de conteúdos`),
align = c('center', 'center'),
line = list(color = "black", width = 1),
fill = list(color = c('white', 'white')),
font = list(family = "Arial", size = 12, color = c("black"))
)
)
fig2
9º Questão
Dados
# Preparar dados: criar coluna de década
df_decadas <- df %>%
filter(!is.na(release_year) & release_year != "") %>%
mutate(
release_year = as.numeric(release_year),
decada = floor(release_year / 10) * 10
) %>%
filter(!is.na(decada))
# Contar por década e tipo
conteudo_decada <- df_decadas %>%
group_by(decada, type) %>%
summarise(quantidade = n(), .groups = 'drop') %>%
arrange(decada)
# Separar séries e filmes
series <- conteudo_decada %>% filter(type == "TV Show")
filmes <- conteudo_decada %>% filter(type == "Movie")
Gráfico de Linhas
# Criar gráfico de linha
fig3 <- plot_ly() %>%
add_trace(
data = series,
x = ~decada,
y = ~quantidade,
type = 'scatter',
mode = 'lines+markers',
name = 'Séries',
line = list(color = 'blue', width = 3),
marker = list(size = 8, color = 'blue')
) %>%
add_trace(
data = filmes,
x = ~decada,
y = ~quantidade,
type = 'scatter',
mode = 'lines+markers',
name = 'Filmes',
line = list(color = 'gold', width = 3),
marker = list(size = 8, color = 'gold')
) %>%
layout(
title = "Quantidade de Conteúdo por Década na Netflix",
xaxis = list(
title = "Década",
tickmode = 'linear',
dtick = 10
),
yaxis = list(
title = "Quantidade de Conteúdo"
),
legend = list(
orientation = 'h',
x = 0.5,
xanchor = 'center',
y = -0.2
),
hovermode = 'x unified'
)
fig3
10º Questão
Dados
# Filtrar apenas filmes entre 2000 e 2010
df_filmes_2000_2010 <- df %>%
filter(type == "Movie") %>%
filter(!is.na(release_year) & release_year != "") %>%
mutate(release_year = as.numeric(release_year)) %>%
filter(release_year >= 2000 & release_year <= 2010)
# Extrair apenas o primeiro gênero da coluna listed_in
df_filmes_2000_2010 <- df_filmes_2000_2010 %>%
mutate(primeiro_genero = trimws(sub(",.*", "", listed_in)))
# Filtrar apenas os três gêneros solicitados
generos_interesse <- c("Dramas", "Action & Adventure", "Comedies")
df_generos_filtrados <- df_filmes_2000_2010 %>%
filter(primeiro_genero %in% generos_interesse)
# Contar quantidade de filmes por ano e gênero
contagem_generos <- df_generos_filtrados %>%
group_by(release_year, primeiro_genero) %>%
summarise(quantidade = n(), .groups = 'drop')
Gráfico de Barras
# Criar o gráfico de barras lado-a-lado
fig_generos <- plot_ly(data = contagem_generos,
x = ~release_year,
y = ~quantidade,
type = 'bar',
color = ~primeiro_genero,
colors = c("Dramas" = "#1f77b4",
"Action & Adventure" = "#ff7f0e",
"Comedies" = "#2ca02c"),
text = ~quantidade,
textposition = 'outside',
hovertemplate = paste('<b>Ano: %{x}</b><br>',
'Gênero: %{data.name}<br>',
'Quantidade: %{y}<br>',
'<extra></extra>')) %>%
layout(
title = "Quantidade de Filmes por Gênero (2000-2010)",
xaxis = list(
title = "Ano de Lançamento",
tickmode = 'linear',
dtick = 1
),
yaxis = list(
title = "Quantidade de Filmes"
),
barmode = 'group', # Barras lado-a-lado
legend = list(
title = list(text = "Gênero"),
orientation = 'v',
x = 1.02,
y = 1
),
hovermode = 'closest'
)
fig_generos