Maintenance - Mise à jour mensuelle Lundi 6 Avril 2020 entre 7h00 et 9h00

Commit a0472678 authored by Celine Noirot's avatar Celine Noirot

Script to compute size for extention per year

parent f6e72598
options(warn=-1)
library(reshape2)
library(ggplot2)
library(RMySQL)
price = 0.150 # per Gb per year
mysqlHost = 'ng6-test.toulouse.inra.fr'
mysqlUser = 'typo3'
mysqlPassword = 'x69mktBYCNiyxIWU'
currentYear = format(Sys.Date(), "%Y")
currentYear = as.numeric(currentYear)
args = commandArgs(trailingOnly=TRUE)
if (length(args)!=2) {
stop("takes two arguments : project name, year payement ending", call.=FALSE)
}
givenYear <- as.numeric(args[2])
# args[1] = "AeschyNod"
mydb = dbConnect(MySQL(), user='typo3', password=mysqlPassword, dbname=mysqlUser, host=mysqlHost)
# print("run disk space in Gb")
rs = dbSendQuery(mydb, paste("select p.name, YEAR( FROM_UNIXTIME( a.tstamp ) ), SUM(a.storage_size/(1024*1024*1024)) from tx_nG6_project as p, tx_nG6_project_analyze as pa, tx_nG6_analyze as a where p.name = \"",args[1],"\" and p.uid = pa.project_id and pa.analyze_id = a.uid group by YEAR( FROM_UNIXTIME( a.tstamp ) )", sep=""))
data = as.data.frame(fetch(rs, n=-1))
names(data) <- c("project","year","analyses")
data$year <- as.numeric(data$year)
dataAnalysis <- data
# print("analysis disk space in Gb")
rs = dbSendQuery(mydb, paste("select p.name, YEAR( FROM_UNIXTIME( r.tstamp ) ), SUM(r.storage_size/(1024*1024*1024)) from tx_nG6_project as p, tx_nG6_project_run as pr, tx_nG6_run as r where p.name = \"",args[1],"\"and p.uid = pr.project_id and pr.run_id = r.uid group by YEAR( FROM_UNIXTIME( r.tstamp ) )", sep=""))
data = as.data.frame(fetch(rs, n=-1))
names(data) <- c("project","year","runs")
data$year <- as.numeric(data$year)
dataRun <- data
data2 <- merge(dataRun, dataAnalysis, c("project","year"), all=T)
data2[is.na(data2)] <- 0
data2$spaceGb = data2$runs + data2$analyses
print("")
print("Disk space table per data type and year")
print("")
data2
minYear <- min(data2$year)
# minYear
nbYear <- givenYear - currentYear
# nbYear
values <- data.frame(matrix(ncol = (nbYear+1), nrow = length(data2$year)))
# values
row.names(values) <- data2$year
names(values) <- currentYear:givenYear
# values
# ncol(values)
# nrow(values)
# dim(values)
print("")
print("Cumulative price table per project and year")
print("")
for (i in 1:nrow(values)){
for (j in 1:ncol(values)){
processedYear = currentYear + j - 1
#print(paste(i,j,processedYear, data2$year[i],data2$year[i]+j-1 , currentYear, currentYear+j -1,givenYear, ((data2$year[i]+j) - (currentYear)), currentYear - data2$year[i],sep=" "))
#print(currentYear)
if (processedYear - data2$year[i] > 2 ){
if (j == 1){
values[i,j] = price * data2$spaceGb[i] * 2
}else{
values[i,j] = values[i,j-1] + price * data2$spaceGb[i] * 2
}
}else{
values[i,j] = 0
}
}
}
values
print("")
print("Total price per year")
print("")
sums = as.data.frame(colSums(values))
names(sums) = c("sums")
sums
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment