python引入本地的包

# -*- coding:utf-8 -*-
# @author Kuangjm
# @date 2022/7/20
# @file flask_demo.py

import sys
sys.path.append('/home/wangyp1008/chronic-diseases-risks/mode_transform')
sys.path.append('/home/wangyp1008/chronic-diseases-risks/parameter_format')
sys.path.append('/home/wangyp1008/chronic-diseases-risks/parameter_verify')

print(sys.path)
from jsonschema import ValidationError
from flask import Flask, request, jsonify

from healthy_lifestyle import HealthyLifestyle
from prostatic_cancer import ProstaticCancer
from stroke import StrokeTrans
from high_blood_pressure import HighBloodPressure
from ischemic_cardiovascular_disease import IschemicCardiovascularDisease
from diabetes import Diabetes
from obesity import Obesity
from metabolic_syndrom import MetabolicSyndrom
from osteoporotic_fracture import OsteoporoticFracture
from breast_cancer import BreastCancer
from dyslipidemia import Dyslipidemia
from lung_cancer import LungCancer

from healthy_lifestyle_verify import healthy_lifestyle_verify
from prostate_cancer_verify import prostate_cancer_verify
from stroke_verify import stroke_verify
from high_blood_pressure_verify import high_blood_pressure_verify
from ischemic_cardiovascular_disease_verify import ischemic_cardiovascular_disease_verify
from diabetes_verify import diabetes_verify

from healthy_lifestyle_params import healthy_lifestyle_params
from prostate_cancer_params import prostate_cancer_params
from stroke_params import stroke_params
from high_blood_pressure_params import high_blood_pressure_params
from ischemic_cardiovascular_disease_params import ischemic_cardiovascular_disease_params
from diabetes_params import diabetes_params
from obesity_params import obesity_params
from metabolic_syndrom_params import metabolic_syndrom_params
from osteoporotic_fracture_params import osteoporotic_fracture_params
from breast_cancer_params import breast_cancer_params
from dyslipidemia_params import dyslipidemia_params
from lung_cancer_params import lung_cancer_params

print("===================================================================================================================")

# from flask import Flask, request, jsonify
# from mode_transform.healthy_lifestyle import HealthyLifestyle
# from mode_transform.prostatic_cancer import ProstaticCancer
# from mode_transform.stroke import StrokeTrans
# from mode_transform.high_blood_pressure import HighBloodPressure
# from mode_transform.ischemic_cardiovascular_disease import IschemicCardiovascularDisease
# from mode_transform.diabetes import Diabetes
# from mode_transform.obesity import Obesity
# from mode_transform.metabolic_syndrom import MetabolicSyndrom
# from mode_transform.osteoporotic_fracture import OsteoporoticFracture
# from mode_transform.breast_cancer import BreastCancer
# from mode_transform.dyslipidemia import Dyslipidemia
# from mode_transform.lung_cancer import LungCancer

# from parameter_verify.healthy_lifestyle_verify import healthy_lifestyle_verify
# from parameter_verify.prostate_cancer_verify import prostate_cancer_verify
# from parameter_verify.stroke_verify import stroke_verify
# from parameter_verify.high_blood_pressure_verify import high_blood_pressure_verify
# from parameter_verify.ischemic_cardiovascular_disease_verify import ischemic_cardiovascular_disease_verify
# from parameter_verify.diabetes_verify import diabetes_verify

# from parameter_format.healthy_lifestyle_params import healthy_lifestyle_params
# from parameter_format.prostate_cancer_params import prostate_cancer_params
# from parameter_format.stroke_params import stroke_params
# from parameter_format.high_blood_pressure_params import high_blood_pressure_params
# from parameter_format.ischemic_cardiovascular_disease_params import ischemic_cardiovascular_disease_params
# from parameter_format.diabetes_params import diabetes_params
# from parameter_format.obesity_params import obesity_params
# from parameter_format.metabolic_syndrom_params import metabolic_syndrom_params
# from parameter_format.osteoporotic_fracture_params import osteoporotic_fracture_params
# from parameter_format.breast_cancer_params import breast_cancer_params
# from parameter_format.dyslipidemia_params import dyslipidemia_params
# from parameter_format.lung_cancer_params import lung_cancer_params




# 实例化app
app = Flask(import_name=__name__)


# 生活方式+健康年龄
@app.route('/healthy_lifestyle', methods=["POST"])
def healthy_lifestyle():
    data = request.get_json()

    try:
        healthy_lifestyle_verify(data)
    except ValidationError as e:
        msg = "参数不符合规定;{} 提示信息: {}".format(" --> ".join([i for i in e.path]), e.message)
        print(msg)
        return jsonify(status=500, msg=msg)

    params_dict = healthy_lifestyle_params(data)

    result = HealthyLifestyle(**params_dict).get_result()

    return jsonify(result)


