Skip to content

Instantly share code, notes, and snippets.

@tomayac
Created November 25, 2014 08:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomayac/e7e58f5af0bc261e30dd to your computer and use it in GitHub Desktop.
Save tomayac/e7e58f5af0bc261e30dd to your computer and use it in GitHub Desktop.
Average Edit Length (Delta) for Wikipedias by Language
// 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)})
*/
@tomayac
Copy link
Author

tomayac commented Nov 26, 2014

FAQ:

  • I get a 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?
  • Two options:
    (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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment