pycityagent 2.0.0a12__py3-none-any.whl → 2.0.0a14__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pycityagent/agent.py +171 -52
- pycityagent/economy/econ_client.py +2 -0
- pycityagent/memory/const.py +1 -0
- pycityagent/simulation/agentgroup.py +78 -42
- pycityagent/simulation/simulation.py +99 -8
- pycityagent/survey/manager.py +58 -0
- pycityagent/survey/models.py +120 -0
- pycityagent/utils/__init__.py +7 -0
- pycityagent/utils/avro_schema.py +85 -0
- pycityagent/utils/survey_util.py +53 -0
- {pycityagent-2.0.0a12.dist-info → pycityagent-2.0.0a14.dist-info}/METADATA +3 -1
- {pycityagent-2.0.0a12.dist-info → pycityagent-2.0.0a14.dist-info}/RECORD +14 -15
- pycityagent/simulation/interview.py +0 -40
- pycityagent/simulation/survey/manager.py +0 -68
- pycityagent/simulation/survey/models.py +0 -52
- pycityagent/simulation/ui/__init__.py +0 -3
- pycityagent/simulation/ui/interface.py +0 -602
- /pycityagent/{simulation/survey → survey}/__init__.py +0 -0
- {pycityagent-2.0.0a12.dist-info → pycityagent-2.0.0a14.dist-info}/WHEEL +0 -0
@@ -1,68 +0,0 @@
|
|
1
|
-
from typing import List, Dict, Optional
|
2
|
-
from datetime import datetime
|
3
|
-
import uuid
|
4
|
-
import json
|
5
|
-
from .models import Survey, Question, QuestionType
|
6
|
-
|
7
|
-
|
8
|
-
class SurveyManager:
|
9
|
-
def __init__(self):
|
10
|
-
self._surveys: Dict[str, Survey] = {}
|
11
|
-
|
12
|
-
def create_survey(
|
13
|
-
self, title: str, description: str, questions: List[dict]
|
14
|
-
) -> Survey:
|
15
|
-
"""创建新问卷"""
|
16
|
-
survey_id = str(uuid.uuid4())
|
17
|
-
|
18
|
-
# 转换问题数据
|
19
|
-
survey_questions = []
|
20
|
-
for q in questions:
|
21
|
-
question = Question(
|
22
|
-
content=q["content"],
|
23
|
-
type=QuestionType(q["type"]),
|
24
|
-
required=q.get("required", True),
|
25
|
-
options=q.get("options", []),
|
26
|
-
min_rating=q.get("min_rating", 1),
|
27
|
-
max_rating=q.get("max_rating", 5),
|
28
|
-
)
|
29
|
-
survey_questions.append(question)
|
30
|
-
|
31
|
-
survey = Survey(
|
32
|
-
id=survey_id,
|
33
|
-
title=title,
|
34
|
-
description=description,
|
35
|
-
questions=survey_questions,
|
36
|
-
)
|
37
|
-
|
38
|
-
self._surveys[survey_id] = survey
|
39
|
-
return survey
|
40
|
-
|
41
|
-
def get_survey(self, survey_id: str) -> Optional[Survey]:
|
42
|
-
"""获取指定问卷"""
|
43
|
-
return self._surveys.get(survey_id)
|
44
|
-
|
45
|
-
def get_all_surveys(self) -> List[Survey]:
|
46
|
-
"""获取所有问卷"""
|
47
|
-
return list(self._surveys.values())
|
48
|
-
|
49
|
-
def add_response(self, survey_id: str, agent_name: str, response: dict) -> bool:
|
50
|
-
"""添加问卷回答"""
|
51
|
-
survey = self.get_survey(survey_id)
|
52
|
-
if not survey:
|
53
|
-
return False
|
54
|
-
|
55
|
-
survey.responses[agent_name] = {"timestamp": datetime.now(), **response}
|
56
|
-
return True
|
57
|
-
|
58
|
-
def export_results(self, survey_id: str) -> str:
|
59
|
-
"""导出问卷结果"""
|
60
|
-
survey = self.get_survey(survey_id)
|
61
|
-
if not survey:
|
62
|
-
return json.dumps({"error": "问卷不存在"})
|
63
|
-
|
64
|
-
return json.dumps(
|
65
|
-
{"survey": survey.to_dict(), "responses": survey.responses},
|
66
|
-
ensure_ascii=False,
|
67
|
-
indent=2,
|
68
|
-
)
|
@@ -1,52 +0,0 @@
|
|
1
|
-
from dataclasses import dataclass, field
|
2
|
-
from typing import List, Dict, Optional
|
3
|
-
from datetime import datetime
|
4
|
-
from enum import Enum
|
5
|
-
import uuid
|
6
|
-
|
7
|
-
|
8
|
-
class QuestionType(Enum):
|
9
|
-
TEXT = "文本"
|
10
|
-
SINGLE_CHOICE = "单选"
|
11
|
-
MULTIPLE_CHOICE = "多选"
|
12
|
-
RATING = "评分"
|
13
|
-
LIKERT = "李克特量表"
|
14
|
-
|
15
|
-
|
16
|
-
@dataclass
|
17
|
-
class Question:
|
18
|
-
content: str
|
19
|
-
type: QuestionType
|
20
|
-
required: bool = True
|
21
|
-
options: List[str] = field(default_factory=list)
|
22
|
-
min_rating: int = 1
|
23
|
-
max_rating: int = 5
|
24
|
-
|
25
|
-
def to_dict(self) -> dict:
|
26
|
-
return {
|
27
|
-
"content": self.content,
|
28
|
-
"type": self.type.value,
|
29
|
-
"required": self.required,
|
30
|
-
"options": self.options,
|
31
|
-
"min_rating": self.min_rating,
|
32
|
-
"max_rating": self.max_rating,
|
33
|
-
}
|
34
|
-
|
35
|
-
|
36
|
-
@dataclass
|
37
|
-
class Survey:
|
38
|
-
id: str
|
39
|
-
title: str
|
40
|
-
description: str
|
41
|
-
questions: List[Question]
|
42
|
-
responses: Dict[str, dict] = field(default_factory=dict)
|
43
|
-
created_at: datetime = field(default_factory=datetime.now)
|
44
|
-
|
45
|
-
def to_dict(self) -> dict:
|
46
|
-
return {
|
47
|
-
"id": self.id,
|
48
|
-
"title": self.title,
|
49
|
-
"description": self.description,
|
50
|
-
"questions": [q.to_dict() for q in self.questions],
|
51
|
-
"response_count": len(self.responses),
|
52
|
-
}
|