-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
62 lines (56 loc) · 2.04 KB
/
app.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
function getBathValue() {
var uiBathrooms = document.getElementsByName("uiBathrooms");
for(var i in uiBathrooms) {
if(uiBathrooms[i].checked) {
return parseInt(i)+1;
}
}
return -1; // Invalid Value
}
function getBHKValue() {
var uiBHK = document.getElementsByName("uiBHK");
for(var i in uiBHK) {
if(uiBHK[i].checked) {
return parseInt(i)+1;
}
}
return -1; // Invalid Value
}
function onClickedEstimatePrice() {
console.log("Estimate price button clicked");
var sqft = document.getElementById("uiSqft");
var bhk = getBHKValue();
var bathrooms = getBathValue();
var location = document.getElementById("uiLocations");
var estPrice = document.getElementById("uiEstimatedPrice");
// var url = "http://127.0.0.1:5000/predict_home_price"; //Use this if you are NOT using nginx which is first 7 tutorials
var url = "/api/predict_home_price"; // Use this if you are using nginx. i.e tutorial 8 and onwards
$.post(url, {
total_sqft: parseFloat(sqft.value),
bhk: bhk,
bath: bathrooms,
location: location.value
},function(data, status) {
console.log(data.estimated_price);
estPrice.innerHTML = "<h2>" + data.estimated_price.toString() + " Lakh</h2>";
console.log(status);
});
}
function onPageLoad() {
console.log( "document loaded" );
// var url = "http://127.0.0.1:5000/get_location_names"; // Use this if you are NOT using nginx which is first 7 tutorials
var url = "/api/get_location_names"; // Use this if you are using nginx. i.e tutorial 8 and onwards
$.get(url,function(data, status) {
console.log("got response for get_location_names request");
if(data) {
var locations = data.locations;
var uiLocations = document.getElementById("uiLocations");
$('#uiLocations').empty();
for(var i in locations) {
var opt = new Option(locations[i]);
$('#uiLocations').append(opt);
}
}
});
}
window.onload = onPageLoad;