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

add administration chart

parent 4e94caa5
......@@ -236,9 +236,9 @@ class tx_nG6_eid {
$full_size = 0;
foreach($tab_ids as $id => $value) {
if ($view == "run") {
$full_size += tx_nG6_db::get_run_size($value, $data_folder);
$full_size += tx_nG6_db::get_run_size($value, $data_folder, true);
} else if ($view == "project") {
$full_size += tx_nG6_db::get_project_size($value, $data_folder);
$full_size += tx_nG6_db::get_project_size($value, $data_folder, true);
}
}
print tx_nG6_utils::get_octet_string_representation($full_size);
......@@ -521,6 +521,23 @@ class tx_nG6_eid {
}
}
} elseif($type == 'get_size_per_group'){
$usergroup = intVal(trim(t3lib_div::_GP('usergroup')));
$data_folder = trim(t3lib_div::_GP('data_folder'));
$step = intVal(trim(t3lib_div::_GP('step')));
$get_analyzes = false;
if(trim(t3lib_div::_GP('get_analyzes')) == '1'){
$get_analyzes = true;
}
$get_cumulatives = false;
if(trim(t3lib_div::_GP('get_cumulatives')) == '1'){
$get_cumulatives = true;
}
$size_tab = tx_nG6_db::get_size($usergroup, $data_folder, $get_analyzes, $get_cumulatives, $step);
$encode_size_tab = json_encode($size_tab);
print $encode_size_tab;
}
}
......
......@@ -51,6 +51,106 @@ 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
$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;
// get all runs the usergroup can access to
$queryParts = array(
'SELECT' => 'tx_nG6_run.uid as run_id, tx_nG6_run.name as name',
'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' => 'tx_nG6_project.uid IN ('.implode(",",$project_list_final).') AND tx_nG6_run.date BETWEEN '.$date_cursors.' AND '.$date_cursore,
'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'], $data_folder, $get_analyzes);
}
$cumulated_size += $current_size;
if ($date_cursore+$total_day_count_tstamp > $date_end) {
if(!$cumul_values){
$res_tab[] = array($date_end*1000, $current_size);
}else{
$res_tab[] = array($date_end*1000, $cumulated_size);
}
} else {
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;
}
/*
* Project functions
......@@ -354,8 +454,9 @@ class tx_nG6_db {
*
* @param string $p_id the project id to return the size
* @param string $data_folder the data folder
* @param boolean $get_analyzes get analyzes size ?
*/
function get_project_size($p_id, $data_folder) {
function get_project_size($p_id, $data_folder, $get_analyzes=false) {
$full_size = 0;
// All runs
......@@ -363,10 +464,12 @@ class tx_nG6_db {
foreach($project_runs as $run_id => $run_values) {
$full_size += tx_nG6_db::get_run_size($run_values['id'], $data_folder);
}
// All analysis
$project_analysis = tx_nG6_db::get_project_analysis($p_id);
foreach($project_analysis as $analyse_id => $analyze_values) {
$full_size += tx_nG6_db::get_analysis_size($analyze_values['id'], $data_folder);
if ($get_analyzes) {
// All analysis
$project_analysis = tx_nG6_db::get_project_analysis($p_id);
foreach($project_analysis as $analyse_id => $analyze_values) {
$full_size += tx_nG6_db::get_analysis_size($analyze_values['id'], $data_folder);
}
}
return $full_size;
}
......@@ -632,20 +735,23 @@ class tx_nG6_db {
*
* @param string $r_id the run id to return the size
* @param string $data_folder the data folder
* @param boolean $get_analyzes get analyzes size ?
*/
function get_run_size($r_id, $data_folder) {
function get_run_size($r_id, $data_folder, $get_analyzes=false) {
$full_size = 0;
$run_analysis = tx_nG6_db::get_run_analysis($r_id);
foreach($run_analysis as $analyse_id => $analyze_values) {
$full_size += tx_nG6_db::get_analysis_size($analyze_values['id'], $data_folder);
if($get_analyzes){
$run_analysis = tx_nG6_db::get_run_analysis($r_id);
foreach($run_analysis as $analyse_id => $analyze_values) {
$full_size += tx_nG6_db::get_analysis_size($analyze_values['id'], $data_folder);
}
}
// Then select the run
$my_run = tx_nG6_db::select_run($r_id);
foreach(scandir($data_folder.$my_run['directory']) as $file) {
foreach(scandir($data_folder.$my_run['directory']) as $file) {
if (is_file($data_folder.$my_run['directory']."/".$file)) {
$full_size += filesize($data_folder.$my_run['directory']."/".$file);
}
}
}
return $full_size;
}
......@@ -692,6 +798,56 @@ class tx_nG6_db {
$GLOBALS['TYPO3_DB']-> exec_UPDATEquery ('tx_nG6_run', 'uid='.$r_id, array('hidden' => '0'));
}
/**
* Get the run min date
*
* @return int timestamp
*/
function get_run_min_date(){
$queryParts = Array(
'SELECT' => 'MIN(tx_nG6_run.date) as min_date ',
'FROM' => 'tx_nG6_run',
'WHERE' => 'tx_nG6_run.date!=0',
'GROUPBY' => '',
'ORDERBY' => '',
'LIMIT' => ''
);
$res = $GLOBALS['TYPO3_DB']->exec_SELECT_queryArray($queryParts);
$min_date = 0;
if($GLOBALS['TYPO3_DB']->sql_num_rows($res) == 1) {
$tab = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
$min_date = intval($tab['min_date']);
}else{
$min_date = -1;
}
return $min_date;
}
/**
* Get the run max date
*
* @return int timestamp
*/
function get_run_max_date(){
$queryParts = Array(
'SELECT' => 'MAX(tx_nG6_run.date) as max_date ',
'FROM' => 'tx_nG6_run',
'WHERE' => 'tx_nG6_run.date!=0',
'GROUPBY' => '',
'ORDERBY' => '',
'LIMIT' => ''
);
$res = $GLOBALS['TYPO3_DB']->exec_SELECT_queryArray($queryParts);
$max_date = 0;
if($GLOBALS['TYPO3_DB']->sql_num_rows($res) == 1) {
$tab = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
$max_date = intval($tab['max_date']);
}else{
$max_date = -1;
}
return $max_date;
}
/*
* Analysis functions
*------------------------------------------------------------*/
......@@ -1522,9 +1678,86 @@ class tx_nG6_db {
$GLOBALS['TYPO3_DB']->exec_INSERTquery('fe_groups', $group_datas);
}
/**
* List all groups <uid,title>
*
* @return array
*/
function get_group_list(){
$queryParts = Array(
'SELECT' => 'fe_groups.uid, fe_groups.title',
'FROM' => 'fe_groups',
'WHERE' => '',
'GROUPBY' => '',
'ORDERBY' => 'fe_groups.uid',
'LIMIT' => '',
);
$res = $GLOBALS['TYPO3_DB']->exec_SELECT_queryArray($queryParts);
$res_tab = null;
while($res_row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
$res_tab[] = array(
'uid' => $res_row['uid'],
'title' => $res_row['title']
);
}
return $res_tab;
}
/**
* List all users in group
*
* @param int $group_id the grou pid
* @return array
*/
function get_all_users_in_group($group_id){
$users_in_group = null;
$queryParts = Array(
'SELECT' => 'fe_users.uid',
'FROM' => 'fe_users',
'WHERE' => 'fe_users.usergroup='.$group_id,
'GROUPBY' => '',
'ORDERBY' => '',
'LIMIT' => '',
);
$res = $GLOBALS['TYPO3_DB']->exec_SELECT_queryArray($queryParts);
while($res_row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
$users_in_group[] = $res_row['uid'];
}
return $users_in_group;
}
/**
* Get group informations.
*
* @param int $group_id
* @return array group information or null
*/
function get_group_informations($group_id){
$queryParts = Array(
'SELECT' => 'fe_groups.uid, fe_groups.title, fe_groups.description, fe_groups.crdate, fe_groups.cruser_id ',
'FROM' => 'fe_groups',
'WHERE' => 'fe_groups.uid='.$group_id,
'GROUPBY' => '',
'ORDERBY' => '',
'LIMIT' => '',
);
$res = $GLOBALS['TYPO3_DB']->exec_SELECT_queryArray($queryParts);
$res_tab = null;
while($res_row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
$res_tab = array(
'uid' => $res_row['uid'],
'title' => $res_row['title'],
'description' => $res_row['description'],
'crdate' => $res_row['crdate'],
'cruser_id' => $res_row['cruser_id']
);
}
return $res_tab;
}
/*
* DB integrity functions
*------------------------------------------------------------*/
*------------------------------------------------------------*/
/**
* Check the integrity of 'fe_rights_levels' table.
......
......@@ -15,4 +15,38 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*}
administration view
<div id="user_information_dialog" title=""></div>
<input type="hidden" id="user_is_login" value="{$login_user}" />
<input type="hidden" id="user_id" value="{$user_id}" />
<input type="hidden" id="data_folder" value="{$data_folder}" />
<input type="hidden" id="usergroup" value="{$group_info.uid}" />
<div id="size_chart"></div>
<div id="chart_options">
Groupe :
<select id="group_list">
{foreach from=$group_list key=g_id item=g_val}
<option value="{$g_val.uid}">{$g_val.uid}: {$g_val.title}</option>
{/foreach}
</select>
&nbsp;&nbsp;|&nbsp;&nbsp;
Pas :
<select id="zoom_rank">
<option value="0" selected="selected">Un mois</option>
<option value="1">Six mois</option>
<option value="2">Une année</option>
</select>
&nbsp;&nbsp;|&nbsp;&nbsp;
<label for="chk_get_analyzes">Inclure les analyses</label>
<input type="checkbox" id="chk_get_analyzes" />
&nbsp;&nbsp;|&nbsp;&nbsp;
<label for="chk_get_cumulative">Données cumulées</label>
<input type="checkbox" id="chk_get_cumulative" />
</div>
......@@ -70,6 +70,8 @@ class tx_nG6_pi6 extends tslib_pibase {
<script type="text/javascript" src="'.t3lib_extMgm::siteRelPath($this->extKey).'res/js/jquery.bgiframe.min.js"></script>
<script type="text/javascript" src="'.t3lib_extMgm::siteRelPath($this->extKey).'res/js/jquery.url.packed.js"></script>
<script type="text/javascript" src="'.t3lib_extMgm::siteRelPath($this->extKey).'res/js/tx_nG6_pi6.js"></script>
<script type="text/javascript" src="'.t3lib_extMgm::siteRelPath($this->extKey).'res/js/jquery.highcharts.exporting.js"></script>
<script type="text/javascript" src="'.t3lib_extMgm::siteRelPath($this->extKey).'res/js/highstock.js"></script>
<link type="text/css" rel="stylesheet" media="screen" href="'.t3lib_extMgm::siteRelPath($this->extKey).'res/css/tx_nG6.css"/>
<link type="text/css" rel="stylesheet" media="screen" href="'.t3lib_extMgm::siteRelPath($this->extKey).'res/css/jquery.ui.core.css"/>
<link type="text/css" rel="stylesheet" media="screen" href="'.t3lib_extMgm::siteRelPath($this->extKey).'res/css/jquery.ui.theme.css"/>
......@@ -89,10 +91,14 @@ class tx_nG6_pi6 extends tslib_pibase {
$smarty->assign('llang', $this->LOCAL_LANG['default']);
}
$group_list = tx_nG6_db::get_group_list();
$smarty->assign('login_user', $GLOBALS['TSFE']->loginUser);
$smarty->assign('user_id', $GLOBALS['TSFE']->fe_user->user['uid']);
$smarty->assign('group_list', $group_list);
$smarty->assign('data_folder', $this->conf["data"]);
return $smarty->fetch('administration_view.tpl');
}
}
if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/nG6/pi6/class.tx_nG6_pi6.php']) {
......
......@@ -280,11 +280,8 @@ td.editable:hover { border: 1px solid #BBBBBB ; cursor: text; }
/* tx-nG-pi6 plugin style */
div#chart_wrapper {
border: 1px #ccc solid;
-moz-border-radius:7px;
-webkit-border-radius: 7px;
border-radius:7px;
margin: auto;
padding-top: 20px;
}
div#chart_test{
width: 90%;
......@@ -295,5 +292,17 @@ div#chart_test{
}
div#chart_options{
padding: 10px;
border-top: 1px solid #ccc; position: relative;
border: 1px solid #ccc;
position: relative;
-moz-border-radius-bottomleft:7px;
-moz-border-radius-bottomright:7px;
-webkit-border-bottom-right-radius: 7px;
-webkit-border-bottom-left-radius: 7px;
border-bottom-right-radius:7px;
border-bottom-left-radius:7px;
}
.chart-loading{
background: white url('../img/mini_light_wait.gif') no-repeat;
background-position: 98% 50%; /* x:right, y:center */
}
This diff is collapsed.
......@@ -26,4 +26,106 @@
* @author PF bioinformatique de Toulouse <>
*/
$(function () { });
\ No newline at end of file
$(function () {
redraw_chart();
// group list
$("select[id=group_list]").change(function(){
redraw_chart();
});
// zoom level
$("select[id=zoom_rank]").change(function(){
redraw_chart();
});
// get analyzes ?
$("#chk_get_analyzes").change(function(){
redraw_chart();
});
// get cumulatives ?
$("#chk_get_cumulative").change(function(){
redraw_chart();
});
// lock/unlock chart options fields when ajax request is sent
function lock_fields(lock){
if(lock==1){
$("select[id=group_list]").attr('disabled','disabled');
$("select[id=zoom_rank]").attr('disabled','disabled');
$("#chk_get_analyzes").attr('disabled','disabled');
$("#chk_get_cumulative").attr('disabled','disabled');
$("#chart_options").attr('disabled','disabled');
}else{
$("select[id=group_list]").removeAttr('disabled');
$("select[id=zoom_rank]").removeAttr('disabled');
$("#chk_get_analyzes").removeAttr('disabled');
$("#chk_get_cumulative").removeAttr('disabled');
$("#chart_options").removeAttr('disabled');
}
}
// redraw chart
function redraw_chart(){
var size_url = "index.php?eID=tx_nG6&type=get_size_per_group";
size_url += "&usergroup="+$("#group_list option:selected").val();
size_url += "&data_folder="+$("#data_folder").val();
size_url += "&step="+$("#zoom_rank option:selected").val();
if($("#chk_get_analyzes").is(':checked')){
size_url += "&get_analyzes=1";
}else{
size_url += "&get_analyzes=0";
}
if($("#chk_get_cumulative").is(':checked')){
size_url += "&get_cumulatives=1";
}else{
size_url += "&get_cumulatives=0";
}
$.ajax({
url: size_url,
dataType: 'json',
timeout: 10000,
beforeSend: function(){
$("#chart_options").addClass("chart-loading");
lock_fields(1);
},
success: function(val, status, xhr) {
chart = new Highcharts.StockChart({
chart: {
renderTo: 'size_chart'
},
rangeSelector: {
selected: 4
},
yAxis: {
plotLines: [{
value: 0,
width: 2,
color: 'silver'
}]
},
credits: { enabled: false },
tooltip: {
pointFormat: '<span style="color:{series.color}">{series.name}</span>: <b>{point.y}</b> ({point.change}%)<br/>',
valueDecimals: 2
},
series: [{name: "sdsds", data: val}]
});
},
// ajax complete event : remove gif loading animation and unlock fields
complete: function(){
$("#chart_options").removeClass("chart-loading");
lock_fields(0);
}
});
}
});
\ No newline at end of file
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