From 22c222813b0c3dd9bb85bc8d85e68f8d2d446de3 Mon Sep 17 00:00:00 2001 From: mxr612 Date: Wed, 5 Mar 2025 11:49:52 +0000 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E4=BA=86=E6=A0=B7=E4=BE=8B?= =?UTF-8?q?=E9=87=8F=E8=A1=A8=EF=BC=8C=E5=A2=9E=E5=8A=A0=E4=BA=86=E6=8F=8F?= =?UTF-8?q?=E8=BF=B0=E4=B8=AD=E6=95=B0=E5=AD=A6=E5=85=AC=E5=BC=8F=E7=9A=84?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 10 +++++----- app.py | 14 +++++++++----- requirements.txt | Bin 122 -> 166 bytes scales/CBF-PI-B.yml | 19 ++++++++++++++----- scales/中庸实践思维量表.yml | 11 +++++++++-- templates/result.html | 11 ++++++++++- templates/scale.html | 11 ++++++++++- 7 files changed, 57 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 8c3359a..3323180 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,16 @@ -# 心尺 PsychoScales (Org) +# 心尺 PsychoScales Org -## 什么是PsychoScales +## 关于PsychoScales PsychoScales网站是一个专业的心理学资源平台,旨在为用户提供全面的心理学测量工具和评估资源。我们汇集了各种心理测量工具,涵盖了情绪、人格、认知能力、心理健康等多个领域,帮助用户更好地了解自己的心理特点和状况。 作为PsychoScales网站的用户,您可以通过简单的在线测试,快速获取关于自己心理特征的详细报告和分析。这些测量工具基于权威的心理学理论和研究,确保了测试结果的准确性和可靠性。 -[心尺主站](https://psygscales.com/) +[PsychoScales主站](https://psygscales.com/) -## 什么是PsychoScales Org +## 关于PsychoScales Org 这个一个开源的量表框架,基于Python搭建。 -本项目的量表加载完全基于json,不使用任何数据库。同时也可以通过易于编辑的txt文件制作可以加载的json。 +本项目的量表加载完全基于YAML,不使用任何数据库。在易于编辑和易于加载中间达到了平衡。 [开源地址](https://git.mxr612.io/PsychoScales/PsychoScales) \ No newline at end of file diff --git a/app.py b/app.py index e766dce..d27225f 100644 --- a/app.py +++ b/app.py @@ -17,10 +17,15 @@ def load_all_scales(): scales = {} for filename in os.listdir(scale_folder): if filename.endswith(('.yaml', '.yml')): - with open(os.path.join(scale_folder, filename), 'r', encoding='utf-8') as f: - scale = yaml.safe_load(f) - scale_id = os.path.splitext(filename)[0] # 使用文件名作为标识 - scales[scale_id] = scale + 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_id = os.path.splitext(filename)[0] # 使用文件名作为标识 + scales[scale_id] = scale + except Exception as e: + print(f"Error loading scale {filename}: {e}") return scales @app.get("/", response_class=HTMLResponse) @@ -64,7 +69,6 @@ async def result(request: Request, scale_id: str): responses[subscale] = 0 ranges[subscale] = [len(scale['range'][0]*qids),len(scale['range'][1]*qids)] for qid in qids: - print(qid) if qid<0: responses[subscale] += scale['range'][0] + scale['range'][1] - int(form_data[str(-qid)]) else: diff --git a/requirements.txt b/requirements.txt index 90c3812a5e17bc8bece4e3037b359844cb1ccb54..187eb52100f8fe39308e21d7572b47e455cfaa49 100644 GIT binary patch delta 50 ucmb {{scale_title}} + + + + @@ -15,7 +22,9 @@
  • {{ key }}: 在 {{ranges[key][0]}} 到 {{ranges[key][1]}} 的量表中得分 {{ value }}
  • {% endfor %} -

    {{scale.description}}

    +
    + {{scale.descriptions|safe}} +
    \ No newline at end of file diff --git a/templates/scale.html b/templates/scale.html index cf4c515..04c997d 100644 --- a/templates/scale.html +++ b/templates/scale.html @@ -6,11 +6,20 @@ {{ scale.title }} + + + +

    {{ scale.title }}

    -

    {{ scale.instructions }}

    +
    + {{ scale.instructions|safe }} +
    {% for id, question in scale.questions.items() %}