diff --git a/application/controllers/Measures.php b/application/controllers/Measures.php index 8f113fb1..415be618 100644 --- a/application/controllers/Measures.php +++ b/application/controllers/Measures.php @@ -280,12 +280,12 @@ function accuracyMeasure() { $watchMeasure = $this->measure->addAccuracyMesure( $this->input->post('measureId'), $referenceTime, $userTime); - //We store the computed accuracy - $result['accuracy'] = $watchMeasure->accuracy; - // If the computed accuracy makes sense, we return success if (is_numeric($watchMeasure->accuracy)) { $result['success'] = true; + //We store the computed accuracy & percentile + $result['accuracy'] = $watchMeasure->accuracy; + $result['percentile'] = $watchMeasure->percentile; } else { $result['success'] = false; } diff --git a/application/models/Measure.php b/application/models/Measure.php index b184715e..75defcc5 100644 --- a/application/models/Measure.php +++ b/application/models/Measure.php @@ -102,6 +102,31 @@ public function computeAccuracy($watchMeasure) { return $watchMeasure; } + /** + * Computes the percentile for an accuracy, i.e, the percentage + * of watches that are less accurate than $accuracy. + * + * The percentile excludes bugged measure (+/- 300 spd) + * + * @param float $accuracy A complete measure with computed + * @return int the percentile for this accuracy. + */ + function computePercentileAccuracy($accuracy){ + + //This have to be kept in line with the computeAccuracy method + $precisionFormulae = 'ABS(((measure.accuracyUserTime + - measure.measureUserTime)*86400)/ + (measure.accuracyReferenceTime - measure.measureReferenceTime) + -86400)'; + + $moreAccurateCount = $this->count_by($precisionFormulae . ' <', + abs($accuracy)); + + $valideMeasuresCount = $this->count_by($precisionFormulae . ' <', 300); + + return round(100 - (($moreAccurateCount / $valideMeasuresCount) * 100)); + } + /** * Add a base measure (1/2) to $watchId given $referenceTime and $userTime * @@ -155,6 +180,9 @@ function addAccuracyMesure($measureId, $referenceTime, $userTime) { $this->notify(NEW_ACCURACY, array('measure' => $watchMeasure)); + $watchMeasure->percentile = + $this->computePercentileAccuracy($watchMeasure->accuracy); + return $watchMeasure; } diff --git a/application/tests/models/Measure_test.php b/application/tests/models/Measure_test.php index b2b44670..2b8365f7 100644 --- a/application/tests/models/Measure_test.php +++ b/application/tests/models/Measure_test.php @@ -262,6 +262,13 @@ public function test_getMeasuresCountByWatchBrand() { $this->assertEquals(6, $count); } + public function test_computePercentileAccuracy(){ + + $this->assertEquals(67, $this->obj->computePercentileAccuracy(1.5)); + $this->assertEquals(0, $this->obj->computePercentileAccuracy(7)); + + } + } ?> diff --git a/application/views/measure/get-accuracy.php b/application/views/measure/get-accuracy.php index a9848730..947f5f3c 100644 --- a/application/views/measure/get-accuracy.php +++ b/application/views/measure/get-accuracy.php @@ -8,7 +8,7 @@
- +
At the end of the countdown, please enter below the exact time as it is on your watch.
Let's check the accuracy of your watch! @@ -43,43 +43,44 @@
-
@@ -97,4 +98,4 @@
- \ No newline at end of file + diff --git a/assets/js/application.js b/assets/js/application.js index eefdf199..5db3894c 100644 --- a/assets/js/application.js +++ b/assets/js/application.js @@ -308,10 +308,11 @@ $(document).ready(function() } $('.watch-accuracy').html(result.accuracy); + $('.watch-percentile').html(result.percentile); $('.share-button').each(function(index){ - $(this).attr("data-text", $(this).attr("data-text").replace("{WatchAccuracy}", result.accuracy)); + $(this).attr("data-text", $(this).attr("data-text").replace("{WatchPercentile}", result.percentile)); }); initShareButton(); diff --git a/assets/js/jquery.sharrre.min.js b/assets/js/jquery.sharrre.min.js index 50b5cf2a..71cf26fe 100644 --- a/assets/js/jquery.sharrre.min.js +++ b/assets/js/jquery.sharrre.min.js @@ -104,8 +104,8 @@ facebook: "https://graph.facebook.com/fql?q=SELECT%20url,%20normalized_url,%20share_count,%20like_count,%20comment_count,%20total_count,commentsbox_count,%20comments_fbid,%20click_count%20FROM%20link_stat%20WHERE%20url=%27{url}%27&callback=?", //old method facebook: "http://graph.facebook.com/?id={url}&callback=?", //facebook : "http://api.ak.facebook.com/restserver.php?v=1.0&method=links.getStats&urls={url}&format=json" - - twitter: "http://cdn.api.twitter.com/1/urls/count.json?url={url}&callback=?", + + twitter: "http://opensharecount.com/count.json?url={url}", digg: "http://services.digg.com/2.0/story.getInfo?links={url}&type=javascript&callback=?", delicious: 'http://feeds.delicious.com/v2/json/urlinfo/data?url={url}&callback=?', //stumbleupon: "http://www.stumbleupon.com/services/1.01/badge.getinfo?url={url}&format=jsonp&callback=?", @@ -208,7 +208,7 @@ '
'+count+'
'+ '
'+ 'Delicious Add
'); - + $(self.element).find('.delicious').on('click', function(){ self.openPopup('delicious'); }); @@ -221,7 +221,7 @@ loading = 1; (function() { var li = document.createElement('script');li.type = 'text/javascript';li.async = true; - li.src = '//platform.stumbleupon.com/1/widgets.js'; + li.src = '//platform.stumbleupon.com/1/widgets.js'; var s = document.getElementsByTagName('script')[0];s.parentNode.insertBefore(li, s); })(); s = window.setTimeout(function(){ @@ -243,7 +243,7 @@ loading = 1; (function() { var li = document.createElement('script');li.type = 'text/javascript';li.async = true; - li.src = '//platform.linkedin.com/in.js'; + li.src = '//platform.linkedin.com/in.js'; var s = document.getElementsByTagName('script')[0];s.parentNode.insertBefore(li, s); })(); } @@ -257,7 +257,7 @@ (function() { var li = document.createElement('script');li.type = 'text/javascript';li.async = true; - li.src = '//assets.pinterest.com/js/pinit.js'; + li.src = '//assets.pinterest.com/js/pinit.js'; var s = document.getElementsByTagName('script')[0];s.parentNode.insertBefore(li, s); })(); } @@ -349,16 +349,16 @@ ================================================== */ function Plugin( element, options ) { this.element = element; - + this.options = $.extend( true, {}, defaults, options); this.options.share = options.share; //simple solution to allow order of buttons - + this._defaults = defaults; this._name = pluginName; - + this.init(); }; - + /* Initialization method ================================================== */ Plugin.prototype.init = function () { @@ -368,7 +368,7 @@ urlJson.stumbleupon = this.options.urlCurl + '?url={url}&type=stumbleupon'; // PHP script for Stumbleupon... } $(this.element).addClass(this.options.className); //add class - + //HTML5 Custom data if(typeof $(this.element).data('title') !== 'undefined'){ this.options.title = $(this.element).attr('data-title'); @@ -379,14 +379,14 @@ if(typeof $(this.element).data('text') !== 'undefined'){ this.options.text = $(this.element).data('text'); } - + //how many social website have been selected $.each(this.options.share, function(name, val) { if(val === true){ self.options.shareTotal ++; } }); - + if(self.options.enableCounter === true){ //if for some reason you don't need counter //get count of social share that have been selected $.each(this.options.share, function(name, val) { @@ -405,7 +405,7 @@ else{ // if you want to use official button like example 3 or 5 this.loadButtons(); } - + //add hover event $(this.element).hover(function(){ //load social button if enable and 1 time @@ -416,14 +416,14 @@ }, function(){ self.options.hide(self, self.options); }); - + //click event $(this.element).click(function(){ self.options.click(self, self.options); return false; }); }; - + /* loadButtons methode ================================================== */ Plugin.prototype.loadButtons = function () { @@ -438,7 +438,7 @@ } }); }; - + /* getSocialJson methode ================================================== */ Plugin.prototype.getSocialJson = function (name) { @@ -471,7 +471,7 @@ self.rendererPerso(); //console.log(json); //debug }) - .error(function() { + .error(function() { self.options.count[name] = 0; self.rendererPerso(); }); @@ -482,7 +482,7 @@ self.rendererPerso(); } }; - + /* launch render methode ================================================== */ Plugin.prototype.rendererPerso = function () { @@ -493,7 +493,7 @@ this.options.render(this, this.options); } }; - + /* render methode ================================================== */ Plugin.prototype.renderer = function () { @@ -502,31 +502,31 @@ if(this.options.shorterTotal === true){ //format number like 1.2k or 5M total = this.shorterTotal(total); } - + if(template !== ''){ //if there is a template template = template.replace('{total}', total); $(this.element).html(template); } else{ //template by defaults $(this.element).html( - '
' + total + '' + + '
' + total + '' + (this.options.title !== '' ? '' : '') + '
' ); } }; - + /* format total numbers like 1.2k or 5M ================================================== */ Plugin.prototype.shorterTotal = function (num) { if (num >= 1e6){ num = (num / 1e6).toFixed(2) + "M" - } else if (num >= 1e3){ + } else if (num >= 1e3){ num = (num / 1e3).toFixed(1) + "k" } return num; }; - + /* Methode for open popup ================================================== */ Plugin.prototype.openPopup = function (site) { @@ -545,14 +545,14 @@ ga('send', 'event', '_trackSocial', tracking[site].site); } }; - + /* Methode for add +1 to a counter ================================================== */ Plugin.prototype.simulateClick = function () { var html = $(this.element).html(); $(this.element).html(html.replace(this.options.total, this.options.total+1)); }; - + /* Methode for add +1 to a counter ================================================== */ Plugin.prototype.update = function (url, text) { @@ -583,4 +583,4 @@ }); } }; -})(jQuery, window, document); \ No newline at end of file +})(jQuery, window, document);