Questão 1

Carregamento dos 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 1: Linhas

layout(matrix(c(1,2), 1, 2))

plot(clock, MRT_1F, type = "l", col = "red", lwd = 2,
     ylim = c(0, max(MRT_1F)), xlab = "Clock (GHz)", ylab = "MRT", main = "Tempo Médio de Resposta")
lines(clock, MRT_3F, col = "blue", lwd = 2)
lines(clock, MRT_5F, col = "green", lwd = 2)
lines(clock, MRT_10F, col = "purple", lwd = 2)
lines(clock, MRT_15F, col = "orange", lwd = 2)
lines(clock, MRT_sem_F, col = "black", lwd = 2)
legend("topright", legend = c("1F", "3F", "5F", "10F", "15F", "Sem F"),
       col = c("red", "blue", "green", "purple", "orange", "black"),
       lty = 1, cex = 0.8)

GRÁFICO(s) 2: Barras

bar_colors <- c("#E6E6E6", "#666666")

# 2.1.) 1F vs Sem Fog
barplot(rbind(MRT_1F, MRT_sem_F),
        beside = TRUE, log = "y", col = bar_colors,
        names.arg = clock,
        xlab = "Clock (GHz)", ylab = "MRT (log)",
        main = "MRT - 1F vs Sem Fog")
legend("topright", legend = c("Com Fog", "Sem Fog"), fill = bar_colors, cex = 0.8)

# 2.2.) 3F vs Sem Fog
barplot(rbind(MRT_3F, MRT_sem_F),
        beside = TRUE, log = "y", col = bar_colors,
        names.arg = clock,
        xlab = "Clock (GHz)", ylab = "MRT (log)",
        main = "MRT - 3F vs Sem Fog")

# 2.3.) 5F vs Sem Fog
barplot(rbind(MRT_5F, MRT_sem_F),
        beside = TRUE, log = "y", col = bar_colors,
        names.arg = clock,
        xlab = "Clock (GHz)", ylab = "MRT (log)",
        main = "MRT - 5F vs Sem Fog")

# 2.4.) 10F vs Sem Fog
barplot(rbind(MRT_10F, MRT_sem_F),
        beside = TRUE, log = "y", col = bar_colors,
        names.arg = clock,
        xlab = "Clock (GHz)", ylab = "MRT (log)",
        main = "MRT - 10F vs Sem Fog")

# 2.5.) 15F vs Sem Fog
barplot(rbind(MRT_15F, MRT_sem_F),
        beside = TRUE, log = "y", col = bar_colors,
        names.arg = clock,
        xlab = "Clock (GHz)", ylab = "MRT (log)",
        main = "MRT - 15F vs Sem Fog")

Questão 2

Carregamento dos dados

meal_price <- c("$10–19", "$20–29", "$30–39", "$40–49")
quality_rating <- c("Good", "Very Good", "Excellent")
dados <- matrix(
  c(53.8, 33.9, 2.6, 0.0,    # Good
    43.6, 54.2, 60.5, 21.4,  # Very Good
     2.6, 11.9, 36.8, 78.6), # Excellent
  nrow = 3, byrow = TRUE
)

rownames(dados) <- quality_rating
colnames(dados) <- meal_price

Montagem do Barplot

barplot(dados,
        beside = TRUE,               
        col = c("#AED6F1", "#5DADE2", "#2E86C1"),
        legend.text = rownames(dados),
        args.legend = list(x = "topright", title = "Quality Rating"),
        xlab = "Meal Price",
        ylab = "Percentage (%)",
        main = "Meal Quality by Price Range")

abline(h = seq(0, 100, 10), col = "gray90", lty = 2)

Questão 3

Carrega os dados

data("airquality")

Realiza as manipulações pedidas

airquality$Temp_C <- (airquality$Temp - 32) / 1.8

maio <- subset(airquality, Month == 5)

Monta o Histograma

hist(maio$Temp_C,
     breaks = 10,
     col = "lightblue",
     border = "white",
     main = "Histograma das Temperaturas em Maio (°C)",
     xlab = "Temperatura (°C)",
     ylab = "Frequência",
     prob = TRUE) 

lines(density(maio$Temp_C, na.rm = TRUE), 
      col = "red", 
      lwd = 2)

Questão 4

Carrega os dados

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

Monta o gráfico

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

pie(sales$SALES, 
    labels = labels,
    col = rainbow(length(sales$COUNTRY)),
    main="Vendas por país")

str(sales)

Questão 5

Carregar os dados

data("InsectSprays")

Montar Boxplot

boxplot(
  count ~ spray, 
  data = InsectSprays,
  main = "Contagem de insetos por tipo de inseticida",
  xlab = "Tipo de Inseticida",
  ylab = "Número de Insetos",
  col = "yellow",
  outline = FALSE  
)

Questão 6

Função auxiliar de conversão

convert_to_mb <- function(mem_str) {
  mem_str <- trimws(mem_str)  # remove espaços
  
  if (grepl("TB", mem_str, ignore.case = TRUE)) {
    as.numeric(gsub("[^0-9.]", "", mem_str)) * 1000000
  } else if (grepl("GB", mem_str, ignore.case = TRUE)) {
    as.numeric(gsub("[^0-9.]", "", mem_str)) * 1024
  } else if (grepl("MB", mem_str, ignore.case = TRUE)) {
    as.numeric(gsub("[^0-9.]", "", mem_str))
  } else {
    NA  # caso não tenha unidade reconhecida
  }
}

Função para processar arquivos

process_file <- function(filepath) {
  df <- read.csv(filepath)
  
  # Converter currentTime em POSIXct e normalizar para horas
  df$currentTime <- as.POSIXct(df$currentTime)
  df$time_hours <- as.numeric(difftime(df$currentTime, df$currentTime[1], units = "hours"))
  
  # Converter memória para MB
  df$usedMemory_MB <- sapply(df$usedMemory, convert_to_mb)
  
  return(df)
}

Carregar dados

# Caminhos dos arquivos
files <- c(
  "/home/felipe/Downloads/monitoringCloudData/monitoringCloudData_NONE.csv",
  "/home/felipe/Downloads/monitoringCloudData/monitoringCloudData_0.1.csv",
  "/home/felipe/Downloads/monitoringCloudData/monitoringCloudData_0.5.csv",
  "/home/felipe/Downloads/monitoringCloudData/monitoringCloudData_1.csv"
)

Processar os dados

# Lê e processa todos
data_list <- lapply(files, process_file)
names(data_list) <- c("NONE", "0.1", "0.5", "1.0")

Monta os gŕaficos

layout(matrix(1:4, ncol = 2, byrow = TRUE))

# Gera os gráficos
for (name in names(data_list)) {
  df <- data_list[[name]]
  plot(df$time_hours, df$usedMemory_MB, type = "l", col = "blue",
       main = paste("Uso de Memória -", name),
       xlab = "Tempo (horas)",
       ylab = "Memória usada (MB)")
}

Questão 7

Questão 8

Questão 9

Questão 10