コード例 #1
0
	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()}
コード例 #2
0
	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)}
コード例 #3
0
def create_recording_feedback_entry(recording):
	data = MyForm(
		Field('comment', validators=[
			validators.is_string,
		]),
		Field('flags', validators=[
			validators.is_list,
			RecordingFlag.check_all_exists,
		]),
		Field('changeMethod', is_mandatory=True, validators=[
			AudioCheckingChangeMethod.is_valid,
		]),
	).get_data()

	change_method = AudioCheckingChangeMethod.from_name(data["changeMethod"])
	flags = RecordingFlag.get_list(*data.get('flags', []))

	entry = RecordingFeedbackEntry(
		recording=recording,
		user=session["current_user"],
		change_method=change_method,
		comment=data.get("comment"),
	)
	db.session.add(entry)
	db.session.flush()
	entry.add_flags(flags)
	db.session.commit()
	return jsonify(entry=RecordingFeedbackEntry.dump(entry))
コード例 #4
0
ファイル: labelsets.py プロジェクト: cubic-g/at-server-backup
def update_label(labelSetId, labelId):
    '''
	updates label settings
	'''
    labelSet = m.LabelSet.query.get(labelSetId)
    if not labelSet:
        raise InvalidUsage(
            _('label set {0} not found').format(labelSetId), 404)
    label = m.Label.query.get(labelId)
    if not label or label.labelSetId != labelSetId:
        raise InvalidUsage(_('label {0} not found').format(lableId), 404)

    data = MyForm(
        Field('name',
              validators=[
                  (check_label_name_uniqueness, (labelSetId, labelId)),
              ]),
        Field('description'),
        Field('shortcutKey',
              validators=[
                  (validators.is_string, (), dict(length=1)),
                  check_label_shortcut_key_non_space,
                  (check_label_shortcut_key_uniqueness, (labelSetId, labelId)),
              ]),
        Field('extract',
              validators=[
                  validators.non_blank,
                  (check_label_extract_uniqueness, (labelSetId, labelId)),
              ]),
        Field('labelGroupId',
              validators=[
                  (check_label_group_existence, (labelSetId, )),
              ]),
        Field('enabled', validators=[
            validators.is_bool,
        ]),
    ).get_data()
    # data['labelSetId'] = labelSetId

    for key in data.keys():
        value = data[key]
        if getattr(label, key) != value:
            setattr(label, key, value)
        else:
            del data[key]
    SS.flush()
    return jsonify({
        'message':
        _('updated label {0} successfully').format(labelId),
        'updatedFields':
        data.keys(),
        'label':
        m.Label.dump(label),
    })
コード例 #5
0
def save_headwords(taskId):
    task = m.Task.query.get(taskId)
    if not task:
        raise InvalidUsage(_('task {0} not found').format(taskId), 404)
    if task.taskType != 'Spelling':
        raise InvalidUsage(
            _('task {0} has unexpected task type').format(taskId))
    data = MyForm(Field(
        'headwords',
        is_mandatory=True,
    )).get_data()
    load = m.Load(taskId=taskId, createdBy=699)
    SS.add(load)
    SS.flush()
    rawPieces = []
    for i, r in enumerate(data['headwords']):
        assemblyContext = 'L_%05d_%05d' % (load.loadId, i)
        allocationContext = 'L_%05d' % load.loadId
        try:
            del r['meta']
        except KeyError:
            pass
        print r
        rawPiece = m.RawPiece(taskId=taskId,
                              loadId=load.loadId,
                              assemblyContext=assemblyContext,
                              allocationContext=allocationContext,
                              words=1,
                              **r)
        rawPieces.append(rawPiece)
        SS.add(rawPiece)
    SS.flush()
    return jsonify(rawPieces=m.RawPiece.dump(rawPieces))
