-
Notifications
You must be signed in to change notification settings - Fork 0
/
pricer.py
83 lines (70 loc) · 3.67 KB
/
pricer.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
import pandas as pd
from flask import Flask, render_template
from flask_ask import Ask, question, statement
app = Flask(__name__)
ask = Ask(app, '/alexa')
@ask.launch
def new_ask():
welcome = render_template('welcome')
reprompt = render_template('reprompt')
return question(welcome).reprompt(reprompt)
@ask.intent('ByCityYearIntent')
def city_year(city, year, type_of_house):
if city is None or year is None or type_of_house is None:
reprompt_msg = render_template('reprompt_general')
return question(reprompt_msg)
else:
df = pd.read_csv('trulia.csv')
df.sort_values(by=['state', 'quarter'], ascending=True, inplace=True)
a = df[(df['city'] == city) & (df['quarter'].str.startswith(year))]
answer = int(a[str(type_of_house)].mean())
message = render_template('city_year', city=city, year=year, type_of_house=type_of_house, answer=str(answer))
return statement(message)
@ask.intent('ByStateYearIntent')
def state_year(state, year, type_of_house):
if state is None or year is None or type_of_house is None:
reprompt_msg = render_template('reprompt_general')
return question(reprompt_msg)
else:
df = pd.read_csv('trulia.csv')
df.sort_values(by=['state', 'quarter'], ascending=True, inplace=True)
a = df[(df['state'] == state) & (df['quarter'].str.startswith(year))]
answer = int(a[str(type_of_house)].mean())
message = render_template('state_year', state=state, year=year, type_of_house=type_of_house, answer=str(answer))
return statement(message)
@ask.intent('ByCityIntent')
def city_only(city, type_of_house):
if city is None or type_of_house is None:
reprompt_msg = render_template('reprompt_general')
return question(reprompt_msg)
else:
df = pd.read_csv('trulia.csv')
df.sort_values(by=['state', 'quarter'], ascending=True, inplace=True)
a = df[(df['city'] == city) & (df['quarter'].str.startswith('2012') |
df['quarter'].str.startswith('2013') |
df['quarter'].str.startswith('2014') |
df['quarter'].str.startswith('2015') |
df['quarter'].str.startswith('2016') |
df['quarter'].str.startswith('2017'))]
answer = int(a[str(type_of_house)].mean())
message = render_template('city_only', city=city, type_of_house=type_of_house, answer=str(answer))
return statement(message)
@ask.intent('ByStateIntent')
def state_only(state, type_of_house):
if state is None or type_of_house is None:
reprompt_msg = render_template('reprompt_general')
return question(reprompt_msg)
else:
df = pd.read_csv('trulia.csv')
df.sort_values(by=['state', 'quarter'], ascending=True, inplace=True)
a = df[(df['state'] == state) & (df['quarter'].str.startswith('2012') |
df['quarter'].str.startswith('2013') |
df['quarter'].str.startswith('2014') |
df['quarter'].str.startswith('2015') |
df['quarter'].str.startswith('2016') |
df['quarter'].str.startswith('2017'))]
answer = int(a[str(type_of_house)].mean())
message = render_template('state_only', state=state, type_of_house=type_of_house, answer=str(answer))
return statement(message)
if __name__ == '__main__':
app.run(debug=True)