# 前列腺癌
@app.route('/prostate_cancer', methods=["POST"])
def prostate_cancer():
    data = request.get_json()

    try:
        prostate_cancer_verify(data)
    except ValidationError as e:
        msg = "参数不符合规定;{} 提示信息: {}".format(" --> ".join([i for i in e.path]), e.message)
        print(msg)
        return jsonify(status=500, msg=msg)

    params_dict = prostate_cancer_params(data)

    result = ProstaticCancer(**params_dict).get_result()

    return jsonify(result)


# 中风评估
@app.route('/stroke', methods=["POST"])
def stroke():
    data = request.get_json()

    try:
        stroke_verify(data)
    except ValidationError as e:
        msg = "参数不符合规定;{} 提示信息: {}".format(" --> ".join([i for i in e.path]), e.message)
        print(msg)
        return jsonify(status=500, msg=msg)

    params_dict = stroke_params(data)

    result = StrokeTrans(**params_dict).get_result()

    return jsonify(result)


# 高血压
@app.route('/high_blood_pressure', methods=["POST"])
def high_blood_pressure():
    data = request.get_json()

    try:
        high_blood_pressure_verify(data)
    except ValidationError as e:
        msg = "参数不符合规定;{} 提示信息: {}".format(" --> ".join([i for i in e.path]), e.message)
        print(msg)
        return jsonify(status=500, msg=msg)

    params_dict = high_blood_pressure_params(data)

    result = HighBloodPressure(**params_dict).get_result()

    return jsonify(result)


# 缺血性心血管病
@app.route('/ischemic_cardiovascular_disease', methods=["POST"])
def ischemic_cardiovascular_disease():
    data = request.get_json()

    try:
        ischemic_cardiovascular_disease_verify(data)
    except ValidationError as e:
        msg = "参数不符合规定;{} 提示信息: {}".format(" --> ".join([i for i in e.path]), e.message)
        print(msg)
        return jsonify(status=500, msg=msg)

    params_dict = ischemic_cardiovascular_disease_params(data)

    result = IschemicCardiovascularDisease(**params_dict).get_result()

    return jsonify(result)


# 糖尿病
@app.route('/diabetes', methods=["POST"])
def diabetes():
    data = request.get_json()

    try:
        diabetes_verify(data)
    except ValidationError as e:
        msg = "参数不符合规定;{} 提示信息: {}".format(" --> ".join([i for i in e.path]), e.message)
        print(msg)
        return jsonify(status=500, msg=msg)

    params_dict = diabetes_params(data)

    result = Diabetes(**params_dict).get_result()

    return jsonify(result)


# 肥胖症
@app.route('/obesity', methods=["POST"])
def obesity():
    data = request.get_json()

    params_dict = obesity_params(data)

    result = Obesity(**params_dict).get_result()

    return jsonify(result)


# 代谢综合征
@app.route('/metabolic_syndrom', methods=["POST"])
def metabolic_syndrom():
    data = request.get_json()

    params_dict = metabolic_syndrom_params(data)

    result = MetabolicSyndrom(**params_dict).get_result()

    return jsonify(result)


# 骨质疏松性骨折
@app.route('/osteoporotic_fracture', methods=["POST"])
def osteoporotic_fracture():
    data = request.get_json()

    params_dict = osteoporotic_fracture_params(data)

    result = OsteoporoticFracture(**params_dict).get_result()

    return jsonify(result)


# 乳腺癌
@app.route('/breast_cancer', methods=["POST"])
def breast_cancer():
    data = request.get_json()

    params_dict = breast_cancer_params(data)

    result = BreastCancer(**params_dict).get_result()

    return jsonify(result)


# 血脂异常
@app.route('/dyslipidemia', methods=["POST"])
def dyslipidemia():
    data = request.get_json()

    params_dict = dyslipidemia_params(data)

    result = Dyslipidemia(**params_dict).get_result()

    return jsonify(result)


# 肺癌
@app.route('/lung_cancer', methods=["POST"])
def lung_cancer():
    data = request.get_json()

    params_dict = lung_cancer_params(data)

    result = LungCancer(**params_dict).get_result()

    return jsonify(result)


if __name__ == '__main__':
    # app.run(debug=True)
    app.run(host='0.0.0.0', threaded=True, port=5013 , debug=False)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值