diff --git a/application/models/Measure.php b/application/models/Measure.php index b70d10a5..75484184 100644 --- a/application/models/Measure.php +++ b/application/models/Measure.php @@ -78,7 +78,26 @@ public function computeAccuracy($watchMeasure) { { $userDelta = $watchMeasure->accuracyUserTime-$watchMeasure->measureUserTime; $refDelta = $watchMeasure->accuracyReferenceTime-$watchMeasure->measureReferenceTime; - $accuracy = ($userDelta*86400/$refDelta)-86400; + + /* + Until 1.3.0, users were asked to enter the time + displayed on their timepiece after a 5 secs countdown. + + Since 1.3.0 users are asked to click when their Watch + display a given time. This reverses the accuracy formulae... + + This side effect of the new measure system (https:github.com/MathieuNls/tw/issues/58) + was reported (#136 and #137) and ignored on the basis that the test harness would have caught it. + + The following testes if the measure was taken before 1.3 - 15 fev 2016 (epoch 1455537600) (commit d861c8e436b5ea8909cd1949f86fd20a14b272b4) and adapts the formulae. + */ + if($watchMeasure->accuracyReferenceTime < 1455537600){ + + $accuracy = ($userDelta*86400/$refDelta)-86400; + }else{ + $accuracy = ($refDelta*86400/$userDelta)-86400; + } + $accuracy = sprintf("%.1f", $accuracy); $watchMeasure->accuracy = $accuracy; diff --git a/application/tests/models/Measure_test.php b/application/tests/models/Measure_test.php index 12fac272..12bddd50 100644 --- a/application/tests/models/Measure_test.php +++ b/application/tests/models/Measure_test.php @@ -5,6 +5,7 @@ class Measure_test extends TestCase { private static $userId; private static $watchId; private static $watchId2; + private static $watchId3; private static $measureId; private static $watch; private static $watchMeasure; @@ -36,7 +37,7 @@ public static function setUpBeforeClass() { self::$watchId = $CI->Watch->addWatch( self::$userId, 'brand', - 'name', + 'name1', 2015, 28, 014 @@ -45,7 +46,16 @@ public static function setUpBeforeClass() { self::$watchId2 = $CI->Watch->addWatch( self::$userId, 'brand', - 'name', + 'name2', + 2015, + 28, + 014 + ); + + self::$watchId3 = $CI->Watch->addWatch( + self::$userId, + 'brand', + 'name3', 2015, 28, 014 @@ -155,7 +165,8 @@ public function test_getMeasuresByUser2() { mesure : 20:52:30 start countdown : 20:52:30 (+3 days) mesure : 20:52:36 - spd : +2 sec per day + spd : -2 sec per day + @before 1.3 */ public function test_addBaseMesure1() { @@ -209,6 +220,7 @@ public function test_getMeasuresByUser4() { start countdown : 17:30:20 (+1.5 days) mesure : 17:31:26 spd : +4 sec per day + @before 1.3 */ public function test_addBaseMesure2() { @@ -233,6 +245,37 @@ public function test_addAccuracyMesure2() { $this->assertEquals(2, $watchMeasure->statusId); } + /* + start countdown : 09:08:01 + mesure : 09:08:01 + start countdown : 09:08:00 (+1 day) + mesure : 09:07:55 + spd : +5 sec per day + @after 1.3 + */ + public function test_addBaseMesure3() { + + self::$measureId = $this->obj->addBaseMesure( + self::$watchId3, + 1458634081, + 1458634081 + ); + + $this->assertEquals(true, is_numeric(self::$measureId)); + } + + public function test_addAccuracyMesure3() { + $watchMeasure = $this->obj->addAccuracyMesure( + self::$measureId, + 1458720480, + 1458720475 + ); + + $this->assertEquals(self::$watchId3, $watchMeasure->watchId); + $this->assertEquals(5.0, $watchMeasure->accuracy, 'it should be 5.0'); + $this->assertEquals(2, $watchMeasure->statusId); + } + public function test_getMeasuresByUser6() { $measures = $this->obj->getMeasuresByUser( @@ -292,25 +335,25 @@ public function test_deleteMeasure() { public function test_getMeasuresCountByWatchBrand() { $count = $this->obj->getMeasuresCountByWatchBrand('brand'); - $this->assertEquals(7, $count); + $this->assertEquals(8, $count); } public function test_computePercentileAccuracy(){ - $this->assertEquals(67, $this->obj->computePercentileAccuracy(1.5)); + $this->assertEquals(75, $this->obj->computePercentileAccuracy(1.5)); $this->assertEquals(0, $this->obj->computePercentileAccuracy(7)); } - public static function tearDownAfterClass() { - $CI = &get_instance(); - $CI->load->model('User'); - $CI->load->model('Watch'); - $CI->load->model('Measure'); - $CI->watch->delete_where(array("watchId >=" => "0")); - $CI->User->delete_where(array("userId >=" => "0")); - $CI->Measure->delete_where(array("id >=" => "0")); - } + // public static function tearDownAfterClass() { + // $CI = &get_instance(); + // $CI->load->model('User'); + // $CI->load->model('Watch'); + // $CI->load->model('Measure'); + // $CI->watch->delete_where(array("watchId >=" => "0")); + // $CI->User->delete_where(array("userId >=" => "0")); + // $CI->Measure->delete_where(array("id >=" => "0")); + // } }