Skip to content

Instantly share code, notes, and snippets.

@bjorngi
Last active Dec 14, 2015
Embed
What would you like to do?
formatdata
{"description":"formatdata","endpoint":"","display":"svg","public":true,"require":[],"fileconfigs":{"inlet.js":{"default":true,"vim":false,"emacs":false,"fontSize":12},"_.md":{"default":true,"vim":false,"emacs":false,"fontSize":12},"config.json":{"default":true,"vim":false,"emacs":false,"fontSize":12},"data.json":{"default":true,"vim":false,"emacs":false,"fontSize":12}},"play":false,"loop":false,"restart":false,"autoinit":true,"pause":true,"loop_type":"period","bv":false,"nclones":15,"clone_opacity":0.4,"duration":3000,"ease":"linear","dt":0.01,"tab":"edit","display_percent":0.7,"thumbnail":"http://i.imgur.com/Z4ghHZY.png","fullscreen":false,"ajax-caching":true}
[
{ "customer": { "alias": "Redacted1", "hotspots": [ { "alias": "hs-redacted1", "id": 28, "logins": [ { "authtype": "open", "friendlyname": "Open", "logins": { "total": 33, "unique": 28 } } ] } ], "id": 24 } }, { "customer": { "alias": "Redacted2", "hotspots": [ { "alias": "hs-redacted2", "id": 60, "logins": [ { "authtype": "radius_external", "friendlyname": "Ekstern RADIUS", "logins": { "total": 56, "unique": 47 } }, { "authtype": "open", "friendlyname": "Open", "logins": { "total": 26, "unique": 23 } } ] }, { "alias": "hs-redacted3", "id": 61, "logins": null } ], "id": 35 } } ]
var data = tributary.data;
var authTypes = [];
data.map(function(d) {
return d.customer.hotspots;
})
.map(function(hsA) {
return hsA.map(function(hs) {
if(hs.logins) {
return hs.logins.map(function(logins) {
authTypes.push(logins);
})
}
})
});
var nestetAuthTypes = d3.nest()
.key(function(d) {
return d.friendlyname;
})
.rollup(function(log) {
var sum = {
'unique': 0,
'total': 0
}
log.map(function(d) {
sum.total += d.logins.total;
sum.unique += d.logins.unique;
})
return sum;
})
.entries(authTypes);
console.log(nestetAuthTypes);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment