|
| 1 | +from datetime import datetime |
1 | 2 | from api import db |
2 | | -import enum |
3 | | -from sqlalchemy.dialects.mysql import DECIMAL, ENUM |
4 | | -from sqlalchemy.orm import relationship |
5 | | -from sqlalchemy import ForeignKey |
6 | | -from typing import List |
| 3 | +from sqlalchemy.dialects.mysql import DECIMAL |
7 | 4 |
|
8 | 5 |
|
9 | 6 | class Sites(db.Model): |
10 | 7 | __bind_key__ = "fastpheno" |
11 | 8 | __tablename__ = "sites" |
12 | 9 |
|
13 | | - sites_pk: db.Mapped[int] = db.mapped_column(db.Integer, nullable=False, primary_key=True) |
| 10 | + sites_pk: db.Mapped[int] = db.mapped_column(db.Integer, primary_key=True, nullable=False) |
14 | 11 | site_name: db.Mapped[str] = db.mapped_column(db.String(45), nullable=False) |
15 | | - site_desc: db.Mapped[str] = db.mapped_column(db.String(99), nullable=True) |
16 | | - children: db.Mapped[List["Trees"]] = relationship() |
| 12 | + lat: db.Mapped[float] = db.mapped_column(DECIMAL(15, 12), nullable=False) |
| 13 | + lng: db.Mapped[float] = db.mapped_column(DECIMAL(15, 12), nullable=False) |
| 14 | + site_desc: db.Mapped[str] = db.mapped_column(db.String(999), nullable=True) |
| 15 | + |
| 16 | + |
| 17 | +class Flights(db.Model): |
| 18 | + __bind_key__ = "fastpheno" |
| 19 | + __tablename__ = "flights" |
| 20 | + |
| 21 | + flights_pk: db.Mapped[int] = db.mapped_column(db.Integer, primary_key=True, nullable=False) |
| 22 | + pilot: db.Mapped[str] = db.mapped_column(db.String(45), nullable=True) |
| 23 | + flight_date: db.Mapped[datetime] = db.mapped_column(db.DateTime, nullable=False) |
| 24 | + sites_pk: db.Mapped[int] = db.mapped_column(db.Integer, nullable=False) |
| 25 | + height: db.Mapped[float] = db.mapped_column(DECIMAL(15, 10), nullable=True) |
| 26 | + speed: db.Mapped[float] = db.mapped_column(DECIMAL(15, 10), nullable=True) |
17 | 27 |
|
18 | 28 |
|
19 | 29 | class Trees(db.Model): |
20 | 30 | __bind_key__ = "fastpheno" |
21 | 31 | __tablename__ = "trees" |
22 | 32 |
|
23 | | - trees_pk: db.Mapped[int] = db.mapped_column(db.Integer, nullable=False, primary_key=True) |
24 | | - sites_pk: db.Mapped[int] = db.mapped_column(ForeignKey("sites.sites_pk")) |
25 | | - longitude: db.Mapped[float] = db.mapped_column(db.Float, nullable=False) |
26 | | - latitude: db.Mapped[float] = db.mapped_column(db.Float, nullable=False) |
27 | | - genotype_id: db.Mapped[str] = db.mapped_column(db.String(5), nullable=True) |
| 33 | + trees_pk: db.Mapped[int] = db.mapped_column(db.Integer, primary_key=True, nullable=False) |
| 34 | + sites_pk: db.Mapped[int] = db.mapped_column(db.Integer, nullable=False) |
| 35 | + longitude: db.Mapped[float] = db.mapped_column(DECIMAL(15, 12), nullable=False) |
| 36 | + latitude: db.Mapped[float] = db.mapped_column(DECIMAL(15, 12), nullable=False) |
| 37 | + tree_site_id: db.Mapped[str] = db.mapped_column(db.String(45), nullable=True) |
| 38 | + family_id: db.Mapped[str] = db.mapped_column(db.String(45), nullable=True) |
28 | 39 | external_link: db.Mapped[str] = db.mapped_column(db.String(200), nullable=True) |
29 | | - tree_given_id: db.Mapped[str] = db.mapped_column(db.String(25), nullable=True) |
30 | | - children: db.Mapped[List["Band"]] = relationship() |
31 | | - |
32 | | - |
33 | | -class MonthChoices(enum.Enum): |
34 | | - jan = "1" |
35 | | - feb = "2" |
36 | | - mar = "3" |
37 | | - apr = "4" |
38 | | - may = "5" |
39 | | - jun = "6" |
40 | | - jul = "7" |
41 | | - aug = "8" |
42 | | - sep = "9" |
43 | | - oct = "10" |
44 | | - nov = "11" |
45 | | - dec = "12" |
46 | | - |
47 | | - |
48 | | -class Band(db.Model): |
| 40 | + block_num: db.Mapped[int] = db.mapped_column(db.Integer, nullable=True) |
| 41 | + seq_id: db.Mapped[str] = db.mapped_column(db.String(25), nullable=True) |
| 42 | + x_pos: db.Mapped[int] = db.mapped_column(db.Integer, nullable=True) |
| 43 | + y_pos: db.Mapped[int] = db.mapped_column(db.Integer, nullable=True) |
| 44 | + height_2022: db.Mapped[str] = db.mapped_column(db.String(10), nullable=True) |
| 45 | + |
| 46 | + |
| 47 | +class TreesFlightsJoinTbl(db.Model): |
49 | 48 | __bind_key__ = "fastpheno" |
50 | | - __tablename__ = "band" |
| 49 | + __tablename__ = "trees_flights_join_tbl" |
| 50 | + |
| 51 | + trees_pk: db.Mapped[int] = db.mapped_column(db.Integer, primary_key=True, nullable=False) |
| 52 | + flights_pk: db.Mapped[int] = db.mapped_column(db.Integer, primary_key=True, nullable=False) |
| 53 | + confidence: db.Mapped[float] = db.mapped_column(DECIMAL(8, 5), nullable=True) |
| 54 | + |
51 | 55 |
|
52 | | - trees_pk: db.Mapped[int] = db.mapped_column(ForeignKey("trees.trees_pk"), primary_key=True) |
53 | | - month: db.Mapped[str] = db.mapped_column(ENUM(MonthChoices), nullable=False, primary_key=True) |
54 | | - band: db.Mapped[float] = db.mapped_column(db.String(100), nullable=False, primary_key=True) |
| 56 | +class Bands(db.Model): |
| 57 | + __bind_key__ = "fastpheno" |
| 58 | + __tablename__ = "bands" |
| 59 | + __table_args__ = (db.Index("bands_flight_band_tree_idx", "flights_pk", "band", "trees_pk"),) |
| 60 | + |
| 61 | + trees_pk: db.Mapped[int] = db.mapped_column(db.Integer, primary_key=True, nullable=False) |
| 62 | + flights_pk: db.Mapped[int] = db.mapped_column(db.Integer, primary_key=True, nullable=False) |
| 63 | + band: db.Mapped[str] = db.mapped_column(db.String(20), primary_key=True, nullable=False) |
| 64 | + value: db.Mapped[float] = db.mapped_column(DECIMAL(8, 5), nullable=False) |
| 65 | + |
| 66 | + |
| 67 | +class Pigments(db.Model): |
| 68 | + __bind_key__ = "fastpheno" |
| 69 | + __tablename__ = "pigments" |
| 70 | + |
| 71 | + trees_pk: db.Mapped[int] = db.mapped_column(db.Integer, primary_key=True, nullable=False) |
| 72 | + flights_pk: db.Mapped[int] = db.mapped_column(db.Integer, primary_key=True, nullable=False) |
| 73 | + pigment: db.Mapped[int] = db.mapped_column(db.Integer, primary_key=True, nullable=False) |
55 | 74 | value: db.Mapped[float] = db.mapped_column(DECIMAL(20, 15), nullable=False) |
56 | 75 |
|
57 | 76 |
|
58 | | -class Height(db.Model): |
| 77 | +class Unispec(db.Model): |
59 | 78 | __bind_key__ = "fastpheno" |
60 | | - __tablename__ = "height" |
| 79 | + __tablename__ = "unispec" |
61 | 80 |
|
62 | | - trees_pk: db.Mapped[int] = db.mapped_column(ForeignKey("trees.trees_pk"), primary_key=True) |
63 | | - month: db.Mapped[str] = db.mapped_column(ENUM(MonthChoices), nullable=False, primary_key=True) |
64 | | - tree_height_proxy: db.Mapped[float] = db.mapped_column(DECIMAL(20, 15), nullable=False) |
65 | | - ground_height_proxy: db.Mapped[float] = db.mapped_column(DECIMAL(20, 15), nullable=False) |
| 81 | + trees_pk: db.Mapped[int] = db.mapped_column(db.Integer, primary_key=True, nullable=False) |
| 82 | + flights_pk: db.Mapped[int] = db.mapped_column(db.Integer, primary_key=True, nullable=False) |
| 83 | + pigment: db.Mapped[int] = db.mapped_column(db.Integer, primary_key=True, nullable=False) |
| 84 | + value: db.Mapped[float] = db.mapped_column(DECIMAL(20, 15), nullable=False) |
0 commit comments