revisit 0.0.10__py2.py3-none-any.whl → 0.0.12__py2.py3-none-any.whl
Sign up to get free protection for your applications and to get access to all the features.
- revisit/StudyConfigSchema.json +2130 -0
- revisit/revisit.py +90 -5
- revisit/static/widget.js +6 -6
- revisit/widget.py +9 -35
- revisit-0.0.12.dist-info/METADATA +291 -0
- revisit-0.0.12.dist-info/RECORD +10 -0
- revisit-0.0.10.dist-info/METADATA +0 -74
- revisit-0.0.10.dist-info/RECORD +0 -9
- {revisit-0.0.10.dist-info → revisit-0.0.12.dist-info}/WHEEL +0 -0
revisit/revisit.py
CHANGED
@@ -59,7 +59,7 @@ class _WrappedResponse(_JSONableBaseModel):
|
|
59
59
|
return self
|
60
60
|
|
61
61
|
def clone(self):
|
62
|
-
return
|
62
|
+
return __response__(**self.root.__dict__)
|
63
63
|
|
64
64
|
|
65
65
|
# Private
|
@@ -77,7 +77,7 @@ class _WrappedComponent(_JSONableBaseModel):
|
|
77
77
|
def responses(self, responses: List[_WrappedResponse]) -> _WrappedComponent:
|
78
78
|
for item in responses:
|
79
79
|
if not isinstance(item, _WrappedResponse):
|
80
|
-
raise
|
80
|
+
raise RevisitError(message=f'Expecting type Response but got {type(item)}')
|
81
81
|
self.root.response = responses
|
82
82
|
return self
|
83
83
|
|
@@ -93,7 +93,7 @@ class _WrappedComponent(_JSONableBaseModel):
|
|
93
93
|
# Get dict
|
94
94
|
response_dict = r.root.__dict__
|
95
95
|
# Create new response
|
96
|
-
new_response =
|
96
|
+
new_response = __response__(**response_dict)
|
97
97
|
# Set with new values
|
98
98
|
new_response.set(**kwargs)
|
99
99
|
# Filter out old response
|
@@ -119,7 +119,7 @@ class _WrappedComponent(_JSONableBaseModel):
|
|
119
119
|
return self
|
120
120
|
|
121
121
|
def clone(self, component_name__):
|
122
|
-
return
|
122
|
+
return __component__(**self.root.__dict__, component_name__=component_name__)
|
123
123
|
|
124
124
|
|
125
125
|
class _WrappedStudyMetadata(_JSONableBaseModel):
|
@@ -156,6 +156,26 @@ class _WrappedComponentBlock(_JSONableBaseModel):
|
|
156
156
|
)
|
157
157
|
return DataIterator(data_list, self)
|
158
158
|
|
159
|
+
def get_component(self, name: str) -> _WrappedComponent:
|
160
|
+
for entry in self.component_objects__:
|
161
|
+
print(f'Comp Name: {entry.component_name__}')
|
162
|
+
print(f'Name: {name}')
|
163
|
+
if entry.component_name__ == name:
|
164
|
+
return entry
|
165
|
+
|
166
|
+
def permute(self, factors: List[str], order: rvt_models.Order, numSamples: Optional[int] = None,) -> None:
|
167
|
+
# Convert to JSON
|
168
|
+
self_json = json.loads(self.__str__())
|
169
|
+
# Get all current component dictionaries
|
170
|
+
components_dict = {c.component_name__: c for c in self.component_objects__}
|
171
|
+
# Recursively start permutation function
|
172
|
+
new_permuted_component_block = _recursive_json_permutation(self_json, factors=factors, order=order, numSamples=numSamples, input_components=components_dict)
|
173
|
+
# Set new objects
|
174
|
+
self.component_objects__ = new_permuted_component_block.component_objects__
|
175
|
+
# Set new root
|
176
|
+
self.root = new_permuted_component_block.root
|
177
|
+
return self
|
178
|
+
|
159
179
|
|
160
180
|
class _WrappedStudyConfig(_JSONableBaseModel):
|
161
181
|
root: rvt_models.StudyConfig
|
@@ -198,7 +218,7 @@ class DataIterator:
|
|
198
218
|
current_dict[key] = value
|
199
219
|
else:
|
200
220
|
current_dict[key] = value
|
201
|
-
curr_component =
|
221
|
+
curr_component = __component__(**current_dict)
|
202
222
|
self.parent_class = self.parent_class + curr_component
|
203
223
|
# Return the parent class calling iterator when component is finished.
|
204
224
|
return self.parent_class
|
@@ -276,6 +296,10 @@ def component(**kwargs) -> _WrappedComponent:
|
|
276
296
|
raise RevisitError(e.errors())
|
277
297
|
|
278
298
|
|
299
|
+
# Shadowing
|
300
|
+
__component__ = component
|
301
|
+
|
302
|
+
|
279
303
|
# Response factory function
|
280
304
|
@overload
|
281
305
|
def response(**kwargs: Unpack[rvt_models.NumericalResponseType]) -> _WrappedResponse: ...
|
@@ -312,6 +336,10 @@ def response(**kwargs) -> _WrappedResponse:
|
|
312
336
|
raise RevisitError(e.errors())
|
313
337
|
|
314
338
|
|
339
|
+
# Shadowing
|
340
|
+
__response__ = response
|
341
|
+
|
342
|
+
|
315
343
|
def studyMetadata(**kwargs: Unpack[rvt_models.StudyMetadataType]):
|
316
344
|
filter_kwargs = _get_filtered_kwargs(rvt_models.StudyMetadata, kwargs)
|
317
345
|
base_model = rvt_models.StudyMetadata(**filter_kwargs)
|
@@ -350,6 +378,10 @@ def sequence(**kwargs: Unpack[rvt_models.ComponentBlockType]):
|
|
350
378
|
return _WrappedComponentBlock(**kwargs, root=base_model, component_objects__=valid_components)
|
351
379
|
|
352
380
|
|
381
|
+
# Shadowing
|
382
|
+
__sequence__ = sequence
|
383
|
+
|
384
|
+
|
353
385
|
@overload
|
354
386
|
def studyConfig(**kwargs: Unpack[_StudyConfigType]) -> _WrappedStudyConfig: ...
|
355
387
|
@overload
|
@@ -646,3 +678,56 @@ def _copy_file(src: str, dest: str):
|
|
646
678
|
|
647
679
|
print(f'Copying file from {src} to {dest}')
|
648
680
|
shutil.copyfile(src, dest)
|
681
|
+
|
682
|
+
|
683
|
+
def _recursive_json_permutation(
|
684
|
+
input_json: dict,
|
685
|
+
factors: List[str],
|
686
|
+
order: rvt_models.Order,
|
687
|
+
numSamples: int,
|
688
|
+
input_components: dict
|
689
|
+
):
|
690
|
+
new_seq = __sequence__(order=order, numSamples=numSamples)
|
691
|
+
while input_json['components']:
|
692
|
+
c = input_json['components'].pop()
|
693
|
+
# If component name
|
694
|
+
if isinstance(c, str):
|
695
|
+
# Get orig component
|
696
|
+
curr_comp = input_components[c]
|
697
|
+
# Create new comp block for permuting this component across all factors
|
698
|
+
curr_seq = __sequence__(order=order, numSamples=numSamples)
|
699
|
+
# Generate new comp for each
|
700
|
+
for entry in factors:
|
701
|
+
# Split factor entry
|
702
|
+
[name, value] = entry.split(":")
|
703
|
+
# Assign params
|
704
|
+
new_params = {name: value}
|
705
|
+
if curr_comp.root.parameters is not None:
|
706
|
+
new_params = {**curr_comp.root.parameters, **new_params}
|
707
|
+
# Create new component
|
708
|
+
curr_comp = __component__(
|
709
|
+
base__=curr_comp,
|
710
|
+
component_name__=f"{c}__{entry}",
|
711
|
+
parameters=new_params
|
712
|
+
)
|
713
|
+
# Add to curr seq block
|
714
|
+
curr_seq = curr_seq + curr_comp
|
715
|
+
# Add seq block to outer seq block
|
716
|
+
else:
|
717
|
+
new_input_json = c
|
718
|
+
temp_num_samples = None
|
719
|
+
if new_input_json.get('numSamples') is not None:
|
720
|
+
temp_num_samples = new_input_json['numSamples']
|
721
|
+
|
722
|
+
curr_seq = _recursive_json_permutation(
|
723
|
+
input_json=new_input_json,
|
724
|
+
order=order,
|
725
|
+
numSamples=numSamples,
|
726
|
+
input_components=input_components,
|
727
|
+
factors=factors
|
728
|
+
)
|
729
|
+
curr_seq.root.order = new_input_json['order']
|
730
|
+
curr_seq.root.numSamples = temp_num_samples
|
731
|
+
new_seq = new_seq + curr_seq
|
732
|
+
return new_seq
|
733
|
+
|