#-- 0.0 markdown options
knitr::opts_chunk$set(
    echo = FALSE,
    eval = TRUE,
    message = FALSE,
    warning = FALSE,
    dpi = 300,
    tinytex.verbose = TRUE,
    tidy = FALSE, 
#    cashe.extra = packageVersion('tufte'),
    fig.align = "center"
    )
#-- 1.0 libraries ----
# library(magrittr)
# library(tidyverse)
library(data.table)
library(rlist)
# library(tidyquant)
# library(RMySQL)
library(lubridate)
# library(ISOweek)
# library(MMWRweek)
library(DataExplorer)

#-- 1.2 Libraries own ----
library(sw.dashboard)

#-- 1.3 libraries graphical ----
library(ggpubr)
library(knitr)
library(ggExtra)
library(viridis)
library(tufte)
#-- 1.3. Settings ----
Sys.setenv(R_CONFIG_ACTIVE = "default") # use "default" for for production, "development" for prototyping
config <- config::get(file = "../inst/golem-config.yml", use_parent = TRUE)

Purpose

r newthought('The goal') of this document is to prepare functions for the report Mailjet.

Read data

sw.dashboard::get_aws_connection()

m_dt <- sw.dashboard::read_table_from_aws(config$table_mailjet_webhooks)

Glimpse

m_dt %>%
    glimpse()

DataExplorer::introduce(m_dt)

#-- dates
m_dt[, `:=` (time = time %>% as.numeric() %>% lubridate::as_datetime())]
ymd_hms_cols <- c("tech_added_at", "tech_parsed_time")
m_dt[, (ymd_hms_cols) := lapply(.SD, lubridate::ymd_hms), .SDcols = ymd_hms_cols]

#-- mjContactId
m_dt[, .N, .(mjContactId)][order(-N)][, .((cumsum(N)/sum(N)) %>% scales::percent())]
mjContactId_dt <- m_dt[, .N, .(mjContactId)][order(-N)][, `:=` ( pct_cs = cumsum(N)/sum(N) )]
setkey(mjContactId_dt, mjContactId)

#-- events
setkey(m_dt, mjContactId)
m_dt[mjContactId_dt[pct_cs < .27]][, .N, .(mjContactId, event)]
m_dt[, .N, .(event, mjContactId)][, .N, .(mjContactId)][order(-N)][N == 3]

#-- mjCampaignId
m_dt[, .N, .(mjCampaignId)]

#-- messageID
m_dt[, .N, .(messageID)]
m_dt[messageID == ""]

#-- messageGUID
m_dt[, .N, .(messageGUID)][order(-N)]
m_dt[messageGUID == "8f9d4e58-3c1c-41a0-bcef-3cf7c7953546"] %>%
    ggplot(aes(time, y = 0)) +
    geom_point()

#-- payload
m_dt[, .N, .(payload)]

#-- errorRelatedTo
m_dt[, .N, .(errorRelatedTo)]
m_dt[!is.na(errorRelatedTo) & errorRelatedTo != ""]
m_dt[str_detect(error, "spam")]

#-- error
m_dt[, .N, .(error)]

#-- smtpReply
m_dt[, .N, .(smtpReply)]

#-- ip
m_dt[, .N, .(ip)]
# https://www.ip2location.com/93.222.240.227

#-- geo
m_dt[, .N, .(geo)]

#-- agent
m_dt[, .N, .(agent)]

#-- url
m_dt[, .N, .(url)]

#-- blocked
m_dt[, .N, .(blocked)]

#-- hardBounce
m_dt[, .N, .(hardBounce)]

#-- 
m_dt[, .N, .(source)]

m_dt[, .N, .(mjListId)]

m_dt[, .N, .(mjContactId, tech_parsed_time)][, .N, .(mjContactId)][order(-N)]
userx_dt <- m_dt[mjContactId == "1720911743"]
userx_dt[, .N, .(ip, agent)]


piotrgruszecki/sw.dashboard documentation built on March 22, 2021, 2:24 a.m.