lot/libs/lotV2.js
2017-09-08 10:45:53 +01:00

115 lines
2.2 KiB
JavaScript

const m = [];
const newNumberContainer = {};
let numberStore = [];
function buildArray() {
for (let x = 0; x < 51; x++) {
const l = [];
for (let y = 0; y < 51; y++)
l.push(0);
m[x] = l;
}
}
function othercalcV2() {
// Var p = 1 / ((-1)*numberStore.length);
const p = 1.0 / (numberStore.length);
for (let i = 0; i < numberStore.length - 1; i++) {
const thisRow = [];
for (let s = 1; s < 6; s++) {
const cv = numberStore[i][s];
for (let n = 1; n < 6; n++)
if (n !== s) {
const workVal = numberStore[i][n];
// Console.log(workVal);
// m[cv-1][workVal-1]++;
// Console.log('mo', mo);
const tempArray = [cv, workVal].sort((a, b) => {
if (a < b)
return -1;
return a > b ? 1 : 0;
});
const id = tempArray.join('-');
if (thisRow.indexOf(id) === -1) {
const record = newNumberContainer[id] || { 'c': 0, 'v': 0, 'id': id };
record.c++;
record.v += (p * i);
newNumberContainer[id] = record;
thisRow.push(id);
}
}
}
}
let flatArray = Object.keys(newNumberContainer).map((key) => newNumberContainer[key]);
flatArray = flatArray.sort((a, b) => {
if (a.c < b.c)
return 1;
return a.c > b.c ? -1 : 0;
});
let line = [];
let lineI = 0;
while (line.length < 5) {
const pair = flatArray[lineI];
pairS = pair.id.split('-');
if (line.indexOf(pairS[0]) === -1 && line.length < 5)
line.push(pairS[0]);
if (line.indexOf(pairS[1]) === -1 && line.length < 5)
line.push(pairS[1]);
// console.log(line);
lineI++;
}
line = line.sort((a, b) => {
if (~~a < ~~b)
return -1;
return ~~a > ~~b ? 1 : 0;
});
//console.log(line);
return line;
}
function performCalcs() {
buildArray();
//BuildTable();
const line = othercalcV2();
console.log('---------------------------------------');
console.log(`line: ${line}`);
// Starcalc();
// tripCalc();
return line;
}
function calculate(data) {
numberStore = data;
return performCalcs();
}
module.exports.calculate = calculate;