def get(): """ Return the data validation schema for the identifier class register. """ common = da.check.schema.common return Schema({ 'title': common.TITLE_TEXT, 'introduction': common.PARAGRAPH_TEXT, 'register': { common.LOWERCASE_NAME: { 'desc': common.TITLE_TEXT, Optional('pfix'): Match(r'[a-z]{1,3}'), Optional('dgts'): Range(1, 12), Optional('expr'): str, 'note': common.PARAGRAPH_TEXT } }, Extra: Reject })
import os.path from good import (Schema, All, Any, Range, Allow, Match, message, Msg, Optional, Exclusive, Length, Entire) @message('Must be a valid directory.') def IsDir(d): d = os.path.expanduser(d) assert os.path.isdir(d) return d seed_schema = Any(None, str, All(int, Range(min=0))) target_subset_schema = Any('random', [All(int, Range(min=0))]) data_schema = Any( # generated from operator # Schema({ # 'type': 'generated', # 'operator': str, # 'bits': All(int, Range(min=1)), # Optional('out_width'): All(int, Range(min=1)), # Optional('add_noise'): Range(min=0.0), # Optional('targets'): target_subset_schema, # }), # read from file Schema({ 'type': 'file', 'filename': str, Optional('dir'): IsDir,
raise DataFormatError('{} format error: {}'.format(name, err)) def _check_and_write_data(data, stream, schema, name): try: schema(copy.deepcopy(data)) except Invalid as err: raise DataFormatError('{} format error: {}'.format(name, err)) yaml.dump(data, stream, Dumper) CameraParameters = namedtuple('CameraParameters', ('fov_y', 'aspect_ratio')) CAMERA_PARAMETERS_SCHEMA = Schema({ Required('camera'): { Required('fov_y'): All(float, Range(min=0)), Required('aspect_ratio'): All(float, Range(min=0)) } }) def read_camera_parameters(stream: IO[str]) -> CameraParameters: data = _check_data_format(stream, CAMERA_PARAMETERS_SCHEMA, 'Camera') return CameraParameters(data['camera']['fov_y'], data['camera']['aspect_ratio']) def write_camera_parameters(camera_parameters: CameraParameters, stream: IO[str]) -> None: data = { 'camera': {
def get_student_schema(schoolclass): def start_before_end(): def validator(d): if 'start_date' not in d or 'end_date' not in d: assert False, "La date d'arrivée dans la classe ou la date de départ ne sont pas renseignées" if not isinstance(d['start_date'], date) or not isinstance( d['end_date'], date): assert False assert d['start_date'] <= d[ 'end_date'], "La date d'arrivée dans la classe doit être antérieur à la date de départ" return d return validator schema = Schema( { 'firstname': Msg(Length(min=1), "Le prénom doit être renseigné."), 'lastname': Msg(Length(min=1), "Le nom doit être renseigné."), Optional('birth_date'): Any( '', Msg(Date('%d/%m/%Y'), "La date de naissance doit être renseignée.")), 'gender': Msg(Any('f', 'm'), "Vous devez sélectionner une valeur pour le sexe"), 'grade': All( Coerce(int), Msg( In([grade.id for grade in schoolclass.grades]), "Le niveau choisi n'est pas disponible pour cette classe.") ), 'start_date': All( Msg(Date('%d/%m/%Y'), "La date d'arrivée dans la classe doit être renseignée."), Msg( Range(schoolclass.schoolyear.start_date, schoolclass.schoolyear.end_date), "La date d'arrivée dans la classe doit être comprise entre le %s et le %s" % (schoolclass.schoolyear.start_date.strftime("%d/%m/%Y"), schoolclass.schoolyear.end_date.strftime("%d/%m/%Y")))), 'end_date': All( Msg(Date('%d/%m/%Y'), "La date de départ de la classe doit être renseignée."), Msg( Range(schoolclass.schoolyear.start_date, schoolclass.schoolyear.end_date), "La date de départ de la classe doit être comprise entre le %s et le %s" % (schoolclass.schoolyear.start_date.strftime("%d/%m/%Y"), schoolclass.schoolyear.end_date.strftime("%d/%m/%Y")))), 'ulis': Any(Msg(Boolean(), "Le champ ULIS doit être renseigné"), Default(False)), Entire: start_before_end() }, default_keys=Required) return schema
Required('recaptcha'): ReCaptcha() }) edit_schema = Schema({ Optional('name'): All(unicode, Length(min=1, max=32)), Optional('starts_at'): int, Optional('ends_at'): int }) team_join_schema = Schema({Required('team_id'): unicode}) problem_create_schema = Schema({ Required('title'): All(unicode, Length(min=1, max=32)), Required('time_limit'): All(Any(float, int), Range(min=0.1, max=10.0)), Required('space_limit'): All(int, Range(min=16, max=256)) }) problem_edit_schema = Schema({ Optional('title'): All(unicode, Length(min=1, max=32)), Optional('time_limit'): All(Any(float, int), Range(min=0.1, max=10.0)), Optional('space_limit'): All(int, Range(min=16, max=256)) }) problem_change_order_schema = Schema({Required('order'): [Schema(int)]})
return FramePair(*frame_pair) DATASET_CONFIG_SCHEMA = Schema({ 'tests': { Any(str): { 'camera': str, 'ground_truth': str, 'rgb': str, Optional('initial_frames'): Any(_check_frame_pair, Default(None)), Optional('translation_error_allowed'): Any(Range(0.0, 1.0), Default(TRANSLATION_ERROR_ALLOWED)), Optional('rotation_deg_error_allowed'): Any( Range(0.0, 360.0), Default(ROTATION_DEG_ERROR_ALLOWED), ) } } }) TestInfo = namedtuple( 'TestInfo', ('camera', 'ground_truth', 'rgb', 'initial_frames', 'translation_error_allowed', 'rotation_deg_error_allowed')) def _create_test_info(camera,