コード例 #6
0
def update_batch_router(batch_router):

    data = MyForm(
        Field("enabled", validators=[
            validators.is_bool,
        ]),
        Field(
            "name",
            validators=[
                validators.is_string,
                # TODO check unique
            ]),
        Field(
            "subTasks",
            validators=[
                simple_validators.is_dict,
                # TODO more complex?
            ])).get_data()

    if "enabled" in data:
        batch_router.enabled = data["enabled"]

    if "name" in data:
        batch_router.name = data["name"]

    if "subTasks" in data:

        for sub_task in batch_router.sub_tasks:
            db.session.delete(sub_task)

        db.session.flush()
        batch_router.update_sub_task_criteria(data["subTasks"])

    db.session.commit()
    return jsonify({"batchRouter": batch_router.serialize()})
コード例 #7
0
def add_wav_audio_sandbox_file(audio_sandbox):

    data = MyForm(
        Field("filePath",
              is_mandatory=True,
              validators=[
                  validators.non_blank,
              ]), ).get_data()

    spec, data_pointer = audio_server.api.parse_wav(data["filePath"])
    waveform_data = audio_server.api.get_waveform(spec, data_pointer,
                                                  data["filePath"])

    audio_sandbox_file = AudioSandboxFile(
        audio_sandbox=audio_sandbox,
        file_path=data["filePath"],
        audio_spec=spec.to_dict(),
        audio_data_pointer=data_pointer.to_dict(),
        is_wav=True,
        data={"stats": {
            "waveform": waveform_data,
        }})

    db.session.add(audio_sandbox_file)
    db.session.flush()

    return jsonify(
        {"audioSandboxFile": AudioSandboxFile.dump(audio_sandbox_file)})
コード例 #8
0
def create_alphabet():
    data = MyForm(
        Field('name',
              is_mandatory=True,
              validators=[
                  validators.non_blank,
                  check_name_uniqueness,
              ]),
        Field('description'),
        Field('dialectId',
              is_mandatory=True,
              validators=[
                  validators.is_number,
                  check_dialect_existence,
              ]),
        Field(
            'url',
            default=lambda: None,
        ),
    ).get_data()

    alphabet = m.Alphabet(**data)
    SS.add(alphabet)
    SS.flush()
    return jsonify({
        'message':
        _('created alphabet {0} successfully').format(alphabet.name),
        'alphabet':
        m.Alphabet.dump(alphabet),
    })
コード例 #9
0
def create_audio_checking_section(recording_platform):

    data = MyForm(
        Field("startPosition",
              is_mandatory=True,
              validators=[(validators.is_number, (), dict(ge=0, lt=1))]),
        Field("endPosition",
              is_mandatory=True,
              validators=[(validators.is_number, (), dict(gt=0, le=1))]),
        Field("checkPercentage",
              is_mandatory=True,
              validators=[(validators.is_number, (), dict(gt=0, le=1))]),
    ).get_data()

    audio_checking_section = AudioCheckingSection(
        recording_platform=recording_platform,
        start_position=data["startPosition"],
        end_position=data["endPosition"],
        check_percentage=data["checkPercentage"],
    )
    db.session.add(audio_checking_section)
    db.session.flush()

    return jsonify({
        "audioCheckingSection":
        AudioCheckingSection.dump(audio_checking_section)
    })
コード例 #10
0
ファイル: labelsets.py プロジェクト: cubic-g/at-server-backup
def create_label_group(labelSetId):
    '''
	creates a new label group
	'''
    labelSet = m.LabelSet.query.get(labelSetId)
    if not labelSet:
        raise InvalidUsage(
            _('label set {0} not found').format(labelSetId), 404)

    data = MyForm(
        Field('name',
              is_mandatory=True,
              validators=[
                  validators.is_string,
                  (check_label_group_name_uniqueness, (labelSetId, None)),
              ]),
        Field('dropDownDisplay',
              default=False,
              validators=[
                  validators.is_bool,
              ]),
        Field('isMandatory', default=False, validators=[
            validators.is_bool,
        ]),
    ).get_data()
    labelGroup = m.LabelGroup(**data)
    SS.add(labelGroup)
    SS.flush()
    return jsonify({
        'message':
        _('created label group {0} successfully').format(labelGroup.name),
        'labelGroup':
        m.LabelGroup.dump(labelGroup),
    })
