コード例 #1
0
def isotope(name):
    if request.method == 'GET':
        return getIsotope(name)
    elif request.method == 'POST':
        # TODO: createdBy should be from the authorization token, need to change this
        try:
            isotopeDict = IsotopeSchema().load(request.get_json())
        except ValidationError:
            result = StandardResponse("Invaild Isotope Parameters")
            response = StandardResponseSchema().dump(result)
            return jsonify(response), 400

        return createIsotope(isotopeDict)
    elif request.method == 'PUT':
        # TODO: createdBy should be from the authorization token, need to change this
        try:
            newIsotopeDict = IsotopeSchema().load(request.get_json())
        except ValidationError:
            result = StandardResponse("Invaild Isotope Parameters")
            response = StandardResponseSchema().dump(result)
            return jsonify(response), 400

        return updateIsotope(name, newIsotopeDict)
    elif request.method == 'DELETE':
        return deleteIsotope(name)
コード例 #2
0
def effectCalc():
    if request.method == 'GET':
        nobs = request.args.get('nobs')
        power = request.args.get('power')
        alpha = request.args.get('alpha')
        test = request.args.get('test')
        alternative = request.args.get('alternative')
        try:
            statisticFormDict = StatisticFormSchema().load({
                'nobs':
                nobs,
                'power':
                power,
                'alpha':
                alpha,
                'test':
                test,
                'alternative':
                alternative
            })
            result = calcEffect(statisticFormDict)
        except ValidationError as e:
            result = StandardResponse(e.__str__())
            response = StandardResponseSchema().dump(result)
            return jsonify(response), 400
        except Exception as e:
            result = StandardResponse(e.__str__())
            response = StandardResponseSchema().dump(result)
            return jsonify(response), 500

        response = StatisticFormResponseSchema().dump({'result': result})
        return jsonify(response), 200
コード例 #3
0
def logout():
    if request.method == 'DELETE':
        try:
            logoutHelper()
        except BaseException as e:
            result = StandardResponse(e.message)
            response = StandardResponseSchema().dump(result)
            return jsonify(response), 500

        result = StandardResponse("success")
        response = StandardResponseSchema().dump(result)
        return jsonify(response), 200
コード例 #4
0
def powerCalcTable():
    if request.method == 'GET':
        effect = request.args.get('effect')
        nobs = request.args.get('nobs')
        alpha = request.args.get('alpha')
        test = request.args.get('test')
        alternative = request.args.get('alternative')

        try:
            statisticFormDict = StatisticFormSchema().load({
                'effect':
                effect,
                'nobs':
                nobs,
                'alpha':
                alpha,
                'test':
                test,
                'alternative':
                alternative
            })
            plot, table = calcPowerGraph(statisticFormDict)
        except Exception as e:
            result = StandardResponse(e.__str__())
            response = StandardResponseSchema().dump(result)
            return jsonify(response), 500

    response = table
    return response, 200
コード例 #5
0
def login():
    if request.method == 'POST':
        try:
            userDict = UserSchema().load(request.get_json())
            result = loginHelper(userDict['email'], userDict['password'])
        except ValidationError as e:
            result = StandardResponse(e.__str__())
            response = StandardResponseSchema().dump(result)
            return jsonify(response), 400
        except InvalidCredentialException as e:
            response = BaseExceptionSchema().dump(e)
            return jsonify(response), 401
        except BaseException as e:
            result = StandardResponse(e.message)
            response = StandardResponseSchema().dump(result)
            return jsonify(response), 500

    response = UserSchema().dump(result)
    return jsonify(response), 200
