class Config(pydantic.BaseModel): num_eval_samples: int = pydantic.Schema(..., alias="num_samples") output_types: Set[OutputType] quantiles: List[str] # FIXME: validate list elements class Config: allow_population_by_alias = True
class Config(pydantic.BaseModel): num_samples: int = pydantic.Schema(100, alias="num_eval_samples") output_types: Set[OutputType] = {"quantiles", "mean"} # FIXME: validate list elements quantiles: List[str] = ["0.1", "0.5", "0.9"] class Config: allow_population_by_alias = True # store additional fields extra = "allow"
class MetaData(pydantic.BaseModel): freq: str = pydantic.Schema(..., alias="time_granularity") # type: ignore target: Optional[BasicFeatureInfo] = None feat_static_cat: List[CategoricalFeatureInfo] = [] feat_static_real: List[BasicFeatureInfo] = [] feat_dynamic_real: List[BasicFeatureInfo] = [] feat_dynamic_cat: List[CategoricalFeatureInfo] = [] prediction_length: Optional[int] = None class Config(pydantic.BaseConfig): allow_population_by_alias = True
class Record(pydantic.BaseModel): ''' A Record essentially represents a row in our Airtable table. ''' # Airtable's unique id for this row, e.g. "recFLEuThPbUkwmsq". id: str # The fields of this row. We need to call it "fields_" because # the attribute "fields" is already used by pydantic. fields_: Fields = pydantic.Schema(default=..., alias='fields') # The date the row was created, e.g. '2018-10-15T20:27:20.000Z'. createdTime: str
class Row(pydantic.BaseModel): BOROUGH: str BLOCK: str LOT: str ADDRESS: str ZIP_CODE: str = pydantic.Schema(..., alias="ZIP CODE") MANAGED_BY: str = pydantic.Schema(..., alias="MANAGED BY") FACILITY: str @property def pad_bbl(self) -> str: boro = BOROUGH_NUMBERS[self.BOROUGH] return to_pad_bbl(boro, int(self.BLOCK), int(self.LOT)) @property def full_address(self) -> str: city = self.BOROUGH if city == MANHATTAN: city = 'NEW YORK' return f'{self.ADDRESS}\n{city}, NY {self.ZIP_CODE}' def is_main_management_office(self) -> bool: return ('DEVELOPMENT MANAGEMENT OFFICE' in self.FACILITY and 'SATELLITE' not in self.FACILITY)
class EnzoModel(BaseModel): hierarchy : EnzoGrid = pydantic.Schema(..., **e) class Config: title = 'Enzo Schema'
class MainModel(pydantic.BaseModel): data : datatypes = pydantic.Schema('test.txt', shape = [3,2,4]) class Config: title = 'New Schema'
class Fields(pydantic.BaseModel): ''' The fields in a row of our Airtable table. Note that these are only the fields we care about and control: the Airtable will likely contain extra fields that matter to users, but that we don't care about for the purposes of syncing. The names of the fields are either attributes of our user model, or they are attributes of related models, which are named using Django's syntax for lookups that span relationships [1]: > To span a relationship, just use the field name of related > fields across models, separated by double underscores, > until you get to the field you want. In some cases, we use pydantic's "alias" feature to ensure that the Airtable field name is more readable than the notation we use internally. [1] https://docs.djangoproject.com/en/2.1/topics/db/queries/ ''' # The primary key of the JustfixUser that the row represents. pk: int = -1 # The user's first name. first_name: str = '' # The user's last name. last_name: str = '' # The admin URL where the user info can be viewed/changed. admin_url: str = '' # The user's phone number. phone_number: str = '' # Whether we can SMS the user. onboarding_info__can_we_sms: bool = pydantic.Schema(default=False, alias='can_we_sms') # The user's lease type. onboarding_info__lease_type: str = pydantic.Schema(default='', alias='lease_type') # When the user's letter of complaint was requested. letter_request__created_at: Optional[str] = pydantic.Schema( # Note that it's important to set dates to None/null in Airtable if they don't # exist, as Airtable will complain that it can't parse the value if we give it # an empty string. default=None, alias='letter_request_date') # The tenant's full mailing address. onboarding_info__address_for_mailing: str = pydantic.Schema( default='', alias='address') # The tenant's boro-block-lot (BBL) number. onboarding_info__pad_bbl: str = pydantic.Schema(default='', alias='pad_bbl') # A link to the letter of complaint PDF. letter_request__admin_pdf_url: str = pydantic.Schema( default='', alias='letter_pdf_url') # The tenant's landlord's name. landlord_details__name: str = pydantic.Schema(default='', alias='landlord_name') # The tenant's landlord's address. landlord_details__address: str = pydantic.Schema(default='', alias='landlord_address') # Whether or not the user wants us to mail the letter for them. letter_request__will_we_mail: bool = pydantic.Schema( default=False, alias='will_we_mail_letter') @classmethod def from_user(cls: Type[T], user: JustfixUser) -> T: ''' Given a user, return the Fields that represent their data. ''' kwargs: Dict[str, Any] = {} for field in cls.__fields__.values(): kwargs[field.alias] = get_user_field_for_airtable(user, field) return cls(**kwargs)
class ApplicationSecret(pydantic.BaseModel): secret: str = pydantic.Schema('CHANGE-ME', description='Application Secret')
class LabMember(pydantic.BaseModel): first: str = pydantic.Schema(..., description='First Name') last: str = pydantic.Schema(..., description='Last Name') year: int = pydantic.Schema(1, description='Years in program.') department: Department = pydantic.Schema('Aero/Astro', description='Student Department')