Skip to content

Instantly share code, notes, and snippets.

@tjstebbing
Created August 19, 2015 00:43
Show Gist options
  • Save tjstebbing/2187413d6ce3bb3660da to your computer and use it in GitHub Desktop.
Save tjstebbing/2187413d6ce3bb3660da to your computer and use it in GitHub Desktop.
function prepData(data) {
let out = [];
Object.keys(data).forEach(function(k) {
let o = data[k];
let variants = [];
let first, latest;
let dist = o.distribution;
let total = 0;
Object.keys(o.count).forEach(function(c) {
total += Number(o.count[c]);
});
Object.keys(o.titles).forEach(function(v) {
first = first ? first : o.first[v];
latest = latest ? latest : o.last[v];
if(o.first[v] < first) first = o.first[v];
if(o.last[v] > latest) latest = o.last[v];
let variant = {};
variant.name = v;
variant.label = o.titles[v];
variant.first = o.first[v];
variant.latest = o.last[v];
variant.count = o.count[v] || 0;
variants.push(variant);
});
out.push({
id : k,
name : k,
variants : variants,
first : first,
latest : latest,
total : total,
dist : dist
});
});
return out;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment