Project

General

Profile

Revision dd80884c

IDdd80884c1222c5f71d9d9e358704c265e20c8a3d
Parent 0e1b6929
Child 8726bde3

Added by Andreas Kohlbecker 7 months ago

ref #8771 finetuning of statistical values display and more tests

View differences:

modules/cdm_dataportal/includes/common.inc
310 310
  $other_vals_array = [];
311 311

  
312 312
  // --- sanitize values
313
  if(statistical_values_equals($stat_vals_arr, 'Min', 'TypicalLowerBoundary')){
313
  if(statistical_values_num_equals($stat_vals_arr, 'Min', 'TypicalLowerBoundary')){
314 314
    $stat_vals_arr['Min'] = NULL;
315 315
  }
316 316

  
317
  if(statistical_values_equals($stat_vals_arr, 'Max', 'TypicalUpperBoundary')){
317
  if(statistical_values_num_equals($stat_vals_arr, 'Max', 'TypicalUpperBoundary')){
318 318
    $stat_vals_arr['Max'] = NULL;
319 319
  }
320 320

  
......
328 328
    $stat_vals_arr['Max'] = NULL;
329 329
  }
330 330

  
331
  if (statistical_values_equals($stat_vals_arr, 'TypicalUpperBoundary', 'TypicalLowerBoundary')) {
331
  if (statistical_values_num_equals($stat_vals_arr, 'TypicalUpperBoundary', 'TypicalLowerBoundary')) {
332 332
    $stat_vals_arr['Average'] = $stat_vals_arr['TypicalUpperBoundary'];
333 333
    $stat_vals_arr['TypicalLowerBoundary'] = NULL;
334 334
    $stat_vals_arr['TypicalUpperBoundary'] = NULL;
......
344 344
    $stat_vals_arr['TypicalUpperBoundary'] = '?';
345 345
  }
346 346

  
347
  if($stat_vals_arr['Average'] && $stat_vals_arr['TypicalUpperBoundary'] !== null && $stat_vals_arr['TypicalLowerBoundary'] !== null) {
347
  if($stat_vals_arr['Average'] && $stat_vals_arr['TypicalUpperBoundary'] !== null && is_numeric($stat_vals_arr['TypicalUpperBoundary']) && $stat_vals_arr['TypicalLowerBoundary'] !== null && is_numeric($stat_vals_arr['TypicalLowerBoundary'] !== null)) {
348 348
    statistical_values_adjust_significant_figures($stat_vals_arr['Average'], $stat_vals_arr['TypicalLowerBoundary'], $stat_vals_arr['TypicalUpperBoundary']);
349 349
  }
350 350

  
......
353 353
    if ($statistical_val !== NULL) {
354 354
      if ($statistical_val == '?') {
355 355
        $val_markup = $statistical_val;
356
      } else {
357
        $val_markup = '<span class="'
356
      }
357
      else {
358
        if (is_numeric($statistical_val->_value)) {
359
          $val_markup = '<span class="'
358 360
            . html_class_attribute_ref($statistical_val) . ' '
359
            . (isset($statistical_val->type) ? $statistical_val->type->termType : '') . ' ' . $key .'" title="'. $key. '">'
361
            . (isset($statistical_val->type) ? $statistical_val->type->termType : '') . ' ' . $key . '" title="' . $key . '">'
360 362
            . $statistical_val->_value . '</span>';
363

  
364
        }
365
        else {
366
          $val_markup = NULL;
367
        }
361 368
      }
362 369

  
363
      switch ($key) {
364
        // ---- min_max_element
365
        case 'Min':
366
          $min_max_markup .= "($val_markup&ndash;)";
367
          break;
368
        case 'Max':
369
          $min_max_markup .= "(&ndash;$val_markup)";
370
          break;
371
        case 'TypicalLowerBoundary':
372
          $min_max_markup .= "$val_markup";
373
          break;
374
        case 'TypicalUpperBoundary':
375
          $min_max_markup .= "&ndash;$val_markup";
376
          break;
370
      if ($val_markup) {
371
        switch ($key) {
372
          // ---- min_max_element
373
          case 'Min':
374
            $min_max_markup .= "($val_markup&ndash;)";
375
            break;
376
          case 'Max':
377
            $min_max_markup .= "(&ndash;$val_markup)";
378
            break;
379
          case 'TypicalLowerBoundary':
380
            $min_max_markup .= "$val_markup";
381
            break;
382
          case 'TypicalUpperBoundary':
383
            $min_max_markup .= "&ndash;$val_markup";
384
            break;
377 385
          // ---- other values
378
        case 'SampleSize':
379
          $other_vals_array[$key] = $val_markup;
380
          break;
381
        case 'Average':
382
          $other_vals_array[$key] = $xbar_equals . $val_markup;
383
          break;
384
        case 'Variance':
385
          $other_vals_array[$key] = 'σ²=' . $val_markup;
386
          break;
387
        case 'StandardDeviation':
388
          $other_vals_array[$key] = 'σ=' . $val_markup;
389
          break;
386
          case 'SampleSize':
387
            $other_vals_array[$key] = $val_markup;
388
            break;
389
          case 'Average':
390
            $other_vals_array[$key] = $xbar_equals . $val_markup;
391
            break;
392
          case 'Variance':
393
            $other_vals_array[$key] = 'σ²=' . $val_markup;
394
            break;
395
          case 'StandardDeviation':
396
            $other_vals_array[$key] = 'σ=' . $val_markup;
397
            break;
398
        }
390 399
      }
391 400
    }
392 401
  }
......
394 403
  if(!$min_max_markup && !empty($other_vals_array['Average'])){
395 404
    // this could be the case in which we only have one value for Average
396 405
    // this trivial case needs to be displayed a simpler way
397
    $min_max_markup = str_replace($xbar_equals, '' ,$other_vals_array['Average']);
398
    if($other_vals_array['SampleSize']){
399
      $min_max_markup .= '['. $other_vals_array['SampleSize'] .']';
400
    }
406
    $min_max_markup = str_replace($xbar_equals, '' , $other_vals_array['Average']);
407
    unset($other_vals_array['Average']);
408
    $min_max_markup .= '[' . join(';', $other_vals_array) . ']';
401 409
  } else {
402 410
    if(count($other_vals_array)){
403 411
      $min_max_markup .= '[' . join(';', $other_vals_array) . ']';
......
461 469

  
462 470

  
463 471
/**
464
 * Used internally in statistical_values() do determine equality of stat_vals_arr values
472
 * Used internally in statistical_values() do determine numerically equality of stat_vals_arr values
465 473
 *
466 474
 * @param $stat_vals_arr
467 475
 * @param $key1
......
469 477
 *
470 478
 * @return bool
471 479
 */
472
function statistical_values_equals($stat_vals_arr, $key1, $key2){
480
function statistical_values_num_equals($stat_vals_arr, $key1, $key2){
473 481

  
474
  return $stat_vals_arr[$key1] !== NULL && $stat_vals_arr[$key2] !== NULL && $stat_vals_arr[$key1]->_value ==  $stat_vals_arr[$key2]->_value;
482
  return $stat_vals_arr[$key1] !== NULL && $stat_vals_arr[$key2] !== NULL && $stat_vals_arr[$key1]->_value == $stat_vals_arr[$key2]->_value && is_numeric($stat_vals_arr[$key1]->_value);
475 483
}
476 484

  
477 485
/**

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)