trc-client-core
Version:
The core of the TRC Client
58 lines (51 loc) • 1.89 kB
JavaScript
var _ = require('lodash');
var PeanutMixin = {
//
// Super Specific to Taraks data structure.
// This probably could be done better
//
// {
// CRO: {achieved: 13, eligible: 0, total: 353, benchmark: 70, gap: 57}
// }
transformToState: function (map, dataObject, keyParse) {
var newState = {};
var max = 0;
// loop through each state option
_.forEach(map, function(chosenKeys, key) {
newState[key] = _.map(dataObject, function (data, subkey) {
var series = _.map(chosenKeys, function(keyName){
var value = data[keyName] || 0;
max = Math.max(max, value);
// round to max 2 places
// return value;
return Math.round(value * 100) / 100;
});
// console.log(data, subkey);
var keyString = (keyParse) ? keyParse(subkey) : subkey;
if(data.certName) {
keyString = data.certName;
}
return {series: series, xlabel: keyString};
});
});
newState.chartMax = max;
return newState;
},
//
// Again, very specific to T-dogs data strucutre. This one is a bit more nested.
//
// {
// CRO: [
// {certName: "DT_HYBC", achieved: 68, eligible: 62, total: 353, benchmark: 10, gap: 99},
// {certName: "DT_ELC", achieved: 68, eligible: 62, total: 353, benchmark: 10, gap: 99}
// ]
// }
transformFromCollection: function (shape, dataObject) {
var collections = {};
_.forEach(dataObject, function (item, key) {
collections[key] = PeanutMixin.transformToState(shape, item);
});
return collections;
}
};
module.exports = PeanutMixin;