izmjena algoritma
This commit is contained in:
14
.vscode/launch.json
vendored
Normal file
14
.vscode/launch.json
vendored
Normal file
@@ -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"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -1,2 +1,2 @@
|
|||||||
PEOPLE_DB=https://docs.google.com/spreadsheets/d/1s4Ytz7mf-YpszVTMTTrYd5iG_dsTGjrCpDQbpIx7zkU/edit#gid=1116948122
|
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
|
||||||
|
|||||||
@@ -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<names.length;i++){
|
||||||
|
for (let j=i+1;j<names.length;j++){
|
||||||
|
let exist = false;
|
||||||
|
pairs.filter((pair)=>{
|
||||||
|
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<AllPairs.length;i++){
|
||||||
|
if ((tmpNames.indexOf(AllPairs[i].name1)!=-1)||(tmpNames.indexOf(AllPairs[i].name2)!=-1)){
|
||||||
|
indexToRemove.push(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
for(let i=indexToRemove.length-1; i>=0;i--){
|
||||||
|
AllPairs.splice(indexToRemove[i],1);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
for(let i=0;i<BatchPairs.length;i++){
|
||||||
|
let index = names.indexOf(BatchPairs[i].name1);
|
||||||
|
if (index!=-1)
|
||||||
|
names.splice(index,1);
|
||||||
|
index = names.indexOf(BatchPairs[i].name2);
|
||||||
|
if (index!=-1)
|
||||||
|
names.splice(index,1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (names.length==0) names=null;
|
||||||
|
|
||||||
|
|
||||||
|
pairsForSave=BatchPairs;
|
||||||
|
|
||||||
|
callback.send({pairs: BatchPairs, left:names});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function SavePairs(callback){
|
function SavePairs(callback){
|
||||||
if (lastRow== null) {
|
if (lastRow== null) {
|
||||||
callback.send({result:true});
|
callback.send({result:true});
|
||||||
@@ -390,7 +454,11 @@ app.use(function(req, res, next) {
|
|||||||
app.get('/getPairs',(req,resp)=>{
|
app.get('/getPairs',(req,resp)=>{
|
||||||
pairsForSave=[];
|
pairsForSave=[];
|
||||||
lastRow=null;
|
lastRow=null;
|
||||||
MakePairs(resp);
|
MakePairsV2(resp);
|
||||||
|
});
|
||||||
|
|
||||||
|
app.get('/getAllPairs',(req,resp)=>{
|
||||||
|
MakePairsV2(resp);
|
||||||
});
|
});
|
||||||
|
|
||||||
app.get('/savePairs', (req,resp)=>{
|
app.get('/savePairs', (req,resp)=>{
|
||||||
@@ -398,7 +466,6 @@ app.get('/savePairs', (req,resp)=>{
|
|||||||
//resp.send({result:true});
|
//resp.send({result:true});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
app.listen(3005, function () {
|
app.listen(3005, function () {
|
||||||
console.log('Server running - port 3005');
|
console.log("Server running - Port 3005");
|
||||||
})
|
})
|
||||||
Reference in New Issue
Block a user