style: 代码格式化,修复缩进问题

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
春河晴
2025-03-21 13:41:43 +08:00
parent 0f1a3bfaba
commit 7cad7786cc
9 changed files with 374 additions and 366 deletions

View File

@@ -15,17 +15,14 @@ env_path = project_root / ".env.prod"
root_path = os.path.abspath(os.path.join(os.path.dirname(__file__), "../../.."))
sys.path.append(root_path)
from src.plugins.personality.scene import get_scene_by_factor,get_all_scenes,PERSONALITY_SCENES
from src.plugins.personality.questionnaire import PERSONALITY_QUESTIONS,FACTOR_DESCRIPTIONS
from src.plugins.personality.offline_llm import LLMModel
from src.plugins.personality.questionnaire import PERSONALITY_QUESTIONS, FACTOR_DESCRIPTIONS # noqa: E402
class BigFiveTest:
def __init__(self):
self.questions = PERSONALITY_QUESTIONS
self.factors = FACTOR_DESCRIPTIONS
def run_test(self):
"""运行测试并收集答案"""
print("\n欢迎参加中国大五人格测试!")
@@ -37,17 +34,17 @@ class BigFiveTest:
print("5 = 比较符合")
print("6 = 完全符合")
print("\n请认真阅读每个描述,选择最符合您实际情况的选项。\n")
# 创建题目序号到题目的映射
questions_map = {q['id']: q for q in self.questions}
questions_map = {q["id"]: q for q in self.questions}
# 获取所有题目ID并随机打乱顺序
question_ids = list(questions_map.keys())
random.shuffle(question_ids)
answers = {}
total_questions = len(question_ids)
for i, question_id in enumerate(question_ids, 1):
question = questions_map[question_id]
while True:
@@ -61,52 +58,43 @@ class BigFiveTest:
print("请输入1-6之间的数字")
except ValueError:
print("请输入有效的数字!")
return self.calculate_scores(answers)
def calculate_scores(self, answers):
"""计算各维度得分"""
results = {}
factor_questions = {
"外向性": [],
"神经质": [],
"严谨性": [],
"开放性": [],
"宜人性": []
}
factor_questions = {"外向性": [], "神经质": [], "严谨性": [], "开放性": [], "宜人性": []}
# 将题目按因子分类
for q in self.questions:
factor_questions[q['factor']].append(q)
factor_questions[q["factor"]].append(q)
# 计算每个维度的得分
for factor, questions in factor_questions.items():
total_score = 0
for q in questions:
score = answers[q['id']]
score = answers[q["id"]]
# 处理反向计分题目
if q['reverse_scoring']:
if q["reverse_scoring"]:
score = 7 - score # 6分量表反向计分为7减原始分
total_score += score
# 计算平均分
avg_score = round(total_score / len(questions), 2)
results[factor] = {
"得分": avg_score,
"题目数": len(questions),
"总分": total_score
}
results[factor] = {"得分": avg_score, "题目数": len(questions), "总分": total_score}
return results
def get_factor_description(self, factor):
"""获取因子的详细描述"""
return self.factors[factor]
def main():
test = BigFiveTest()
results = test.run_test()
print("\n测试结果:")
print("=" * 50)
for factor, data in results.items():
@@ -114,9 +102,10 @@ def main():
print(f"平均分: {data['得分']} (总分: {data['总分']}, 题目数: {data['题目数']})")
print("-" * 30)
description = test.get_factor_description(factor)
print("维度说明:", description['description'][:100] + "...")
print("\n特征词:", ", ".join(description['trait_words']))
print("维度说明:", description["description"][:100] + "...")
print("\n特征词:", ", ".join(description["trait_words"]))
print("=" * 50)
if __name__ == "__main__":
main()