from sqlalchemy import Table, Column, Integer, String from sqlalchemy.ext.declarative import declarative_base from .models_core import StationmetaCore from .models_global import StationmetaGlobal from .models_global_services import StationmetaGlobalService from .models_role import StationmetaRole, stationmeta_core_stationmeta_roles_table from .models_annotation import StationmetaAnnotation, stationmeta_core_stationmeta_annotations_table from .models_aux import StationmetaAuxDoc, StationmetaAuxImage, StationmetaAuxUrl from toardb.base import Base # controlled vocabulary # Station Climatic Zone CZ_enum_table = Table("cz_vocabulary", Base.metadata, Column("enum_val", Integer, primary_key=True), Column("enum_str", String), Column("enum_display_str", String) ) # After loosing one day without solution, the following workaround is introduced! from collections import namedtuple Enumdict=namedtuple("Dict",["value","string","display_str"]) #def __get_enum_dict(table: Table, db: Session = Depends(get_db)): # This is not working (whereever I put it!) -- I have to investigate, how to do testing # (and using tables in my testing environment!)" # AND (EVEN MORE IMPORTANT): # How to load enum_dicts once?! # This is important to be able to use the enum_dicts within the validator of the pydantic model # The following code is just a workaround: CZ_enum = ( Enumdict(-1, 'Undefined', 'undefined'), Enumdict( 0, 'Unclassified', 'unclassified'), Enumdict( 1, 'WarmTemperateMoist', 'warm temperate moist'), Enumdict( 2, 'WarmTemperateDry', 'warm temperate dry'), Enumdict( 3, 'CoolTemperateMoist', 'cool temperate moist'), Enumdict( 4, 'CoolTemperateDry', 'cool temperate dry'), Enumdict( 5, 'PolarMoist', 'polar moist'), Enumdict( 6, 'PolarDry', 'polar dry'), Enumdict( 7, 'BorealMoist', 'boreal moist'), Enumdict( 8, 'BorealDry', 'boreal dry'), Enumdict( 9, 'TropicalMontane', 'tropical montane'), Enumdict(10, 'TropicalWet', 'tropical wet'), Enumdict(11, 'TropicalMoist', 'tropical moist'), Enumdict(12, 'TropicalDry', 'tropical dry') ) # Station Coordinate Validity CV_enum_table = Table("cv_vocabulary", Base.metadata, Column("enum_val", Integer, primary_key=True), Column("enum_str", String), Column("enum_display_str", String) ) # The following code is just a workaround (see above): CV_enum = ( Enumdict(0, 'NotChecked', 'not checked'), Enumdict(1, 'Verified', 'verified'), Enumdict(2, 'Plausible', 'plausible'), Enumdict(3, 'Doubtful', 'doubtful'), Enumdict(4, 'Unverifyable', 'not verifyable') ) # Station Types ST_enum_table = Table("st_vocabulary", Base.metadata, Column("enum_val", Integer, primary_key=True), Column("enum_str", String), Column("enum_display_str", String) ) # The following code is just a workaround (see above): ST_enum = ( Enumdict(0, 'Unknown', 'unknown'), Enumdict(1, 'Background', 'background'), Enumdict(2, 'Traffic', 'traffic'), Enumdict(3, 'Industrial', 'industrial'), Enumdict(4, 'Other', 'other') ) # Station Types of Area TA_enum_table = Table("ta_vocabulary", Base.metadata, Column("enum_val", Integer, primary_key=True), Column("enum_str", String), Column("enum_display_str", String) ) # The following code is just a workaround (see above): TA_enum = ( Enumdict(0, 'Unknown', 'unknown'), Enumdict(1, 'Urban', 'urban'), Enumdict(2, 'Suburban', 'suburban'), Enumdict(3, 'Rural', 'rural'), Enumdict(4, 'Remote', 'remote') ) # Station TOAR Categories TC_enum_table = Table("tc_vocabulary", Base.metadata, Column("enum_val", Integer, primary_key=True), Column("enum_str", String), Column("enum_display_str", String) ) # The following code is just a workaround (see above): TC_enum = ( Enumdict(-1, 'Unknown', 'unknown'), Enumdict( 0, 'Unclassified', 'unclassified'), Enumdict( 1, 'RuralLowElevation', 'rural low elevation'), Enumdict( 2, 'RuralHighElevation', 'rural high elevation'), Enumdict( 3, 'Urban', 'urban') ) # Station HTAP Regions (TIER1) TR_enum_table = Table("tr_vocabulary", Base.metadata, Column("enum_val", Integer, primary_key=True), Column("enum_str", String), Column("enum_display_str", String) ) # The following code is just a workaround (see above): TR_enum = ( Enumdict(-1, 'HTAPTier1Undefined', '-1 (undefined)'), Enumdict( 1, 'HTAPTier1World', '1 (World)'), Enumdict( 2, 'HTAPTier1OCN', '2 (OCN Non-arctic/Antarctic Ocean)'), Enumdict( 3, 'HTAPTier1NAM', '3 (NAM US+Canada (upto 66 N; polar circle))'), Enumdict( 4, 'HTAPTier1EUR', '4 (EUR Western + Eastern EU+Turkey (upto 66 N polar circle))'), Enumdict( 5, 'HTAPTier1SAS', '5 (SAS South Asia: India, Nepal, Pakistan, Afghanistan, Bangadesh, Sri Lanka)'), Enumdict( 6, 'HTAPTier1EAS', '6 (EAS East Asia: China, Korea, Japan)'), Enumdict( 7, 'HTAPTier1SEA', '7 (SEA South East Asia)'), Enumdict( 8, 'HTAPTier1PAN', '8 (PAN Pacific, Australia+ New Zealand)'), Enumdict( 9, 'HTAPTier1NAF', '9 (NAF Northern Africa+Sahara+Sahel)'), Enumdict(10, 'HTAPTier1SAF', '10 (SAF Sub Saharan/sub Sahel Africa)'), Enumdict(11, 'HTAPTier1MDE', '11 (MDE Middle East: S. Arabia, Oman, etc, Iran, Iraq)'), Enumdict(12, 'HTAPTier1MCA', '12 (MCA Mexico, Central America, Caribbean, Guyanas, Venezuela, Columbia)'), Enumdict(13, 'HTAPTier1SAM', '13 (SAM S. America)'), Enumdict(14, 'HTAPTier1RBU', '14 (RBU Russia, Belarussia, Ukraine)'), Enumdict(15, 'HTAPTier1CAS', '15 (CAS Central Asia)'), Enumdict(16, 'HTAPTier1NPO', '16 (NPO Arctic Circle (North of 66 N) + Greenland)'), Enumdict(17, 'HTAPTier1SPO', '17 (SPO Antarctic)') ) # Station Dominant Landcover Types DL_enum_table = Table("dl_vocabulary", Base.metadata, Column("enum_val", Integer, primary_key=True), Column("enum_str", String), Column("enum_display_str", String) ) # The following code is just a workaround (see above): DL_enum = ( Enumdict( -1, 'Undefined', '-1 (undefined)'), Enumdict( 0, 'Water', '0 (Water)'), Enumdict( 1, 'EGNeedleleaf', '1 (Evergreen Needleleaf forest)'), Enumdict( 2, 'EGBroadleaf', '2 (Evergreen Broadleaf forest)'), Enumdict( 3, 'DCNeedleleaf', '3 (Deciduous Needleleaf forest)'), Enumdict( 4, 'DCBroadleaf', '4 (Deciduous Broadleaf forest)'), Enumdict( 5, 'MixedForest', '5 (Mixed forest)'), Enumdict( 6, 'ClosedShrublands', '6 (Closed shrublands)'), Enumdict( 7, 'OpenShrublands', '7 (Open shrublands)'), Enumdict( 8, 'WoodySavannas', '8 (Woody savannas)'), Enumdict( 9, 'Savannas', '9 (Savannas)'), Enumdict( 10, 'Grasslands', '10 (Grasslands)'), Enumdict( 11, 'Wetlands', '11 (Permanent wetlands)'), Enumdict( 12, 'Croplands', '12 (Croplands)'), Enumdict( 13, 'Urban', '13 (Urban and built-up)'), Enumdict( 14, 'Mosaic', '14 (Cropland/Natural vegetation mosaic)'), Enumdict( 15, 'Snow', '15 (Snow and ice)'), Enumdict( 16, 'Barren', '16 (Barren or sparsely vegetated)'), Enumdict(255, 'Fill', '255 (Fill Value/Unclassified)') ) # Result Types RT_enum_table = Table("rt_vocabulary", Base.metadata, Column("enum_val", Integer, primary_key=True), Column("enum_str", String), Column("enum_display_str", String) ) # The following code is just a workaround (see above): RT_enum = ( Enumdict(0, 'String', 'str'), Enumdict(1, 'Integer', 'int'), Enumdict(2, 'Float', 'float') )