Skip to content

Commit a00140c

Browse files
committed
update
1 parent b9641db commit a00140c

File tree

9 files changed

+99
-33
lines changed

9 files changed

+99
-33
lines changed

package-lock.json

Lines changed: 26 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
"nodemon": "^1.19.1",
3434
"rxjs": "~6.4.0",
3535
"tslib": "^1.9.0",
36+
"watson-ml-model-utils": "0.0.3",
3637
"zone.js": "~0.9.1"
3738
},
3839
"devDependencies": {

server.js

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,26 @@ app.use(function (req, res, next) {
1717
next();
1818
});
1919

20+
21+
const { WatsonMLScoringEndpoint } = require("watson-ml-model-utils");
22+
23+
24+
var features = ['LOTAREA', 'BLDGTYPE', 'HOUSESTYLE', 'OVERALLCOND', 'YEARBUILT',
25+
'ROOFSTYLE', 'EXTERCOND', 'FOUNDATION', 'BSMTCOND', 'HEATING',
26+
'HEATINGQC', 'CENTRALAIR', 'ELECTRICAL', 'FULLBATH', 'HALFBATH',
27+
'BEDROOMABVGR', 'KITCHENABVGR', 'KITCHENQUAL', 'TOTRMSABVGRD',
28+
'FIREPLACES', 'FIREPLACEQU', 'GARAGETYPE', 'GARAGEFINISH', 'GARAGECARS',
29+
'GARAGECOND', 'POOLAREA', 'POOLQC', 'FENCE', 'MOSOLD', 'YRSOLD' ];
30+
31+
let endpoint = new WatsonMLScoringEndpoint(features, {
32+
servicePath: 'https://ibm-watson-ml.mybluemix.net',
33+
username: '04c75888-357b-4548-9a3d-824b0fdf4355',
34+
password: '1626bb66-81f2-4d17-962d-b750eedce230',
35+
instanceId: 'ee215244-7c33-4ffb-ae7f-e2aac55d92f4',
36+
modelId: 'fbb8ab9f-4600-470b-95f0-55dd30925d6e',
37+
deploymentId: 'c3cf73a6-4cbb-493f-879d-e60d30c3f26f'
38+
});
39+
2040
var NodeGeocoder = require('node-geocoder');
2141

2242
var options = {
@@ -34,6 +54,8 @@ var geocoder = NodeGeocoder(options);
3454
let connStr = "DATABASE="+process.env.DB_DATABASE+";HOSTNAME="+process.env.DB_HOSTNAME+";PORT="+process.env.DB_PORT+";PROTOCOL=TCPIP;UID="+process.env.DB_UID+";PWD="+process.env.DB_PWD+";";
3555

3656

57+
58+
3759
//let connStr = "DATABASE=BLUDB;HOSTNAME=db2whoc-flex-zipnqsp.services.au-syd.bluemix.net;PORT=50000;PROTOCOL=TCPIP;UID=bluadmin;PWD=zWG@U4q1uFpDTi0v8jVBDI7_PtSr0;";
3860

3961
app.post('/newDataEntry', function(request, response){
@@ -77,7 +99,8 @@ let connStr = "DATABASE="+process.env.DB_DATABASE+";HOSTNAME="+process.env.DB_HO
7799

78100
})
79101

80-
app.post('/getData', function(request, response){
102+
app.post('/getData', function(request, response){
103+
console.log('hi')
81104
ibmdb.open(connStr, function (err,conn) {
82105
if (err){
83106
return response.json({success:-1, message:err});
@@ -93,7 +116,7 @@ app.post('/getData', function(request, response){
93116
});
94117
})
95118

96-
app.post('/getUniqueData', function(request, response){
119+
app.post('/getUniqueData', function(request, response){
97120
ibmdb.open(connStr, function (err,conn) {
98121
if (err){
99122
return response.json({success:-1, message:err});
@@ -123,7 +146,7 @@ app.post('/getUniqueData', function(request, response){
123146
});
124147
})
125148

126-
app.post('/updateDataEntry', function(request, response){
149+
app.post('/updateDataEntry', function(request, response){
127150
ibmdb.open(connStr, function (err,conn) {
128151
if (err){
129152
return response.json({success:-1, message:err});
@@ -179,7 +202,7 @@ app.post('/updateDataEntry', function(request, response){
179202
})
180203

181204

182-
app.post('/deleteData', function(request, response){
205+
app.post('/deleteData', function(request, response){
183206
ibmdb.open(connStr, function (err,conn) {
184207
if (err){
185208
return response.json({success:-1, message:err});
@@ -203,7 +226,16 @@ app.post('/deleteData', function(request, response){
203226
});
204227
})
205228

206-
app.get('/predict', function(request, response){
229+
230+
app.post('/WML_Predict', function(request, response){
231+
endpoint.score(request.body.values).then(
232+
output => {
233+
console.log(output.prediction);
234+
return response.json({success:1, value:output.prediction});
235+
}).catch(err => console.log(err));
236+
})
237+
238+
app.get('/predict', function(request, response){
207239
console.log(request);
208240
return response.json({
209241
"address1":"10892 Northfield Sq",

src/app/edit-data/edit-data.component.html

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ <h1 style="color:#B2B2B2; " *ngIf=showMessage> Loading Data . . .</h1>
8484

8585
<option> Select BldgType</option>
8686
<option>1Fam</option>
87-
<option>2FmCon</option>
87+
<option>2fmCon</option>
8888
<option>Duplx</option>
8989
<option>TwnhsE</option>
9090
<option>TwnhsI</option>
@@ -176,7 +176,6 @@ <h1 style="color:#B2B2B2; " *ngIf=showMessage> Loading Data . . .</h1>
176176
<option>TA</option>
177177
<option>Fa</option>
178178
<option>Po</option>
179-
<option>NA</option>
180179
</select>
181180
</div>
182181

@@ -241,7 +240,7 @@ <h1 style="color:#B2B2B2; " *ngIf=showMessage> Loading Data . . .</h1>
241240
<div class="col-md-2 mb-3">
242241
<label for="country"><strong>Bsmt Contition</strong></label><select class="form-control" required [(ngModel)]="model.bsmtCond" #opCarrier="ngModel" name="bsmtCond">
243242
<option>Select BsmtCond</option>
244-
<option>Ex</option>
243+
245244
<option>Gd</option>
246245
<option>TA</option>
247246
<option>Fa</option>
@@ -260,7 +259,6 @@ <h1 style="color:#B2B2B2; " *ngIf=showMessage> Loading Data . . .</h1>
260259
<option>Gd</option>
261260
<option>TA</option>
262261
<option>Fa</option>
263-
<option>Po</option>
264262
<option>NA</option>
265263
</select>
266264
</div>
@@ -293,7 +291,7 @@ <h1 style="color:#B2B2B2; " *ngIf=showMessage> Loading Data . . .</h1>
293291
<option>2Types</option>
294292
<option>Attchd</option>
295293
<option>Basment</option>
296-
<option>Builtin</option>
294+
297295
<option>CarPort</option>
298296
<option>Detchd</option>
299297
<option>NA</option>

src/app/http.service.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ export class HttpService {
1313

1414
}
1515

16+
17+
1618
httpOptions = {
1719
headers: new HttpHeaders({
1820
'Content-Type': 'application/json;charset=UTF-8',
@@ -44,14 +46,19 @@ export class HttpService {
4446
}
4547

4648
predict(predictOption: string, houseInfo: PredictHouseInfo) {
47-
const payload = JSON.stringify(houseInfo);
49+
console.log(houseInfo);
50+
console.log(houseInfo['lotArea']);
51+
var payload = JSON.stringify(houseInfo);
4852
let api = '';
4953
if (predictOption.toLowerCase() === 'db2') {
5054
api = environment.GO_DB2_API;
55+
return this.http.post(api, payload, this.httpOptions);
5156
} else {
52-
api = environment.IBM_WML_API;
53-
}
54-
return this.http.post(api, payload, this.httpOptions);
57+
return this.http.post(environment.NODE_HOST + 'WML_Predict', { values: [Number(houseInfo['lotArea']), houseInfo['bldgType'], houseInfo['houseStyle'], Number(houseInfo['overallCond']), Number(houseInfo['yearBuilt']), houseInfo['roofStyle'], houseInfo['exterCond'], houseInfo['foundation'], houseInfo['bsmtCond'],
58+
houseInfo['heating'], houseInfo['heatingQC'], houseInfo['centralAir'], houseInfo['electrical'], Number(houseInfo['fullBath']), Number(houseInfo['halfBath']), Number(houseInfo['bedroomAbvGr']), Number(houseInfo['kitchenAbvGr']), houseInfo['kitchenQual'], Number(houseInfo['totalRmsAbvGrd']), Number(houseInfo['fireplaces']), houseInfo['fireplaceQu'], houseInfo['garageType'],
59+
houseInfo['garageFinish'], Number(houseInfo['garageCars']), houseInfo['garageCond'], Number(houseInfo['poolArea']), houseInfo['poolQC'], houseInfo['fence'], Number(houseInfo['moSold']), Number(houseInfo['yrSold'])] }, this.httpOptions);
60+
}
61+
5562
}
5663

5764
getCoordinates(address1, city, state, zipcode) {

src/app/load-data/load-data.component.html

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ <h3 class="text-dark mb-4" >House Information</h3>
7575

7676
<option> Select BldgType</option>
7777
<option>1Fam</option>
78-
<option>2FmCon</option>
78+
<option>2fmCon</option>
7979
<option>Duplx</option>
8080
<option>TwnhsE</option>
8181
<option>TwnhsI</option>
@@ -136,7 +136,6 @@ <h3 class="text-dark mb-4" >House Information</h3>
136136
<option>Gd</option>
137137
<option>TA</option>
138138
<option>Fa</option>
139-
<option>Po</option>
140139
</select>
141140
<small
142141
class="text-danger" *ngIf=errKitchenQual>Please Choose An Option</small>
@@ -248,7 +247,7 @@ <h3 class="text-dark mb-4" >House Information</h3>
248247
<div class="col-md-2 mb-3">
249248
<label for="country"><strong>Bsmt Contition</strong></label><select class="form-control" required [(ngModel)]="model.bsmtCond" #opCarrier="ngModel" name="bsmtCond">
250249
<option>Select BsmtCond</option>
251-
<option>Ex</option>
250+
252251
<option>Gd</option>
253252
<option>TA</option>
254253
<option>Fa</option>
@@ -268,7 +267,6 @@ <h3 class="text-dark mb-4" >House Information</h3>
268267
<option>Gd</option>
269268
<option>TA</option>
270269
<option>Fa</option>
271-
<option>Po</option>
272270
</select>
273271
<small
274272
class="text-danger" *ngIf=errPoolQC>Please Choose An Option</small>
@@ -308,7 +306,7 @@ <h3 class="text-dark mb-4" >House Information</h3>
308306
<option>2Types</option>
309307
<option>Attchd</option>
310308
<option>Basment</option>
311-
<option>Builtin</option>
309+
312310
<option>CarPort</option>
313311
<option>Detchd</option>
314312
<option>NA</option>

src/app/predict-data/predict-data.component.html

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ <h3 class="text-dark mb-4">House Information</h3>
117117

118118
<option> Select BldgType</option>
119119
<option>1Fam</option>
120-
<option>2FmCon</option>
120+
<option>2fmCon</option>
121121
<option>Duplx</option>
122122
<option>TwnhsE</option>
123123
<option>TwnhsI</option>
@@ -207,7 +207,6 @@ <h3 class="text-dark mb-4">House Information</h3>
207207
<option>Gd</option>
208208
<option>TA</option>
209209
<option>Fa</option>
210-
<option>Po</option>
211210
</select>
212211
<small class="text-danger" *ngIf=errKitchenQual>Please choose an option</small>
213212
</div>
@@ -220,7 +219,7 @@ <h3 class="text-dark mb-4">House Information</h3>
220219
<p class="text-primary m-0 font-weight-bold">Utilities</p>
221220
</div>
222221
<div class="card-body">
223-
<div class="form-row" style="margin-bottom:0px;">
222+
<div class="form-row" style="margin-bottom:0px;">
224223
<div class="col-md-2 mb-3">
225224
<label for="email"><strong>Heating</strong></label><select class="form-control"
226225
required [(ngModel)]="model.heating" #heating="ngModel" name="heating">
@@ -320,7 +319,6 @@ <h3 class="text-dark mb-4">House Information</h3>
320319
class="form-control" required [(ngModel)]="model.bsmtCond" #bsmtCond="ngModel"
321320
name="bsmtCond">
322321
<option>Select BsmtCond</option>
323-
<option>Ex</option>
324322
<option>Gd</option>
325323
<option>TA</option>
326324
<option>Fa</option>
@@ -341,9 +339,8 @@ <h3 class="text-dark mb-4">House Information</h3>
341339
<option>Select PoolQC</option>
342340
<option>Ex</option>
343341
<option>Gd</option>
344-
<option>TA</option>
345342
<option>Fa</option>
346-
<option>Po</option>
343+
<option>NA</option>
347344
</select>
348345
<small class="text-danger" *ngIf=errPoolQC>Please choose an option</small>
349346

@@ -389,7 +386,7 @@ <h3 class="text-dark mb-4">House Information</h3>
389386
<option>2Types</option>
390387
<option>Attchd</option>
391388
<option>Basment</option>
392-
<option>Builtin</option>
389+
393390
<option>CarPort</option>
394391
<option>Detchd</option>
395392
<option>NA</option>
@@ -464,7 +461,7 @@ <h3 class="text-dark mb-4">House Information</h3>
464461
type="text" placeholder="Year Sold" required [(ngModel)]="model.yrSold"
465462
#yrSold="ngModel" name="yrSold"><small class="text-danger"
466463
*ngIf=errYrSold>Please enter a valid number</small>
467-
</div>
464+
</div>
468465
<div class="col-md-2 mb-3" style="margin-top:35px; margin-left:15px;">
469466

470467
<button class="btn btn-primary btn-sm" type="submit" (click)=predict()>SUBMIT
@@ -477,4 +474,4 @@ <h3 class="text-dark mb-4">House Information</h3>
477474
</div>
478475
</div>
479476
</div>
480-
</div>
477+
</div>

src/app/predict-data/predict-data.component.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,17 @@ export class PredictDataComponent implements OnInit {
141141
(predictions) => {
142142
console.log('Predictions Result');
143143
console.log(predictions);
144+
145+
146+
147+
148+
149+
150+
151+
152+
153+
154+
144155
});
145156
}
146157
}

src/environments/environment.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export const environment = {
66
production: false,
77
GO_DB2_API: 'http://localhost:8080/predict',
88
IBM_WML_API: 'https://us-south.ml.cloud.ibm.com/v3/wml_instances/ee215244-7c33-4ffb-ae7f-e2aac55d92f4/deployments/3cfaa43b-4cae-403a-a4ed-db8b3de009dd/online',
9-
NODE_HOST: 'http://localhost:8888'
9+
NODE_HOST: 'http://localhost:8888/'
1010
};
1111

1212
/*

0 commit comments

Comments
 (0)