From 72db5c8b8309057c00903db68967106a3f08bbe3 Mon Sep 17 00:00:00 2001 From: mxr612 Date: Tue, 22 Apr 2025 21:19:22 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=E4=B8=AD=E5=BA=B8?= =?UTF-8?q?=E5=AE=9E=E8=B7=B5=E6=80=9D=E7=BB=B4=E9=87=8F=E8=A1=A8=E5=92=8C?= =?UTF-8?q?SCL90=E9=87=8F=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 新增中文版中庸实践思维量表和英文版SCL90量表,用于心理评估。同时优化了加载问卷数据的逻辑,支持递归遍历文件夹以加载所有问卷文件。 --- app.py | 32 +++++++++---------- .../Symptom Checklist-90 (SCL90).yml | 0 scales/{ => 中文}/中庸实践思维量表.yml | 0 3 files changed, 16 insertions(+), 16 deletions(-) rename scales/{ => English}/Symptom Checklist-90 (SCL90).yml (100%) rename scales/{ => 中文}/中庸实践思维量表.yml (100%) diff --git a/app.py b/app.py index 16fbd0e..63dff40 100644 --- a/app.py +++ b/app.py @@ -13,7 +13,6 @@ app.mount("/static", StaticFiles(directory="static"), name="static") # 加载所有问卷数据 def load_all_scales(): - scale_folder = os.path.realpath('scales') scales = {} tags = {} try: @@ -21,21 +20,22 @@ def load_all_scales(): tagmap = yaml.safe_load(f) except Exception as e: print(f"Error loading scale langmap: {e}") - for filename in os.listdir(scale_folder): - if filename.endswith(('.yaml', '.yml')): - try: - with open(os.path.join(scale_folder, filename), 'r', encoding='utf-8') as f: - scale = yaml.safe_load(f) - scale['instructions']=markdown.markdown(scale['instructions'], extensions=['fenced_code','tables','mdx_math']) - scale['descriptions']=markdown.markdown(scale['descriptions'], extensions=['fenced_code','tables','mdx_math']) - scale['abstract']=markdown.markdown(scale['abstract'], extensions=['fenced_code','tables','mdx_math']) - if 'tag' not in scale or scale['tag'] not in tagmap: - scale['tag']='other' - tags[scale['tag']]=tagmap[scale['tag']] - scale_id = os.path.splitext(filename)[0] # 使用文件名作为标识 - scales[scale_id] = scale - except Exception as e: - print(f"Error loading scale {filename}: {e}") + for root, dirs, files in os.walk(os.path.realpath('scales')): + for filename in files: + if filename.endswith(('.yaml', '.yml')): + try: + with open(os.path.join(root, filename), 'r', encoding='utf-8') as f: + scale = yaml.safe_load(f) + scale['instructions']=markdown.markdown(scale['instructions'], extensions=['fenced_code','tables','mdx_math']) + scale['descriptions']=markdown.markdown(scale['descriptions'], extensions=['fenced_code','tables','mdx_math']) + scale['abstract']=markdown.markdown(scale['abstract'], extensions=['fenced_code','tables','mdx_math']) + if 'tag' not in scale or scale['tag'] not in tagmap: + scale['tag']='other' + tags[scale['tag']]=tagmap[scale['tag']] + scale_id = os.path.splitext(filename)[0] # 使用文件名作为标识 + scales[scale_id] = scale + except Exception as e: + print(f"Error loading scale {filename}: {e}") return tags, scales @app.get("/", response_class=HTMLResponse) diff --git a/scales/Symptom Checklist-90 (SCL90).yml b/scales/English/Symptom Checklist-90 (SCL90).yml similarity index 100% rename from scales/Symptom Checklist-90 (SCL90).yml rename to scales/English/Symptom Checklist-90 (SCL90).yml diff --git a/scales/中庸实践思维量表.yml b/scales/中文/中庸实践思维量表.yml similarity index 100% rename from scales/中庸实践思维量表.yml rename to scales/中文/中庸实践思维量表.yml