Skip to content

Commit

Permalink
Merge pull request #61 from katmastt/main
Browse files Browse the repository at this point in the history
Merged owner and participant tables at user_statistics view
  • Loading branch information
eleni-adamidi authored Oct 18, 2023
2 parents 8f62872 + 40ae8ff commit b66ebda
Show file tree
Hide file tree
Showing 4 changed files with 268 additions and 171 deletions.
4 changes: 2 additions & 2 deletions controllers/ProjectController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3425,8 +3425,8 @@ public function actionUserStatistics()
$user=Userw::getCurrentUser();
$uid=$user['id'];
$username=explode('@',$user['username'])[0];
$usage_owner=Project::userStatisticsOwner($uid);
$usage_participant=Project::userStatisticsParticipant($uid);
$usage_owner=Project::userStatisticsOwner($uid, $user['username']);
$usage_participant=Project::userStatisticsParticipant($uid, $user['username']);
return $this->render('user_statistics', ['usage_participant'=>$usage_participant,'usage_owner'=>$usage_owner, 'username'=>$username]);
}

Expand Down
121 changes: 119 additions & 2 deletions models/Project.php
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,7 @@ public static function getMaximumActiveAcceptedProjects($project_type, $requeste
return $max_per_role[$requested_role];
}

public static function userStatisticsParticipant($uid)
public static function userStatisticsParticipant($uid, $username)
{
$query=new Query;

Expand Down Expand Up @@ -894,6 +894,63 @@ public static function userStatisticsParticipant($uid)
->andWhere("$uid = ANY(pr.user_list)")
->andWhere(['<>','pr.submitted_by',$uid])
->count();

$query=new Query;
$active_notebooks=$query->select(['pr.id'])
->from('project_request as pr')
->innerJoin('jupyter_request_n as o','o.request_id=pr.id')
->where(['IN','pr.status',[1,2]])
->andWhere(['>','pr.end_date','NOW()'])
->andWhere("$uid = ANY(pr.user_list)")
->andWhere(['<>','pr.submitted_by',$uid])
->count();

$query=new Query;
$expired_notebooks=$query->select(['pr.id'])
->from('project_request as pr')
->innerJoin('jupyter_request_n as o','o.request_id=pr.id')
->where(['IN','pr.status',[1,2]])
->andWhere(['<=','pr.end_date','NOW()'])
->andWhere("$uid = ANY(pr.user_list)")
->andWhere(['<>','pr.submitted_by',$uid])
->count();

$query=new Query;
$total_notebooks=$query->select(['pr.id'])
->from('project_request as pr')
->innerJoin('jupyter_request_n as o','o.request_id=pr.id')
->where(['IN','pr.status',[1,2]])
->andWhere("$uid = ANY(pr.user_list)")
->andWhere(['<>','pr.submitted_by',$uid])
->count();

$query=new Query;
$active_servers=$query->select(['s.id'])
->from('project_request as pr')
->innerJoin('jupyter_request_n as o','o.request_id=pr.id')
->innerJoin('jupyter_server as s','pr.name=s.project')
->where(['s.created_by'=>$username])
->andwhere(['IN','pr.status',[1,2]])
->andWhere(['s.active'=>'t'])
->andWhere("$uid = ANY(pr.user_list)")
->andWhere(['<>','pr.submitted_by',$uid])
->count();

$query=new Query;
$inactive_servers=$query->select(['s.id'])
->from('project_request as pr')
->innerJoin('jupyter_request_n as o','o.request_id=pr.id')
->innerJoin('jupyter_server as s','pr.name=s.project')
->andwhere(['IN','pr.status',[1,2]])
->where(['s.created_by'=>$username])
->andWhere(['s.active'=>'f'])
->andWhere("$uid = ANY(pr.user_list)")
->andWhere(['<>','pr.submitted_by',$uid])
->count();

$total_servers=$active_servers+$inactive_servers;




$final=[
Expand Down Expand Up @@ -931,13 +988,19 @@ public static function userStatisticsParticipant($uid)
'number_volumes_machines'=>$volumes_machines['number'],
'size_storage_service'=>$volumes_service['total']/1024.0,
'size_storage_machines'=>$volumes_machines['total']/1024.0,
'active_notebooks'=>$active_notebooks,
'expired_notebooks'=>$expired_notebooks,
'total_notebooks'=>$total_notebooks,
'active_servers'=>$active_servers,
'inactive_servers'=>$inactive_servers,
'total_servers'=>$total_servers,


];
return $final;
}

public static function userStatisticsOwner($uid)
public static function userStatisticsOwner($uid, $username)
{
$query=new Query;

Expand Down Expand Up @@ -1148,6 +1211,54 @@ public static function userStatisticsOwner($uid)
->andWhere(['pr.submitted_by'=>$uid])
->count();

$query=new Query;
$active_notebooks=$query->select(['p.id'])
->from('project_request as pr')
->innerJoin('project as p', 'p.latest_project_request_id=pr.id' )
->innerJoin('jupyter_request_n as o','o.request_id=pr.id')
->where(['IN','pr.status',[1,2]])
->andWhere(['>','pr.end_date','NOW()'])
->andWhere(['pr.submitted_by'=>$uid])
->count();

$query=new Query;

$expired_notebooks=$query->select(['p.id'])
->from('project_request as pr')
->innerJoin('project as p', 'p.latest_project_request_id=pr.id' )
->innerJoin('jupyter_request_n as o','o.request_id=pr.id')
->where(['IN','pr.status',[1,2]])
->andWhere(['<','pr.end_date','NOW()'])
->andWhere(['pr.submitted_by'=>$uid])
->count();

$query=new Query;

$total_notebooks=$query->select(['p.id'])
->from('project_request as pr')
->innerJoin('project as p', 'p.latest_project_request_id=pr.id' )
->innerJoin('jupyter_request_n as o','o.request_id=pr.id')
->where(['IN','pr.status',[1,2]])
->andWhere(['pr.submitted_by'=>$uid])
->count();

$query=new Query;
$active_servers=$query->select(['s.id'])
->from('jupyter_server as s')
->where(['s.created_by'=>$username])
->andWhere(['s.active'=>'t'])
->count();

$query=new Query;
$inactive_servers=$query->select(['s.id'])
->from('jupyter_server as s')
->where(['s.created_by'=>$username])
->andWhere(['s.active'=>'f'])
->count();

$total_servers=$active_servers+$inactive_servers;


$final=[
'active_services'=>$active_services,
'expired_services'=>$expired_services,
Expand Down Expand Up @@ -1183,6 +1294,12 @@ public static function userStatisticsOwner($uid)
'number_volumes_machines'=>$volumes_machines['number'],
'size_storage_service'=>$volumes_service['total']/1024.0,
'size_storage_machines'=>$volumes_machines['total']/1024.0,
'active_notebooks'=>$active_notebooks,
'expired_notebooks'=>$expired_notebooks,
'total_notebooks'=>$total_notebooks,
'active_servers'=>$active_servers,
'inactive_servers'=>$inactive_servers,
'total_servers'=>$total_servers,


];
Expand Down
Loading

0 comments on commit b66ebda

Please sign in to comment.