rm(list = ls())
setwd("C:/Users/ESTUDA.COM/estuda_app")

## PACOTES
library(tidyverse)
library(lubridate)
library(gridExtra)
library(data.table)

Tabela

Por Dispositivo

nota_dispositivo  <- fread("nota_dispositivo.csv")
dispositivo03 <- fread("202103_device.csv")

quant_disp <- dispositivo03 %>% 
  filter(Date == '2021-03-27') %>%
  select(Device, Active.Device.Installs) %>%
  arrange(desc(Active.Device.Installs))

# sum(quant_disp$Active.Device.Installs)

nota_dispositivo1 <- nota_dispositivo %>% 
  filter(Date == '2021-03-27') %>% 
  select(Device, Total.Average.Rating)

nota_dispositivo2 <- nota_dispositivo %>% 
  select(Date, Device, Daily.Average.Rating, Total.Average.Rating) %>% 
  filter(Date >= '2019-03-27' & Date <= "2021-03-27") %>%
  filter(!is.na(Daily.Average.Rating)) %>% 
  group_by(Device) %>% 
  summarise(Media = round(mean(Daily.Average.Rating),4)) 

tabela_disp <- quant_disp %>% 
  left_join(nota_dispositivo1,by = "Device") %>% 
  left_join(nota_dispositivo2,by = "Device")

names(tabela_disp) <- c('Dispositivo', 'Instalações Ativas', 'Média Total',
                        'Média Diaria (Ultimos 2 anos)')

DT::datatable(tabela_disp)

Por Regiao

instal_regiao    <- fread("instal_regiao.csv") 
nota_regiao      <- fread("nota_regiao.csv")

quant_regiao <- instal_regiao %>% 
  filter(Date == '2021-03-27') %>%
  select(Country, Active.Device.Installs) %>%
  mutate(Porc  =
          round(Active.Device.Installs/sum(Active.Device.Installs)*100,2)) %>% 
  arrange(desc(Active.Device.Installs))

nota_regiao2 <- nota_regiao %>% 
  filter(Date == '2021-03-27') %>%
  select(Country, Total.Average.Rating)

tabela_regiao <- quant_regiao %>% 
  left_join(nota_regiao2,by = "Country") 
  #filter(Country %in% c('BR','PT','US','AO','MZ','JP'))

names(tabela_regiao) <- c('País', 'Instalações Ativas', 'Porcentagem (%)',
                          'Nota Média Total')
library(DT)
datatable(tabela_regiao)

Gráficos

#Importacao dos dados
nota  <-  fread("nota.csv", sep = "\t")
geral <-  fread("nota_geral.csv")

falha_geral   <- fread("falha_geral.csv")

#Transformação
nota = nota %>%
  mutate(data = dmy(data))

geral1 <- 
  geral %>% 
  mutate(Date = as.Date(Date)) %>% 
  rename(data = Date) %>% 
  left_join(nota) %>% 
  filter(!is.na(id)) 

geral1 <- geral1 %>% select(data, nota_daily = Total.Average.Rating, nota = Nota)
geral2 <- geral1 %>% select(data, media_google = nota)
geral1 <- geral1 %>% select(data, media_diaria = nota_daily)

Gráfico 1: Média Total do app desde o surgimento:

##Geral de todos os tempos
ggplot(geral) +
 aes(x = Date, y = Total.Average.Rating) +
 geom_line(size = 1, colour = "blue") +
 labs(x = "Tempo", y = "Média Total ") +
 theme_minimal() +
  ylim(3.5,5) 

Gráfico 2: Comparação média do google com média total

##Média Geral desde 2020
g1 = geral %>%
  filter(Date >= "2020-03-20" & Date <= "2021-03-21") %>%
    ggplot() +
  aes(x = Date, y = Total.Average.Rating) +
  geom_line(size = 1L, colour = "#0c4c8a") +
  labs(x = "Tempo", y = "Média Total") +
  ylim(4,4.7) +
  theme_minimal()

##Grafico da Nota
g2 = ggplot(nota) +
  aes(x = data, y = Nota) +
  geom_line(size = 1L, colour = "#26828e") +
  labs(x = "Tempo", y = "Média Padrão Google") +
  ylim(4,4.7) +
  theme_minimal()

# grid.arrange(g1 ,g2, ncol=2)

ggplot() +
  geom_line(data = geral2, aes(x = data, y = media_google), size = 1,
            colour = "#26927e") +
  geom_line(data = geral1, aes(x = data, y = media_diaria), size = 1, 
            color = "blue") +
  labs(x = "Tempo", y = "Nota média ") +
  theme_minimal() +
  ylim(3.5,5) 

Gráfico 3: Falhas

# ggplot(falha_geral) +
#   aes(x = Date, y = Daily.Crashes) +
#   geom_line() +
#   labs(x = "Ano", y = "Daily Crashes ") +
#   theme_minimal() 

falha_geral %>%
  filter(Date >= "2018-01-01") %>%
    ggplot() +
  aes(x = Date, y = Daily.Crashes) +
  geom_line() +
  labs(x = "Ano", y = "Daily Crashes ") +
  theme_minimal() 

Falhas em 2021

falha_geral %>%
  filter(Date >= "2021-01-01") %>%
    ggplot() +
  aes(x = Date, y = Daily.Crashes) +
  geom_line() +
  labs(x = "Ano", y = "Daily Crashes ") +
  theme_minimal() 

##Grafico da Nota
  nota %>%
  filter(data >= "2021-01-01") %>%
  ggplot() +
  aes(x = data, y = Nota) +
  geom_line(size = 1L, colour = "#26828e") +
  labs(x = "Tempo", y = "Média Padrão Google") +
  ylim(4.2,4.6) +
  theme_minimal()