Subversion Repositories yaws

Rev

Rev 1 | Rev 14 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 ron 1
#!/usr/bin/env python3
2
# -*- coding: utf-8 -*-
3
#
4
#  database/samples.py
5
#
6
#  Copyright 2020 Ron Wellsted <ron@wellsted.org.uk>
7
#
8
# This program is free software; you can redistribute it and/or modify
9
# it under the terms of the GNU General Public License as published by
10
# the Free Software Foundation; either version 2 of the License, or
11
# (at your option) any later version.
12
#
13
# This program is distributed in the hope that it will be useful,
14
# but WITHOUT ANY WARRANTY; without even the implied warranty of
15
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
# GNU General Public License for more details.
17
#
18
# You should have received a copy of the GNU General Public License
19
# along with this program; if not, write to the Free Software
20
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21
 
22
from sqlalchemy import create_engine
23
 
13 ron 24
engine = create_engine('sqlite:///yaws.sqlite3', echo=True)
1 ron 25
from sqlalchemy.orm import sessionmaker
26
 
27
Session = sessionmaker(bind=engine)
28
session = Session()
29
import datetime
30
from sqlalchemy import Table, Column, DateTime, Boolean, Float
31
from sqlalchemy.ext.declarative import declarative_base
32
 
33
Base = declarative_base()
34
 
35
class Samples(Base):
36
    __tablename__ = 'samples'
37
    sampled = Column(DateTime, primary_key=True, default=datetime.datetime.utcnow)
38
    airtemp = Column(Float)
39
    gndtemp = Column(Float)
40
    pressure = Column(Float)
41
    humidity = Column(Float)
42
    windspeed = Column(Float)
43
    rain = Column(Boolean)
44
    rainfall = Column(Float)
45
    sunlight = Column(Float)
46
    cputemp = Column(Float)
47
 
48
    def __repr__(self):
49
        return {'sampled':self.sampled, 'airtemp':self.airtemp,
50
            'gndtemp':self.gndtemp, 'pressure':self.pressure,
51
            'humidity':self.humidity, 'windspeed':self.windspeed,
52
            'rain':self.rain, 'rainfall':self.rainfall,
53
            'sunlight':self.sunlight, 'cputemp':self.cputemp}
54
 
55
    def __str__(self):
56
        return (f'Sampled={self.sampled}\n'
57
            f'AirTemp={self.airtemp}\n'
58
            f'GndTemp={self.gndtemp}\n'
59
            f'Pressure={self.pressure}\n'
60
            f'Humidity={self.humidity}\n'
61
            f'Windspeed={self.windspeed}\n'
62
            f'Rain={self.rain}\n'
63
            f'Rainfall={self.rainfall}\n'
64
            f'Sunlight={self.sunlight}\n'
65
            f'CPUTemp={self.cputemp}')
66
 
67
Base.metadata.create_all(engine)