Atividade 11 CPAD
01
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)
layout(matrix(1:2, nrow=2))
clock <- c(0.1, 0.5, 1, 1.5, 2, 2.5, 3)
plot(clock, MRT_1F, type = "o", col = "black", pch = 4, xlab = "Time between things requests (seconds)", ylab = "Response Time (sec.)")
lines(clock,MRT_3F, type = "o", col = "yellow", pch = 8)
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 = 11)
lines(clock,MRT_sem_F, type = "o", col = "green", pch = 0)
legend("topright", legend=c("1 Fog", "3 Fogs", "5 Fogs", "10 Fogs", "15 Fogs", "w/0 Fog"), col=c("black", "yellow", "red", "blue", "purple", "green"), pch = c(4,8, 1, 2, 11, 0), lty=1 )

layout(matrix(1:6, nrow = 3, ncol = 2))
barplot(rbind(MRT_sem_F, MRT_1F), beside=TRUE, log="y", col=c("#E6E6E6", "#666666"), names.arg=clock, xlab="Time between things requests", ylab="Response Time (s)")
legend("topright", legend=c("w/0 Fog", "1 Fog"), fill=c("#E6E6E6", "#666666"))
barplot(rbind(MRT_sem_F, MRT_3F), beside=TRUE, log="y", col=c("#E6E6E6", "#666666"), names.arg=clock, xlab="Time between things requests", ylab="Response Time (s)")
legend("topright", legend=c("w/0 Fog", "3 Fog"), fill=c("#E6E6E6", "#666666"))
barplot(rbind(MRT_sem_F, MRT_5F), beside=TRUE, log="y", col=c("#E6E6E6", "#666666"), names.arg=clock, xlab="Time between things requests", ylab="Response Time (s)")
legend("topright", legend=c("w/0 Fog", "5 Fog"), fill=c("#E6E6E6", "#666666"))
barplot(rbind(MRT_sem_F, MRT_10F), beside=TRUE, log="y", col=c("#E6E6E6", "#666666"), names.arg=clock, xlab="Time between things requests", ylab="Response Time (s)")
legend("topright", legend=c("w/0 Fog", "10 Fog"), fill=c("#E6E6E6", "#666666"))
barplot(rbind(MRT_sem_F, MRT_15F), beside=TRUE, log="y", col=c("#E6E6E6", "#666666"), names.arg=clock, xlab="Time between things requests", ylab="Response Time (s)")
legend("topright", legend=c("w/0 Fog", "15 Fog"), fill=c("#E6E6E6", "#666666"))
plot.new()

02
quality <- c("Good", "Very Good", "Excelent")
meal_price <- c("$10-19","$20-29","$30-39","$40-49")
line_1 <- c(53.8,33.9,2.6,0)
line_2 <- c(43.6,54.2,60.5,21.4)
line_3 <- c(2.6,11.9,36.8,78.6)
mtx <- rbind(line_1, line_2, line_3)
colors <- c("darkgoldenrod1", "pink", "chartreuse3")
barplot(mtx, main = "Quality Rating",
names.arg = meal_price, xlab = "Meal price", ylab = "%", col = colors, beside = FALSE)
legend("topright", pch = 15, col = colors, legend = quality)

03
data("airquality")
may_fahrenheit <- airquality$Temp[airquality$Month == 5]
may_celsius <- (may_fahrenheit - 32) / 1.8
hist(may_celsius,
main = "Histograma do Airquality em graus celsius - Maio",
xlab = "Temperatura (°C)",
ylab = "Frequência",
col = "bisque",
border = "darkorange2",
prob = TRUE)
lines(density(may_celsius), col = "coral2", lwd = 3)

04
sales <- read.table("https://training-course-material.com/images/8/8f/Sales.txt", header = TRUE)
sales$PERCENT <- round(sales$SALES / sum(sales$SALES) * 100, 2)
colors <- topo.colors(nrow(sales))
pie(x= sales$SALES,
labels = paste(sales$SALES, sales$PERCENT, "%"),
col = colors,
main = "Porcentagem de Vendas por País")
legend("topright", legend = sales$COUNTRY, fill = colors)

05
data_insect <- InsectSprays
boxplot(data_insect$count ~ data_insect$spray,
data = data_insect,
main = "Contagens de insetos por tipo de inseticida",
xlab = "Tipo de inseticida",
ylab = "Contagem de insetos",
col = "yellow",
boxwex = 0.3,
outline = FALSE)

