修复了量表计算逻辑,修复了量表required提示

This commit is contained in:
mxr612 2025-03-10 12:48:42 +00:00
parent 7e85847a41
commit 4fc9660f8b
3 changed files with 10 additions and 5 deletions

6
app.py
View File

@ -88,10 +88,12 @@ async def result(request: Request, scale_id: str):
ranges = {}
for subscale, qids in scale['subscales'].items():
responses[subscale] = 0
ranges[subscale] = [len(scale['range'][0]*qids),len(scale['range'][1]*qids)]
min_val = min(scale['range'].keys())
max_val = max(scale['range'].keys())
ranges[subscale] = [min_val*len(qids),max_val*len(qids)]
for qid in qids:
if qid<0:
responses[subscale] += scale['range'][0] + scale['range'][1] - int(form_data[str(-qid)])
responses[subscale] += min_val + max_val - int(form_data[str(-qid)])
else:
responses[subscale] += int(form_data[str(qid)])
return templates.TemplateResponse("result.html", {

View File

@ -119,7 +119,11 @@ main {
display: flex;
input[type="radio"] {
display: none;
position: absolute;
clip: rect(0 0 0 0);
width: 1px;
height: 1px;
margin: -1px;
}
label {

View File

@ -14,8 +14,7 @@
<label for="{{ id }}">{{ id }}. {{ question }}</label>
<div class="scale-button">
{% for option, lable in scale.range.items() %}
<input type="radio" id="{{ id }}_{{ option }}" name="{{ id }}" value="{{ option }}" {% if not ( 'optional' in
question and question.optional) %}required{% endif %}>
<input type="radio" id="{{ id }}_{{ option }}" name="{{ id }}" value="{{ option }}" required>
<label for="{{ id }}_{{ option }}">{{ option }}</label>
{% endfor %}
</div>