<filename>huey/data/models/buoy.py
# AUTOGENERATED! DO NOT EDIT! File to edit: nbs/04_data.models.buoy.ipynb (unless otherwise specified).

__all__ = ['Buoy', 'BuoyRawSpectralWaveData']

# Cell
from ...imports import *

# Cell
from flask_appbuilder import Model
# from flask_appbuilder.models.mixins import AuditMixin

from sqlalchemy import Column, Integer, String, ForeignKey, \
    Float, DateTime, UniqueConstraint

from sqlalchemy.orm import relationship
from sqlalchemy.dialects import postgresql

from geoalchemy2.types import Geometry

# Cell
class Buoy(Model):
    id = Column(Integer, primary_key=True)
    station_id =  Column(String(150), unique = True, nullable=False)
    name = Column(String(564))
    owner = Column(String(564))
    pgm = Column(String(564))
    station_type = Column(String(150))
    lat = Column(Float())
    lng = Column(Float())
    point = Column(Geometry(geometry_type='POINT', srid=4326))

    elevation = Column(Float())
    hull = Column(String(100))
    anemom_height = Column(Float())

    def __repr__(self):
        return f"{self.station_id} - {self.name}"

# Cell
class BuoyRawSpectralWaveData(Model):
    id = Column(Integer, primary_key=True)
    buoy_id = Column(Integer, ForeignKey('buoy.id'), nullable=False)
    buoy = relationship("Buoy")
    ts = Column(DateTime(timezone=True), nullable=False)
    sep_freq = Column(Float())
    spec_x = Column(postgresql.ARRAY(Float), default='{}')
    spec_y = Column(postgresql.ARRAY(Float), default='{}')
    created_at = Column(DateTime(timezone=True), default=datetime.utcnow)
    updated_at = Column(DateTime(timezone=True))
    __table_args__ = (
        UniqueConstraint('buoy_id', 'ts', name='unique_buoy_raw_spectral_wave_data_ts'),
    )

    def __repr__(self):
        return f"{self.buoy_id} - {self.ts}"

    @classmethod
    def from_data_line(cls, line):
        columns = line.split()

        ob = cls()
        ob.ts = datetime(int(columns[0]), int(columns[1]), int(columns[2]), int(columns[3]), int(columns[4]), tzinfo=timezone.utc)
        ob.sep_freq = columns[5]

        x, y = [], []
        count = 0
        for val in columns[6:]:
            if (count % 2 == 0):
                x.append(float(val))
            else:
                val = val.replace('(', '')
                val = val.replace(')', '')
                y.append(float(val))

            count += 1

        ob.spec_x = x
        ob.spec_y = y

        return ob
<filename>huey/data/models/buoy.py
# AUTOGENERATED! DO NOT EDIT! File to edit: nbs/04_data.models.buoy.ipynb (unless otherwise specified).

__all__ = ['Buoy', 'BuoyRawSpectralWaveData']

# Cell
from ...imports import *

# Cell
from flask_appbuilder import Model
# from flask_appbuilder.models.mixins import AuditMixin

from sqlalchemy import Column, Integer, String, ForeignKey, \
    Float, DateTime, UniqueConstraint

from sqlalchemy.orm import relationship
from sqlalchemy.dialects import postgresql

from geoalchemy2.types import Geometry

# Cell
class Buoy(Model):
    id = Column(Integer, primary_key=True)
    station_id =  Column(String(150), unique = True, nullable=False)
    name = Column(String(564))
    owner = Column(String(564))
    pgm = Column(String(564))
    station_type = Column(String(150))
    lat = Column(Float())
    lng = Column(Float())
    point = Column(Geometry(geometry_type='POINT', srid=4326))

    elevation = Column(Float())
    hull = Column(String(100))
    anemom_height = Column(Float())

    def __repr__(self):
        return f"{self.station_id} - {self.name}"

# Cell
class BuoyRawSpectralWaveData(Model):
    id = Column(Integer, primary_key=True)
    buoy_id = Column(Integer, ForeignKey('buoy.id'), nullable=False)
    buoy = relationship("Buoy")
    ts = Column(DateTime(timezone=True), nullable=False)
    sep_freq = Column(Float())
    spec_x = Column(postgresql.ARRAY(Float), default='{}')
    spec_y = Column(postgresql.ARRAY(Float), default='{}')
    created_at = Column(DateTime(timezone=True), default=datetime.utcnow)
    updated_at = Column(DateTime(timezone=True))
    __table_args__ = (
        UniqueConstraint('buoy_id', 'ts', name='unique_buoy_raw_spectral_wave_data_ts'),
    )

    def __repr__(self):
        return f"{self.buoy_id} - {self.ts}"

    @classmethod
    def from_data_line(cls, line):
        columns = line.split()

        ob = cls()
        ob.ts = datetime(int(columns[0]), int(columns[1]), int(columns[2]), int(columns[3]), int(columns[4]), tzinfo=timezone.utc)
        ob.sep_freq = columns[5]

        x, y = [], []
        count = 0
        for val in columns[6:]:
            if (count % 2 == 0):
                x.append(float(val))
            else:
                val = val.replace('(', '')
                val = val.replace(')', '')
                y.append(float(val))

            count += 1

        ob.spec_x = x
        ob.spec_y = y

        return ob
# AUTOGENERATED! DO NOT EDIT! File to edit: nbs/04_data.models.buoy.ipynb (unless otherwise specified). # Cell # Cell # from flask_appbuilder.models.mixins import AuditMixin # Cell # Cell