06
#install.packages("anytime")
library(anytime)
library(tidyr)
library(dplyr)
data_1 <- read.csv2(file="~/ufrpe/2024_1/analise_dados/monitoringCloudData_NONE.csv", sep=",")
data_2 <- read.csv2(file="~/ufrpe/2024_1/analise_dados/monitoringCloudData_0.1.csv", sep=",")
data_3 <- read.csv2(file="~/ufrpe/2024_1/analise_dados/monitoringCloudData_0.5.csv", sep=",")
data_4 <- read.csv2(file="~/ufrpe/2024_1/analise_dados/monitoringCloudData_1.csv", sep=",")
data_1 <- data_1 %>% separate(col="usedMemory", into=c("usedMemory","umUnit"), sep=-2)
data_1$usedMemory <- as.double(data_1$usedMemory)
data_2 <- data_2 %>% separate(col="usedMemory", into=c("usedMemory","umUnit"), sep=-2)
data_2$usedMemory <- as.double(data_2$usedMemory)
data_3 <- data_3 %>% separate(col="usedMemory", into=c("usedMemory","umUnit"), sep=-2)
data_3$usedMemory <- as.double(data_3$usedMemory)
data_4 <- data_4 %>% separate(col="usedMemory", into=c("usedMemory","umUnit"), sep=-2)
data_4$usedMemory <- as.double(data_4$usedMemory)
data_1 <- data_1 %>% mutate(usedMemory = ifelse(umUnit == "GB", usedMemory * 1024, usedMemory))
data_2 <- data_2 %>% mutate(usedMemory = ifelse(umUnit == "GB", usedMemory * 1024, usedMemory))
data_3 <- data_3 %>% mutate(usedMemory = ifelse(umUnit == "GB", usedMemory * 1024, usedMemory))
data_4 <- data_4 %>% mutate(usedMemory = ifelse(umUnit == "GB", usedMemory * 1024, usedMemory))
data_1 <- transform(data_1, ct = anytime(currentTime))
data_2 <- transform(data_2, ct = anytime(currentTime))
data_3 <- transform(data_3, ct = anytime(currentTime))
data_4 <- transform(data_4, ct = anytime(currentTime))
data_1 <- data_1 %>% mutate(ct2 = difftime(ct, min(ct), units = "hours"))
data_2 <- data_2 %>% mutate(ct2 = difftime(ct, min(ct), units = "hours"))
data_3 <- data_3 %>% mutate(ct2 = difftime(ct, min(ct), units = "hours"))
data_4 <- data_4 %>% mutate(ct2 = difftime(ct, min(ct), units = "hours"))
layout(matrix(c(1,2,3,4), 2, 2, byrow = TRUE))
with(data_1, plot(ct2, usedMemory, type = "l", main = "Memory Analysis (None Workload)", xlab = "Time (hour)", ylab = "Used Memory (MB)", font.main = 2))
with(data_2, plot(ct2, usedMemory, type = "l", main = "Memory Analysis (Workload of 0.1)", xlab = "Time (hour)", ylab = "Used Memory (MB)", font.main = 2))
with(data_3, plot(ct2, usedMemory, type = "l", main = "Memory Analysis (Workload of 0.5)", xlab = "Time (hour)", ylab = "Used Memory (MB)", font.main = 2))
with(data_4, plot(ct2, usedMemory, type = "l", main = "Memory Analysis (Workload of 1.0)", xlab = "Time (hour)", ylab = "Used Memory (MB)", font.main = 2))

07
netflix <- read.csv2(file="~/ufrpe/2024_1/analise_dados/netflix_titles.csv", sep=",")
netflix <- transform(netflix, country = trimws(country))
netflix_filtered <- subset(netflix, !is.na(country) & !grepl(",", country))
top_10_countries <- netflix_filtered %>% filter(country != "") %>% group_by(country) %>% summarise(count = n()) %>% arrange(desc(count)) %>% head(10)
top_10_countries$country[top_10_countries$country == ""] <- "Outros"
plot_pie_netflix <-plot_ly(
top_10_countries,
labels = ~country,
values = ~count,
type = 'pie',
textinfo = 'label+percent',
marker = list(colors = rainbow(10)),
title = 'Top 10 Países Netflix'
)
plot_pie_netflix
plot_pie_netflix
08
df_top_10_countries <- data.frame(country = top_10_countries$country,count = top_10_countries$count)
plot_table_netflix <-plot_ly(
type = 'table',
header = list(values = colnames(df_top_10_countries), align = 'center', font = list(size = 12, color = 'white'), fill = list(color = 'darkgray') ),
cells = list(values = rbind(df_top_10_countries$country, df_top_10_countries$count), align = 'center', font = list(size = 11, color = 'white'), fill = list(color = 'gray') )
)
plot_table_netflix
09
netflix$decada <- as.numeric(substr(netflix$release_year, 1, 3)) * 10
dados_decada <- netflix %>%filter(!is.na(release_year)) %>%group_by(decada, type) %>%summarise(count = n()) %>%ungroup()
plot_ly(dados_decada, x = ~decada, y = ~count, color = ~type, type = 'scatter', mode = 'lines+markers', colors = c('coral1', 'blue3')) %>%
layout(xaxis = list(title = 'Década'), yaxis = list(title = 'Qnd. Conteúdo'), legend = list(title = 'Tipo de Conteúdo', x = 1, y = 1))
10
library(dplyr)
library(tidyr)
library(stringr)
library(plotly)
filmes <- netflix %>%
filter(type == "Movie", release_year >= 2000, release_year <= 2010) %>%
mutate(primeiro_genero = str_extract(listed_in, "^[^,]+")) %>%
filter(primeiro_genero %in% c("Dramas", "Action & Adventure", "Comedies"))
filmes_genero <- filmes %>%
count(release_year, primeiro_genero) %>%
pivot_wider(names_from = primeiro_genero, values_from = n, values_fill = list(n = 0))
plot_ly(filmes_genero, x = ~release_year) %>%
add_bars(y = ~Dramas, name = 'Drama', marker = list(color = 'blue')) %>%
add_bars(y = ~`Action & Adventure`, name = 'Ação e Aventura', marker = list(color = 'darkorange')) %>%
add_bars(y = ~Comedies, name = 'Comédia', marker = list(color = 'darkgreen')) %>%
layout(barmode = 'group',xaxis = list(title = 'Ano de Lançamento'),yaxis = list(title = 'Qnt. de Lançamentos'))