コード例 #11
0
ファイル: subtasks.py プロジェクト: cubic-g/at-server-backup
def create_sub_task_rate_record(subTaskId):
    subTask = m.SubTask.query.get(subTaskId)
    if not subTask:
        raise InvalidUsage(_('sub task {0} not found').format(subTaskId))

    data = MyForm(
        Field('rateId', is_mandatory=True, validators=[]),
        Field('multiplier',
              is_mandatory=True,
              normalizer=lambda data, key, value: float(value),
              validators=[
                  (validators.is_number, (), dict(min_value=0)),
              ]),
        Field('bonus',
              default=None,
              validators=[
                  (validators.is_number, (), dict(ge=0)),
              ]),
    ).get_data()

    me = session['current_user']

    subTaskRate = m.SubTaskRate(taskId=subTask.taskId,
                                updatedBy=me.userId,
                                **data)
    SS.add(subTaskRate)
    SS.flush()
    return jsonify({
        'message':
        _('created sub task rate {0} successfully').format(
            subTaskRate.subTaskRateId),
        'subTaskRate':
        m.SubTaskRate.dump(subTaskRate),
    })
コード例 #12
0
def create_error_type():
    '''
	creates a new error type
	'''
    data = MyForm(
        Field('name',
              is_mandatory=True,
              validators=[
                  validators.non_blank,
                  check_name_uniqueness,
              ]),
        Field('errorClassId',
              is_mandatory=True,
              validators=[
                  check_error_class_existence,
              ]),
        Field('defaultSeverity',
              is_mandatory=True,
              normalizer=lambda data, key, value: float(value),
              validators=[
                  (validators.is_number, (), dict(max_value=1, min_value=0)),
              ]),
    ).get_data()

    errorType = m.ErrorType(**data)
    SS.add(errorType)
    SS.flush()
    return jsonify({
        'message':
        _('created error type {0} successfully').format(errorType.name),
        'errorType':
        m.ErrorType.dump(errorType),
    })
コード例 #13
0
def update_performance_flag(performance_flag):

	data = MyForm(
		Field('name', validators=[
			performance_flag.check_updated_name_unique,
		]),
		Field('severity', validators=[
			PerformanceFlag.check_valid_severity
		]),
		Field('enabled', validators=[
			validators.is_bool,
		]),
	).get_data()

	if "name" in data:
		performance_flag.name = data["name"]

	if "severity" in data:
		performance_flag.severity = data["severity"]

	if "enabled" in data:
		performance_flag.enabled = data["enabled"]

	db.session.flush()
	return jsonify({"performanceFlag": PerformanceFlag.dump(performance_flag)})
コード例 #14
0
ファイル: loaders.py プロジェクト: cubic-g/at-server-backup
def get_loaders():

    data = MyForm(
        Field("taskTypeId",
              validators=[validators.is_number, TaskType.check_exists]),
        Field("recordingPlatformTypeId",
              validators=[
                  validators.is_number, RecordingPlatformType.check_exists
              ]),
    ).get_data(is_json=False, use_args=True)

    if "taskTypeId" in data:
        task_type = TaskType.query.get(data["taskTypeId"])
        loaders = get_available_loaders(task_type=task_type.name)

    elif "recordingPlatformTypeId" in data:
        recording_platform_type = RecordingPlatformType.query.get(
            data["recordingPlatformTypeId"])
        loaders = get_available_loaders(
            recording_platform_type=recording_platform_type.name)

    else:
        loaders = []

    return jsonify(loaders=loaders)
コード例 #15
0
ファイル: handlers.py プロジェクト: cubic-g/at-server-backup
def webservices_available_qualifications():
    data = MyForm(
        Field('userId',
              is_mandatory=True,
              default=lambda: None,
              normalizer=normalize_u),
        Field('languageIds',
              is_mandatory=True,
              default=[],
              normalizer=normalize_l),
    ).get_data(is_json=False, copy=True)
    userId = data['userId']
    languageIds = data['languageIds']

    user = _get_user(userId)
    if not user or not user.isActive:
        raise InvalidUsage('user {} not found or inactive'.format(userId))

    candidates = m.Test.query.filter_by(isEnabled=True).order_by(
        m.Test.testId).all()
    result = Filterable()
    for test in candidates:
        record = TestManager.report_eligibility(test, user, languageIds)
        if record is None:
            continue
        result.append(record)
    return dict(entries=result)
