-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmodels.py
50 lines (38 loc) · 1.71 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
#This is models.py
from flask_sqlalchemy import SQLAlchemy
from sqlalchemy.dialects.mysql import VARCHAR
# Initialize the database
db = SQLAlchemy()
class TerminalData(db.Model):
__tablename__ = 'terminal_data'
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
timestamp = db.Column(db.DateTime, nullable=False)
sai = db.Column(db.String(255), nullable=False)
device_id = db.Column(db.String(255), nullable=False)
latitude = db.Column(db.Float, nullable=False)
longitude = db.Column(db.Float, nullable=False)
district = db.Column(db.String(255), nullable=False)
state = db.Column(db.String(255), nullable=False)
def __repr__(self):
return f"<TerminalData {self.device_id}>"
class District(db.Model):
__tablename__ = 'districts'
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
state = db.Column(db.String(255), nullable=False)
district = db.Column(db.String(255), nullable=False)
geometry = db.Column(db.Text, nullable=False) # GeoJSON data stored as text
def __repr__(self):
return f"<District {self.district}, {self.state}>"
class Terminal(db.Model):
__tablename__ = 'terminals'
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
device_id = db.Column(db.String(255), nullable=False, unique=True)
name = db.Column(db.String(255), nullable=False)
last_latitude = db.Column(db.Float, nullable=True)
last_longitude = db.Column(db.Float, nullable=True)
last_timestamp = db.Column(db.DateTime, nullable=True)
def __repr__(self):
return f"<Terminal {self.device_id}>"
# Utility function to create all tables
def create_tables():
db.create_all()