rAnk 
Install
npm install rank
Usage
rAnk
var rAnk = require('rank');
Methods
rAnk()
.factors([f1, f2])
.factors(f3)
.conditions({})
.weights([w1, w2, w3])
.data([a, b, c, d])
.run(); -> {}:
result.data;
result.stat;
result.factor;
result.weight;
factors
Each factor is described by factor's description, wich has the following properties:
{
id: 'my factor',
invert: true,
value: function(item, conditons) {
return new Date - item.ts;
},
valueAll: function(data, conditions) {
return data.map(function(item) { return new Date - item.ts; });
}
}
You also may want to delete some item from the resulting dataset. You should use removeItem()
for it:
value: function(item) {
if (item.ts < 0) {
this.removeItem();
} else {
return item.ts;
}
}
If value doesn't mean anything for given factor or it is to small, but you don't want to remove it from the resulting set, you can use neutralValue()
:
value: function(item) {
if (count in item) {
return item.count;
} else {
return this.neutralValue();
}
}
For both removeItem()
and neutralValue()
when you use it in valueAll
function you should pass index of item as an argument:
valueAll: function(data) {
var that = this;
return data.map(function(item, i) {
if (item.ts < 0) {
that.removeItem(i);
} else {
return item.ts ? new Date - item.ts : that.minValue(i);
}
});
}