edsl 0.1.38.dev1__py3-none-any.whl → 0.1.38.dev2__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.
- edsl/Base.py +3 -3
- edsl/BaseDiff.py +7 -7
- edsl/__init__.py +2 -1
- edsl/__version__.py +1 -1
- edsl/agents/Agent.py +17 -14
- edsl/agents/AgentList.py +29 -17
- edsl/auto/SurveyCreatorPipeline.py +1 -1
- edsl/auto/utilities.py +1 -1
- edsl/base/Base.py +3 -13
- edsl/coop/coop.py +3 -0
- edsl/data/Cache.py +18 -15
- edsl/exceptions/agents.py +4 -0
- edsl/exceptions/cache.py +5 -0
- edsl/jobs/Jobs.py +22 -11
- edsl/jobs/buckets/TokenBucket.py +3 -0
- edsl/jobs/interviews/Interview.py +18 -18
- edsl/jobs/runners/JobsRunnerAsyncio.py +38 -15
- edsl/jobs/runners/JobsRunnerStatus.py +196 -196
- edsl/jobs/tasks/TaskHistory.py +12 -3
- edsl/language_models/LanguageModel.py +9 -7
- edsl/language_models/ModelList.py +20 -13
- edsl/notebooks/Notebook.py +7 -8
- edsl/questions/QuestionBase.py +21 -17
- edsl/questions/QuestionBaseGenMixin.py +1 -1
- edsl/questions/QuestionBasePromptsMixin.py +0 -17
- edsl/questions/QuestionFunctional.py +10 -3
- edsl/questions/derived/QuestionTopK.py +2 -0
- edsl/results/Result.py +31 -25
- edsl/results/Results.py +22 -22
- edsl/scenarios/Scenario.py +12 -14
- edsl/scenarios/ScenarioList.py +16 -16
- edsl/surveys/MemoryPlan.py +1 -1
- edsl/surveys/Rule.py +1 -5
- edsl/surveys/RuleCollection.py +1 -1
- edsl/surveys/Survey.py +9 -17
- edsl/surveys/instructions/ChangeInstruction.py +9 -7
- edsl/surveys/instructions/Instruction.py +9 -7
- edsl/{conjure → utilities}/naming_utilities.py +1 -1
- {edsl-0.1.38.dev1.dist-info → edsl-0.1.38.dev2.dist-info}/METADATA +1 -1
- {edsl-0.1.38.dev1.dist-info → edsl-0.1.38.dev2.dist-info}/RECORD +42 -56
- edsl/conjure/AgentConstructionMixin.py +0 -160
- edsl/conjure/Conjure.py +0 -62
- edsl/conjure/InputData.py +0 -659
- edsl/conjure/InputDataCSV.py +0 -48
- edsl/conjure/InputDataMixinQuestionStats.py +0 -182
- edsl/conjure/InputDataPyRead.py +0 -91
- edsl/conjure/InputDataSPSS.py +0 -8
- edsl/conjure/InputDataStata.py +0 -8
- edsl/conjure/QuestionOptionMixin.py +0 -76
- edsl/conjure/QuestionTypeMixin.py +0 -23
- edsl/conjure/RawQuestion.py +0 -65
- edsl/conjure/SurveyResponses.py +0 -7
- edsl/conjure/__init__.py +0 -9
- edsl/conjure/examples/placeholder.txt +0 -0
- edsl/conjure/utilities.py +0 -201
- {edsl-0.1.38.dev1.dist-info → edsl-0.1.38.dev2.dist-info}/LICENSE +0 -0
- {edsl-0.1.38.dev1.dist-info → edsl-0.1.38.dev2.dist-info}/WHEEL +0 -0
@@ -126,7 +126,6 @@ class QuestionBasePromptsMixin:
|
|
126
126
|
|
127
127
|
@classmethod
|
128
128
|
def default_question_presentation(cls):
|
129
|
-
# template_text = cls._read_template("question_presentation.jinja")
|
130
129
|
template_text = template_manager.get_template(
|
131
130
|
cls.question_type, "question_presentation.jinja"
|
132
131
|
)
|
@@ -142,22 +141,6 @@ class QuestionBasePromptsMixin:
|
|
142
141
|
def answering_instructions(self, value) -> None:
|
143
142
|
self._answering_instructions = value
|
144
143
|
|
145
|
-
# @classmethod
|
146
|
-
# def default_answering_instructions(cls) -> str:
|
147
|
-
# with resources.open_text(
|
148
|
-
# f"edsl.questions.templates.{cls.question_type}",
|
149
|
-
# "answering_instructions.jinja",
|
150
|
-
# ) as file:
|
151
|
-
# return Prompt(text=file.read())
|
152
|
-
|
153
|
-
# @classmethod
|
154
|
-
# def default_question_presentation(cls):
|
155
|
-
# with resources.open_text(
|
156
|
-
# f"edsl.questions.templates.{cls.question_type}",
|
157
|
-
# "question_presentation.jinja",
|
158
|
-
# ) as file:
|
159
|
-
# return Prompt(text=file.read())
|
160
|
-
|
161
144
|
@property
|
162
145
|
def question_presentation(self):
|
163
146
|
if self._question_presentation is None:
|
@@ -108,15 +108,22 @@ class QuestionFunctional(QuestionBase):
|
|
108
108
|
def question_html_content(self) -> str:
|
109
109
|
return "NA for QuestionFunctional"
|
110
110
|
|
111
|
-
@add_edsl_version
|
112
|
-
def to_dict(self):
|
113
|
-
|
111
|
+
# @add_edsl_version
|
112
|
+
def to_dict(self, add_edsl_version=True):
|
113
|
+
d = {
|
114
114
|
"question_name": self.question_name,
|
115
115
|
"function_source_code": self.function_source_code,
|
116
116
|
"question_type": "functional",
|
117
117
|
"requires_loop": self.requires_loop,
|
118
118
|
"function_name": self.function_name,
|
119
119
|
}
|
120
|
+
if add_edsl_version:
|
121
|
+
from edsl import __version__
|
122
|
+
|
123
|
+
d["edsl_version"] = __version__
|
124
|
+
d["edsl_class_name"] = self.__class__.__name__
|
125
|
+
|
126
|
+
return d
|
120
127
|
|
121
128
|
@classmethod
|
122
129
|
def example(cls):
|
@@ -21,6 +21,7 @@ class QuestionTopK(QuestionCheckBox):
|
|
21
21
|
question_presentation: Optional[str] = None,
|
22
22
|
answering_instructions: Optional[str] = None,
|
23
23
|
include_comment: Optional[bool] = True,
|
24
|
+
use_code: Optional[bool] = True,
|
24
25
|
):
|
25
26
|
"""Initialize the question.
|
26
27
|
|
@@ -39,6 +40,7 @@ class QuestionTopK(QuestionCheckBox):
|
|
39
40
|
question_presentation=question_presentation,
|
40
41
|
answering_instructions=answering_instructions,
|
41
42
|
include_comment=include_comment,
|
43
|
+
use_code=use_code,
|
42
44
|
)
|
43
45
|
if min_selections != max_selections:
|
44
46
|
raise QuestionCreationValidationError(
|
edsl/results/Result.py
CHANGED
@@ -156,15 +156,15 @@ class Result(Base, UserDict):
|
|
156
156
|
if key in self.question_to_attributes:
|
157
157
|
# You might be tempted to just use the naked key
|
158
158
|
# but this is a bad idea because it pollutes the namespace
|
159
|
-
question_text_dict[
|
160
|
-
key
|
161
|
-
|
162
|
-
question_options_dict[
|
163
|
-
key
|
164
|
-
|
165
|
-
question_type_dict[
|
166
|
-
key
|
167
|
-
|
159
|
+
question_text_dict[key + "_question_text"] = (
|
160
|
+
self.question_to_attributes[key]["question_text"]
|
161
|
+
)
|
162
|
+
question_options_dict[key + "_question_options"] = (
|
163
|
+
self.question_to_attributes[key]["question_options"]
|
164
|
+
)
|
165
|
+
question_type_dict[key + "_question_type"] = (
|
166
|
+
self.question_to_attributes[key]["question_type"]
|
167
|
+
)
|
168
168
|
|
169
169
|
return {
|
170
170
|
"agent": self.agent.traits
|
@@ -324,14 +324,24 @@ class Result(Base, UserDict):
|
|
324
324
|
###############
|
325
325
|
# Serialization
|
326
326
|
###############
|
327
|
-
def
|
328
|
-
"""Return a dictionary representation of the Result object.
|
329
|
-
|
330
|
-
|
327
|
+
def to_dict(self, add_edsl_version=True) -> dict[str, Any]:
|
328
|
+
"""Return a dictionary representation of the Result object.
|
329
|
+
|
330
|
+
>>> r = Result.example()
|
331
|
+
>>> r.to_dict()['scenario']
|
332
|
+
{'period': 'morning', 'edsl_version': '...', 'edsl_class_name': 'Scenario'}
|
333
|
+
"""
|
334
|
+
|
335
|
+
def convert_value(value, add_edsl_version=True):
|
331
336
|
if hasattr(value, "to_dict"):
|
332
|
-
|
337
|
+
return value.to_dict(add_edsl_version=add_edsl_version)
|
333
338
|
else:
|
334
|
-
|
339
|
+
return value
|
340
|
+
|
341
|
+
d = {}
|
342
|
+
for key, value in self.items():
|
343
|
+
d[key] = convert_value(value, add_edsl_version=add_edsl_version)
|
344
|
+
|
335
345
|
if key == "prompt":
|
336
346
|
new_prompt_dict = {}
|
337
347
|
for prompt_name, prompt_obj in value.items():
|
@@ -341,23 +351,19 @@ class Result(Base, UserDict):
|
|
341
351
|
else prompt_obj.to_dict()
|
342
352
|
)
|
343
353
|
d[key] = new_prompt_dict
|
344
|
-
|
354
|
+
if add_edsl_version:
|
355
|
+
from edsl import __version__
|
345
356
|
|
346
|
-
|
347
|
-
|
348
|
-
"""Return a dictionary representation of the Result object.
|
357
|
+
d["edsl_version"] = __version__
|
358
|
+
d["edsl_class_name"] = "Result"
|
349
359
|
|
350
|
-
|
351
|
-
>>> r.to_dict()['scenario']
|
352
|
-
{'period': 'morning', 'edsl_version': '...', 'edsl_class_name': 'Scenario'}
|
353
|
-
"""
|
354
|
-
return self._to_dict()
|
360
|
+
return d
|
355
361
|
|
356
362
|
def __hash__(self):
|
357
363
|
"""Return a hash of the Result object."""
|
358
364
|
from edsl.utilities.utilities import dict_hash
|
359
365
|
|
360
|
-
return dict_hash(self.
|
366
|
+
return dict_hash(self.to_dict(add_edsl_version=False))
|
361
367
|
|
362
368
|
@classmethod
|
363
369
|
@remove_edsl_version
|
edsl/results/Results.py
CHANGED
@@ -261,25 +261,39 @@ class Results(UserList, Mixins, Base):
|
|
261
261
|
return f"Results(data = {reprlib.repr(self.data)}, survey = {repr(self.survey)}, created_columns = {self.created_columns})"
|
262
262
|
|
263
263
|
def _repr_html_(self) -> str:
|
264
|
-
from IPython.display import HTML
|
264
|
+
# from IPython.display import HTML
|
265
265
|
|
266
|
-
json_str = json.dumps(self.to_dict()["data"], indent=4)
|
266
|
+
json_str = json.dumps(self.to_dict(add_edsl_version=False)["data"], indent=4)
|
267
267
|
return f"<pre>{json_str}</pre>"
|
268
268
|
|
269
|
-
def
|
269
|
+
def to_dict(self, sort=False, add_edsl_version=False) -> dict[str, Any]:
|
270
270
|
from edsl.data.Cache import Cache
|
271
271
|
|
272
272
|
if sort:
|
273
273
|
data = sorted([result for result in self.data], key=lambda x: hash(x))
|
274
274
|
else:
|
275
275
|
data = [result for result in self.data]
|
276
|
-
|
277
|
-
|
278
|
-
"
|
276
|
+
|
277
|
+
d = {
|
278
|
+
"data": [
|
279
|
+
result.to_dict(add_edsl_version=add_edsl_version) for result in data
|
280
|
+
],
|
281
|
+
"survey": self.survey.to_dict(add_edsl_version=add_edsl_version),
|
279
282
|
"created_columns": self.created_columns,
|
280
|
-
"cache":
|
283
|
+
"cache": (
|
284
|
+
Cache()
|
285
|
+
if not hasattr(self, "cache")
|
286
|
+
else self.cache.to_dict(add_edsl_version=add_edsl_version)
|
287
|
+
),
|
281
288
|
"task_history": self.task_history.to_dict(),
|
282
289
|
}
|
290
|
+
if add_edsl_version:
|
291
|
+
from edsl import __version__
|
292
|
+
|
293
|
+
d["edsl_version"] = __version__
|
294
|
+
d["edsl_class_name"] = "Results"
|
295
|
+
|
296
|
+
return d
|
283
297
|
|
284
298
|
def compare(self, other_results):
|
285
299
|
"""
|
@@ -302,22 +316,8 @@ class Results(UserList, Mixins, Base):
|
|
302
316
|
def has_unfixed_exceptions(self):
|
303
317
|
return self.task_history.has_unfixed_exceptions
|
304
318
|
|
305
|
-
@add_edsl_version
|
306
|
-
def to_dict(self) -> dict[str, Any]:
|
307
|
-
"""Convert the Results object to a dictionary.
|
308
|
-
|
309
|
-
The dictionary can be quite large, as it includes all of the data in the Results object.
|
310
|
-
|
311
|
-
Example: Illustrating just the keys of the dictionary.
|
312
|
-
|
313
|
-
>>> r = Results.example()
|
314
|
-
>>> r.to_dict().keys()
|
315
|
-
dict_keys(['data', 'survey', 'created_columns', 'cache', 'task_history', 'edsl_version', 'edsl_class_name'])
|
316
|
-
"""
|
317
|
-
return self._to_dict()
|
318
|
-
|
319
319
|
def __hash__(self) -> int:
|
320
|
-
return dict_hash(self.
|
320
|
+
return dict_hash(self.to_dict(sort=True, add_edsl_version=False))
|
321
321
|
|
322
322
|
@property
|
323
323
|
def hashes(self) -> set:
|
edsl/scenarios/Scenario.py
CHANGED
@@ -137,7 +137,7 @@ class Scenario(Base, UserDict, ScenarioHtmlMixin):
|
|
137
137
|
new_scenario[key] = value
|
138
138
|
return new_scenario
|
139
139
|
|
140
|
-
def
|
140
|
+
def to_dict(self, add_edsl_version=True) -> dict:
|
141
141
|
"""Convert a scenario to a dictionary.
|
142
142
|
|
143
143
|
Example:
|
@@ -145,26 +145,24 @@ class Scenario(Base, UserDict, ScenarioHtmlMixin):
|
|
145
145
|
>>> s = Scenario({"food": "wood chips"})
|
146
146
|
>>> s.to_dict()
|
147
147
|
{'food': 'wood chips', 'edsl_version': '...', 'edsl_class_name': 'Scenario'}
|
148
|
+
|
149
|
+
>>> s.to_dict(add_edsl_version = False)
|
150
|
+
{'food': 'wood chips'}
|
151
|
+
|
148
152
|
"""
|
149
153
|
from edsl.scenarios.FileStore import FileStore
|
150
154
|
|
151
155
|
d = self.data.copy()
|
152
156
|
for key, value in d.items():
|
153
157
|
if isinstance(value, FileStore):
|
154
|
-
d[key] = value.to_dict()
|
155
|
-
|
158
|
+
d[key] = value.to_dict(add_edsl_version=add_edsl_version)
|
159
|
+
if add_edsl_version:
|
160
|
+
from edsl import __version__
|
156
161
|
|
157
|
-
|
158
|
-
|
159
|
-
"""Convert a scenario to a dictionary.
|
160
|
-
|
161
|
-
Example:
|
162
|
+
d["edsl_version"] = __version__
|
163
|
+
d["edsl_class_name"] = "Scenario"
|
162
164
|
|
163
|
-
|
164
|
-
>>> s.to_dict()
|
165
|
-
{'food': 'wood chips', 'edsl_version': '...', 'edsl_class_name': 'Scenario'}
|
166
|
-
"""
|
167
|
-
return self._to_dict()
|
165
|
+
return d
|
168
166
|
|
169
167
|
def __hash__(self) -> int:
|
170
168
|
"""
|
@@ -178,7 +176,7 @@ class Scenario(Base, UserDict, ScenarioHtmlMixin):
|
|
178
176
|
"""
|
179
177
|
from edsl.utilities.utilities import dict_hash
|
180
178
|
|
181
|
-
return dict_hash(self.
|
179
|
+
return dict_hash(self.to_dict(add_edsl_version=False))
|
182
180
|
|
183
181
|
def print(self):
|
184
182
|
from rich import print_json
|
edsl/scenarios/ScenarioList.py
CHANGED
@@ -20,7 +20,7 @@ from edsl.scenarios.Scenario import Scenario
|
|
20
20
|
from edsl.scenarios.ScenarioListPdfMixin import ScenarioListPdfMixin
|
21
21
|
from edsl.scenarios.ScenarioListExportMixin import ScenarioListExportMixin
|
22
22
|
|
23
|
-
from edsl.
|
23
|
+
from edsl.utilities.naming_utilities import sanitize_string
|
24
24
|
from edsl.utilities.utilities import is_valid_variable_name
|
25
25
|
|
26
26
|
|
@@ -239,7 +239,7 @@ class ScenarioList(Base, UserList, ScenarioListMixin):
|
|
239
239
|
"""
|
240
240
|
from edsl.utilities.utilities import dict_hash
|
241
241
|
|
242
|
-
return dict_hash(self.
|
242
|
+
return dict_hash(self.to_dict(sort=True, add_edsl_version=False))
|
243
243
|
|
244
244
|
def __repr__(self):
|
245
245
|
return f"ScenarioList({self.data})"
|
@@ -958,24 +958,24 @@ class ScenarioList(Base, UserList, ScenarioListMixin):
|
|
958
958
|
|
959
959
|
return cls(observations)
|
960
960
|
|
961
|
-
def
|
961
|
+
def to_dict(self, sort=False, add_edsl_version=True) -> dict:
|
962
|
+
"""
|
963
|
+
>>> s = ScenarioList([Scenario({'food': 'wood chips'}), Scenario({'food': 'wood-fired pizza'})])
|
964
|
+
>>> s.to_dict()
|
965
|
+
{'scenarios': [{'food': 'wood chips', 'edsl_version': '...', 'edsl_class_name': 'Scenario'}, {'food': 'wood-fired pizza', 'edsl_version': '...', 'edsl_class_name': 'Scenario'}], 'edsl_version': '...', 'edsl_class_name': 'ScenarioList'}
|
966
|
+
|
967
|
+
"""
|
962
968
|
if sort:
|
963
969
|
data = sorted(self, key=lambda x: hash(x))
|
964
970
|
else:
|
965
971
|
data = self
|
966
|
-
|
967
|
-
|
968
|
-
|
969
|
-
def to_dict(self) -> dict[str, Any]:
|
970
|
-
"""Return the `ScenarioList` as a dictionary.
|
972
|
+
d = {"scenarios": [s.to_dict(add_edsl_version=add_edsl_version) for s in data]}
|
973
|
+
if add_edsl_version:
|
974
|
+
from edsl import __version__
|
971
975
|
|
972
|
-
|
973
|
-
|
974
|
-
|
975
|
-
>>> s.to_dict()
|
976
|
-
{'scenarios': [{'food': 'wood chips', 'edsl_version': '...', 'edsl_class_name': 'Scenario'}, {'food': 'wood-fired pizza', 'edsl_version': '...', 'edsl_class_name': 'Scenario'}], 'edsl_version': '...', 'edsl_class_name': 'ScenarioList'}
|
977
|
-
"""
|
978
|
-
return {"scenarios": [s.to_dict() for s in self]}
|
976
|
+
d["edsl_version"] = __version__
|
977
|
+
d["edsl_class_name"] = self.__class__.__name__
|
978
|
+
return d
|
979
979
|
|
980
980
|
@classmethod
|
981
981
|
def gen(cls, scenario_dicts_list: List[dict]) -> ScenarioList:
|
@@ -1061,7 +1061,7 @@ class ScenarioList(Base, UserList, ScenarioListMixin):
|
|
1061
1061
|
elif isinstance(key, int):
|
1062
1062
|
return super().__getitem__(key)
|
1063
1063
|
else:
|
1064
|
-
return self.
|
1064
|
+
return self.to_dict(add_edsl_version=False)[key]
|
1065
1065
|
|
1066
1066
|
def to_agent_list(self):
|
1067
1067
|
"""Convert the ScenarioList to an AgentList.
|
edsl/surveys/MemoryPlan.py
CHANGED
@@ -143,7 +143,7 @@ class MemoryPlan(UserDict):
|
|
143
143
|
for question in prior_questions:
|
144
144
|
self.add_single_memory(focal_question, question)
|
145
145
|
|
146
|
-
def to_dict(self) -> dict:
|
146
|
+
def to_dict(self, add_edsl_version=True) -> dict:
|
147
147
|
"""Serialize the memory plan to a dictionary.
|
148
148
|
|
149
149
|
>>> mp = MemoryPlan.example()
|
edsl/surveys/Rule.py
CHANGED
@@ -148,10 +148,7 @@ class Rule:
|
|
148
148
|
def _checks(self):
|
149
149
|
pass
|
150
150
|
|
151
|
-
|
152
|
-
|
153
|
-
# @add_edsl_version
|
154
|
-
def to_dict(self):
|
151
|
+
def to_dict(self, add_edsl_version=True):
|
155
152
|
"""Convert the rule to a dictionary for serialization.
|
156
153
|
|
157
154
|
>>> r = Rule.example()
|
@@ -166,7 +163,6 @@ class Rule:
|
|
166
163
|
"question_name_to_index": self.question_name_to_index,
|
167
164
|
"before_rule": self.before_rule,
|
168
165
|
}
|
169
|
-
# return self._to_dict()
|
170
166
|
|
171
167
|
@classmethod
|
172
168
|
@remove_edsl_version
|
edsl/surveys/RuleCollection.py
CHANGED
@@ -46,7 +46,7 @@ class RuleCollection(UserList):
|
|
46
46
|
"""
|
47
47
|
return f"RuleCollection(rules={self.data}, num_questions={self.num_questions})"
|
48
48
|
|
49
|
-
def to_dict(self):
|
49
|
+
def to_dict(self, add_edsl_version=True):
|
50
50
|
"""Create a dictionary representation of the RuleCollection object."""
|
51
51
|
return {
|
52
52
|
"rules": [rule.to_dict() for rule in self],
|
edsl/surveys/Survey.py
CHANGED
@@ -445,35 +445,27 @@ class Survey(SurveyExportMixin, SurveyFlowVisualizationMixin, Base):
|
|
445
445
|
"""Return a hash of the question."""
|
446
446
|
from edsl.utilities.utilities import dict_hash
|
447
447
|
|
448
|
-
return dict_hash(self.
|
448
|
+
return dict_hash(self.to_dict(add_edsl_version=False))
|
449
449
|
|
450
|
-
def
|
450
|
+
def to_dict(self, add_edsl_version=True) -> dict[str, Any]:
|
451
451
|
"""Serialize the Survey object to a dictionary.
|
452
452
|
|
453
453
|
>>> s = Survey.example()
|
454
|
-
>>> s.
|
454
|
+
>>> s.to_dict(add_edsl_version = False).keys()
|
455
455
|
dict_keys(['questions', 'memory_plan', 'rule_collection', 'question_groups'])
|
456
456
|
"""
|
457
457
|
return {
|
458
458
|
"questions": [
|
459
|
-
q.
|
459
|
+
q.to_dict(add_edsl_version=add_edsl_version)
|
460
|
+
for q in self.recombined_questions_and_instructions()
|
460
461
|
],
|
461
|
-
"memory_plan": self.memory_plan.to_dict(),
|
462
|
-
"rule_collection": self.rule_collection.to_dict(
|
462
|
+
"memory_plan": self.memory_plan.to_dict(add_edsl_version=add_edsl_version),
|
463
|
+
"rule_collection": self.rule_collection.to_dict(
|
464
|
+
add_edsl_version=add_edsl_version
|
465
|
+
),
|
463
466
|
"question_groups": self.question_groups,
|
464
467
|
}
|
465
468
|
|
466
|
-
@add_edsl_version
|
467
|
-
def to_dict(self) -> dict[str, Any]:
|
468
|
-
"""Serialize the Survey object to a dictionary.
|
469
|
-
|
470
|
-
>>> s = Survey.example()
|
471
|
-
>>> s.to_dict().keys()
|
472
|
-
dict_keys(['questions', 'memory_plan', 'rule_collection', 'question_groups', 'edsl_version', 'edsl_class_name'])
|
473
|
-
|
474
|
-
"""
|
475
|
-
return self._to_dict()
|
476
|
-
|
477
469
|
@classmethod
|
478
470
|
@remove_edsl_version
|
479
471
|
def from_dict(cls, data: dict) -> Survey:
|
@@ -24,22 +24,24 @@ class ChangeInstruction:
|
|
24
24
|
def __str__(self):
|
25
25
|
return self.text
|
26
26
|
|
27
|
-
def
|
28
|
-
|
27
|
+
def to_dict(self, add_edsl_version=True):
|
28
|
+
d = {
|
29
29
|
"keep": self.keep,
|
30
30
|
"drop": self.drop,
|
31
|
-
"edsl_class_name": "ChangeInstruction",
|
32
31
|
}
|
32
|
+
if add_edsl_version:
|
33
|
+
from edsl import __version__
|
33
34
|
|
34
|
-
|
35
|
-
|
36
|
-
|
35
|
+
d["edsl_version"] = __version__
|
36
|
+
d["edsl_class_name"] = "ChangeInstruction"
|
37
|
+
|
38
|
+
return d
|
37
39
|
|
38
40
|
def __hash__(self) -> int:
|
39
41
|
"""Return a hash of the question."""
|
40
42
|
from edsl.utilities.utilities import dict_hash
|
41
43
|
|
42
|
-
return dict_hash(self.
|
44
|
+
return dict_hash(self.to_dict(add_edsl_version=False))
|
43
45
|
|
44
46
|
@classmethod
|
45
47
|
@remove_edsl_version
|
@@ -18,28 +18,30 @@ class Instruction:
|
|
18
18
|
def __repr__(self):
|
19
19
|
return """Instruction(name="{}", text="{}")""".format(self.name, self.text)
|
20
20
|
|
21
|
-
def
|
22
|
-
|
21
|
+
def to_dict(self, add_edsl_version=True):
|
22
|
+
d = {
|
23
23
|
"name": self.name,
|
24
24
|
"text": self.text,
|
25
25
|
"edsl_class_name": "Instruction",
|
26
26
|
"preamble": self.preamble,
|
27
27
|
}
|
28
|
+
if add_edsl_version:
|
29
|
+
from edsl import __version__
|
30
|
+
|
31
|
+
d["edsl_version"] = __version__
|
32
|
+
d["edsl_class_name"] = "Instruction"
|
33
|
+
return d
|
28
34
|
|
29
35
|
def add_question(self, question) -> "Survey":
|
30
36
|
from edsl import Survey
|
31
37
|
|
32
38
|
return Survey([self, question])
|
33
39
|
|
34
|
-
@add_edsl_version
|
35
|
-
def to_dict(self):
|
36
|
-
return self._to_dict()
|
37
|
-
|
38
40
|
def __hash__(self) -> int:
|
39
41
|
"""Return a hash of the question."""
|
40
42
|
from edsl.utilities.utilities import dict_hash
|
41
43
|
|
42
|
-
return dict_hash(self.
|
44
|
+
return dict_hash(self.to_dict(add_edsl_version=False))
|
43
45
|
|
44
46
|
@classmethod
|
45
47
|
@remove_edsl_version
|
@@ -257,7 +257,7 @@ def sanitize_string(input_string, max_length=35):
|
|
257
257
|
# print()
|
258
258
|
|
259
259
|
if __name__ == "__main__":
|
260
|
-
from edsl.conjure.InputData import InputDataABC
|
260
|
+
# from edsl.conjure.InputData import InputDataABC
|
261
261
|
import doctest
|
262
262
|
|
263
263
|
doctest.testmod(optionflags=doctest.ELLIPSIS)
|