Feat(SQL, UI): 1. Calc and Get Many Stored Procedures created for Weather, Lighting Level, Assessment, Distraction Type, Distraction Intensity Level, Distraction, Bribe, Assessment Command Modality Link, Response Quality Metric, Obedience Level, and Assessment Response. \n 2. Assessments and Assessment pages created with data loading and hooked up, but not saving.
This commit is contained in:
180
business_objects/dog/weather.py
Normal file
180
business_objects/dog/weather.py
Normal file
@@ -0,0 +1,180 @@
|
||||
"""
|
||||
Project: PARTS Website
|
||||
Author: Edward Middleton-Smith
|
||||
Precision And Research Technology Systems Limited
|
||||
|
||||
Technology: Business Objects
|
||||
Feature: Button Shape Business Object
|
||||
"""
|
||||
|
||||
# internal
|
||||
from business_objects.base import Base
|
||||
from business_objects.db_base import SQLAlchemy_ABC, Get_Many_Parameters_Base
|
||||
from business_objects.dog.image import Image
|
||||
import lib.argument_validation as av
|
||||
from extensions import db
|
||||
# from forms.dog.weather import Filters_Weather
|
||||
from helpers.helper_app import Helper_App
|
||||
# external
|
||||
from dataclasses import dataclass
|
||||
from typing import ClassVar
|
||||
|
||||
|
||||
class Weather(SQLAlchemy_ABC, Base):
|
||||
ATTR_ID_WEATHER: ClassVar[str] = 'id_weather'
|
||||
FLAG_WEATHER: ClassVar[str] = 'weather'
|
||||
NAME_ATTR_OPTION_VALUE: ClassVar[str] = ATTR_ID_WEATHER
|
||||
NAME_ATTR_OPTION_TEXT: ClassVar[str] = Base.FLAG_NAME
|
||||
|
||||
__tablename__ = 'DOG_Weather'
|
||||
__table_args__ = { 'extend_existing': True }
|
||||
|
||||
id_weather = db.Column(db.Integer, primary_key=True)
|
||||
code = db.Column(db.String(250))
|
||||
name = db.Column(db.String(250))
|
||||
active = db.Column(db.Boolean)
|
||||
created_on = db.Column(db.DateTime)
|
||||
|
||||
def __init__(self):
|
||||
self.id_weather = 0
|
||||
self.is_new = False
|
||||
super().__init__()
|
||||
|
||||
@classmethod
|
||||
def from_db_weather(cls, query_row):
|
||||
_m = f'{cls.__qualname__}.from_db_weather'
|
||||
weather = cls()
|
||||
weather.id_weather = query_row[0]
|
||||
weather.code = query_row[1]
|
||||
weather.name = query_row[2]
|
||||
weather.active = av.input_bool(query_row[3], 'active', _m)
|
||||
return weather
|
||||
|
||||
@classmethod
|
||||
def from_db_assessment(cls, query_row):
|
||||
_m = f'{cls.__qualname__}.from_db_assessment'
|
||||
weather = cls()
|
||||
weather.id_weather = query_row[1]
|
||||
weather.name = query_row[2]
|
||||
weather.active = True
|
||||
return weather
|
||||
|
||||
@classmethod
|
||||
def from_json(cls, json):
|
||||
_m = f'{cls.__qualname__}.from_json'
|
||||
weather = cls()
|
||||
if json is None: return weather
|
||||
# Helper_App.console_log(f'{_m}\njson: {json}')
|
||||
weather.id_weather = json.get(Weather.ATTR_ID_WEATHER, -1)
|
||||
weather.name = json[cls.FLAG_NAME]
|
||||
weather.code = json.get(cls.FLAG_CODE, weather.name.upper().replace(" ", "_"))
|
||||
weather.active = json[cls.FLAG_ACTIVE]
|
||||
weather.created_on = json.get(cls.FLAG_CREATED_ON, None)
|
||||
# Helper_App.console_log(f'Weather: {weather}')
|
||||
return weather
|
||||
|
||||
def to_json(self):
|
||||
as_json = {
|
||||
**self.get_shared_json_attributes(self)
|
||||
, self.ATTR_ID_WEATHER: self.id_weather
|
||||
, self.FLAG_CODE: self.code
|
||||
, self.FLAG_NAME: self.name
|
||||
, self.FLAG_ACTIVE: self.active
|
||||
, self.FLAG_CREATED_ON: self.created_on
|
||||
}
|
||||
# Helper_App.console_log(f'as_json: {as_json}')
|
||||
return as_json
|
||||
|
||||
def __repr__(self):
|
||||
return f'''
|
||||
{self.__class__.__name__}(
|
||||
{self.FLAG_WEATHER}: {self.id_weather}
|
||||
{self.FLAG_CODE}: {self.code}
|
||||
{self.FLAG_NAME}: {self.name}
|
||||
{self.FLAG_ACTIVE}: {self.active}
|
||||
{self.FLAG_CREATED_ON}: {self.created_on}
|
||||
)
|
||||
'''
|
||||
|
||||
class Weather_Temp(db.Model, Base):
|
||||
__tablename__ = 'DOG_Weather_Temp'
|
||||
__table_args__ = { 'extend_existing': True }
|
||||
id_temp = db.Column(db.Integer, primary_key=True)
|
||||
id_weather = db.Column(db.Integer)
|
||||
code = db.Column(db.String(250))
|
||||
name = db.Column(db.String(250))
|
||||
active = db.Column(db.Boolean)
|
||||
# created_on = db.Column(db.DateTime)
|
||||
guid: str = db.Column(db.String(36))
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
||||
@classmethod
|
||||
def from_weather(cls, weather):
|
||||
_m = 'Weather_Temp.from_weather'
|
||||
temp = cls()
|
||||
temp.id_weather = weather.id_weather
|
||||
temp.code = weather.code
|
||||
temp.name = weather.name
|
||||
temp.active = weather.active
|
||||
# temp.created_on = weather.created_on
|
||||
return temp
|
||||
|
||||
def __repr__(self):
|
||||
return f'''
|
||||
{self.__class__.__name__}(
|
||||
{Weather.FLAG_WEATHER}: {self.id_weather}
|
||||
{self.FLAG_CODE}: {self.code}
|
||||
{self.FLAG_NAME}: {self.name}
|
||||
{self.FLAG_ACTIVE}: {self.active}
|
||||
)
|
||||
'''
|
||||
|
||||
class Parameters_Weather(Get_Many_Parameters_Base):
|
||||
get_all_weather: bool
|
||||
get_inactive_weather: bool
|
||||
ids_weather: str
|
||||
names_weather: str
|
||||
require_all_id_search_filters_met: bool
|
||||
require_any_id_search_filters_met: bool
|
||||
require_all_non_id_search_filters_met: bool
|
||||
require_any_non_id_search_filters_met: bool
|
||||
|
||||
@classmethod
|
||||
def get_default(cls):
|
||||
return cls(
|
||||
get_all_weather = True
|
||||
, get_inactive_weather = False
|
||||
, ids_weather = ''
|
||||
, names_weather = ''
|
||||
, require_all_id_search_filters_met = True
|
||||
, require_any_id_search_filters_met = True
|
||||
, require_all_non_id_search_filters_met = False
|
||||
, require_any_non_id_search_filters_met = True
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def from_json(cls, json):
|
||||
return cls(
|
||||
get_all_weather = json.get('a_get_all_weather', False)
|
||||
, get_inactive_weather = json.get('a_get_inactive_weather', False)
|
||||
, ids_weather = json.get('a_ids_weather', '')
|
||||
, names_weather = json.get('a_names_weather', '')
|
||||
, require_all_id_search_filters_met = json.get('a_require_all_id_search_filters_met', True)
|
||||
, require_any_id_search_filters_met = json.get('a_require_any_id_search_filters_met', True)
|
||||
, require_all_non_id_search_filters_met = json.get('a_require_all_non_id_search_filters_met', False)
|
||||
, require_any_non_id_search_filters_met = json.get('a_require_any_non_id_search_filters_met', True)
|
||||
)
|
||||
|
||||
def to_json(self):
|
||||
return {
|
||||
'a_get_all_weather': self.get_all_weather
|
||||
, 'a_get_inactive_weather': self.get_inactive_weather
|
||||
, 'a_ids_weather': self.ids_weather
|
||||
, 'a_names_weather': self.names_weather
|
||||
, 'a_require_all_id_search_filters_met': self.require_all_id_search_filters_met
|
||||
, 'a_require_any_id_search_filters_met': self.require_any_id_search_filters_met
|
||||
, 'a_require_all_non_id_search_filters_met': self.require_all_non_id_search_filters_met
|
||||
, 'a_require_any_non_id_search_filters_met': self.require_any_non_id_search_filters_met
|
||||
}
|
||||
Reference in New Issue
Block a user