Skip to content

Commit

Permalink
Merge pull request #96 from MathieuNls/61_sharing
Browse files Browse the repository at this point in the history
New relative sharing tool (%age)
  • Loading branch information
AlphonseJr committed Jan 12, 2016
2 parents 620377c + bfa556a commit 88c13c4
Show file tree
Hide file tree
Showing 11 changed files with 76 additions and 647 deletions.
8 changes: 4 additions & 4 deletions application/controllers/Measures.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ public function get_accuracy() {
$this->event->add(ACCURACY_LOAD);

$this->_headerData['headerClass'] = 'blue';
array_push($this->_headerData['javaScripts'], "jquery.sharrre.min", "sharrre.logic", "watch.animation");
array_push($this->_headerData['javaScripts'], "watch.animation");
$this->load->view('header', $this->_headerData);

$this->_bodyData['selectedWatch'] = $this->watch->getWatch($this->input->post('watchId'));
Expand Down Expand Up @@ -285,12 +285,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;
}
Expand Down
28 changes: 28 additions & 0 deletions application/models/Measure.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -155,6 +180,9 @@ function addAccuracyMesure($measureId, $referenceTime, $userTime) {
$this->notify(NEW_ACCURACY,
array('measure' => $watchMeasure));

$watchMeasure->percentile =
$this->computePercentileAccuracy($watchMeasure->accuracy);

return $watchMeasure;
}

Expand Down
7 changes: 7 additions & 0 deletions application/tests/models/Measure_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));

}

}

?>
49 changes: 35 additions & 14 deletions application/views/measure/get-accuracy.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<div class="col-md-6 col-md-offset-3">
<form class="form-horizontal" method="post" name="newAccuracy">


<div id="mainExplanation" class="form-group">
<center>
At the end of the countdown, please enter below the exact time as it is on your watch. <br>Let's check the accuracy of your watch!
Expand Down Expand Up @@ -43,43 +43,64 @@
</div>
</div>

<div class="form-group sync-success" style="display:none; text-align: center">
<div class="form-group sync-success" style="display:none; text-align: center">

<div class="col-sm-12">

<canvas class="col-sm-4" id="canvas_animated_watch" width="250" height="250"></canvas>
<div class="col-sm-8">

<div class="col-sm-8">
<h1>Congratulations!</h1> <br/> <p class="accuracy-subtitle"> The accuracy of your <strong><span class="watch-brand"><?php echo $selectedWatch->brand;?></span></strong> is </p>
</div>
<div class="col-sm-8">
<strong><span class="watch-accuracy"></span> seconds a day!</strong>
<strong><span class="watch-accuracy"></span> seconds a day!</strong>
</div>
</div>

<div class="share-plugin col-md-offset-1 col-sm-10">
<center><p><br /><br />We are happy to have you around, help us spread the love for mechanical watches and share your accuracy on:</p></center>
<center><p><br /><br />Your watch is <b>more accurate than <span class="watch-percentile"></span>%</b> of all tested watches.</p></center>

<div class="col-sm-12">
<div class="share-button" id="twitter" data-url="<?php echo base_url() . 'result' ;?>" data-text="My #<?php echo $selectedWatch->brand;?> runs at {WatchAccuracy} spd on @toolwatchapp"></div>
<div class="share-button" id="facebook" data-url="<?php echo base_url() . 'result' ;?>" data-text="My <?php echo $selectedWatch->brand;?> runs at {WatchAccuracy} spd on https://www.facebook.com/Toolwatch"></div>
<div class="share-button" id="googleplus" data-url="<?php echo base_url() . 'result' ;?>" data-text="My #<?php echo $selectedWatch->brand;?> runs at {WatchAccuracy} spd on https://plus.google.com/104724190750629608501/"></div>
<a class="share-button"
href="https://twitter.com/intent/tweet?text=My watch is more accurate than {WatchPercentile}%25 of all tested watches on @ToolWatchApp&url=https://toolwatch.io"
target="_blank">
<img src="<?php echo base_url();?>assets/img/tweet.png" alt="Tweet on tweeter" />
</a>

<a class="share-button"
href="http://www.facebook.com/sharer.php?s=100&p[url]=https://toolwatch.io&p[title]=I just tested the accuracy of my watch&p[summary]=My watch is more accurate than {WatchPercentile}%25 of all tested watches on https://www.facebook.com/Toolwatch"
target="_blank">
<img src="<?php echo base_url();?>assets/img/facebook.png" alt="Share on timeline" />
</a>

<a class="share-button"
href="https://plus.google.com/share?url=https://toolwatch.io"
target="_blank">
<img src="<?php echo base_url();?>assets/img/google-plus.png" alt="Share on timeline" />
</a>

<a class="share-button"
href="mailto:?to=&Subject=I just tested the accuracy of my watch&body=My watch is more accurate than {WatchPercentile}%25 of all tested watches on https://toolwatch.io"
target="_top">
<img src="<?php echo base_url();?>assets/img/email-share.png" alt="Share by email" />
</a>
</div>


<br/>

<center><p><br /><br />We <i style="color:#4d77a7" class="fa fa-heart"></i> <a href="https://instagram.com/toolwatchapp/">Instagram</a>, tag us with your wristshots and share your results using #ToolwatchApp !</p></center>

<!-- www.intagme.com -->
<iframe src="http://www.intagme.com/in/?u=dG9vbHdhdGNoYXBwfGlufDEwMHw0fDJ8fHllc3w1fHVuZGVmaW5lZHx5ZXM=" allowTransparency="true" frameborder="0" scrolling="no" style="margin-left:5px; border:none; overflow:hidden; width:auto; height: 230px" ></iframe>

</div>

</div>

</div>


</div>

<div class="form-group">
Expand All @@ -97,4 +118,4 @@
</div>
</div>
<img style="display:none" id="watch" src="<?php echo img_url('flatwatch-blank.png');?>">
</div>
</div>
Binary file added assets/img/email-share.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/img/facebook.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/img/google-plus.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/img/tweet.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 2 additions & 4 deletions assets/js/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -308,14 +308,12 @@ $(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("href", $(this).attr("href").replace("{WatchPercentile}", result.percentile));
});

initShareButton();

}
}
else
Expand Down
Loading

0 comments on commit 88c13c4

Please sign in to comment.