lot/oldapp/lotV2.js

153 lines
3.0 KiB
JavaScript
Raw Normal View History

2017-05-30 08:25:14 +00:00
const jsonfile = require('jsonfile'),
https = require('https'),
UltraSES = require('ultrases'), cron = require('node-cron');
const Sugar = require('sugar-date');
2017-09-08 09:45:53 +00:00
const pusher = require('./pusher');
2017-05-30 08:25:14 +00:00
const file = 'data/data.json';
2017-09-08 09:45:53 +00:00
const m = [];
2017-05-30 08:25:14 +00:00
2017-09-08 09:45:53 +00:00
const newNumberContainer = {};
2017-05-30 08:25:14 +00:00
let numberStore = [];
let resultsObj = {};
function buildArray() {
for (let x = 0; x < 51; x++) {
const l = [];
2017-09-08 09:45:53 +00:00
for (let y = 0; y < 51; y++)
2017-05-30 08:25:14 +00:00
l.push(0);
2017-09-08 09:45:53 +00:00
2017-05-30 08:25:14 +00:00
m[x] = l;
}
}
function sortNumber(a, b) {
return a - b;
}
function dynamicSort(property) {
let sortOrder = 1;
if (property[0] === '-') {
sortOrder = -1;
property = property.substr(1);
}
2017-09-08 09:45:53 +00:00
2017-05-30 08:25:14 +00:00
return function(a, b) {
2017-09-08 09:45:53 +00:00
const result = (a[property] < b[property]) ? -1 : (a[property] > b[property]) ? 1 : 0;
return result * sortOrder;
};
2017-05-30 08:25:14 +00:00
}
function othercalcV2() {
2017-09-08 09:45:53 +00:00
// Var p = 1 / ((-1)*numberStore.length);
2017-05-30 08:25:14 +00:00
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];
2017-09-08 09:45:53 +00:00
for (let n = 1; n < 6; n++)
2017-05-30 08:25:14 +00:00
if (n !== s) {
2017-09-08 09:45:53 +00:00
const workVal = numberStore[i][n];
2017-05-30 08:25:14 +00:00
// Console.log(workVal);
// m[cv-1][workVal-1]++;
// Console.log('mo', mo);
const tempArray = [cv, workVal].sort((a, b) => {
2017-09-08 09:45:53 +00:00
if (a < b)
return -1;
return a > b ? 1 : 0;
});
2017-05-30 08:25:14 +00:00
const id = tempArray.join('-');
if (thisRow.indexOf(id) === -1) {
2017-09-08 09:45:53 +00:00
const record = newNumberContainer[id] || { 'c': 0, 'v': 0, 'id': id };
2017-05-30 08:25:14 +00:00
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) => {
2017-09-08 09:45:53 +00:00
if (a.c < b.c)
return 1;
return a.c > b.c ? -1 : 0;
});
2017-05-30 08:25:14 +00:00
let line = [];
let lineI = 0;
while (line.length < 5) {
2017-09-08 09:45:53 +00:00
const pair = flatArray[lineI];
2017-05-30 08:25:14 +00:00
pairS = pair.id.split('-');
2017-09-08 09:45:53 +00:00
if (line.indexOf(pairS[0]) === -1 && line.length < 5)
2017-05-30 08:25:14 +00:00
line.push(pairS[0]);
2017-09-08 09:45:53 +00:00
if (line.indexOf(pairS[1]) === -1 && line.length < 5)
2017-05-30 08:25:14 +00:00
line.push(pairS[1]);
2017-09-08 09:45:53 +00:00
// console.log(line);
2017-05-30 08:25:14 +00:00
lineI++;
}
line = line.sort((a, b) => {
2017-09-08 09:45:53 +00:00
if (~~a < ~~b)
return -1;
return ~~a > ~~b ? 1 : 0;
});
//console.log(line);
2017-05-30 08:25:14 +00:00
2017-09-08 09:45:53 +00:00
return line;
2017-05-30 08:25:14 +00:00
}
function performCalcs() {
buildArray();
//BuildTable();
2017-09-08 09:45:53 +00:00
let line = othercalcV2();
2017-05-30 08:25:14 +00:00
console.log('---------------------------------------');
2017-09-08 09:45:53 +00:00
console.log(`line: ${line}`);
pusher.push(`line: ${line}`);
2017-05-30 08:25:14 +00:00
// Starcalc();
// tripCalc();
}
function GO() {
numberStore = [];
resultsObj = {};
jsonfile.readFile(file, function(err, obj) {
2017-09-08 09:45:53 +00:00
console.log(err);
numberStore = obj;
2017-05-30 08:25:14 +00:00
2017-09-08 09:45:53 +00:00
// Console.log(numberStore);
performCalcs();
2017-05-30 08:25:14 +00:00
2017-09-08 09:45:53 +00:00
//PrepareResults();
2017-05-30 08:25:14 +00:00
2017-09-08 09:45:53 +00:00
// console.log(resultsObj);
});
2017-05-30 08:25:14 +00:00
}
GO();