-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathroutes.js
170 lines (138 loc) · 3.62 KB
/
routes.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
var XenoUser = require('./models/user');
var path = process.cwd()
var csv = require('csvtojson')
module.exports = function(app,passport){
app.get('/', function(req, res){
res.render('signuporlogin.ejs')
});
app.get('/login',function(req,res){
res.sendFile(path+'/views/login.html');
})
app.post('/login', passport.authenticate('local-login', {
successRedirect: '/codescrap',
failureRedirect: '/login',
failureFlash: true
}));
app.get('/signup', function(req, res){
res.sendFile(path+'/views/signup.html');
});
app.post('/signup', passport.authenticate('local-signup', {
successRedirect: '/',
failureRedirect: '/signup',
failureFlash: true
}));
app.get('/codescrap',isLoggedIn,function(req,res){
res.render('index.ejs')
})
app.post('/compare',isLoggedIn,function(req,res){
//console.log('post successful')
res.render('compare.ejs')
});
app.post('/analyse2',isLoggedIn,function(req,res){
//console.log('post successful')
res.render('compare2.ejs')
});
app.post('/com2',isLoggedIn,function(req,res){
console.log(req.body)
var user1= req.body.u1name;
var user2 = req.body.u2name;
var dataarr=[]
if(req.body.codeforces)
title='CodeForces';
else
title='CodeChef';
var arr = [user1,user2];
function doit(filename,user){
var userarr=[]
csv()
.fromFile(filename)
.on('json',(data)=>{
userarr.push(data[0])
})
.on('done',(error)=>
{
console.log("problems: "+userarr)
dataarr.push({"title":title,"user":user,"userarray":userarr})
return (dataarr);
})
};
for ( i =0;i<2;i++)
{
filename=path+"/"+title+"/csvdatabase/"+arr[i]+".csv"
doit(filename,arr[i])
setTimeout(function(){console.log("dataarr: "+JSON.stringify(dataarr))
var arrsend=[]
var arr1 = dataarr[0].userarray;
var arr2 = dataarr[1].userarray;
var arri = intersect(arr1,arr2)
console.log(arri)
function intersect(a, b) {
var t;
if (b.length > a.length) t = b, b = a, a = t; // indexOf to loop over shorter
return a.filter(function (e) {
return b.indexOf(e) > -1;
});
}
arrsend.push({"title":title,"user":"Problems Solved by both "+user1+" and "+user2,"userarray":arri})
var arrd=arr_diff(arr1,arr2)
arrsend.push({"title":title,"user":"Problems Solved by "+user1+" and not by "+user2,"userarray":intersect(arrd,arr1)})
arrsend.push({"title":title,"user":"Problems Solved by "+user2+" and not by "+user1,"userarray":intersect(arrd,arr2)})
function arr_diff (a1, a2) {
var a = [], diff = [];
for (var i = 0; i < a1.length; i++) {
a[a1[i]] = true;
}
for (var i = 0; i < a2.length; i++) {
if (a[a2[i]]) {
delete a[a2[i]];
} else {
a[a2[i]] = true;
}
}
for (var k in a) {
diff.push(k);
}
return diff;
};
res.render('com',{data:arrsend})
},3000)}
})
function isLoggedIn(req, res, next) {
if(req.isAuthenticated()){
return next();
}
res.redirect('/login');
}
app.post('/analyse2',isLoggedIn,function(req,res){
//console.log('post successful')
res.render('compare2.ejs')
});
app.post('/com',isLoggedIn,function(req,res){
console.log(req.body)
var dataarr=[]
var title = req.body.title;
var opt = req.body.options
var arr = opt.split('\r\n')
function doit(filename,user){
var userarr=[]
csv()
.fromFile(filename)
.on('json',(data)=>{
userarr.push(data[0])
})
.on('done',(error)=>
{
console.log("problems: "+userarr)
dataarr.push({"title":title,"user":user,"userarray":userarr})
return (dataarr);
})
};
for ( i =0;i<arr.length;i++)
{
filename=path+"/"+title+"/csvdatabase/"+arr[i]+".csv"
doit(filename,arr[i])
setTimeout(function(){console.log("dataarr: "+JSON.stringify(dataarr))
res.render('com',{data:dataarr})
},3000)}
})
}