Skip to content

Instantly share code, notes, and snippets.

@arianpasquali
Last active December 17, 2016 02:53
Show Gist options
  • Save arianpasquali/281cef8ac3d51a417c5d94cf68ca3324 to your computer and use it in GitHub Desktop.
Save arianpasquali/281cef8ac3d51a417c5d94cf68ca3324 to your computer and use it in GitHub Desktop.
r homework
data.gateway = read.csv("gateway.csv", header = TRUE, sep = ";" , dec=",")
data.adquirente = read.csv("adquirente.csv", header = TRUE, sep = ";" , dec=",")
data.sumup = read.table("BASE_sumup.csv", header = TRUE, sep = ";", dec=",")
summary(data.sumup)
summary(data.adquirente)
summary(data.gateway)
# questao 1
data.sumup.approved <- data.sumup[data.sumup$TransactionStatus == "Aprovada",]
data.gateway.approved <- data.gateway[data.gateway$TransactionStatus == 6,]
data.adquirente.approved <- data.adquirente[data.adquirente$TransactionStatus == "1.Transaction Approved Succesfully",]
data.sumup.approved$Amount <- as.numeric(data.sumup.approved$Amount)
data.gateway.approved$Amount <- as.numeric(data.gateway.approved$Amount)
data.adquirente.approved$Amount <- as.numeric(data.adquirente.approved$Amount)
sum(data.sumup.approved$Amount)
sum(data.gateway.approved$Amount)
sum(data.adquirente.approved$Amount)
entities <- c('gateway','adquirente','sumup')
amount <- c(sum(data.gateway.approved$Amount), sum(data.adquirente.approved$Amount), sum(data.sumup.approved$Amount))
amount_df <- data.frame(entities, amount)
amount_df
write.csv(amount_df, file = "questao_1.csv")
# questao 2
diff_adquirente_sumup <- sum(data.adquirente.approved$Amount) - sum(data.sumup.approved$Amount)
# questao 3
df_sumup_gateway <- merge(data.sumup, data.gateway, by= "TransactionID", all.x= TRUE, all.y= TRUE)
unique(df_sumup_gateway[df_sumup_gateway$TransactionStatus.x == "Iniciada",]$TransactionStatus.y)
na.omit(df_sumup_gateway[df_sumup_gateway$TransactionStatus.y == "4",]$TransactionStatus.y)
# questao 4
ids_faltantes_em_adquirente <- setdiff(data.sumup$TransactionID, data.adquirente$TransactionID)
length(ids_faltantes_em_adquirente)
write.csv(ids_faltantes_em_adquirente, file = "questao_4.csv")
# questao 5
#df[df$Installments.x != df$Installments,c("Installments","Installments.x","Installments.y")]
df_sumup_gateway_ <- merge(data.sumup, data.gateway, by= "TransactionID", all.x= FALSE, all.y= FALSE)
df_sumup_gateway_adquirente_full_match <- merge(df_sumup_gateway_, data.adquirente, by= "TransactionID", all.x= FALSE, all.y= FALSE)
df_sumup_gateway_adquirente_full_match <- na.omit(df_sumup_gateway_adquirente)
write.csv(df_sumup_gateway_adquirente_full_match, file = "transactions_full_match.csv")
dim(df_sumup_gateway_adquirente_full_match)
df_sumup_gateway_adquirente_full_match[df_sumup_gateway_adquirente_full_match$Installments.x != df_sumup_gateway_adquirente_full_match$Installments.y | df_sumup_gateway_adquirente_full_match$Installments.y != df_sumup_gateway_adquirente_full_match$Installments,c("TransactionID","Installments.x","Installments.y","Installments")]
discrepancias <- df_sumup_gateway_adquirente_full_match[df_sumup_gateway_adquirente_full_match$Installments.x != df_sumup_gateway_adquirente_full_match$Installments.y | df_sumup_gateway_adquirente_full_match$Installments.y != df_sumup_gateway_adquirente_full_match$Installments,c("TransactionID","Installments.x","Installments.y","Installments","TransactionStatus.x")]
write.csv(discrepancias, file = "questao_5.csv")
# questao 6
df_sumup_adquirente <- merge(data.sumup, data.adquirente, by= "TransactionID", all.x= TRUE, all.y= TRUE)
resposta_6 <- na.omit(df_sumup_adquirente[df_sumup_adquirente$TransactionStatus.x == "Aprovada" & df_sumup_adquirente$TransactionStatus.y == "113.Gateway Error. Please contact provider",])
write.csv(resposta_6, file = "questao_6.csv")
# questao 7
data.adquirente.auth_code <- data.adquirente[data.adquirente$auth_code != "",]
inconsistent_aprovals <- data.adquirente.auth_code[data.adquirente.auth_code$TransactionStatus != "1.Transaction Approved Succesfully",]
sum(inconsistent_aprovals$Amount)
write.csv(inconsistent_aprovals, file = "questao_7.csv")
# questao 10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment