-
Notifications
You must be signed in to change notification settings - Fork 6
/
models.py
214 lines (157 loc) · 7.33 KB
/
models.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
213
214
import datetime
from app import db
class FireIncident(db.Model):
__bind_key__ = 'lbc_data'
__tablename__ = 'standardized_fire_incidents'
cad_call_number = db.Column(db.Integer, primary_key=True)
incident_number = db.Column(db.Integer)
alarm_datetime = db.Column(db.DateTime(timezone=True))
district = db.Column(db.String(6))
x_coordinate = db.Column(db.String(7))
y_coordinate = db.Column(db.String(7))
street_number = db.Column(db.String(10))
street_prefix = db.Column(db.String(30))
street_name = db.Column(db.String(200))
street_type = db.Column(db.String(20))
street_suffix = db.Column(db.String(20))
cross_street_prefix = db.Column(db.String(30))
cross_street_name = db.Column(db.String(200))
cross_street_type = db.Column(db.String(20))
cross_street_suffix = db.Column(db.String(20))
incident_address = db.Column(db.String(255))
apartment_number = db.Column(db.String(20))
incident_cross_street = db.Column(db.String(255))
postal_code = db.Column(db.String(10))
common_name = db.Column(db.String(200))
initial_cad_call_type = db.Column(db.String(20))
initial_cad_call_type_description = db.Column(db.String(100))
final_cad_call_type = db.Column(db.String(20))
final_cad_call_type_description = db.Column(db.String(100))
actual_nfirs_incident_type = db.Column(db.String(20))
actual_nfirs_incident_type_description = db.Column(db.String(100))
intersection = db.Column(db.String(6))
standardized_address = db.Column(db.String)
class FireDispatch(db.Model):
__bind_key__ = 'lbc_data'
__tablename__ = 'fire_dispatches'
incident_number = db.Column(db.Integer, primary_key=True)
apparatus_id = db.Column(db.String(6), primary_key=True)
apparatus_type = db.Column(db.String(3))
apparatus_description = db.Column(db.String(100))
dispatch_datetime = db.Column(db.String(30))
enroute_scene_datetime = db.Column(db.String(30))
arrival_datetime = db.Column(db.String(30))
depart_scene_datetime = db.Column(db.String(30))
arrived_facility_datetime = db.Column(db.String(30))
clear_datetime = db.Column(db.String(30))
turnout_time_in_sec = db.Column(db.Integer)
travel_time_nfpa_response_time_in_sec = db.Column(db.Integer)
response_time_in_sec = db.Column(db.Integer)
total_response_time_in_sec = db.Column(db.Integer)
on_scene_time_where_transport_in_sec = db.Column(db.Integer)
total_on_scene_time_with_or_without_transport_in_sec = db.Column(db.Integer)
transport_time_in_sec = db.Column(db.Integer)
turnaround_time_in_sec = db.Column(db.Integer)
duration_time_in_sec = db.Column(db.Integer)
class BusinessLicense(db.Model):
__bind_key__ = 'lbc_data'
__tablename__ = 'all_business_licenses'
name = db.Column(db.String(200), primary_key=True)
business_service_description = db.Column(db.String(100))
business_product = db.Column(db.String(40))
business_address = db.Column(db.String(200), primary_key=True)
business_street_number = db.Column(db.String(10))
business_street_prefix = db.Column(db.String(30))
business_street_name = db.Column(db.String(200))
business_street_type = db.Column(db.String(20))
business_street_suffix = db.Column(db.String(20))
business_zip = db.Column(db.String(20))
class PoliceIncident(db.Model):
__bind_key__ = 'lbc_data'
__tablename__ = 'standardized_police_incidents'
cad_call_number = db.Column(db.String(25), primary_key=True)
incident_number = db.Column(db.String(25))
call_datetime = db.Column(db.DateTime(timezone=True))
x_coordinate = db.Column(db.String(7))
y_coordinate = db.Column(db.String(7))
incident_address = db.Column(db.String(255))
street_number = db.Column(db.String(10))
street_prefix = db.Column(db.String(30))
street_name = db.Column(db.String(200))
street_type = db.Column(db.String(20))
street_suffix = db.Column(db.String(20))
initial_cad_call_type = db.Column(db.String(20))
initial_cad_call_type_description = db.Column(db.String(100))
final_cad_call_type = db.Column(db.String(20))
final_cad_call_type_description = db.Column(db.String(100))
standardized_address = db.Column(db.String)
class AddressSummary(db.Model):
__tablename__ = 'address_summaries'
address = db.Column(db.String(50), primary_key=True)
fire_incidents_last7 = db.Column(db.Integer)
fire_incidents_prev7 = db.Column(db.Integer)
police_incidents_last7 = db.Column(db.Integer)
police_incidents_prev7 = db.Column(db.Integer)
fire_incidents_last30 = db.Column(db.Integer)
fire_incidents_prev30 = db.Column(db.Integer)
police_incidents_last30 = db.Column(db.Integer)
police_incidents_prev30 = db.Column(db.Integer)
fire_incidents_last90 = db.Column(db.Integer)
fire_incidents_prev90 = db.Column(db.Integer)
police_incidents_last90 = db.Column(db.Integer)
police_incidents_prev90 = db.Column(db.Integer)
fire_incidents_last365 = db.Column(db.Integer)
fire_incidents_prev365 = db.Column(db.Integer)
police_incidents_last365 = db.Column(db.Integer)
police_incidents_prev365 = db.Column(db.Integer)
business_count = db.Column(db.Integer, default=0)
business_names = db.Column(db.Text, default="")
business_types = db.Column(db.Text, default="")
active = db.Column(db.Boolean)
def counts_for_days_ago(self, days):
return {
'fire': {
'last': getattr(self, "fire_incidents_last%d" % days),
'prior': getattr(self, "fire_incidents_prev%d" % days)
},
'police': {
'last': getattr(self, "police_incidents_last%d" % days),
'prior': getattr(self, "police_incidents_prev%d" % days)
}
}
class AuditLogEntry(db.Model):
__tablename__ = 'audit_log'
timestamp = db.Column(db.DateTime(timezone=True), default=db.func.now(), primary_key=True)
resource = db.Column(db.String(100), primary_key=True)
method = db.Column(db.String(10), primary_key=True)
response_code = db.Column(db.String(3), primary_key=True)
user_id = db.Column(db.String(8), db.ForeignKey('users.id'), primary_key=True)
user = db.relationship('User', primaryjoin='AuditLogEntry.user_id==User.id')
class User(db.Model):
__tablename__ = 'users'
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(75))
email = db.Column(db.String(100), unique=True)
date_created = db.Column(db.DateTime(timezone=True), default=db.func.now())
can_view_fire_data = db.Column(db.Boolean, default=False)
def is_authenticated(self):
return True
def is_active(self):
# @todo: crossreference with Google Doc or LDAP.
return True
def is_anonymous(self):
return False
def get_id(self):
return unicode(self.id)
class Action(db.Model):
__tablename__ = 'actions'
id = db.Column(db.Integer, primary_key=True)
type = db.Column(db.String)
address = db.Column(db.String)
content = db.Column(db.Text)
user_id = db.Column(db.Integer, db.ForeignKey('users.id'))
created = db.Column(db.DateTime(timezone=True), default=db.func.now())
user = db.relationship('User')
class ActivatedAddress(db.Model):
__tablename__ = 'activated_addresses'
address = db.Column(db.String, primary_key=True)