library(dlstats)
library(ggplot2)

today <- substr(Sys.time(), 1, 8)

# All list of packages:
# x <- cran_stats(c("CSTools", "ClimProjDiags", "startR", "easyNCDF", "multiApply", "s2dverification", "ggplot2", "climatol", "rSQM", "SCI", "seas", "SpecsVerification"))


#x <- cran_stats(c("CSTools", "ClimProjDiags",  "s2dverification",
#                  "SpecsVerification", "verification"))


x <- cran_stats(c("CSTools", "ClimProjDiags",  "s2dverification",
"SpecsVerification", "climatol", "ClimInd"))

data <- subset(x, x$package != "ggplot2" & x$start >= as.Date("2018-09-01", "%Y-%m-%d"))

ggplot(data, aes(end, downloads, group = package, color=package)) +
geom_line() + geom_point(aes(shape = package)) # +
ggsave(paste0("/home/Earth/nperez/MEDSCOPE/CTools_", today, "Download.png"))

cum_downloads <- NULL
for (i in 1 : length(unique(data$package))) {
  cum_downloads <- c(cum_downloads, cumsum(data$downloads[which(data$package ==
                                          unique(data$package)[i])]))
}

data[,"cum_downloads"] <- cum_downloads

ggplot(data, aes(end, cum_downloads, group=package, color=package)) +
  geom_line() + geom_point(aes(shape=package))
ggsave(paste0("./MEDSCOPE/CTools_Cumulative_", today, "Downloads.png"))
