Revision 2eb6acb7
ref #8786 improved display of min, max, mean and other statistical values
modules/cdm_dataportal/includes/common.inc  

215  215 
/** 
216  216 
* Creates an array suitable to be used in min_max_markup() 
217  217 
* The min max structure is suitable for being used in the context 
218 
* of GatheringEvents and StatisticalMeasures (see render_quantitative_statistics()) 

218 
* of GatheringEvents and StatisticalMeasures (see render_quantitative_statistics()). 

219 
* 

220 
* The order of the items is important for the display and must not be changed. 

219  221 
* 
220  222 
* @return array 
221  223 
*/ 
...  ...  
224  226 
$min_max = [ 
225  227 
'Min' => NULL, 
226  228 
'TypicalLowerBoundary' => NULL, 
227 
'Average' => NULL, 

228  229 
'TypicalUpperBoundary' => NULL, 
229  230 
'Max' => NULL, 
231 
'SampleSize' => NULL, 

232 
'Average' => NULL, 

230  233 
'Variance' => NULL, 
231  234 
'StandardDeviation' => NULL, 
232  235 
]; 
...  ...  
251  254 
*/ 
252  255 
function min_max_markup($min_max, $unit = '') { 
253  256  
257 
static $xbar_equals = 'x̄='; // x̄ is xbar 

258  
254  259 
$min_max_markup = ''; 
260 
$other_vals_array = []; 

255  261  
256  262 
//  sanitize values 
257  263 
if(min_max_equals($min_max, 'Min', 'TypicalLowerBoundary')){ 
...  ...  
272  278 
$min_max['Max'] = NULL; 
273  279 
} 
274  280  
275 
if (min_max_equals($min_max, 'Min', 'Max')) {


276 
$min_max['Average'] = $min_max['Min'];


277 
$min_max['Min'] = NULL;


278 
$min_max['Max'] = NULL;


281 
if (min_max_equals($min_max, 'TypicalUpperBoundary', 'TypicalLowerBoundary')) {


282 
$min_max['Average'] = $min_max['TypicalUpperBoundary'];


283 
$min_max['TypicalLowerBoundary'] = NULL;


284 
$min_max['TypicalUpperBoundary'] = NULL;


279  285 
} 
280  286  
281  287 
//  check for inconsistent cases, eg. only Max and average given 
...  ...  
289  295 
} 
290  296  
291  297 
foreach ($min_max as $key => $statistical_val) { 
298  
292  299 
if ($statistical_val !== NULL) { 
293  300 
if ($statistical_val == '?') { 
294  301 
$val_markup = $statistical_val; 
...  ...  
299  306 
. $statistical_val>_value . '</span>'; 
300  307 
} 
301  308  
302 
if (strlen($min_max_markup)) { 

303 
$min_max_markup .= '–'; 

304 
} 

305  309 
switch ($key) { 
310 
//  min_max_element 

306  311 
case 'Min': 
312 
$min_max_markup .= "($val_markup–)"; 

313 
break; 

307  314 
case 'Max': 
308 
$val_markup = "($val_markup)"; 

315 
$min_max_markup .= "(–$val_markup)"; 

316 
break; 

317 
case 'TypicalLowerBoundary': 

318 
$min_max_markup .= "$val_markup"; 

319 
break; 

320 
case 'TypicalUpperBoundary': 

321 
$min_max_markup .= "–$val_markup"; 

322 
break; 

323 
//  other values 

324 
case 'SampleSize': 

325 
$other_vals_array[$key] = $val_markup; 

326 
break; 

327 
case 'Average': 

328 
$other_vals_array[$key] = $xbar_equals . $val_markup; 

309  329 
break; 
310  330 
case 'Variance': 
311 
$val_markup = 'σ²=' . $val_markup;


331 
$other_vals_array[$key] = 'σ²=' . $val_markup;


312  332 
break; 
313  333 
case 'StandardDeviation': 
314 
$val_markup = 'σ=' . $val_markup;


334 
$other_vals_array[$key] = 'σ=' . $val_markup;


315  335 
break; 
316  336 
} 
317 
$min_max_markup .= $val_markup; 

318  337 
} 
319  338 
} 
320  339  
321  
340 
if(!$min_max_markup && $other_vals_array['Average']){ 

341 
// this could be the case in which we only have one value for Average 

342 
// this trivial case needs to be displayed a simpler way 

343 
$min_max_markup = str_replace($xbar_equals, '' ,$other_vals_array['Average']); 

344 
if($other_vals_array['SampleSize']){ 

345 
$min_max_markup .= '['. $other_vals_array['SampleSize'] .']'; 

346 
} 

347 
} else { 

348 
if(count($other_vals_array)){ 

349 
$min_max_markup .= '[' . join(';', $other_vals_array) . ']'; 

350 
} 

351 
} 

322  352  
323  353 
return $min_max_markup . ($unit ? ' ' . $unit : ''); 
324  354 
} 
Also available in: Unified diff