Skip to content

Commit 8142d2d

Browse files
jpwhite4xdmod
andauthored
Move non-namespaced library functions into classes. (#89)
* 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 <ccr-xdmod-help@buffalo.edu>
1 parent 949f2c0 commit 8142d2d

File tree

8 files changed

+132
-143
lines changed

8 files changed

+132
-143
lines changed

build.json

-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
"appkernel",
2323
"classes",
2424
"html",
25-
"libraries",
2625
{ "templates": "templates/appkernels" }
2726
],
2827
"bin": [

classes/AppKernel/PerformanceMap.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -665,7 +665,7 @@ function ($value) use ($arr_db) {
665665
$problemSize = end(explode('.', $row['reporternickname']));
666666
$collected = $row['collected'];
667667

668-
$resource_id = arrayValue($resource, $this->resource_ids);
668+
$resource_id = array_key_exists($resource, $this->resource_ids) ? $this->resource_ids[$resource] : null;
669669
$ak_id = null;
670670
if (array_key_exists($appKer, $ak_ids) && array_key_exists($problemSize, $ak_ids[$appKer])) {
671671
$ak_id = $ak_ids[$appKer][$problemSize];

classes/AppKernel/ProblemDetector/AppKernelLevel.php

+27-4
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,29 @@ public function __construct($runStatsAppKernel,$runStatsProblemSize,$appKerShort
2929
$this->appKerShortname=$appKerShortname;
3030
}
3131

32+
/**
33+
* Format an array as a human readable string.
34+
*
35+
* @param array $a the input array
36+
*
37+
* @return string
38+
*/
39+
private function implodeSmart($a)
40+
{
41+
$s="";
42+
for ($i=0; $i<count($a); $i++) {
43+
$s.=$a[$i];
44+
if ($i<count($a)-1) {
45+
if ($i==count($a)-2) {
46+
$s.=' and ';
47+
} else {
48+
$s.=', ';
49+
}
50+
}
51+
}
52+
return $s;
53+
}
54+
3255
public function detect(){
3356
$max_days=max(array_keys($this->runStatsAppKernel->NE));
3457
$all_problems=array();
@@ -106,8 +129,8 @@ public function detect(){
106129
}
107130
if($count>0){
108131
$days=$days/$count;
109-
$msg.="{$this->appKerShortname} was $verb ".implode_smart($failedTimes)." times";
110-
$msg.=" on ".implode_smart($problemSizes)." nodes";
132+
$msg.="{$this->appKerShortname} was $verb ". $this->implodeSmart($failedTimes)." times";
133+
$msg.=" on ". $this->implodeSmart($problemSizes)." nodes";
111134
if($count>1)$msg.=" respectively";
112135
$msg.=" during last ".number_format($days,0)." days";
113136

@@ -187,8 +210,8 @@ public function detect(){
187210
if($count>0){
188211
$daysR=$daysR/$count;
189212

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

classes/Rest/Controllers/AppKernelControllerProvider.php

+94-6
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,94 @@ class AppKernelControllerProvider extends BaseControllerProvider
3434

3535
const DEFAULT_DELIM=',';
3636

37+
/**
38+
* Format NotificationSettings from client form submittion
39+
*
40+
* @param array $s the input array.
41+
* @param bool $preserveCheckBoxes ?
42+
*
43+
* @return null
44+
*/
45+
public static function formatNotificationSettingsFromClient(&$s, $preserveCheckBoxes = false)
46+
{
47+
//set report periodisity
48+
$groupCombine=array('daily_report','weekly_report','monthly_report');
49+
50+
foreach ($groupCombine as $g) {
51+
$s[$g]=array();
52+
foreach ($s as $key => $value) {
53+
if (strpos($key, $g.'_') === 0) {
54+
$s[$g][str_replace($g.'_', '', $key)]=$value;
55+
unset($s[$key]);
56+
}
57+
}
58+
}
59+
//make list of resources and appkernels
60+
$s['resource']=array();
61+
$s['appKer']=array();
62+
foreach ($s as $key => $value) {
63+
if (strpos($key, 'resourcesList_') === 0) {
64+
$s['resource'][]=str_replace('resourcesList_', '', $key);
65+
if ($preserveCheckBoxes) {
66+
$s[$key]='';
67+
} else {
68+
unset($s[$key]);
69+
}
70+
}
71+
if (strpos($key, 'appkernelsList_') === 0) {
72+
$s['appKer'][]=str_replace('appkernelsList_', '', $key);
73+
if ($preserveCheckBoxes) {
74+
$s[$key]='';
75+
} else {
76+
unset($s[$key]);
77+
}
78+
}
79+
}
80+
81+
if (count($s['resource'])==1 && $s['resource'][0]=='all') {
82+
$s["resource"]=array();//None means all
83+
}
84+
if (count($s['appKer'])==1 && $s['appKer'][0]=='all') {
85+
$s["appKer"]=array();//None means all
86+
}
87+
}
88+
89+
/**
90+
* Format NotificationSettings for client
91+
*
92+
* @param array $s the input array
93+
*
94+
* @return null
95+
*/
96+
public static function formatNotificationSettingsForClient(&$s)
97+
{
98+
//make list of resources and appkernels
99+
if (count($s['resource'])==0) {
100+
$s["resource"]=array('all');//None means all
101+
}
102+
if (count($s['appKer'])==0) {
103+
$s["appKer"]=array('all');//None means all
104+
}
105+
foreach ($s['resource'] as $value) {
106+
$s['resourcesList_'.$value]='on';
107+
}
108+
foreach ($s['appKer'] as $value) {
109+
$s['appkernelsList_'.$value]='on';
110+
}
111+
112+
unset($s['resource']);
113+
unset($s['appKer']);
114+
115+
$groupCombine=array('daily_report','weekly_report','monthly_report');
116+
117+
foreach ($groupCombine as $g) {
118+
foreach ($s[$g] as $key => $value) {
119+
$s[$g.'_'.$key]=$value;
120+
}
121+
unset($s[$g]);
122+
}
123+
}
124+
37125
/**
38126
* @see BaseControllerProvider::setupRoutes
39127
*/
@@ -737,7 +825,7 @@ public function getNotifications(Request $request, Application $app)
737825

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

740-
formatNotificationSettingsFromClient($curent_tmp_settings, true);
828+
self::formatNotificationSettingsFromClient($curent_tmp_settings, true);
741829

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

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

784-
formatNotificationSettingsFromClient($curent_tmp_settings);
872+
self::formatNotificationSettingsFromClient($curent_tmp_settings);
785873

786874
$send_report_daily = ($curent_tmp_settings['daily_report']['send_on_event'] === 'sendNever') ? (0) : (1);
787875
$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']);
@@ -846,13 +934,13 @@ public function getDefaultNotifications(Request $request, Application $app)
846934
$curent_tmp_settings = $this->getStringParam($request, 'curent_tmp_settings', true);
847935
$curent_tmp_settings = json_decode($curent_tmp_settings, true);
848936

849-
formatNotificationSettingsFromClient($curent_tmp_settings, true);
937+
self::formatNotificationSettingsFromClient($curent_tmp_settings, true);
850938

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

855-
formatNotificationSettingsForClient($curent_tmp_settings);
943+
self::formatNotificationSettingsForClient($curent_tmp_settings);
856944

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

1001-
formatNotificationSettingsFromClient($report_param);
1089+
self::formatNotificationSettingsFromClient($report_param);
10021090

10031091
$report = new Report(array(
10041092
'start_date' => $start_date,
+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"+include_dirs": [
3-
"classes/AppKernel"
3+
"classes/AppKernel",
4+
"classes"
45
]
56
}

html/controllers/arr/send_report.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
require_once dirname(__FILE__).'/../../../configuration/linker.php';
44

55
use CCR\DB;
6+
use Rest\Controllers;
67

78
@session_start();
89

@@ -49,7 +50,7 @@
4950
$end_date = new DateTime($_REQUEST['end_date']);
5051

5152
$report_param=json_decode($_REQUEST['report_param'],true);
52-
formatNotificationSettingsFromClient($report_param);
53+
AppKernelControllerProvider::formatNotificationSettingsFromClient($report_param);
5354
//print_r($report_param);
5455
//throw new Exception(print_r($report_param,true));
5556

html/controllers/arr/settings.php

+6-5
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
require_once dirname(__FILE__).'/../../../configuration/linker.php';
44

55
use CCR\DB;
6+
use Rest\Controllers;
67

78
@session_start();
89

@@ -102,7 +103,7 @@
102103
case 'save_notification_settings' :
103104
try{
104105
$curent_tmp_settings=json_decode($_REQUEST['curent_tmp_settings'],true);
105-
formatNotificationSettingsFromClient($curent_tmp_settings);
106+
AppKernelControllerProvider::formatNotificationSettingsFromClient($curent_tmp_settings);
106107

107108
$send_report_daily=($curent_tmp_settings['daily_report']['send_on_event']==='sendNever')?(0):(1);
108109
$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']);
@@ -154,7 +155,7 @@
154155
else
155156
throw new Exception('curent_tmp_settings is not set');
156157

157-
formatNotificationSettingsFromClient($curent_tmp_settings,true);
158+
AppKernelControllerProvider::formatNotificationSettingsFromClient($curent_tmp_settings,true);
158159

159160
$sqlres=$pdo->query('SELECT user_id,send_report_daily,send_report_weekly,send_report_monthly,settings
160161
FROM mod_appkernel.report
@@ -171,7 +172,7 @@
171172
else{
172173
throw new Exception('settings is not set in db use default');
173174
}
174-
formatNotificationSettingsForClient($curent_tmp_settings);
175+
AppKernelControllerProvider::formatNotificationSettingsForClient($curent_tmp_settings);
175176
$response['data'] = $curent_tmp_settings;
176177
$response['success'] = true;
177178
echo json_encode($response);
@@ -187,12 +188,12 @@
187188
else
188189
throw new Exception('curent_tmp_settings is not set in templates');
189190

190-
formatNotificationSettingsFromClient($curent_tmp_settings,true);
191+
AppKernelControllerProvider::formatNotificationSettingsFromClient($curent_tmp_settings,true);
191192

192193
$curent_tmp_settings["controlThresholdCoeff"]='1.0';
193194
$curent_tmp_settings["resourcesList"]=array();//None means all
194195
$curent_tmp_settings["appkernelsList"]=array();//None means all
195-
formatNotificationSettingsForClient($curent_tmp_settings);
196+
AppKernelControllerProvider::formatNotificationSettingsForClient($curent_tmp_settings);
196197
$response['data'] = $curent_tmp_settings;
197198
$response['success'] = true;
198199
}

0 commit comments

Comments
 (0)