コード例 #16
0
    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()}
コード例 #17
0
    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)}
コード例 #18
0
ファイル: tracks.py プロジェクト: cubic-g/at-server-backup
def update_track(track):

    data = MyForm(
        Field("trackIndex",
              validators=[
                  simple_validators.is_number(min_value=0),
                  track.check_updated_index_unique,
              ]),
        Field("name",
              validators=[
                  validators.non_blank,
                  track.check_updated_name_unique,
              ]),
        Field("mode",
              validators=[
                  validators.is_string,
                  Track.is_valid_mode(validator=True)
              ]),
    ).get_data()

    if "trackIndex" in data:
        track.track_index = data["trackIndex"]

    if "name" in data:
        track.name = data["name"]

    if "mode" in data:
        track.update_mode(data["mode"])

    db.session.commit()
    return jsonify(track=Track.dump(track))
コード例 #19
0
def update_audio_checking_group(audio_checking_group):

    data = MyForm(
        Field('name',
              is_mandatory=True,
              validators=[audio_checking_group.check_other_name_unique]),
        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()

    # update group
    audio_checking_group.name = data["name"]
    audio_checking_group.selection_size = data["selectionSize"]
    audio_checking_group.assign_corpus_codes(data["corpusCodes"])

    db.session.flush()
    db.session.commit()

    return jsonify(
        {"audioCheckingGroup": AudioCheckingGroup.dump(audio_checking_group)})
コード例 #20
0
ファイル: pools.py プロジェクト: cubic-g/at-server-backup
def create_pool():
    data = MyForm(
        Field('name',
              is_mandatory=True,
              validators=[
                  validators.non_blank,
                  (check_pool_name_uniqueness, (None, )),
              ]),
        Field('meta',
              is_mandatory=True,
              default='{}',
              normalizer=normalize_pool_meta_data),
        Field('taskTypeId',
              is_mandatory=True,
              validators=[
                  validators.is_number,
                  check_task_type_existence,
              ]),
        Field('autoScoring',
              is_mandatory=True,
              normalizer=normalize_bool_literal,
              validators=[
                  validators.is_bool,
              ]),
        Field('tagSetId', validators=[
            check_tag_set_existence,
        ]),
        Field('dataFile', is_mandatory=True),
        Field('questions',
              is_mandatory=True,
              default=[],
              normalizer=load_questions),
    ).get_data(is_json=False)

    questions = data.pop('questions')
    del data['dataFile']

    pool = m.Pool(**data)
    SS.add(pool)
    for qd in questions:
        q = m.Question(**qd)
        pool.questions.append(q)

    SS.flush()
    return jsonify({
        'pool': m.Pool.dump(pool, context={'level': 0}),
    })
コード例 #21
0
def submit_marking(sheetId):
    sheet = m.Sheet.query.get(sheetId)
    if not sheet:
        raise InvalidUsage(_('sheet {0} not found').format(sheetId), 404)

    # TODO: add policy check to enable/disable re-marking and/or marking of expired sheets

    data = MyForm(
        Field('moreAttempts',
              is_mandatory=True,
              validators=[
                  validators.is_bool,
              ]),
        Field('comment', validators=[
            validators.is_string,
        ]),
        Field('markings', is_mandatory=True,
              normalizer=normalize_marking_data),
        Field('score',
              is_mandatory=True,
              default=0,
              normalizer=calculate_sheet_score),
    ).get_data()

    # TODO: define relationship marking on SheetEntry

    me = session['current_user']
    markings = data.pop('markings')
    for entry, md in zip(sheet.entries, markings):
        marking = m.Marking(**md)
        marking.sheetEntryId = entry.sheetEntryId
        marking.scorerId = me.userId
        SS.add(marking)
        SS.flush()
        entry.markingId = marking.markingId

    for key in ['moreAttempts', 'comment', 'score']:
        setattr(sheet, key, data[key])

    return jsonify({
        'message':
        _('marked sheet {0} successfully').format(sheetId),
        'sheet':
        m.Sheet.dump(sheet),
    })
コード例 #22
0
ファイル: labelsets.py プロジェクト: cubic-g/at-server-backup
def update_label_group(labelSetId, labelGroupId):
    '''
	updates label group settings
	'''
    labelSet = m.LabelSet.query.get(labelSetId)
    if not labelSet:
        raise InvalidUsage(
            _('label set {0} not found').format(labelSetId), 404)
    labelGroup = m.LabelGroup.query.get(labelGroupId)
    if not labelGroup or labelGroup.labelSetId != labelSetId:
        raise InvalidUsage(
            _('label group {0} not found').format(labelGroupId), 404)

    data = MyForm(
        Field('name',
              validators=[
                  validators.is_string,
                  (check_label_group_name_uniqueness, (labelSetId,
                                                       labelGroupId)),
              ]),
        Field('dropDownDisplay', validators=[
            validators.is_bool,
        ]),
        Field('isMandatory', validators=[
            validators.is_bool,
        ]),
    ).get_data()

    for key in data.keys():
        value = data[key]
        if getattr(labelGroup, key) != value:
            setattr(labelGroup, key, value)
        else:
            del data[key]
    SS.flush()
    return jsonify({
        'message':
        _('updated label group {0} successfully').format(labelGroup.name),
        'labelGroup':
        m.LabelGroup.dump(labelGroup),
        'updatedFields':
        data.keys(),
    })
コード例 #23
0
def update_corpus_code(corpus_code):

    data = MyForm(
        Field("code",
              is_mandatory=True,
              validators=[
                  corpus_code.check_updated_code_unique,
              ]),
        Field("regex"),
        Field("isScripted", is_mandatory=True,
              validators=[validators.is_bool]),
    ).get_data()

    corpus_code.code = data.get("code")
    corpus_code.regex = data["regex"]
    corpus_code.is_scripted = data["isScripted"]
    db.session.commit()

    return jsonify({"corpusCode": CorpusCode.dump(corpus_code)})
コード例 #24
0
def update_api_access_pair(api_access_pair):

    data = MyForm(
        Field("enabled", is_mandatory=True,
              validators=[validators.is_bool]), ).get_data()

    api_access_pair.enabled = data["enabled"]
    db.session.commit()

    return jsonify({"apiAccessPair": ApiAccessPair.dump(api_access_pair)})
コード例 #25
0
    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)}