コード例 #6
0
def biodiCsv():
    if request.method == 'POST':
        try:
            # print(json.load(request.files['studyInfo']))
            # print(json.load(request.files['gammaInfo']))
            studyInfoDict = StudyInfoSchema().load(
                json.load(request.files['studyInfo']))

            studyInfo = prepareStudyInformation(studyInfoDict)
            print(request.files)

            for i in range(0, studyInfoDict['numGammaRuns']):
                gammaInfoDict = GammaInfoSchema().load(
                    json.load(request.files['gammaInfo' + str(i)]))
                print(gammaInfoDict)
                gammaInfo = prepareGammaRunInformation(gammaInfoDict, i, 0,
                                                       studyInfo.studyDate)
                print(gammaInfo)
                # mouseInfo = handleMouseCsv(request.files['mouseCsvs' + str(i)])
                organInfo = handleMouseAndOrganCsv(
                    request.files['mouseCsvs' + str(i)],
                    request.files['organCsvs' + str(i)])

            # if gammaInfo['gammaCounter'] == "Hidex":
            #     handleHidexStudy(biodiFile,studyInfo, gammaInfo, mouseInfo, organInfo)
            # elif gammaInfo['gammaCounter'] == "PE":
            #     handlePEStudy(biodiFile, studyInfo, gammaInfo, mouseInfo, organInfo)

        except BaseException as e:
            result = BaseException(e.message)
            response = BaseExceptionSchema().dump(result)
            return jsonify(response), 400

        print("GOT HERE FINE")
        result = StandardResponse("success")
        response = StandardResponseSchema().dump(result)
        return jsonify(response), 200

    elif request.method == 'GET':
        try:
            result, studyName = getBiodiCsvRaw(request.args.get('id'))
        except BaseException as e:
            result = BaseException(e.message)
            response = BaseExceptionSchema().dump(result)
            return jsonify(response), 500

        response = make_response(result)
        response.headers[
            "Content-Disposition"] = "attachment; filename=" + studyName
        response.headers["Content-Type"] = "text/csv; charset=UTF-8"

        return response, 200
コード例 #7
0
def counter():
    # if request.method == 'GET':
    #     return getIsotope(name)
    if request.method == 'POST':
        # TODO: implement rest of API
        try:
            counterDict = GammaCounterSchema().load(request.get_json())
        except ValidationError:
            result = StandardResponse("Invaild counter Parameters")
            response = StandardResponseSchema().dump(result)
            return jsonify(response), 400

        return createCounter(counterDict)
コード例 #8
0
def createCounter(counterDict):
    gammaCounter = GammaCounter(counterDict['model'])
    try:
        result = db.createCounter(gammaCounter)
    except IntegrityException as e:
        response = BaseExceptionSchema().dump(e)
        return jsonify(response), 400
    except BaseException as e:
        response = BaseExceptionSchema().dump(e)
        return jsonify(response), 500

    result = StandardResponse("Success")
    response = StandardResponseSchema().dump(result)
    return jsonify(response), 200
コード例 #9
0
def deleteIsotope(name):
    try:
        isotopeToDelete = db.getIsotope(name)
        db.deleteIsotope(isotopeToDelete)
    except NotFoundException as e:
        response = BaseExceptionSchema().dump(e)
        return jsonify(response), 400
    except BaseException as e:
        response = BaseExceptionSchema().dump(e)
        return jsonify(response), 500

    result = StandardResponse("Success")
    response = StandardResponseSchema().dump(result)
    return jsonify(response), 200
コード例 #10
0
def createIsotope(isotopeDict):
    isotope = Isotope(isotopeDict['isotopeName'], isotopeDict['halfLife'], isotopeDict['createdBy'])
    try:
        result = db.createIsotope(isotope)
    except IntegrityException as e:
        response = BaseExceptionSchema().dump(e)
        return jsonify(response), 400
    except BaseException as e:
        response = BaseExceptionSchema().dump(e)
        return jsonify(response), 500

    result = StandardResponse("Success")
    response = StandardResponseSchema().dump(result)
    return jsonify(response), 200
コード例 #11
0
def updateIsotope(name, newIsotopeDict):
    newIsotope = Isotope(newIsotopeDict['isotopeName'], newIsotopeDict['halfLife'], newIsotopeDict['createdBy'])

    try:
        isotopeToUpdate = db.getIsotope(name)
        db.updateIsotope(isotopeToUpdate, newIsotope, newIsotope.createdBy)
    except NotFoundException as e:
        response = BaseExceptionSchema().dump(e)
        return jsonify(response), 400
    except IntegrityException as e:
        response = BaseExceptionSchema().dump(e)
        return jsonify(response), 400
    except BaseException as e:
        response = BaseExceptionSchema().dump(e)
        return jsonify(response), 500

    result = StandardResponse("Success")
    response = StandardResponseSchema().dump(result)
    return jsonify(response), 200