edsl 0.1.39__py3-none-any.whl → 0.1.39.dev1__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 +116 -197
- edsl/__init__.py +7 -15
- edsl/__version__.py +1 -1
- edsl/agents/Agent.py +147 -351
- edsl/agents/AgentList.py +73 -211
- edsl/agents/Invigilator.py +50 -101
- edsl/agents/InvigilatorBase.py +70 -62
- edsl/agents/PromptConstructor.py +225 -143
- edsl/agents/__init__.py +1 -0
- edsl/agents/prompt_helpers.py +3 -3
- edsl/auto/AutoStudy.py +5 -18
- edsl/auto/StageBase.py +40 -53
- edsl/auto/StageQuestions.py +1 -2
- edsl/auto/utilities.py +6 -0
- edsl/config.py +2 -22
- edsl/conversation/car_buying.py +1 -2
- edsl/coop/PriceFetcher.py +1 -1
- edsl/coop/coop.py +47 -125
- edsl/coop/utils.py +14 -14
- edsl/data/Cache.py +27 -45
- edsl/data/CacheEntry.py +15 -12
- edsl/data/CacheHandler.py +12 -31
- edsl/data/RemoteCacheSync.py +46 -154
- edsl/data/__init__.py +3 -4
- edsl/data_transfer_models.py +1 -2
- edsl/enums.py +0 -27
- edsl/exceptions/__init__.py +50 -50
- edsl/exceptions/agents.py +0 -12
- edsl/exceptions/questions.py +6 -24
- edsl/exceptions/scenarios.py +0 -7
- edsl/inference_services/AnthropicService.py +19 -38
- edsl/inference_services/AwsBedrock.py +2 -0
- edsl/inference_services/AzureAI.py +2 -0
- edsl/inference_services/GoogleService.py +12 -7
- edsl/inference_services/InferenceServiceABC.py +85 -18
- edsl/inference_services/InferenceServicesCollection.py +79 -120
- edsl/inference_services/MistralAIService.py +3 -0
- edsl/inference_services/OpenAIService.py +35 -47
- edsl/inference_services/PerplexityService.py +3 -0
- edsl/inference_services/TestService.py +10 -11
- edsl/inference_services/TogetherAIService.py +3 -5
- edsl/jobs/Answers.py +14 -1
- edsl/jobs/Jobs.py +431 -356
- edsl/jobs/JobsChecks.py +10 -35
- edsl/jobs/JobsPrompts.py +4 -6
- edsl/jobs/JobsRemoteInferenceHandler.py +133 -205
- edsl/jobs/buckets/BucketCollection.py +3 -44
- edsl/jobs/buckets/TokenBucket.py +21 -53
- edsl/jobs/interviews/Interview.py +408 -143
- edsl/jobs/runners/JobsRunnerAsyncio.py +403 -88
- edsl/jobs/runners/JobsRunnerStatus.py +165 -133
- edsl/jobs/tasks/QuestionTaskCreator.py +19 -21
- edsl/jobs/tasks/TaskHistory.py +18 -38
- edsl/jobs/tasks/task_status_enum.py +2 -0
- edsl/language_models/KeyLookup.py +30 -0
- edsl/language_models/LanguageModel.py +236 -194
- edsl/language_models/ModelList.py +19 -28
- edsl/language_models/__init__.py +2 -1
- edsl/language_models/registry.py +190 -0
- edsl/language_models/repair.py +2 -2
- edsl/language_models/unused/ReplicateBase.py +83 -0
- edsl/language_models/utilities.py +4 -5
- edsl/notebooks/Notebook.py +14 -19
- edsl/prompts/Prompt.py +39 -29
- edsl/questions/{answer_validator_mixin.py → AnswerValidatorMixin.py} +2 -47
- edsl/questions/QuestionBase.py +214 -68
- edsl/questions/{question_base_gen_mixin.py → QuestionBaseGenMixin.py} +50 -57
- edsl/questions/QuestionBasePromptsMixin.py +3 -7
- edsl/questions/QuestionBudget.py +1 -1
- edsl/questions/QuestionCheckBox.py +3 -3
- edsl/questions/QuestionExtract.py +7 -5
- edsl/questions/QuestionFreeText.py +3 -2
- edsl/questions/QuestionList.py +18 -10
- edsl/questions/QuestionMultipleChoice.py +23 -67
- edsl/questions/QuestionNumerical.py +4 -2
- edsl/questions/QuestionRank.py +17 -7
- edsl/questions/{response_validator_abc.py → ResponseValidatorABC.py} +26 -40
- edsl/questions/SimpleAskMixin.py +3 -4
- edsl/questions/__init__.py +1 -2
- edsl/questions/derived/QuestionLinearScale.py +3 -6
- edsl/questions/derived/QuestionTopK.py +1 -1
- edsl/questions/descriptors.py +3 -17
- edsl/questions/question_registry.py +1 -1
- edsl/results/CSSParameterizer.py +1 -1
- edsl/results/Dataset.py +7 -170
- edsl/results/DatasetExportMixin.py +305 -168
- edsl/results/DatasetTree.py +8 -28
- edsl/results/Result.py +206 -298
- edsl/results/Results.py +131 -149
- edsl/results/ResultsDBMixin.py +238 -0
- edsl/results/ResultsExportMixin.py +0 -2
- edsl/results/{results_selector.py → Selector.py} +13 -23
- edsl/results/TableDisplay.py +171 -98
- edsl/results/__init__.py +1 -1
- edsl/scenarios/FileStore.py +239 -150
- edsl/scenarios/Scenario.py +193 -90
- edsl/scenarios/ScenarioHtmlMixin.py +3 -4
- edsl/scenarios/{scenario_join.py → ScenarioJoin.py} +6 -10
- edsl/scenarios/ScenarioList.py +244 -415
- edsl/scenarios/ScenarioListExportMixin.py +7 -0
- edsl/scenarios/ScenarioListPdfMixin.py +37 -15
- edsl/scenarios/__init__.py +2 -1
- edsl/study/ObjectEntry.py +1 -1
- edsl/study/SnapShot.py +1 -1
- edsl/study/Study.py +12 -5
- edsl/surveys/Rule.py +4 -5
- edsl/surveys/RuleCollection.py +27 -25
- edsl/surveys/Survey.py +791 -270
- edsl/surveys/SurveyCSS.py +8 -20
- edsl/surveys/{SurveyFlowVisualization.py → SurveyFlowVisualizationMixin.py} +9 -11
- edsl/surveys/__init__.py +2 -4
- edsl/surveys/descriptors.py +2 -6
- edsl/surveys/instructions/ChangeInstruction.py +2 -1
- edsl/surveys/instructions/Instruction.py +13 -4
- edsl/surveys/instructions/InstructionCollection.py +6 -11
- edsl/templates/error_reporting/interview_details.html +1 -1
- edsl/templates/error_reporting/report.html +1 -1
- edsl/tools/plotting.py +1 -1
- edsl/utilities/utilities.py +23 -35
- {edsl-0.1.39.dist-info → edsl-0.1.39.dev1.dist-info}/METADATA +10 -12
- edsl-0.1.39.dev1.dist-info/RECORD +277 -0
- {edsl-0.1.39.dist-info → edsl-0.1.39.dev1.dist-info}/WHEEL +1 -1
- edsl/agents/QuestionInstructionPromptBuilder.py +0 -128
- edsl/agents/QuestionTemplateReplacementsBuilder.py +0 -137
- edsl/agents/question_option_processor.py +0 -172
- edsl/coop/CoopFunctionsMixin.py +0 -15
- edsl/coop/ExpectedParrotKeyHandler.py +0 -125
- edsl/exceptions/inference_services.py +0 -5
- edsl/inference_services/AvailableModelCacheHandler.py +0 -184
- edsl/inference_services/AvailableModelFetcher.py +0 -215
- edsl/inference_services/ServiceAvailability.py +0 -135
- edsl/inference_services/data_structures.py +0 -134
- edsl/jobs/AnswerQuestionFunctionConstructor.py +0 -223
- edsl/jobs/FetchInvigilator.py +0 -47
- edsl/jobs/InterviewTaskManager.py +0 -98
- edsl/jobs/InterviewsConstructor.py +0 -50
- edsl/jobs/JobsComponentConstructor.py +0 -189
- edsl/jobs/JobsRemoteInferenceLogger.py +0 -239
- edsl/jobs/RequestTokenEstimator.py +0 -30
- edsl/jobs/async_interview_runner.py +0 -138
- edsl/jobs/buckets/TokenBucketAPI.py +0 -211
- edsl/jobs/buckets/TokenBucketClient.py +0 -191
- edsl/jobs/check_survey_scenario_compatibility.py +0 -85
- edsl/jobs/data_structures.py +0 -120
- edsl/jobs/decorators.py +0 -35
- edsl/jobs/jobs_status_enums.py +0 -9
- edsl/jobs/loggers/HTMLTableJobLogger.py +0 -304
- edsl/jobs/results_exceptions_handler.py +0 -98
- edsl/language_models/ComputeCost.py +0 -63
- edsl/language_models/PriceManager.py +0 -127
- edsl/language_models/RawResponseHandler.py +0 -106
- edsl/language_models/ServiceDataSources.py +0 -0
- edsl/language_models/key_management/KeyLookup.py +0 -63
- edsl/language_models/key_management/KeyLookupBuilder.py +0 -273
- edsl/language_models/key_management/KeyLookupCollection.py +0 -38
- edsl/language_models/key_management/__init__.py +0 -0
- edsl/language_models/key_management/models.py +0 -131
- edsl/language_models/model.py +0 -256
- edsl/notebooks/NotebookToLaTeX.py +0 -142
- edsl/questions/ExceptionExplainer.py +0 -77
- edsl/questions/HTMLQuestion.py +0 -103
- edsl/questions/QuestionMatrix.py +0 -265
- edsl/questions/data_structures.py +0 -20
- edsl/questions/loop_processor.py +0 -149
- edsl/questions/response_validator_factory.py +0 -34
- edsl/questions/templates/matrix/__init__.py +0 -1
- edsl/questions/templates/matrix/answering_instructions.jinja +0 -5
- edsl/questions/templates/matrix/question_presentation.jinja +0 -20
- edsl/results/MarkdownToDocx.py +0 -122
- edsl/results/MarkdownToPDF.py +0 -111
- edsl/results/TextEditor.py +0 -50
- edsl/results/file_exports.py +0 -252
- edsl/results/smart_objects.py +0 -96
- edsl/results/table_data_class.py +0 -12
- edsl/results/table_renderers.py +0 -118
- edsl/scenarios/ConstructDownloadLink.py +0 -109
- edsl/scenarios/DocumentChunker.py +0 -102
- edsl/scenarios/DocxScenario.py +0 -16
- edsl/scenarios/PdfExtractor.py +0 -40
- edsl/scenarios/directory_scanner.py +0 -96
- edsl/scenarios/file_methods.py +0 -85
- edsl/scenarios/handlers/__init__.py +0 -13
- edsl/scenarios/handlers/csv.py +0 -49
- edsl/scenarios/handlers/docx.py +0 -76
- edsl/scenarios/handlers/html.py +0 -37
- edsl/scenarios/handlers/json.py +0 -111
- edsl/scenarios/handlers/latex.py +0 -5
- edsl/scenarios/handlers/md.py +0 -51
- edsl/scenarios/handlers/pdf.py +0 -68
- edsl/scenarios/handlers/png.py +0 -39
- edsl/scenarios/handlers/pptx.py +0 -105
- edsl/scenarios/handlers/py.py +0 -294
- edsl/scenarios/handlers/sql.py +0 -313
- edsl/scenarios/handlers/sqlite.py +0 -149
- edsl/scenarios/handlers/txt.py +0 -33
- edsl/scenarios/scenario_selector.py +0 -156
- edsl/surveys/ConstructDAG.py +0 -92
- edsl/surveys/EditSurvey.py +0 -221
- edsl/surveys/InstructionHandler.py +0 -100
- edsl/surveys/MemoryManagement.py +0 -72
- edsl/surveys/RuleManager.py +0 -172
- edsl/surveys/Simulator.py +0 -75
- edsl/surveys/SurveyToApp.py +0 -141
- edsl/utilities/PrettyList.py +0 -56
- edsl/utilities/is_notebook.py +0 -18
- edsl/utilities/is_valid_variable_name.py +0 -11
- edsl/utilities/remove_edsl_version.py +0 -24
- edsl-0.1.39.dist-info/RECORD +0 -358
- /edsl/questions/{register_questions_meta.py → RegisterQuestionsMeta.py} +0 -0
- /edsl/results/{results_fetch_mixin.py → ResultsFetchMixin.py} +0 -0
- /edsl/results/{results_tools_mixin.py → ResultsToolsMixin.py} +0 -0
- {edsl-0.1.39.dist-info → edsl-0.1.39.dev1.dist-info}/LICENSE +0 -0
@@ -27,6 +27,13 @@ def decorate_methods_from_mixin(cls, mixin_cls):
|
|
27
27
|
return cls
|
28
28
|
|
29
29
|
|
30
|
+
# def decorate_all_methods(cls):
|
31
|
+
# for attr_name, attr_value in cls.__dict__.items():
|
32
|
+
# if callable(attr_value):
|
33
|
+
# setattr(cls, attr_name, to_dataset(attr_value))
|
34
|
+
# return cls
|
35
|
+
|
36
|
+
|
30
37
|
# @decorate_all_methods
|
31
38
|
class ScenarioListExportMixin(DatasetExportMixin):
|
32
39
|
"""Mixin class for exporting Results objects."""
|
@@ -1,9 +1,22 @@
|
|
1
|
+
import fitz # PyMuPDF
|
1
2
|
import os
|
2
|
-
import re
|
3
3
|
import copy
|
4
|
-
import atexit
|
5
|
-
import tempfile
|
6
4
|
import subprocess
|
5
|
+
import requests
|
6
|
+
import tempfile
|
7
|
+
import os
|
8
|
+
|
9
|
+
# import urllib.parse as urlparse
|
10
|
+
from urllib.parse import urlparse
|
11
|
+
|
12
|
+
# from edsl import Scenario
|
13
|
+
|
14
|
+
import requests
|
15
|
+
import re
|
16
|
+
import tempfile
|
17
|
+
import os
|
18
|
+
import atexit
|
19
|
+
from urllib.parse import urlparse, parse_qs
|
7
20
|
|
8
21
|
|
9
22
|
class GoogleDriveDownloader:
|
@@ -12,8 +25,6 @@ class GoogleDriveDownloader:
|
|
12
25
|
|
13
26
|
@classmethod
|
14
27
|
def fetch_from_drive(cls, url, filename=None):
|
15
|
-
import requests
|
16
|
-
|
17
28
|
# Extract file ID from the URL
|
18
29
|
file_id = cls._extract_file_id(url)
|
19
30
|
if not file_id:
|
@@ -56,8 +67,6 @@ class GoogleDriveDownloader:
|
|
56
67
|
|
57
68
|
@staticmethod
|
58
69
|
def _extract_file_id(url):
|
59
|
-
from urllib.parse import urlparse, parse_qs
|
60
|
-
|
61
70
|
# Try to extract file ID from '/file/d/' format
|
62
71
|
file_id_match = re.search(r"/d/([a-zA-Z0-9-_]+)", url)
|
63
72
|
if file_id_match:
|
@@ -83,8 +92,6 @@ class GoogleDriveDownloader:
|
|
83
92
|
|
84
93
|
def fetch_and_save_pdf(url, filename):
|
85
94
|
# Send a GET request to the URL
|
86
|
-
import requests
|
87
|
-
|
88
95
|
response = requests.get(url)
|
89
96
|
|
90
97
|
# Check if the request was successful
|
@@ -107,6 +114,11 @@ def fetch_and_save_pdf(url, filename):
|
|
107
114
|
return temp_file_path
|
108
115
|
|
109
116
|
|
117
|
+
# Example usage:
|
118
|
+
# url = "https://example.com/sample.pdf"
|
119
|
+
# fetch_and_save_pdf(url, "sample.pdf")
|
120
|
+
|
121
|
+
|
110
122
|
class ScenarioListPdfMixin:
|
111
123
|
@classmethod
|
112
124
|
def from_pdf(cls, filename_or_url, collapse_pages=False):
|
@@ -139,8 +151,6 @@ class ScenarioListPdfMixin:
|
|
139
151
|
|
140
152
|
@staticmethod
|
141
153
|
def is_url(string):
|
142
|
-
from urllib.parse import urlparse
|
143
|
-
|
144
154
|
try:
|
145
155
|
result = urlparse(string)
|
146
156
|
return all([result.scheme, result.netloc])
|
@@ -179,8 +189,7 @@ class ScenarioListPdfMixin:
|
|
179
189
|
|
180
190
|
@staticmethod
|
181
191
|
def extract_text_from_pdf(pdf_path):
|
182
|
-
from edsl
|
183
|
-
import fitz # PyMuPDF
|
192
|
+
from edsl import Scenario
|
184
193
|
|
185
194
|
# TODO: Add test case
|
186
195
|
# Ensure the file exists
|
@@ -234,6 +243,19 @@ class ScenarioListPdfMixin:
|
|
234
243
|
|
235
244
|
|
236
245
|
if __name__ == "__main__":
|
237
|
-
|
246
|
+
pass
|
247
|
+
|
248
|
+
# from edsl import ScenarioList
|
249
|
+
|
250
|
+
# class ScenarioListNew(ScenarioList, ScenaroListPdfMixin):
|
251
|
+
# pass
|
252
|
+
|
253
|
+
# #ScenarioListNew.create_hello_world_pdf('hello_world')
|
254
|
+
# #scenarios = ScenarioListNew.from_pdf('hello_world.pdf')
|
255
|
+
# #print(scenarios)
|
238
256
|
|
239
|
-
|
257
|
+
# from edsl import ScenarioList, QuestionFreeText
|
258
|
+
# homo_silicus = ScenarioList.from_pdf('w31122.pdf')
|
259
|
+
# q = QuestionFreeText(question_text = "What is the key point of the text in {{ text }}?", question_name = "key_point")
|
260
|
+
# results = q.by(homo_silicus).run(progress_bar = True)
|
261
|
+
# results.select('scenario.page', 'answer.key_point').order_by('page').print()
|
edsl/scenarios/__init__.py
CHANGED
edsl/study/ObjectEntry.py
CHANGED
edsl/study/SnapShot.py
CHANGED
@@ -32,7 +32,7 @@ class SnapShot:
|
|
32
32
|
{'Cache': <class 'edsl.data.Cache.Cache'>}
|
33
33
|
"""
|
34
34
|
from edsl.Base import RegisterSubclassesMeta
|
35
|
-
from edsl
|
35
|
+
from edsl import QuestionBase
|
36
36
|
|
37
37
|
all_edsl_objects = RegisterSubclassesMeta.get_registry()
|
38
38
|
|
edsl/study/Study.py
CHANGED
@@ -7,9 +7,7 @@ import socket
|
|
7
7
|
from datetime import datetime
|
8
8
|
from typing import Dict, Optional, Union
|
9
9
|
from uuid import UUID, uuid4
|
10
|
-
|
11
|
-
from edsl.data.Cache import Cache
|
12
|
-
from edsl import set_session_cache, unset_session_cache
|
10
|
+
from edsl import Cache, set_session_cache, unset_session_cache
|
13
11
|
from edsl.utilities.utilities import dict_hash
|
14
12
|
from edsl.study.ObjectEntry import ObjectEntry
|
15
13
|
from edsl.study.ProofOfWork import ProofOfWork
|
@@ -407,7 +405,7 @@ class Study:
|
|
407
405
|
|
408
406
|
study_file = tempfile.NamedTemporaryFile()
|
409
407
|
with cls(filename=study_file.name, verbose=verbose) as study:
|
410
|
-
from edsl
|
408
|
+
from edsl import QuestionFreeText
|
411
409
|
|
412
410
|
q = QuestionFreeText.example(randomize=randomize)
|
413
411
|
return study
|
@@ -466,7 +464,7 @@ class Study:
|
|
466
464
|
def push(self) -> dict:
|
467
465
|
"""Push the objects to coop."""
|
468
466
|
|
469
|
-
from edsl
|
467
|
+
from edsl import Coop
|
470
468
|
|
471
469
|
coop = Coop()
|
472
470
|
return coop.create(self, description=self.description)
|
@@ -519,3 +517,12 @@ if __name__ == "__main__":
|
|
519
517
|
import doctest
|
520
518
|
|
521
519
|
doctest.testmod(optionflags=doctest.ELLIPSIS)
|
520
|
+
|
521
|
+
# with Study(name = "cool_study") as study:
|
522
|
+
# from edsl import QuestionFreeText
|
523
|
+
# q = QuestionFreeText.example()
|
524
|
+
|
525
|
+
# assert len(study.objects) == 1
|
526
|
+
|
527
|
+
# print(study.versions())
|
528
|
+
# {'q': [ObjectEntry(variable_name='q', object=Question('free_text', question_name = """how_are_you""", question_text = """How are you?"""), description='Question name: how_are_you', coop_info=None, created_at=1720276402.561273, edsl_class_name='QuestionFreeText')]}
|
edsl/surveys/Rule.py
CHANGED
@@ -21,13 +21,13 @@ import ast
|
|
21
21
|
import random
|
22
22
|
from typing import Any, Union, List
|
23
23
|
|
24
|
-
|
25
|
-
|
24
|
+
from jinja2 import Template
|
25
|
+
from rich import print
|
26
26
|
from simpleeval import EvalWithCompoundTypes
|
27
27
|
|
28
28
|
from edsl.exceptions.surveys import SurveyError
|
29
29
|
|
30
|
-
from edsl.exceptions
|
30
|
+
from edsl.exceptions import (
|
31
31
|
SurveyRuleCannotEvaluateError,
|
32
32
|
SurveyRuleCollectionHasNoRulesAtNodeError,
|
33
33
|
SurveyRuleRefersToFutureStateError,
|
@@ -37,7 +37,7 @@ from edsl.exceptions.surveys import (
|
|
37
37
|
)
|
38
38
|
from edsl.surveys.base import EndOfSurvey
|
39
39
|
from edsl.utilities.ast_utilities import extract_variable_names
|
40
|
-
from edsl.utilities.
|
40
|
+
from edsl.utilities.decorators import add_edsl_version, remove_edsl_version
|
41
41
|
|
42
42
|
|
43
43
|
class QuestionIndex:
|
@@ -253,7 +253,6 @@ class Rule:
|
|
253
253
|
...
|
254
254
|
edsl.exceptions.surveys.SurveyRuleCannotEvaluateError...
|
255
255
|
"""
|
256
|
-
from jinja2 import Template
|
257
256
|
|
258
257
|
def substitute_in_answers(expression, current_info_env):
|
259
258
|
"""Take the dictionary of answers and substitute them into the expression."""
|
edsl/surveys/RuleCollection.py
CHANGED
@@ -1,17 +1,20 @@
|
|
1
1
|
"""A collection of rules for a survey."""
|
2
2
|
|
3
3
|
from typing import List, Union, Any, Optional
|
4
|
-
from collections import defaultdict, UserList
|
4
|
+
from collections import defaultdict, UserList
|
5
5
|
|
6
|
-
from edsl.exceptions
|
6
|
+
from edsl.exceptions import (
|
7
7
|
SurveyRuleCannotEvaluateError,
|
8
8
|
SurveyRuleCollectionHasNoRulesAtNodeError,
|
9
9
|
)
|
10
|
-
|
10
|
+
from edsl.utilities.interface import print_table_with_rich
|
11
11
|
from edsl.surveys.Rule import Rule
|
12
12
|
from edsl.surveys.base import EndOfSurvey
|
13
13
|
from edsl.surveys.DAG import DAG
|
14
14
|
|
15
|
+
# from graphlib import TopologicalSorter
|
16
|
+
|
17
|
+
from collections import namedtuple
|
15
18
|
|
16
19
|
NextQuestion = namedtuple(
|
17
20
|
"NextQuestion", "next_q, num_rules_found, expressions_evaluating_to_true, priority"
|
@@ -43,24 +46,6 @@ class RuleCollection(UserList):
|
|
43
46
|
"""
|
44
47
|
return f"RuleCollection(rules={self.data}, num_questions={self.num_questions})"
|
45
48
|
|
46
|
-
def to_dataset(self):
|
47
|
-
"""Return a Dataset object representation of the RuleCollection object."""
|
48
|
-
from edsl.results.Dataset import Dataset
|
49
|
-
|
50
|
-
keys = ["current_q", "expression", "next_q", "priority", "before_rule"]
|
51
|
-
rule_list = {}
|
52
|
-
for rule in sorted(self, key=lambda r: r.current_q):
|
53
|
-
for k in keys:
|
54
|
-
rule_list.setdefault(k, []).append(getattr(rule, k))
|
55
|
-
|
56
|
-
return Dataset([{k: v} for k, v in rule_list.items()])
|
57
|
-
|
58
|
-
def _repr_html_(self):
|
59
|
-
"""Return an HTML representation of the RuleCollection object."""
|
60
|
-
from edsl.results.Dataset import Dataset
|
61
|
-
|
62
|
-
return self.to_dataset()._repr_html_()
|
63
|
-
|
64
49
|
def to_dict(self, add_edsl_version=True):
|
65
50
|
"""Create a dictionary representation of the RuleCollection object."""
|
66
51
|
return {
|
@@ -121,7 +106,12 @@ class RuleCollection(UserList):
|
|
121
106
|
│ 1 │ q1 == 'no' │ 2 │ 1 │ False │
|
122
107
|
└───────────┴─────────────┴────────┴──────────┴─────────────┘
|
123
108
|
"""
|
124
|
-
|
109
|
+
keys = ["current_q", "expression", "next_q", "priority", "before_rule"]
|
110
|
+
rule_list = []
|
111
|
+
for rule in sorted(self, key=lambda r: r.current_q):
|
112
|
+
rule_list.append({k: getattr(rule, k) for k in keys})
|
113
|
+
|
114
|
+
print_table_with_rich(rule_list)
|
125
115
|
|
126
116
|
def skip_question_before_running(self, q_now: int, answers: dict[str, Any]) -> bool:
|
127
117
|
"""Determine if a question should be skipped before running the question.
|
@@ -193,6 +183,17 @@ class RuleCollection(UserList):
|
|
193
183
|
NextQuestion(next_q=3, num_rules_found=2, expressions_evaluating_to_true=1, priority=1)
|
194
184
|
|
195
185
|
"""
|
186
|
+
# # is this the first question? If it is, we need to check if it should be skipped.
|
187
|
+
# if q_now == 0:
|
188
|
+
# if self.skip_question_before_running(q_now, answers):
|
189
|
+
# return NextQuestion(
|
190
|
+
# next_q=q_now + 1,
|
191
|
+
# num_rules_found=0,
|
192
|
+
# expressions_evaluating_to_true=0,
|
193
|
+
# priority=-1,
|
194
|
+
# )
|
195
|
+
|
196
|
+
# breakpoint()
|
196
197
|
expressions_evaluating_to_true = 0
|
197
198
|
next_q = None
|
198
199
|
highest_priority = -2 # start with -2 to 'pick up' the default rule added
|
@@ -214,6 +215,7 @@ class RuleCollection(UserList):
|
|
214
215
|
f"No rules found for question {q_now}"
|
215
216
|
)
|
216
217
|
|
218
|
+
# breakpoint()
|
217
219
|
## Now we need to check if the *next question* has any 'before; rules that we should follow
|
218
220
|
for rule in self.applicable_rules(next_q, before_rule=True):
|
219
221
|
if rule.evaluate(answers): # rule evaluates to True
|
@@ -258,7 +260,8 @@ class RuleCollection(UserList):
|
|
258
260
|
[2, 3]
|
259
261
|
|
260
262
|
"""
|
261
|
-
# If it's the end of the survey, all questions between the start_q and the end of the survey
|
263
|
+
# If it's the end of the survey, all questions between the start_q and the end of the survey
|
264
|
+
# now depend on the start_q
|
262
265
|
if end_q == EndOfSurvey:
|
263
266
|
if self.num_questions is None:
|
264
267
|
raise ValueError(
|
@@ -378,8 +381,7 @@ class RuleCollection(UserList):
|
|
378
381
|
|
379
382
|
|
380
383
|
if __name__ == "__main__":
|
384
|
+
# pass
|
381
385
|
import doctest
|
382
386
|
|
383
387
|
doctest.testmod(optionflags=doctest.ELLIPSIS)
|
384
|
-
|
385
|
-
print(RuleCollection.example()._repr_html_())
|