2022-02-21 15:07:04 +00:00
|
|
|
'''
|
|
|
|
Tutorial link: https://docs.sqlalchemy.org/en/latest/orm/tutorial.html
|
2022-02-22 15:36:49 +00:00
|
|
|
Sqlalchemy version: 1.4.31
|
|
|
|
Python version: 3.10
|
2022-02-21 15:07:04 +00:00
|
|
|
'''
|
2022-02-22 15:36:49 +00:00
|
|
|
#!/usr/bin/python# -*- coding: utf-8 -*-
|
2022-02-21 15:07:04 +00:00
|
|
|
|
|
|
|
from datetime import datetime
|
|
|
|
# from config import db, ma
|
|
|
|
|
|
|
|
# import os
|
|
|
|
from sqlalchemy import (Column, Integer,
|
2022-02-23 15:46:47 +00:00
|
|
|
String, DateTime, ForeignKey, Numeric)
|
2022-02-21 15:07:04 +00:00
|
|
|
from sqlalchemy.ext.declarative import declarative_base
|
2022-02-23 15:46:47 +00:00
|
|
|
from sqlalchemy.orm import session, relationship
|
|
|
|
#from marshmallow import Schema
|
2022-02-22 15:36:49 +00:00
|
|
|
from marshmallow_sqlalchemy import SQLAlchemyAutoSchema
|
2022-02-23 15:46:47 +00:00
|
|
|
from db.pg_models import create_pg_session
|
|
|
|
|
2022-02-21 15:07:04 +00:00
|
|
|
|
|
|
|
Base = declarative_base()
|
|
|
|
|
|
|
|
|
2022-02-23 15:46:47 +00:00
|
|
|
class Observation(Base):
|
|
|
|
""" observation class """
|
|
|
|
__tablename__ = 'observation'
|
|
|
|
__table_args__ = {"schema": "gba"}
|
|
|
|
|
|
|
|
id = Column('observation_id', Integer, primary_key=True)
|
|
|
|
name = Column('name', String)
|
|
|
|
value_type = Column('value_type', String)
|
|
|
|
# pitch = Column('PITCH', String)
|
|
|
|
# roll = Column('ROLL', String)
|
|
|
|
sampling_time_start = Column('sampling_time_start', DateTime)
|
|
|
|
sampling_time_end = Column('sampling_time_end', DateTime)
|
|
|
|
result_time = Column('result_time', DateTime)
|
|
|
|
sta_identifier = Column('sta_identifier', String)
|
|
|
|
value_quantity = Column('value_quantity', Numeric(20, 10), nullable=False)
|
|
|
|
|
|
|
|
# fk_dataset_id = Column('fk_dataset_id', Integer,
|
|
|
|
# ForeignKey('gba.dataset.dataset_id'))
|
|
|
|
# dataset = relationship("Dataset", lazy="joined",
|
|
|
|
# foreign_keys=[fk_dataset_id])
|
|
|
|
fk_dataset_id = Column(Integer, ForeignKey(
|
|
|
|
'gba.dataset.dataset_id'), nullable=False)
|
|
|
|
# dataset = relationship("Dataset", back_populates="observations")
|
|
|
|
|
|
|
|
class ObservationSchema(SQLAlchemyAutoSchema):
|
|
|
|
""" Platform class """
|
|
|
|
class Meta:
|
|
|
|
""" Platform class """
|
|
|
|
model = Observation
|
|
|
|
include_relationships = True
|
|
|
|
load_instance = True
|
|
|
|
#pg_session: session = create_pg_session()
|
|
|
|
sqla_session: session = create_pg_session()
|
|
|
|
|
|
|
|
|
2022-02-21 15:07:04 +00:00
|
|
|
class Person(Base):
|
|
|
|
""" Platform class """
|
2022-02-22 15:36:49 +00:00
|
|
|
__tablename__ = 'accounts'
|
|
|
|
__table_args__ = {"schema": "gba"}
|
|
|
|
person_id = Column('id', Integer, primary_key=True)
|
|
|
|
lname = Column('last_name', String(255), index=True)
|
|
|
|
fname = Column('first_name', String(255))
|
|
|
|
login = Column(String(255))
|
|
|
|
timestamp = Column('updated_at', DateTime, default=datetime.utcnow,
|
2022-02-21 15:07:04 +00:00
|
|
|
onupdate=datetime.utcnow)
|
2022-02-23 15:46:47 +00:00
|
|
|
|
2022-02-22 15:36:49 +00:00
|
|
|
def __repr__(self):
|
|
|
|
return "<User(name='%s', lastname='%s')>" % (
|
2022-02-23 15:46:47 +00:00
|
|
|
self.login, self.lname)
|
2022-02-21 15:07:04 +00:00
|
|
|
|
|
|
|
|
2022-02-22 15:36:49 +00:00
|
|
|
class PersonSchema(SQLAlchemyAutoSchema):
|
2022-02-21 15:07:04 +00:00
|
|
|
""" Platform class """
|
|
|
|
class Meta:
|
|
|
|
""" Platform class """
|
|
|
|
model = Person
|
2022-02-22 15:36:49 +00:00
|
|
|
include_relationships = True
|
|
|
|
load_instance = True
|
2022-02-21 15:07:04 +00:00
|
|
|
#pg_session: session = create_pg_session()
|
|
|
|
sqla_session: session = create_pg_session()
|