-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
259 lines (203 loc) · 6.77 KB
/
index.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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
var express=require('express')
var path=require('path')
var app=express()
var alfa=express.Router()
var mysql=require('mysql');
var pythonshell=require('python-shell')
var port=process.env.PORT || 5000
var con=mysql.createConnection({
host: "ec2-52-37-241-124.us-west-2.compute.amazonaws.com",
user: "root",
password: "password",
database: "credit_data"
});
con.connect(function(err){
if(err)
throw err;
else
console.log("Connection established succesfully");
});
app.use(express.static(__dirname+'/'))
app.use(function(req, res, next) {
res.setHeader('Access-Control-Allow-Origin', '*');
res.setHeader('Access-Control-Allow-Methods', 'GET, POST,PUT');
res.setHeader('Access-Control-Allow-Headers', 'X-Requested-With,content-type,Authorization');
next();
});
// 25144400,2,2,360,1,2,1,59,1,2,1
app.use(express.static(__dirname+'/'))
alfa.get('/',function(req,res){
res.sendFile(path.join(__dirname+'/pages/home.html'));
});
alfa.get('/income=:u_income/purpose=:loan_purpose/coop=:coop/term_months=:term/state=:state/first=:first/gender=:gender/age=:age/units=:units/score=:score/prop_type=:prop_type',function(req,res){
var parameters=new Array()
parameters.push(req.params.u_income)
parameters.push(req.params.loan_purpose)
parameters.push(req.params.coop)
parameters.push(req.params.term)
parameters.push(req.params.state)
parameters.push(req.params.first)
parameters.push(req.params.gender)
parameters.push(req.params.age)
parameters.push(req.params.units)
parameters.push(req.params.score)
parameters.push(req.params.prop_type)
var options = {
args: parameters
};
pythonshell.run('scikitscripts/loan_approval_prediction.py',options,function(err,result){
if(err) throw err;
console.log(result)
res.json(result)
})
})
alfa.get('/gender=:u_gender/age=:age/debt=:debt/Marital=:marital/edulevel=:edulevel/ethnicity=:ethnicity/employedyrs=:employedyrs/priorDefault=:priorDefault/employed=:employed/creditscore=:creditscore/license=:license/citizen=:citizen/zipCode=:zipCode/income=:income',function(req,res){
var parameters=new Array()
parameters.push(req.params.u_gender)
parameters.push(req.params.age)
parameters.push(req.params.debt)
parameters.push(req.params.marital)
parameters.push(req.params.edulevel)
parameters.push(req.params.ethnicity)
parameters.push(req.params.employedyrs)
parameters.push(req.params.priorDefault)
parameters.push(req.params.employed)
parameters.push(req.params.creditscore)
parameters.push(req.params.license)
parameters.push(req.params.citizen)
parameters.push(req.params.zipCode)
parameters.push(req.params.income)
var options = {
args: parameters
};
pythonshell.run('scikitscripts/credit_approval_prediction.py',options,function(err,result){
if(err) throw err;
console.log(result)
res.json(result)
})
})
alfa.get('/pending_credit',function(req,res){
// con.connect(function(err){
// if(err)
// throw err;
// else
// console.log("Connection established succesfully")
// });
var statement="select * from Credit_Prediction_Uniq where Actual='PENDING'";
con.query(statement,function(err,rows){
if(err) throw err;
else{
console.log("Data Retrieval Success");
res.json(rows);
}
})
})
alfa.get('/pending_loan',function(req,res){
//con.connect(function(err){
// if(err)
// throw err;
// else
// console.log("Connection established succesfully")
// });
var statement="select * from Bank_Prediction_Uniq Bank_Prediction_Uniq where Actual_Interest_rate='PENDING'";
con.query(statement,function(err,rows){
if(err) throw err;
else{
console.log("Data Retrieval Success");
res.json(rows);
}
})
})
alfa.put('/credit_approved_for=:uid',function(req,res){
var statement="UPDATE Credit_Prediction_Uniq set Actual='APPROVED' where Uid="+req.params.uid+";"
con.query(statement,function(err,rows){
if(err) throw err;
else{
console.log("Data Retrieval Success");
res.json("Credit Approved for uid" + req.params.uid);
}
})
})
alfa.put('/credit_denied_for=:uid',function(req,res){
var statement="UPDATE Credit_Prediction_Uniq set Actual='DENIED' where Uid="+req.params.uid+";"
con.query(statement,function(err,rows){
if(err) throw err;
else{
console.log("Data Retrieval Success");
res.json(req.params.uid);
}
})
})
alfa.put('/loan_interest_accepted=:uid',function(req,res){
var statement="update Bank_Prediction_Uniq set Actual_Interest_rate=prediction_int_rate where uid="+req.params.uid+";"
con.query(statement,function(err,rows){
if(err) throw err;
else{
console.log("Data Retrieval Success");
res.json("Credit Approved for uid" + req.params.uid);
}
})
})
alfa.put('/loan_interest_modified=:newrate/for_uid=:uid',function(req,res){
var statement="UPDATE Bank_Prediction_Uniq set Actual_Interest_rate='"+ req.params.newrate +"' where Uid="+req.params.uid+";"
con.query(statement,function(err,rows){
if(err) throw err;
else{
console.log("Data Retrieval Success");
res.json(req.params.uid);
}
})
})
alfa.get('/get_my_credit_application_details=:uid',function(req,res){
var statement="select * from Credit_Prediction_Uniq where Uid="+req.params.uid+";"
con.query(statement,function(err,rows){
if(err) throw err;
else{
console.log("Data Retrieval Success");
res.json(rows[0].Actual);
}
})
})
alfa.get('/get_my_loan_application_details=:uid',function(req,res){
var statement="select * from Bank_Prediction_Uniq where Uid="+req.params.uid+";"
con.query(statement,function(err,rows){
if(err) throw err;
else{
console.log("Data Retrieval Success");
res.json("Your actual interest rate is "+ rows[0].Actual_Interest_rate+" And predicted value is: "+ rows[0].prediction_int_rate);
}
})
})
alfa.get('/loan_dash_statewide_count',function(req,res){
var statement="select count(*) as applications,state_clean as state from Bank_Prediction_Uniq group by state_clean;"
con.query(statement,function(err,rows){
if(err) throw err;
else{
console.log("Data Retrieval Success");
res.json(rows);
}
})
})
app.get('/approved',function(req,res){
var statement="select count(*) as value from dummy_credit_predict where dummy='APPROVED'";
con.query(statement,function(err,rows){
if(err) throw err;
else{
console.log("Data Retrieval Success");
res.json(rows);
}
})
})
app.get('/notapproved',function(req,res){
var statement="select count(*) as value from dummy_credit_predict where dummy='NOT APPROVED'";
con.query(statement,function(err,rows){
if(err) throw err;
else{
console.log("Data Retrieval Success");
res.json(rows);
}
})
})
app.use('/',alfa)
app.listen(port);
console.log('Go to the port : ' + port);