-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodels.py
108 lines (94 loc) · 2.66 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
from datetime import datetime, timedelta
from sqlalchemy import create_engine, Column, DateTime, Float, Numeric
from sqlalchemy.ext.declarative import declarative_base
import os
from dotenv import load_dotenv
load_dotenv()
# Configure the PostgreSQL connection
db_user = 'mpappas'
db_password = os.environ['db_password']
# db_password = 'postgres'
db_host = 'localhost'
db_port = '5432'
db_name = 'van_data'
db_url = f'postgresql://{db_user}:{db_password}@{db_host}:{db_port}/{db_name}'
# Create a database connection
engine = create_engine(db_url)
# Create a base class for declarative table definitions
Base = declarative_base()
# Define the Water class representing the table
class Water(Base):
__tablename__ = 'water'
timestamp = Column(
DateTime,
primary_key=True,
default=datetime.utcnow()-timedelta(hours=7))
consumption = Column(
Numeric,
nullable=False,
unique=False
)
percent_remain = Column(
Numeric,
nullable=False,
unique=False
)
# Define the Battery class representing the table
class Battery(Base):
__tablename__ = 'battery'
timestamp = Column(
DateTime,
primary_key=True,
default=datetime.utcnow())
volts = Column(
Numeric,
nullable=False,
unique=False
)
amps = Column(
Numeric,
nullable=False,
unique=False
)
remain = Column(
Numeric,
nullable=False,
unique=False
)
percent = Column(
Numeric,
nullable=False,
unique=False
)
temp1 = Column(
Numeric,
nullable=False,
unique=False
)
temp2 = Column(
Numeric,
nullable=False,
unique=False
)
cell1 = Column(
Float,
nullable=False,
unique=False
)
cell2 = Column(
Float,
nullable=False,
unique=False
)
cell3 = Column(
Float,
nullable=False,
unique=False
)
cell4 = Column(
Float,
nullable=False,
unique=False
)
# Create the table in the database
Base.metadata.create_all(engine)