コード例 #26
0
    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()}
コード例 #27
0
def create_new_alphabet_rule(alphabetId):
    alphabet = m.Alphabet.query.get(alphabetId)
    if not alphabet:
        raise InvalidUsage(_('alphabet {0} not found').format(alphabetId), 404)
    data = MyForm(
        Field('name'),
        Field('type'),
        Field('description'),
    ).get_data()
    rule = m.Rule(**data)
    rule.alphabetId = alphabetId
    SS.add(rule)
    SS.flush()
    return jsonify(rule=m.Rule.dump(rule))
コード例 #28
0
def create_performance_feedback_entry(performance):
    data = MyForm(
        Field('comment', validators=[
            validators.is_string,
        ]),
        Field('flags',
              validators=[
                  validators.is_list,
                  PerformanceFlag.check_all_exists,
              ]),
        Field('changeMethod',
              is_mandatory=True,
              validators=[
                  AudioCheckingChangeMethod.is_valid,
              ]),
    ).get_data()

    entry = performance.add_feedback(session["current_user"],
                                     data["changeMethod"], data.get("comment"),
                                     data.get("flags", []))
    db.session.commit()

    return jsonify(entry=PerformanceFeedbackEntry.dump(entry))
コード例 #29
0
def add_api_access_pair():

    data = MyForm(
        Field("description",
              is_mandatory=True,
              validators=[validators.is_string]), ).get_data()

    api_access_pair = ApiAccessPair.create(session["current_user"].user_id,
                                           data["description"])

    db.session.add(api_access_pair)
    db.session.flush()

    return jsonify({"apiAccessPair": ApiAccessPair.dump(api_access_pair)})
コード例 #30
0
    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)}