Created
January 10, 2012 09:37
-
-
Save 9re/1588092 to your computer and use it in GitHub Desktop.
take the daily diff of active installs from flashvar parameters
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
(function(){ | |
var embed = document.getElementsByTagName('embed')[0]; | |
var flashvars = embed.getAttribute('flashvars'); | |
flashvars = parseQueary(flashvars); | |
this.flashvars = flashvars; | |
var data = []; | |
for each (var name in flashvars) { | |
if (/data_\d/.test(name)) { | |
parseCSV(decodeURIComponent(flashvars[name])); | |
break; | |
} | |
} | |
var prev = 0; | |
var csv = data.map(function(i) { | |
var value = i[1]; | |
value -= prev; | |
prev = i[1]; | |
return value; | |
}).join('\n'); | |
window.open("data:," + encodeURIComponent(csv), "scrollbars=yes,"); | |
function parseCSV(csv) { | |
var lines = csv.split('\n'); | |
lines.forEach(function(line) { | |
if (line.indexOf(',') == -1) return; | |
var csvLine = line.split(','); | |
var date = new Date(1000 * parseFloat(csvLine[0])); | |
csvLine[0] = date; | |
data.push(csvLine); | |
}); | |
} | |
function parseQueary(query) { | |
var data = {}; | |
var pairs = query.split('&'); | |
pairs.forEach(function(pairStr){ | |
var pair = pairStr.split('='); | |
var key = pair[0]; | |
var value = pair[1]; | |
data[key] = value; | |
}); | |
return data; | |
} | |
})(); |
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
(function(){function f(a){a.split("\n").forEach(function(b){-1!=b.indexOf(",")&&(b=b.split(","),b[0]=new Date(1E3*parseFloat(b[0])),d.push(b))})}var a=document.getElementsByTagName("embed")[0].getAttribute("flashvars");this.a=a=function(a){var b={};a.split("&").forEach(function(a){a=a.split("=");b[a[0]]=a[1]});return b}(a);var d=[],c;for(c in a)if(/data_\d/.test(c)){f(decodeURIComponent(a[c]));break}var e=0,a=d.map(function(a){var b=a[1],b=b-e;e=a[1];return b}).join("\n");window.open("data:,"+encodeURIComponent(a), | |
"scrollbars=yes,")})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment