From c28efc7e9d97032a7bd67ba0cc23150d1faf6bbb Mon Sep 17 00:00:00 2001 From: GotPPay Date: Wed, 25 Oct 2017 20:39:14 +0200 Subject: [PATCH] izmjena algoritma --- .vscode/launch.json | 14 +++++++++ backend/.env | 2 +- backend/app.js | 73 +++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 85 insertions(+), 4 deletions(-) create mode 100644 .vscode/launch.json diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 00000000..d6e74d64 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,14 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "type": "node", + "request": "launch", + "name": "Launch Program", + "program": "${workspaceFolder}/backend/app.js" + } + ] +} \ No newline at end of file diff --git a/backend/.env b/backend/.env index f5d15c46..19703772 100644 --- a/backend/.env +++ b/backend/.env @@ -1,2 +1,2 @@ PEOPLE_DB=https://docs.google.com/spreadsheets/d/1s4Ytz7mf-YpszVTMTTrYd5iG_dsTGjrCpDQbpIx7zkU/edit#gid=1116948122 -PAIRS_LIST=https://docs.google.com/spreadsheets/d/1gPuRhTry3YoJ_ibI2BfL1ue2_YLlhtW56OP39ADJY_4/edit#gid=0 +PAIRS_LIST=https://docs.google.com/spreadsheets/d/1gPuRhTry3YoJ_ibI2BfL1ue2_YLlhtW56OP39ADJY_4/edit diff --git a/backend/app.js b/backend/app.js index 7a8f53f9..0c2979e8 100644 --- a/backend/app.js +++ b/backend/app.js @@ -322,6 +322,70 @@ function MakePairs(callback){ }); } +function MakePairsV2(callback){ + executeAPI(getAvailableNames, function(names){ + executeAPI(getPairs, function(pairs){ + const AllPairs = []; + const BatchPairs = []; + + for(let i=0;i{ + if (((pair.name1 == names[i])&&(pair.name2 == names[j]))||((pair.name1==names[j])&&(pair.name2==names[i]))){ + exist=true; + return; + } + }); + if (!exist){ + AllPairs.push({name1: names[i], name2: names[j]}); + } + } + } + + while(AllPairs.length>0){ + + BatchPairs.push(AllPairs[0]); + + let tmpNames = []; + let indexToRemove = []; + + tmpNames.push(AllPairs[0].name1); + tmpNames.push(AllPairs[0].name2); + + for (let i=0;i=0;i--){ + AllPairs.splice(indexToRemove[i],1); + } + + } + + + for(let i=0;i{ pairsForSave=[]; lastRow=null; - MakePairs(resp); + MakePairsV2(resp); +}); + +app.get('/getAllPairs',(req,resp)=>{ + MakePairsV2(resp); }); app.get('/savePairs', (req,resp)=>{ @@ -398,7 +466,6 @@ app.get('/savePairs', (req,resp)=>{ //resp.send({result:true}); }); - app.listen(3005, function () { - console.log('Server running - port 3005'); + console.log("Server running - Port 3005"); }) \ No newline at end of file