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
/**
modules/cdm_dataportal/test/phpUnit/src/unit/StatisticalValuesTest.php
23 23
    return $stat_val;
24 24
  }
25 25

  
26
  function create_statistical_values($typicalLowerBoundary = null, $typicalUpperrBoundary = null, $average  = null, $sampleSize = null){
26
  function create_statistical_values($typicalLowerBoundary = null, $typicalUpperrBoundary = null, $average  = null, $sampleSize = null, $variance = null, $standard_deviation = null){
27 27
    $stat_vals = statistical_values_array();
28 28
    $stat_vals['TypicalLowerBoundary'] = $this->new_statistical_value($typicalLowerBoundary);
29 29
    $stat_vals['TypicalUpperBoundary'] = $this->new_statistical_value($typicalUpperrBoundary);
30 30
    $stat_vals['SampleSize'] = $this->new_statistical_value($sampleSize);
31 31
    $stat_vals['Average'] = $this->new_statistical_value($average);
32
    if($variance){
33
      $stat_vals['Variance'] = $this->new_statistical_value($variance);
34
    }
35
    if($standard_deviation){
36
      $stat_vals['StandardDeviation'] = $this->new_statistical_value($standard_deviation);
37
    }
32 38
    return $stat_vals;
33 39
  }
34 40

  
......
36 42
    return  html_entity_decode(strip_tags($html), ENT_COMPAT, 'utf-8');
37 43
  }
38 44

  
39
  function test_statistical_values() {
45
  function test_statistical_values_significant_figures_avarage() {
40 46

  
41
    $stat_vals = $this->create_statistical_values(0.123457,  0.123456, 0.123456523847, 5);
47
    $stat_vals = $this->create_statistical_values(0.123457,  0.123456, 0.1234565345, 5);
42 48
    $this->assertEquals('0.123457–0.123456[5;x̄=0.1234565]', $this->html2text(statistical_values($stat_vals)));
43 49

  
44 50
    $stat_vals = $this->create_statistical_values(12.23,  14.2, 13.2231423, 15);
......
56 62
    $stat_vals = $this->create_statistical_values(0.00000001,  1, (1 - 0.00000001) / 2, 20);
57 63
    $this->assertEquals('1.0E-8–1[20;x̄=0.5]', $this->html2text(statistical_values($stat_vals)));
58 64

  
65
    $stat_vals = $this->create_statistical_values(22,  23, 22.5, 4);
66
    $this->assertEquals('22–23[4;x̄=22.5]', $this->html2text(statistical_values($stat_vals)));
67

  
68
    // see https://dev.e-taxonomy.eu/redmine/issues/8771#note-17
69
    $stat_vals = $this->create_statistical_values(22,  23, 22.047619, 24);
70
    $this->assertEquals('22–23[24;x̄=22]', $this->html2text(statistical_values($stat_vals)));
71
  }
72

  
73

  
74
  function test_statistical_values_no_min_max() {
75

  
76
    $stat_vals = $this->create_statistical_values(null,  null, 0.1234, 5);
77
    $this->assertEquals('0.1234[5]', $this->html2text(statistical_values($stat_vals)));
78

  
79
    // as discussed in https://dev.e-taxonomy.eu/redmine/issues/8771#note-16 variance etc should not be suppressed
80
    $stat_vals = $this->create_statistical_values(null,  null, 0.1234, 5, 0.3, 0.12);
81
    $this->assertEquals('0.1234[5;σ²=0.3;σ=0.12]', $this->html2text(statistical_values($stat_vals)));
59 82
  }
60 83

  
61 84
}
modules/cdm_dataportal/test/phpUnit/src/unit/testTest.php
1
<?php
2

  
3

  
4
use PHPUnit\Framework\TestCase;
5

  
6

  
7
/**
8
 * test to test if phpUnit is ok
9
 * @author a.kohlbecker
10
 *
11
 */
12
class TestTests extends TestCase {
13

  
14
  function test_fancymodule() {
15
    $this->assertTrue(true);
16
  }
17

  
18
}

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)