-
Notifications
You must be signed in to change notification settings - Fork 0
/
model.py
155 lines (112 loc) · 4.66 KB
/
model.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
from flask_sqlalchemy import SQLAlchemy
db = SQLAlchemy()
# This is the connection to the SQLite database; we're getting this through
# the Flask-SQLAlchemy helper library. On this, we can find the `session`
# object, where we do most of our interactions (like committing, etc.)
class Taxonomy(db.Model):
""" Taxonomy of Walmart Website
For this table, I am reading through the imported JSON object
and identifying the
KEY - the unique nesting id
which holds
id - nesting_id
name - the string that describes/holds key words for product seearch
path - more string desription holding key words for product seearch
children : [ new array with further nested values to import to table]"""
__tablename__ = "taxonomy"
nesting_id = db.Column(db.Integer, autoincrement=True, primary_key=True)
category_node = db.Column(db.String(64), nullable=False)
name = db.Column(db.String(64), nullable=False)
path = db.Column(db.String(64))
children = db.Column(db.Boolean)
def __repr__(self):
"""This is a helpful representation"""
return "<Taxonomy category_node=%s name=%s>" % (self.category_node, self.name)
# if children:
# import values
class User(db.Model):
"""This is our fake user database"""
__tablename__ = "users"
user_id = db.Column(db.Integer, autoincrement=True, primary_key=True)
name = db.Column(db.String(64), nullable=False)
email = db.Column(db.String(64), nullable=False)
password = db.Column(db.String(64), nullable=False)
gender = db.Column(db.String(64))
halal = db.Column(db.Boolean)
free_range = db.Column(db.Boolean)
slow_growth = db.Column(db.Boolean)
pastured = db.Column(db.Boolean)
non_gmo = db.Column(db.Boolean)
antibiotics = db.Column(db.Boolean)
organic_100 = db.Column(db.Boolean)
organic_95 = db.Column(db.Boolean)
price = db.Column(db.Integer)
preference1 = db.Column(db.Integer)
preference2 = db.Column(db.Integer)
preference3 = db.Column(db.Integer)
preference4 = db.Column(db.Integer)
preference5 = db.Column(db.Integer)
preference6 = db.Column(db.Integer)
preference7 = db.Column(db.Integer)
preference8 = db.Column(db.Integer)
preference9 = db.Column(db.Integer)
preference10 = db.Column(db.Integer)
def __repr__(self):
"""This is a helpful representation"""
return "<User name=%s email=%s>" % (self.name, self.email)
class Brand(db.Model):
"""This the brand database for Walmart products in the category of Food: """
__tablename__ = "brands"
brand_id = db.Column(db.Integer, autoincrement=True, primary_key=True)
brand_name = db.Column(db.String(64), nullable=False)
parent_company = db.Column(db.String(64))
brand_website = db.Column(db.String(64), nullable=False)
brand_youtube = db.Column(db.String(64))
brand_facebook = db.Column(db.String(64))
brand_instagram = db.Column(db.String(64))
brand_twitter = db.Column(db.String(64))
brand_pintrest = db.Column(db.String(64))
brand_google_plus = db.Column(db.String(64))
brand_conventional = db.Column(db.Boolean)
brand_organic = db.Column(db.Boolean)
brand_free_range = db.Column(db.Boolean)
brand_pastured = db.Column(db.Boolean)
brand_slow_growth = db.Column(db.Boolean)
class SearchActivity(db.Model):
"""Database for user search activity"""
__tablename__ = "search_activity"
query_id = db.Column(db.Integer, autoincrement=True, primary_key=True)
user_id = db.Column(db.Integer, nullable=False)
search_query = db.Column(db.String(64), nullable=False)
datetime = db.Column(db.DateTime)
class PurchaseActivity(db.Model):
"""Database for user purchase activity"""
__tablename__ = "purchases"
purchase_id = db.Column(db.Integer, autoincrement=True, primary_key=True)
user_id = db.Column(db.Integer, db.ForeignKey('users.user_id'))
item_id = db.Column(db.Integer, nullable=False)
datetime = db.Column(db.DateTime)
purchased = db.Column(db.Boolean)
conventional = db.Column(db.Boolean)
organic = db.Column(db.Boolean)
free_range = db.Column(db.Boolean)
pastured = db.Column(db.Boolean)
user = db.relationship("User", backref=db.backref("purchases"))
# class Activity(db.Model):
# __tablename__ = "activities"
# activity_key =
# user_id = db
##############################################################################
# Helper functions
def connect_to_db(app):
"""Connect the database to our Flask app."""
# Configure to use our SQLite database
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///poultrywatch.db'
db.app = app
db.init_app(app)
if __name__ == "__main__":
# As a convenience, if we run this module interactively, it will leave
# you in a state of being able to work with the database directly.
from server import app
connect_to_db(app)
print "Connected to DB."