Last active
August 29, 2015 14:17
-
-
Save fatso83/b7e97f572465bbcca474 to your computer and use it in GitHub Desktop.
Helper functions to validate shown Rescue Time stats. Simply sums up the time values and prints the sum in the console
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Helper functions to validate Rescue Time stats | |
// Copy paste into the console or add to Code Snippets in Chrome => run | |
// run in the console by running `printStats()` | |
function findElems() { | |
return $('.report-table tr td:nth-child(2)'); | |
} | |
function t(time) { | |
var tmp, min, sek; | |
tmp=time.match(/(\d+)m/); | |
min = tmp?parseInt(tmp[1],10):0; | |
tmp=time.match(/(\d+)s/); | |
sek = tmp?parseInt(tmp[1],10):0; | |
return min*60 + sek; | |
} | |
function sum() { | |
var total=0; | |
findElems() | |
.each(function(i,e) { total+=t(e.innerHTML); }) | |
return total; | |
} | |
function printStats() { | |
var tmp=sum(), m = tmp/60 >> 0, s=tmp%60; | |
console.log(m + ':' + s); | |
} | |
printStats(); | |
// tests | |
// function c(pred){ console.log(pred) } | |
// c( t('1m 22s')===82) | |
// c( t('22s') === 22 ) | |
// c( t(' \n20m \n') === 1200 ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment