Skip to content

Commit

Permalink
Move non-namespaced library functions into classes. (#89)
Browse files Browse the repository at this point in the history
* Move non-namespaced library functions into classes.

This change is needed dues to the changes in the linker. One function arrayValues()
has been removed since it was only used in a single place and had unused
code in it.

* Update linker settings

* Update syntax to match linting rules.

Co-authored-by: The XDMoD Team <[email protected]>
  • Loading branch information
jpwhite4 and xdmod authored May 17, 2021
1 parent 949f2c0 commit 8142d2d
Show file tree
Hide file tree
Showing 8 changed files with 132 additions and 143 deletions.
1 change: 0 additions & 1 deletion build.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
"appkernel",
"classes",
"html",
"libraries",
{ "templates": "templates/appkernels" }
],
"bin": [
Expand Down
2 changes: 1 addition & 1 deletion classes/AppKernel/PerformanceMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,7 @@ function ($value) use ($arr_db) {
$problemSize = end(explode('.', $row['reporternickname']));
$collected = $row['collected'];

$resource_id = arrayValue($resource, $this->resource_ids);
$resource_id = array_key_exists($resource, $this->resource_ids) ? $this->resource_ids[$resource] : null;
$ak_id = null;
if (array_key_exists($appKer, $ak_ids) && array_key_exists($problemSize, $ak_ids[$appKer])) {
$ak_id = $ak_ids[$appKer][$problemSize];
Expand Down
31 changes: 27 additions & 4 deletions classes/AppKernel/ProblemDetector/AppKernelLevel.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,29 @@ public function __construct($runStatsAppKernel,$runStatsProblemSize,$appKerShort
$this->appKerShortname=$appKerShortname;
}

/**
* Format an array as a human readable string.
*
* @param array $a the input array
*
* @return string
*/
private function implodeSmart($a)
{
$s="";
for ($i=0; $i<count($a); $i++) {
$s.=$a[$i];
if ($i<count($a)-1) {
if ($i==count($a)-2) {
$s.=' and ';
} else {
$s.=', ';
}
}
}
return $s;
}

public function detect(){
$max_days=max(array_keys($this->runStatsAppKernel->NE));
$all_problems=array();
Expand Down Expand Up @@ -106,8 +129,8 @@ public function detect(){
}
if($count>0){
$days=$days/$count;
$msg.="{$this->appKerShortname} was $verb ".implode_smart($failedTimes)." times";
$msg.=" on ".implode_smart($problemSizes)." nodes";
$msg.="{$this->appKerShortname} was $verb ". $this->implodeSmart($failedTimes)." times";
$msg.=" on ". $this->implodeSmart($problemSizes)." nodes";
if($count>1)$msg.=" respectively";
$msg.=" during last ".number_format($days,0)." days";

Expand Down Expand Up @@ -187,8 +210,8 @@ public function detect(){
if($count>0){
$daysR=$daysR/$count;

$msg.="{$this->appKerShortname} was $verb ".implode_smart($failedPercentage)."%";
$msg.=" on ".implode_smart($problemSizes)." nodes";
$msg.="{$this->appKerShortname} was $verb ". $this->implodeSmart($failedPercentage)."%";
$msg.=" on ". $this->implodeSmart($problemSizes)." nodes";
$msg.=" during last ".number_format($daysR,0)." days";
if($count>1)$msg.=" respectively";

Expand Down
100 changes: 94 additions & 6 deletions classes/Rest/Controllers/AppKernelControllerProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,94 @@ class AppKernelControllerProvider extends BaseControllerProvider

const DEFAULT_DELIM=',';

/**
* Format NotificationSettings from client form submittion
*
* @param array $s the input array.
* @param bool $preserveCheckBoxes ?
*
* @return null
*/
public static function formatNotificationSettingsFromClient(&$s, $preserveCheckBoxes = false)
{
//set report periodisity
$groupCombine=array('daily_report','weekly_report','monthly_report');

foreach ($groupCombine as $g) {
$s[$g]=array();
foreach ($s as $key => $value) {
if (strpos($key, $g.'_') === 0) {
$s[$g][str_replace($g.'_', '', $key)]=$value;
unset($s[$key]);
}
}
}
//make list of resources and appkernels
$s['resource']=array();
$s['appKer']=array();
foreach ($s as $key => $value) {
if (strpos($key, 'resourcesList_') === 0) {
$s['resource'][]=str_replace('resourcesList_', '', $key);
if ($preserveCheckBoxes) {
$s[$key]='';
} else {
unset($s[$key]);
}
}
if (strpos($key, 'appkernelsList_') === 0) {
$s['appKer'][]=str_replace('appkernelsList_', '', $key);
if ($preserveCheckBoxes) {
$s[$key]='';
} else {
unset($s[$key]);
}
}
}

if (count($s['resource'])==1 && $s['resource'][0]=='all') {
$s["resource"]=array();//None means all
}
if (count($s['appKer'])==1 && $s['appKer'][0]=='all') {
$s["appKer"]=array();//None means all
}
}

/**
* Format NotificationSettings for client
*
* @param array $s the input array
*
* @return null
*/
public static function formatNotificationSettingsForClient(&$s)
{
//make list of resources and appkernels
if (count($s['resource'])==0) {
$s["resource"]=array('all');//None means all
}
if (count($s['appKer'])==0) {
$s["appKer"]=array('all');//None means all
}
foreach ($s['resource'] as $value) {
$s['resourcesList_'.$value]='on';
}
foreach ($s['appKer'] as $value) {
$s['appkernelsList_'.$value]='on';
}

unset($s['resource']);
unset($s['appKer']);

$groupCombine=array('daily_report','weekly_report','monthly_report');

foreach ($groupCombine as $g) {
foreach ($s[$g] as $key => $value) {
$s[$g.'_'.$key]=$value;
}
unset($s[$g]);
}
}

/**
* @see BaseControllerProvider::setupRoutes
*/
Expand Down Expand Up @@ -737,7 +825,7 @@ public function getNotifications(Request $request, Application $app)

$user_id = $this->getUserFromRequest($request)->getUserID();

formatNotificationSettingsFromClient($curent_tmp_settings, true);
self::formatNotificationSettingsFromClient($curent_tmp_settings, true);

$sqlres = $pdo->query(
'SELECT user_id,send_report_daily,send_report_weekly,send_report_monthly,settings
Expand All @@ -755,7 +843,7 @@ public function getNotifications(Request $request, Application $app)
} else {
throw new Exception('settings is not set in db use default');
}
formatNotificationSettingsForClient($curent_tmp_settings);
self::formatNotificationSettingsForClient($curent_tmp_settings);
$response['data'] = $curent_tmp_settings;
$response['success'] = true;
return $app->json($response);
Expand All @@ -781,7 +869,7 @@ public function putNotifications(Request $request, Application $app)

$user_id = $this->getUserFromRequest($request)->getUserID();

formatNotificationSettingsFromClient($curent_tmp_settings);
self::formatNotificationSettingsFromClient($curent_tmp_settings);

$send_report_daily = ($curent_tmp_settings['daily_report']['send_on_event'] === 'sendNever') ? (0) : (1);
$send_report_weekly = ($curent_tmp_settings['weekly_report']['send_on_event'] === 'sendNever') ? (-$curent_tmp_settings['weekly_report']['send_on']) : ($curent_tmp_settings['weekly_report']['send_on']);
Expand Down Expand Up @@ -846,13 +934,13 @@ public function getDefaultNotifications(Request $request, Application $app)
$curent_tmp_settings = $this->getStringParam($request, 'curent_tmp_settings', true);
$curent_tmp_settings = json_decode($curent_tmp_settings, true);

formatNotificationSettingsFromClient($curent_tmp_settings, true);
self::formatNotificationSettingsFromClient($curent_tmp_settings, true);

$curent_tmp_settings["controlThresholdCoeff"] = '1.0';
$curent_tmp_settings["resource"] = array();//None means all
$curent_tmp_settings["appKer"] = array();//None means all

formatNotificationSettingsForClient($curent_tmp_settings);
self::formatNotificationSettingsForClient($curent_tmp_settings);

$response['data'] = $curent_tmp_settings;
$response['success'] = true;
Expand Down Expand Up @@ -998,7 +1086,7 @@ public function sendNotification(Request $request, Application $app)
$report_param = $this->getStringParam($request, 'report_param', true);
$report_param = json_decode($report_param, true);

formatNotificationSettingsFromClient($report_param);
self::formatNotificationSettingsFromClient($report_param);

$report = new Report(array(
'start_date' => $start_date,
Expand Down
3 changes: 2 additions & 1 deletion configuration/linker.d/appkernels.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"+include_dirs": [
"classes/AppKernel"
"classes/AppKernel",
"classes"
]
}
3 changes: 2 additions & 1 deletion html/controllers/arr/send_report.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
require_once dirname(__FILE__).'/../../../configuration/linker.php';

use CCR\DB;
use Rest\Controllers;

@session_start();

Expand Down Expand Up @@ -49,7 +50,7 @@
$end_date = new DateTime($_REQUEST['end_date']);

$report_param=json_decode($_REQUEST['report_param'],true);
formatNotificationSettingsFromClient($report_param);
AppKernelControllerProvider::formatNotificationSettingsFromClient($report_param);
//print_r($report_param);
//throw new Exception(print_r($report_param,true));

Expand Down
11 changes: 6 additions & 5 deletions html/controllers/arr/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
require_once dirname(__FILE__).'/../../../configuration/linker.php';

use CCR\DB;
use Rest\Controllers;

@session_start();

Expand Down Expand Up @@ -102,7 +103,7 @@
case 'save_notification_settings' :
try{
$curent_tmp_settings=json_decode($_REQUEST['curent_tmp_settings'],true);
formatNotificationSettingsFromClient($curent_tmp_settings);
AppKernelControllerProvider::formatNotificationSettingsFromClient($curent_tmp_settings);

$send_report_daily=($curent_tmp_settings['daily_report']['send_on_event']==='sendNever')?(0):(1);
$send_report_weekly=($curent_tmp_settings['weekly_report']['send_on_event']==='sendNever')?(-$curent_tmp_settings['weekly_report']['send_on']):($curent_tmp_settings['weekly_report']['send_on']);
Expand Down Expand Up @@ -154,7 +155,7 @@
else
throw new Exception('curent_tmp_settings is not set');

formatNotificationSettingsFromClient($curent_tmp_settings,true);
AppKernelControllerProvider::formatNotificationSettingsFromClient($curent_tmp_settings,true);

$sqlres=$pdo->query('SELECT user_id,send_report_daily,send_report_weekly,send_report_monthly,settings
FROM mod_appkernel.report
Expand All @@ -171,7 +172,7 @@
else{
throw new Exception('settings is not set in db use default');
}
formatNotificationSettingsForClient($curent_tmp_settings);
AppKernelControllerProvider::formatNotificationSettingsForClient($curent_tmp_settings);
$response['data'] = $curent_tmp_settings;
$response['success'] = true;
echo json_encode($response);
Expand All @@ -187,12 +188,12 @@
else
throw new Exception('curent_tmp_settings is not set in templates');

formatNotificationSettingsFromClient($curent_tmp_settings,true);
AppKernelControllerProvider::formatNotificationSettingsFromClient($curent_tmp_settings,true);

$curent_tmp_settings["controlThresholdCoeff"]='1.0';
$curent_tmp_settings["resourcesList"]=array();//None means all
$curent_tmp_settings["appkernelsList"]=array();//None means all
formatNotificationSettingsForClient($curent_tmp_settings);
AppKernelControllerProvider::formatNotificationSettingsForClient($curent_tmp_settings);
$response['data'] = $curent_tmp_settings;
$response['success'] = true;
}
Expand Down
Loading

0 comments on commit 8142d2d

Please sign in to comment.