Created
November 25, 2014 08:20
-
-
Save tomayac/e7e58f5af0bc261e30dd to your computer and use it in GitHub Desktop.
Average Edit Length (Delta) for Wikipedias by Language
This file contains hidden or 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
// Full source | |
var source = new EventSource('http://wikipedia-edits.herokuapp.com/sse'); | |
var languages = {}; | |
var avgDeltas = {}; | |
source.addEventListener('message', function(e) { | |
var edit = JSON.parse(e.data); | |
if (!languages[edit.language]) { | |
languages[edit.language] = []; | |
} | |
languages[edit.language].push(parseInt(edit.delta, 10)); | |
for (var key in languages) { | |
avgDeltas[key] = languages[key].reduce(function(sum, value, i, self) { | |
return self.length === i - 1 ? | |
sum + value : Math.floor((sum + value) / self.length); | |
}, 0); | |
} | |
console.log(avgDeltas); | |
}); | |
/* | |
// Uglified | |
e=new EventSource("http://wikipedia-edits.herokuapp.com/sse"),a={},n={} | |
e.addEventListener("message",function(e){var g,t=JSON.parse(e.data) | |
a[t.language]||(a[t.language]=[]),a[t.language].push(parseInt(t.delta,10)) | |
for(g in a)n[g]=a[g].reduce(function(e,a,n,g){return g.length==n-1?e+a:~~((e+a)/g.length)},0) | |
console.log(n)}) | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
FAQ:
Mixed Content: The page at 'https://example.org/' was loaded over HTTPS, but requested an insecure EventSource endpoint 'http://wikipedia-edits.herokuapp.com/sse'. This request has been blocked; the content must be served over HTTPS.
error. What now?(i) open a new empty tab and try again.
(ii) change the URL from http://wikipedia-edits.herokuapp.com/sse to https://wikipedia-edits.herokuapp.com/sse (https as the protocol).