This commit is contained in:
Donnelly 2017-05-30 09:25:14 +01:00
parent a472108107
commit 0fe7c900ca
2 changed files with 169 additions and 13 deletions

26
lot.js
View File

@ -161,9 +161,9 @@ function calc() {
console.log("row: " + cv);
for (var n = 1; n < 6; n++) {
if (n != s) {
wv = re[i][n];
console.log(wv);
m[cv - 1][wv - 1]++;
workVal = re[i][n];
console.log(workVal);
m[cv - 1][workVal - 1]++;
}
}
}
@ -185,12 +185,12 @@ function othercalc() {
// console.log("row: " + cv);
for (var n = 1; n < 6; n++) {
if (n != s) {
wv = re[i][n];
// console.log(wv);
// m[cv-1][wv-1]++;
workVal = re[i][n];
// console.log(workVal);
// m[cv-1][workVal-1]++;
var flag = false;
for (var t = 0; t < mo.length; t++) {
if (mo[t].a == cv && mo[t].b == wv) {
if (mo[t].a == cv && mo[t].b == workVal) {
if (typeof mo[t].c == 'undefined' || mo[t].c == null)
{
mo[t].c = 0;
@ -220,7 +220,7 @@ function othercalc() {
if (!flag) {
mo.push({
a: cv,
b: wv,
b: workVal,
v: 1
});
}
@ -347,12 +347,12 @@ function starcalc() {
// console.log("row: " + cv);
for (var n = 6; n < 8; n++) {
if (n != s) {
wv = re[i][n];
// console.log(wv);
// m[cv-1][wv-1]++;
workVal = re[i][n];
// console.log(workVal);
// m[cv-1][workVal-1]++;
var flag = false;
for (var t = 0; t < mo.length; t++) {
if (mo[t].a == cv && mo[t].b == wv) {
if (mo[t].a == cv && mo[t].b == workVal) {
flag = true;
mo[t].v++;
@ -362,7 +362,7 @@ function starcalc() {
if (!flag) {
mo.push({
a: cv,
b: wv,
b: workVal,
v: 1
});
}

156
lotV2.js Normal file
View File

@ -0,0 +1,156 @@
const jsonfile = require('jsonfile'),
https = require('https'),
UltraSES = require('ultrases'), cron = require('node-cron');
const Sugar = require('sugar-date');
const file = 'data/data.json';
const m = [],
prev = [],
mo = [],
star = [],
trip = [],
results = [],
line = [];
let newNumberContainer = {};
let numberStore = [];
let resultsObj = {};
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 sortNumber(a, b) {
return a - b;
}
function dynamicSort(property) {
let sortOrder = 1;
if (property[0] === '-') {
sortOrder = -1;
property = property.substr(1);
}
return function(a, b) {
const result = (a[property] < b[property]) ? -1 : (a[property] > b[property]) ? 1 : 0;
return result * sortOrder;
}
}
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) {
let 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) {
let 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);
}
function performCalcs() {
buildArray();
//BuildTable();
othercalcV2();
console.log('---------------------------------------');
// Starcalc();
// tripCalc();
}
function GO() {
numberStore = [];
resultsObj = {};
jsonfile.readFile(file, function(err, obj) {
console.log(err);
numberStore = obj;
// Console.log(numberStore);
performCalcs();
//PrepareResults();
// console.log(resultsObj);
});
}
GO();