Skip to content

Commit 6efce28

Browse files
Merge pull request #9 from IBM/update-WML-API
Update wml api
2 parents 1803d91 + f1b13b8 commit 6efce28

12 files changed

+127
-44
lines changed

env.sample

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,9 @@ DB_PORT=50000
77
DB_UID=<username>
88
DB_PWD=<password>
99
DB_SCHEMA=<schema name>
10+
WML_SERVICEPATH=<service url name>
11+
WML_UID=<wml service user name>
12+
WML_PWD=<wml service password name>
13+
WML_INSTANCEID=<service instance id >
14+
WML_MODELID=<model id>
15+
WML_DEPLOYMENTID=<deployment id>

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: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,27 @@ 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+
32+
let endpoint = new WatsonMLScoringEndpoint(features, {
33+
servicePath: process.env.WML_SERVICEPATH,
34+
username: process.env.WML_UID,
35+
password: process.env.WML_PWD,
36+
instanceId: process.env.WML_INSTANCEID,
37+
modelId: process.env.WML_MODELID,
38+
deploymentId: process.env.WML_DEPLOYMENTID
39+
});
40+
2041
var NodeGeocoder = require('node-geocoder');
2142

2243
var options = {
@@ -34,6 +55,8 @@ var geocoder = NodeGeocoder(options);
3455
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+";";
3556

3657

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

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

78101
})
79102

80-
app.post('/getData', function(request, response){
103+
app.post('/getData', function(request, response){
104+
console.log('hi')
81105
ibmdb.open(connStr, function (err,conn) {
82106
if (err){
83107
return response.json({success:-1, message:err});
@@ -93,7 +117,7 @@ app.post('/getData', function(request, response){
93117
});
94118
})
95119

96-
app.post('/getUniqueData', function(request, response){
120+
app.post('/getUniqueData', function(request, response){
97121
ibmdb.open(connStr, function (err,conn) {
98122
if (err){
99123
return response.json({success:-1, message:err});
@@ -123,7 +147,7 @@ app.post('/getUniqueData', function(request, response){
123147
});
124148
})
125149

126-
app.post('/updateDataEntry', function(request, response){
150+
app.post('/updateDataEntry', function(request, response){
127151
ibmdb.open(connStr, function (err,conn) {
128152
if (err){
129153
return response.json({success:-1, message:err});
@@ -179,7 +203,7 @@ app.post('/updateDataEntry', function(request, response){
179203
})
180204

181205

182-
app.post('/deleteData', function(request, response){
206+
app.post('/deleteData', function(request, response){
183207
ibmdb.open(connStr, function (err,conn) {
184208
if (err){
185209
return response.json({success:-1, message:err});
@@ -203,7 +227,16 @@ app.post('/deleteData', function(request, response){
203227
});
204228
})
205229

206-
app.get('/predict', function(request, response){
230+
231+
app.post('/WML_Predict', function(request, response){
232+
endpoint.score(request.body.values).then(
233+
output => {
234+
console.log(output.prediction);
235+
return response.json({success:1, value:output.prediction});
236+
}).catch(err => console.log(err));
237+
})
238+
239+
app.get('/predict', function(request, response){
207240
console.log(request);
208241
return response.json({
209242
"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',
@@ -45,14 +47,19 @@ export class HttpService {
4547
}
4648

4749
predict(predictOption: string, houseInfo: PredictHouseInfo) {
48-
const payload = JSON.stringify(houseInfo);
50+
console.log(houseInfo);
51+
console.log(houseInfo['lotArea']);
52+
var payload = JSON.stringify(houseInfo);
4953
let api = '';
5054
if (predictOption.toLowerCase() === 'db2') {
5155
api = environment.GO_DB2_API;
56+
// return this.http.get(environment.NODE_HOST + 'predict', payload, this.httpOptions);
5257
} else {
53-
api = environment.IBM_WML_API;
54-
}
55-
return this.http.post(api, payload, this.httpOptions);
58+
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'],
59+
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'],
60+
houseInfo['garageFinish'], Number(houseInfo['garageCars']), houseInfo['garageCond'], Number(houseInfo['poolArea']), houseInfo['poolQC'], houseInfo['fence'], Number(houseInfo['moSold']), Number(houseInfo['yrSold'])] }, this.httpOptions);
61+
}
62+
5663
}
5764

5865
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: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,19 @@ <h3 class="text-dark mb-4">House Information</h3>
3737
</div>
3838
<div class="card shadow mb-3">
3939
<div class="card-header py-3">
40-
<p class="text-primary m-0 font-weight-bold">address Information</p>
40+
<p class="text-primary m-0 font-weight-bold">Address Information</p>
4141
</div>
4242
<div class="card-body">
4343
<div class="form-row" style="margin-bottom:0px;">
4444
<div class="col-md-2 mb-3">
45-
<label for="address1">address 1</label>
45+
<label for="address1">Address 1</label>
4646
<input type="text" class="form-control" id="address1" placeholder="1234 abc st."
4747
required [(ngModel)]="addressModel.address1" #address1="ngModel"
4848
name="address1">
4949
<small class="text-danger" *ngIf=errAddress1>Please enter a valid address</small>
5050
</div>
5151
<div class="col-md-2 mb-3">
52-
<label for="address2">address2</label>
52+
<label for="address2">Address2</label>
5353
<input type="text" class="form-control" id="address2" placeholder="Apt 4" required
5454
[(ngModel)]="addressModel.address2" #address2="ngModel" name="address2">
5555
<small class="text-danger" *ngIf=errAddress2>Please enter a valid address</small>
@@ -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>

0 commit comments

Comments
 (0)