class UploadResource(Resource): method_decorators = [ get_model(RecordingPlatform), caps(), api ] def post(self, recording_platform): # TODO check configured loader if recording_platform.performance_meta_categories: raise InvalidUsage("performance meta categories already exist; unable to upload config file") if not "file" in request.files: raise InvalidUsage("no config file provided") amr_config_file = AmrConfigFile.load(request.files["file"]) for amr_category in amr_config_file.demographics: validator = MetaValidator.from_amr_demographic_category(amr_category) meta_category = PerformanceMetaCategory( recording_platform=recording_platform, name=amr_category.title, extractor={"source": "Log File", "key": amr_category.id}, # TODO get log file string from loader constant validator_spec=validator.to_dict(), ) db.session.add(meta_category) db.session.commit() return {"metaCategories": PerformanceMetaCategory.dump(recording_platform.performance_meta_categories)}
class ListResource(Resource): method_decorators = [get_model(RecordingPlatform), caps(), api] def get(self, recording_platform): return {"tracks": Track.dump(recording_platform.tracks)} def post(self, recording_platform): data = MyForm( Field("trackIndex", is_mandatory=True, validators=[ simple_validators.is_number(min_value=0), Track.check_new_index_unique(recording_platform), ]), Field("name", is_mandatory=True, validators=[ validators.non_blank, Track.check_new_name_unique(recording_platform), ]), ).get_data() track = Track( recording_platform=recording_platform, track_index=data["trackIndex"], name=data["name"], ) db.session.add(track) db.session.flush() return {"track": Track.dump(track)}
class ListResource(Resource): method_decorators = [get_model(RecordingPlatform), caps(), api] def get(self, recording_platform): return { "corpusCodes": CorpusCode.dump(recording_platform.corpus_codes) } def post(self, recording_platform): data = MyForm( Field("code", default="", validators=[ CorpusCode.check_new_code_unique(recording_platform) ]), Field("regex"), Field("isScripted", is_mandatory=True, validators=[validators.is_bool]), ).get_data() corpus_code = CorpusCode( recording_platform=recording_platform, code=data["code"], regex=data.get("regex"), is_scripted=data["isScripted"], ) db.session.add(corpus_code) db.session.flush() return {"corpusCode": CorpusCode.dump(corpus_code)}
class ListResource(Resource): method_decorators = [get_model(Task), caps(), api] def get(self, task): if not task.is_type(TaskType.TRANSCRIPTION, TaskType.AUDIO_CHECKING): raise InvalidUsage( "audio uploads are only available for audio tasks", 400) data = MyForm( Field("visibleOnly", normalizer=normalizers.to_json, validators=[ validators.is_bool, ])).get_data(is_json=False, use_args=True) query = AudioUpload.query.filter_by(task=task) if data.get("visibleOnly"): query = query.filter_by(hidden=False) audio_uploads = query.all() return {"audioUploads": AudioUpload.dump(audio_uploads)} def post(self, task): if not task.is_type(TaskType.TRANSCRIPTION, TaskType.AUDIO_CHECKING): raise InvalidUsage( "audio uploads are only available for audio tasks", 400) data = MyForm( Field("loadManager", is_mandatory=True, validators=[ simple_validators.is_dict(), ]), Field("isEmpty", is_mandatory=True, validators=[ validators.is_bool, ]), ).get_data() audio_upload = AudioUpload( task=task, data=data["loadManager"], hidden=AudioUpload.get_hidden_flag(data["loadManager"], data["isEmpty"]), ) db.session.add(audio_upload) db.session.commit() return {"audioUpload": audio_upload.serialize()}
class ListResource(Resource): method_decorators = [ caps(), api, ] def get(self): recording_platform_types = RecordingPlatformType.query.all() return { "recordingPlatformTypes": RecordingPlatformType.dump(recording_platform_types) }
class ModelResource(Resource): method_decorators = [get_model(RecordingPlatform), caps(), api] def put(self, recording_platform): recording_platform.set_loader(request.json) db.session.commit() return {"success": True} def delete(self, recording_platform): recording_platform.set_loader(None) db.session.commit() return {"success": True}
class ModelResource(Resource): method_decorators = [get_model(AudioUpload), caps(), api] def put(self, audio_upload): data = MyForm(Field("hidden", validators=[ validators.is_bool, ])).get_data() if "hidden" in data: audio_upload.hidden = data["hidden"] db.session.commit() return {"audioUpload": audio_upload.serialize()}
class ListResource(Resource): method_decorators = [get_model(RecordingPlatform), caps(), api] def get(self, recording_platform): return { "audioCheckingGroups": AudioCheckingGroup.dump(recording_platform.audio_checking_groups) } def post(self, recording_platform): data = MyForm( Field('name', is_mandatory=True, validators=[ (AudioCheckingGroup.check_name_unique, (recording_platform, )), ]), Field('selectionSize', is_mandatory=True, validators=[ (validators.is_number, (), dict(min_value=1)), ]), Field('corpusCodes', is_mandatory=True, validators=[ validators.is_list, CorpusCode.check_all_exists, ]), ).get_data() # create group audio_checking_group = AudioCheckingGroup( recording_platform=recording_platform, name=data["name"], selection_size=data["selectionSize"], ) db.session.add(audio_checking_group) db.session.flush() # assign corpus codes audio_checking_group.assign_corpus_codes(data["corpusCodes"]) db.session.commit() return { "audioCheckingGroup": AudioCheckingGroup.dump(audio_checking_group) }
class ModelResource(Resource): method_decorators = [ get_model(PerformanceMetaCategory), caps(), api ] def get(self, performance_meta_category): return {"metaCategory": performance_meta_category.serialize()} def put(self, performance_meta_category): data = MyForm( Field('name', is_mandatory=True, validators=[ performance_meta_category.check_other_name_unique, ]), Field('extractor', is_mandatory=True, normalizer=PerformanceMetaCategory.normalize_extractor, validators=[ performance_meta_category.recording_platform.check_extractor ] ), Field('validatorSpec', is_mandatory=True, validators=[ PerformanceMetaCategory.check_validator ] ), ).get_data() performance_meta_category.name = data["name"] performance_meta_category.extractor = data.get("extractor") performance_meta_category.validator_spec = data["validatorSpec"] db.session.flush() return {"metaCategory": PerformanceMetaCategory.dump(performance_meta_category)} def delete(self, performance_meta_category): db.session.delete(performance_meta_category) db.session.commit() return {"deleted": True}
class ListResource(Resource): method_decorators = [ get_model(RecordingPlatform), caps(), api ] def get(self, recording_platform): return {"metaCategories": PerformanceMetaCategory.dump(recording_platform.performance_meta_categories)} def post(self, recording_platform): data = MyForm( Field('name', is_mandatory=True, validators=[ (PerformanceMetaCategory.check_name_unique, (recording_platform,)), ]), Field('extractor', is_mandatory=True, normalizer=PerformanceMetaCategory.normalize_extractor, validators=[ recording_platform.check_extractor, ] ), Field('validatorSpec', is_mandatory=True, validators=[ PerformanceMetaCategory.check_validator, ] ), ).get_data() performance_meta_category = PerformanceMetaCategory( recording_platform=recording_platform, name=data["name"], extractor=data.get("extractor"), validator_spec=data["validatorSpec"], ) db.session.add(performance_meta_category) db.session.commit() return {"metaCategory": performance_meta_category.serialize()}
class UploadResource(Resource): method_decorators = [get_model(RecordingPlatform), caps(), api] def post(self, recording_platform): if recording_platform.corpus_codes: raise InvalidUsage("recording platform already has corpus codes") if not "file" in request.files: raise InvalidUsage("no corpus code list uploaded") fp = request.files["file"] reader = csv.reader(fp) for row in reader: if not row: continue code = row[0] # if type included if len(row) > 1: type = row[1] type = type.strip() # type is non-empty if type: # check if scripted if type.lower() == CorpusCode.SCRIPTED.lower(): type = CorpusCode.SCRIPTED # check if spontaneous elif type.lower() == CorpusCode.SPONTANEOUS.lower(): type = CorpusCode.SPONTANEOUS # invalid type else: raise InvalidUsage( "Line {0}: invalid type: {1}".format( reader.line_num, type)) else: type = CorpusCode.SCRIPTED # no type included else: type = CorpusCode.SCRIPTED corpus_code = CorpusCode( recording_platform=recording_platform, code=code, is_scripted=(type == CorpusCode.SCRIPTED), ) db.session.add(corpus_code) db.session.commit() return { "corpusCodes": CorpusCode.dump(recording_platform.corpus_codes) }