Commit f5f81272 authored by Jerome Mariette's avatar Jerome Mariette
Browse files

data evolution ok

parent b1c4d8b3
......@@ -50,130 +50,7 @@ class tx_nG6_db {
}
$GLOBALS['TYPO3_DB']-> exec_UPDATEquery ($table, 'uid='.$id, array($field => $value));
}
/**
* Return the size used by ng6 datas from a starting date to a end date
*
* @param int $usergroup the usergroup
* @param string $data_folder the folder data
* @param bool $get_analyzes true if the admin wants to include analyzes
* @param bool $cumul_values true if the admin wants cumulatives values
* @param int $step the step (0 = one month, 1 = six months, 2 = one year)
* @param int $date_start the date start
* @param int $date_end the date end
* @return array
*/
function get_size($usergroup, $data_folder, $get_analyzes=false, $cumul_values=false, $step=2, $date_start=0, $date_end=0){
//const - tstamp is in seconds, nb of seconds in one day
$one_day_val = 24 * 3600;
// init min max
if($date_start==0){ $date_start = intval(tx_nG6_db::get_run_min_date()); }
if($date_end==0){ $date_end = intval(tx_nG6_db::get_run_max_date()); }
$date_cursors = $date_start;
$res_tab = null;
// get all users
if ($usergroup != "0") {
$users_in_group = tx_nG6_db::get_all_users_in_group($usergroup);
$project_list_final = array();
foreach($users_in_group as $list_current_user_id){
// get all user projects
$all_user_projects = tx_nG6_db::select_all_user_projects($list_current_user_id);
foreach($all_user_projects as $p_val){
if(!in_array($p_val['id'], $project_list_final)){
$project_list_final[] = $p_val['id'];
}
}
}
}
$cumulated_size = 0;
while($date_cursors < $date_end){
// increment step iterator
$total_day_count_tstamp = 0;
switch ($step) {
case 0: // 1 month
$nb_days_in_month = date('t', $date_cursors);
$total_day_count_tstamp = $one_day_val * $nb_days_in_month;
break;
case 1: // 6 months
$date_cursor_tmp = $date_cursors;
for($i = 0;$i < 6; $i++){
$nb_days_in_month = cal_days_in_month(CAL_GREGORIAN, date('n', $date_cursor_tmp), date('Y', $date_cursor_tmp));
$total_day_count_tstamp += $one_day_val * $nb_days_in_month;
// +1 month * 6
$date_cursor_tmp = strtotime('+1 month', $date_cursor_tmp);
}
break;
case 2: // 1 year
$nb_days_in_year = date("z", mktime(0,0,0,12,31,date('Y', $date_cursors)));
$total_day_count_tstamp = $one_day_val * $nb_days_in_year;
break;
}
$date_cursore = $date_cursors + $total_day_count_tstamp;
$current_size = 0;
if ($usergroup != "0") {
$where = 'tx_nG6_project.uid IN ('.implode(",",$project_list_final).') AND tx_nG6_run.date BETWEEN '.$date_cursors.' AND '.$date_cursore;
} else {
$where = 'tx_nG6_run.date BETWEEN '.$date_cursors.' AND '.$date_cursore;
}
// get all runs the usergroup can access to
$queryParts = array(
'SELECT' => 'tx_nG6_run.uid as run_id',
'FROM' => 'tx_nG6_project '
.' INNER JOIN tx_nG6_project_run ON tx_nG6_project.uid=tx_nG6_project_run.project_id '
.' INNER JOIN tx_nG6_run ON tx_nG6_project_run.run_id=tx_nG6_run.uid ',
'WHERE' => $where,
'GROUPBY' => '',
'ORDERBY' => '',
'LIMIT' => ''
);
$res = $GLOBALS['TYPO3_DB']->exec_SELECT_queryArray($queryParts);
while($res_row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
$current_size += tx_nG6_db::get_run_size($res_row['run_id'], $get_analyzes);
}
// get all project analysis the usergroup can access to
if ($get_analyzes) {
if ($usergroup != "0") {
$where = 'tx_nG6_project.uid IN ('.implode(",",$project_list_final).') AND tx_nG6_analyze.date BETWEEN '.$date_cursors.' AND '.$date_cursore;
} else {
$where = 'tx_nG6_analyze.date BETWEEN '.$date_cursors.' AND '.$date_cursore;
}
$queryParts = array(
'SELECT' => 'tx_nG6_analyze.uid as analyze_id',
'FROM' => 'tx_nG6_project '
.' INNER JOIN tx_nG6_project_analyze ON tx_nG6_project.uid=tx_nG6_project_analyze.project_id '
.' INNER JOIN tx_nG6_analyze ON tx_nG6_project_analyze.analyze_id=tx_nG6_analyze.uid ',
'WHERE' => $where,
'GROUPBY' => '',
'ORDERBY' => '',
'LIMIT' => ''
);
$res = $GLOBALS['TYPO3_DB']->exec_SELECT_queryArray($queryParts);
while($res_row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
$current_size += tx_nG6_db::get_analysis_size($res_row['analyze_id']);
}
}
$cumulated_size += $current_size;
if(!$cumul_values){
$res_tab[] = array($date_cursore*1000, $current_size);
}else{
$res_tab[] = array($date_cursore*1000, $cumulated_size);
}
$date_cursors = $date_cursore + 1;
}
return $res_tab;
}
/**
* Select all project for the current user
*
......@@ -371,9 +248,6 @@ class tx_nG6_db {
$analyses_size += intval($analyze_values["storage_size"]);
}
}
if( in_array($res_row[$by], $values) ) {
if( array_key_exists( $res_row[$by], $results) ) {
......@@ -396,7 +270,69 @@ class tx_nG6_db {
}
function select_storage_evolution($values, $by, $role, $get_analyzes, $octet, $cumulate) {
if ($by == "organism" || $by == "location") {
$by = "tx_nG6_".$by;
}
$storage_unit = "full_seq_size";
if ($octet) {
$storage_unit = "storage_size";
}
$from = "" ;
$where = "fe_groups.".$by." IN ('".implode("', '", $values)."')" ;
if ($role == "create_user") {
$from = 'tx_nG6_project '
.' INNER JOIN tx_nG6_project_run ON tx_nG6_project_run.project_id= tx_nG6_project.uid'
.' INNER JOIN tx_nG6_run ON tx_nG6_project_run.run_id= tx_nG6_run.uid'
.' INNER JOIN fe_users ON tx_nG6_project.cruser_id=fe_users.uid '
.' INNER JOIN fe_groups ON fe_groups.uid=fe_users.usergroup ' ;
} else if ($role == "manager") {
$from = 'tx_nG6_project '
.' INNER JOIN tx_nG6_project_run ON tx_nG6_project_run.project_id= tx_nG6_project.uid'
.' INNER JOIN tx_nG6_run ON tx_nG6_project_run.run_id= tx_nG6_run.uid'
.' INNER JOIN fe_rights ON tx_nG6_project.uid=fe_rights.project_id '
.' INNER JOIN fe_users ON fe_rights.fe_user_id=fe_users.uid '
.' INNER JOIN fe_groups ON fe_groups.uid=fe_users.usergroup ';
$where .= " AND fe_rights.right_id=1" ;
}
$queryParts = array(
'SELECT' => 'tx_nG6_run.uid, tx_nG6_run.crdate, tx_nG6_run.'.$storage_unit.', fe_groups.'.$by,
'FROM' => $from,
'WHERE' => $where,
'GROUPBY' => '',
'ORDERBY' => 'tx_nG6_run.crdate',
'LIMIT' => ''
);
$results = array();
$res = $GLOBALS['TYPO3_DB']->exec_SELECT_queryArray($queryParts);
while($res_row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
$analyses_size = 0;
if ($get_analyzes && $octet) {
$run_analysis = tx_nG6_db::get_run_analysis($res_row["uid"]);
foreach($run_analysis as $analyse_id => $analyze_values) {
$analyses_size += intval($analyze_values["storage_size"]);
}
}
if( array_key_exists( $res_row["crdate"], $results) ) {
$results[$res_row["crdate"]] += $res_row[$storage_unit] + $analyses_size;
} else {
$results[$res_row["crdate"]] = $res_row[$storage_unit] + $analyses_size;
}
}
$final_results = array();
foreach($results as $group_key => $group_values) {
if ($cumulate && count($final_results) > 0) {
$final_results[] = array( $group_key, $group_values + $final_results[count($final_results)-1][1]);
} else {
$final_results[] = array( $group_key, $group_values );
}
}
return $final_results;
}
/*
......
......@@ -393,7 +393,6 @@ function dataDistributionHandler(){
color: '#000000',
connectorColor: '#000000',
formatter: function() {
console.log(this)
return '<b>'+ this.point.name + '</b>';
}
}
......@@ -413,7 +412,53 @@ function dataDistributionHandler(){
}
function dataEvolutionHandler(){
$("table[id^=data_table_]").each(function(){
if ($(this).parent('div.dataTables_wrapper').first().css("display") != 'none') {
var group_by = $("[name=group_by]:checked").val();
var real_group = "laboratories";
if (group_by == "organism") {
real_group = "organizations";
} else if (group_by == "location") {
real_group = "locations";
}
var role = $("[name=users_to_consider]:checked").val();
var values = new Array();
$(this).find(":checked").each(function(){
values.push($(this).val());
});
$.ajax({
url: "index.php?eID=tx_nG6&type=data_evolution&by="+group_by+"&role="+role+"&values="+values.join(","),
dataType: 'json',
success: function(val, status, xhr) {
// reformat the data with values to integer
for (var i=0; i <val.length; i++ ) {
val[i][0] = parseInt(val[i][0])*1000;
val[i][1] = parseInt(val[i][1]);
}
chart = new Highcharts.StockChart({
chart: {
renderTo: 'highcharts_graph'
},
rangeSelector: {
selected: 4
},
yAxis: {
min: 0,
plotLines: [{
value: 0,
width: 2,
color: 'silver'
}]
},
credits: { enabled: false },
series: [{name: "data storage size", data: val}]
});
$("#refresh_graph_btn").addClass("disabled")
$("#refresh_graph_btn").unbind("click");
}
});
}
});
}
function updateButtons () {
......
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