feat: 新增中庸实践思维量表和SCL90量表
新增中文版中庸实践思维量表和英文版SCL90量表,用于心理评估。同时优化了加载问卷数据的逻辑,支持递归遍历文件夹以加载所有问卷文件。
This commit is contained in:
parent
c4efd778a9
commit
72db5c8b83
32
app.py
32
app.py
@ -13,7 +13,6 @@ app.mount("/static", StaticFiles(directory="static"), name="static")
|
|||||||
|
|
||||||
# 加载所有问卷数据
|
# 加载所有问卷数据
|
||||||
def load_all_scales():
|
def load_all_scales():
|
||||||
scale_folder = os.path.realpath('scales')
|
|
||||||
scales = {}
|
scales = {}
|
||||||
tags = {}
|
tags = {}
|
||||||
try:
|
try:
|
||||||
@ -21,21 +20,22 @@ def load_all_scales():
|
|||||||
tagmap = yaml.safe_load(f)
|
tagmap = yaml.safe_load(f)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Error loading scale langmap: {e}")
|
print(f"Error loading scale langmap: {e}")
|
||||||
for filename in os.listdir(scale_folder):
|
for root, dirs, files in os.walk(os.path.realpath('scales')):
|
||||||
if filename.endswith(('.yaml', '.yml')):
|
for filename in files:
|
||||||
try:
|
if filename.endswith(('.yaml', '.yml')):
|
||||||
with open(os.path.join(scale_folder, filename), 'r', encoding='utf-8') as f:
|
try:
|
||||||
scale = yaml.safe_load(f)
|
with open(os.path.join(root, filename), 'r', encoding='utf-8') as f:
|
||||||
scale['instructions']=markdown.markdown(scale['instructions'], extensions=['fenced_code','tables','mdx_math'])
|
scale = yaml.safe_load(f)
|
||||||
scale['descriptions']=markdown.markdown(scale['descriptions'], extensions=['fenced_code','tables','mdx_math'])
|
scale['instructions']=markdown.markdown(scale['instructions'], extensions=['fenced_code','tables','mdx_math'])
|
||||||
scale['abstract']=markdown.markdown(scale['abstract'], extensions=['fenced_code','tables','mdx_math'])
|
scale['descriptions']=markdown.markdown(scale['descriptions'], extensions=['fenced_code','tables','mdx_math'])
|
||||||
if 'tag' not in scale or scale['tag'] not in tagmap:
|
scale['abstract']=markdown.markdown(scale['abstract'], extensions=['fenced_code','tables','mdx_math'])
|
||||||
scale['tag']='other'
|
if 'tag' not in scale or scale['tag'] not in tagmap:
|
||||||
tags[scale['tag']]=tagmap[scale['tag']]
|
scale['tag']='other'
|
||||||
scale_id = os.path.splitext(filename)[0] # 使用文件名作为标识
|
tags[scale['tag']]=tagmap[scale['tag']]
|
||||||
scales[scale_id] = scale
|
scale_id = os.path.splitext(filename)[0] # 使用文件名作为标识
|
||||||
except Exception as e:
|
scales[scale_id] = scale
|
||||||
print(f"Error loading scale {filename}: {e}")
|
except Exception as e:
|
||||||
|
print(f"Error loading scale {filename}: {e}")
|
||||||
return tags, scales
|
return tags, scales
|
||||||
|
|
||||||
@app.get("/", response_class=HTMLResponse)
|
@app.get("/", response_class=HTMLResponse)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user