-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathviews.py
212 lines (204 loc) · 9.04 KB
/
views.py
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
from flask import render_template, request
from saleawhen import app
from saleawhen import sale_model
communities = [
"", "01F", "01G", "05D", "06A", "09K", "12A", "12B", "12C", "12J", "13K",
"Abbeydale", "Acadia", "Alberta Park/Radisson Heights", "Altadore",
"Alyth/Bonnybrook", "Applewood Park", "Arbour Lake", "Aspen Woods",
"Auburn Bay", "Aurora Business Paprk", "Banff Trail", "Bankview",
"Bayview", "Beddington Heights", "Bel-Aire", "Belmont", "Beltline",
"Belvedere", "Bonavista Downs", "Bowness", "Braeside", "Brentwood",
"Bridgeland/Riverside", "Bridlewood", "Britannia", "Burns Industrial",
"Calgary International Airport", "Cambrian Heights", "Canyon Meadows",
"Capitol Hill", "Carrington", "Castleridge", "Cedarbrae", "Chaparral",
"Charleswood", "Chinatown", "Chinook Park", "Christie Park", "Citadel",
"Cityscape", "Cliff Bungalow", "Coach Hill", "Collingwood", "Copperfield",
"Coral Springs", "Cornerstone", "Cougar Ridge", "Country Hills",
"Country Hills Village", "Coventry Hills", "Cranston", "Crescent Heights",
"Crestmont", "Currie Barracks", "Dalhousie", "Deer Ridge", "Deer Run",
"Deerfoot Business Centre", "Diamond Cove", "Discovery Ridge",
"Douglasdale/Glen", "Dover", "Downtown Commercial Core",
"Downtown East Village", "Downtown West End", "Eagle Ridge",
"East Fairview Industrial", "East Shepard Industrial", "Eastfield",
"Eau Claire", "Edgemont", "Elbow Park", "Elboya", "Erin Woods", "Erlton",
"Evanston", "Evergreen", "Fairview", "Fairview Industrial", "Falconridge",
"Fish Creek Park", "Foothills", "Forest Heights", "Forest Lawn",
"Forest Lawn Industrial", "Garrison Green", "Garrison Woods", "Glamorgan",
"Glenbrook", "Glendale", "Greenview", "Greenview Industrial Park",
"Hamptons", "Harvest Hills", "Hawkwood", "Haysboro", "Hidden Valley",
"Highfield", "Highland Park", "Highwood", "Hillhurst", "Horizon",
"Hounsfield Heights/Briar Hill", "Huntington Hills", "Inglewood",
"Kelvin Grove", "Killarney/Glengarry", "Kincora", "Kingsland",
"Lake Bonavista", "Lakeview", "Legacy", "Lincoln Park", "Livingston",
"Lower Mount Royal", "Macewan Glen", "Mahogany", "Manchester",
"Manchester Industrial", "Maple Ridge", "Marlborough", "Marlborough Park",
"Martindale", "Mayfair", "Mayland Heights", "McCall", "McKenzie Lake",
"McKenzie Towne", "Meadowlark Park", "Meridian", "Midnapore", "Millrise",
"Mission", "Monterey Park", "Montgomery", "Mount Pleasant", "New Brighton",
"Nolan HIll", "North Airways", "North Glenmore Park", "North Haven",
"North Haven Upper", "Nose Hill Park", "Oakridge", "Ogden", "Palliser",
"Panorama Hills", "Parkdale", "Parkdale", "Parkhill", "Parkland",
"Patterson", "Penbrooke Meadows", "Pineridge", "Point McKay", "Pump Hill",
"Queensland", "Ramsay", "Ranchlands", "Red Carpet", "Redstone", "Renfrew",
"Richmond", "Rideau Park", "Rocky Ridge", "Rosedale", "Rosemont",
"Rosscarrock", "Roxboro", "Royal Oak", "Royal Vista", "Rundle",
"Rutland Park", "Saddle Ridge", "Sage Hill", "Sandstone Valley",
"Scarboro", "Scarboro/Sunalta West", "Scenic Acres", "Seton", "Shaganappi",
"Shawnee Slopes", "Shawnessy", "Shepard Industrial", "Sherwood",
"Signal Hill", "Silver Springs", "Silverado", "Skyline East",
"Skyview Ranch", "Somerset", "South Airways", "South Calgary",
"Southview", "Southwood", "Springbank Hill", "Spruce Cliff",
"St. Andrews Heights", "Starfield", "Stoney 1", "Strathcona Park",
"Sunalta", "Sundance", "Sunnyside", "Sunridge", "Taradale", "Temple",
"Thorncliffe", "Tuscany", "Tuxedo Park", "University District",
"University Heights", "Upper Mount Royal", "Valley Ridge", "Valleyfield",
"Varsity", "Vista Heights", "Walden", "West Hillhurst", "West Springs",
"Westgate", "Westwinds", "Whitehorn", "Wildwood", "Willow Park",
"Windsor Park", "Winston Heights/Mountview", "Woodbine", "Woodlands"]
# The Flask class has a method called route that takes a string (representing a
# path) and returns a decorator that defines a routine (called serve) that
# causes my function askawhen_index() to be called when serve("/") is called.
# i.e., it registers my "view function" with the route "/" so that whenever
# there is a request to the "/" route, this view function will be invoked and
# its result will be sent back to the client.
@app.route("/")
@app.route("/index")
def askawhen_index():
return render_template("form/form.html")
@app.route("/results")
def askawhen_result():
# Get the data from the submitted form.
# The month when the listing is posted.
month = request.args.get('month')
# The listed community.
comm = request.args.get('community')
# The number of bedrooms.
br = request.args.get('brs')
# The number of bedrooms above ground.
brag = request.args.get('brags')
# The number of full bathrooms
bath = request.args.get('baths')
# The number of half bathrooms
hbath = request.args.get('hbaths')
# The square footage of the home.
sqft = request.args.get('sqft')
# The annual property tax on the home.
tax = request.args.get('tax')
# The age of the home in years.
age = request.args.get('age')
# Is the home an apartment?
isapt = request.args.get('prop_apt')
# Is the home in a flood zone?
isflood = request.args.get('prop_flood')
# Is the property fenced?
isfence = request.args.get('prop_fence')
# Does the home contain a hot tub?
ishottub = request.args.get('prop_hottub')
# Does the home come with window coverings?
iscurts = request.args.get('prop_curts')
# Does the home have vinyl siding?
isvinyl = request.args.get('prop_vinyl')
# Does the home have non-ceramic tile flooring?
isnctile = request.args.get('prop_floor')
# Are pets disallowed from the property (like in some condos)?
isnopet = request.args.get('prop_pets')
# The requested quantile of the survival function.
quantile = request.args.get('conflevel')
if isapt is None:
isapt = 0
aptchecked = ""
else:
isapt = 1
aptchecked = "checked"
if isflood is None:
isflood = 0
floodchecked = ""
else:
isflood = 1
floodchecked = "checked"
if isfence is None:
isfence = 0
fencechecked = ""
else:
isfence = 1
fencechecked = "checked"
if ishottub is None:
ishottub = 0
hottubchecked = ""
else:
ishottub = 1
hottubchecked = "checked"
if iscurts is None:
iscurts = 0
curtschecked = ""
else:
iscurts = 1
curtschecked = "checked"
if isvinyl is None:
isvinyl = 0
vinylchecked = ""
else:
isvinyl = 1
vinylchecked = "checked"
if isnctile is None:
isnctile = 0
nctilechecked = ""
else:
isnctile = 1
nctilechecked = "checked"
if isnopet is None:
isnopet = 0
petchecked = ""
else:
isnopet = 1
petchecked = "checked"
if brag > br:
message = 'Error: The number of bedrooms above ground is greater ' + \
'than the total number of bedrooms.'
else:
iserr = False
try:
sqftval = float(sqft)
if sqftval < 0 or sqftval > 1000000:
raise ValueError
except ValueError:
message = "Error: invalid entry for the home's square footage."
iserr = True
try:
taxval = float(tax)
if taxval < 0 or taxval > 10000000:
raise ValueError
except ValueError:
message = "Error: invalid entry for the home's property tax."
iserr = True
try:
ageval = float(age)
if ageval < 0 or ageval > 150:
raise ValueError
except ValueError:
message = "Error: invalid entry for the home's age."
iserr = True
try:
qval = float(quantile)
if qval < 0 or qval > 99.9999:
raise ValueError
except ValueError:
message = "Error: invalid entry for the level of confidence. " + \
"Choose a number between 0 and 100."
iserr = True
if not iserr:
# Calculate the expected sale time.
sale = sale_model.saletimeCalgary(
int(month), int(brag), int(bath), sqftval, taxval, ageval,
isapt, isflood, isfence, ishottub, iscurts, isvinyl, isnctile,
isnopet, qval)
message = F'This listing is {quantile}% likely to sell ' + \
F'in {sale} days.'
return render_template(
"form/form2.html", message=message, month=month,
comm=comm, community=communities[int(comm)], br=br, brag=brag,
bath=bath, hbath=hbath, sqft=sqft, tax=tax, age=age,
aptchecked=aptchecked, floodchecked=floodchecked,
fencechecked=fencechecked, hottubchecked=hottubchecked,
curtschecked=curtschecked, vinylchecked=vinylchecked,
nctilechecked=nctilechecked, petchecked=petchecked, conflevel=quantile)