revisit 0.0.11__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/revisit.py CHANGED
@@ -59,7 +59,7 @@ class _WrappedResponse(_JSONableBaseModel):
59
59
  return self
60
60
 
61
61
  def clone(self):
62
- return response(**self.root.__dict__)
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 ValueError(f'Expecting type Response got {type(item)}')
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 = response(**response_dict)
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 component(**self.root.__dict__, component_name__=component_name__)
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 = component(**current_dict)
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
+
revisit/static/widget.css CHANGED
@@ -1,2 +1 @@
1
1
  .revisit_notebook_widget button{background:#f0f0f0;border-radius:5px;border:1px solid #ccc;cursor:pointer;font-family:Roboto,sans-serif;font-size:1em;margin:5px;padding:5px 10px;transition:box-shadow .25s ease-in-out;&:hover{background:#e0e0e0;box-shadow:0 0 5px #ccc}&:active{background:#d0d0d0;box-shadow:0 0 5px #ccc inset}}.revisit_notebook_widget iframe{border:0;margin:0;width:100%}.revisit_notebook_widget{.sequence{width:100%;display:flex}.sequenceComponent{display:flex;padding-left:4px;padding-right:4px;padding-bottom:2px;&:hover{background:#0000001a}}.sequenceComponentIndividual{background:#000;width:5px;height:20px;margin-top:5px}}
2
- /*# sourceMappingURL=data:application/json;base64,ewogICJ2ZXJzaW9uIjogMywKICAic291cmNlcyI6IFsiLi4vLi4vLi4vanMvd2lkZ2V0LmNzcyJdLAogICJzb3VyY2VzQ29udGVudCI6IFsiLnJldmlzaXRfbm90ZWJvb2tfd2lkZ2V0IGJ1dHRvbiB7XG5cdGJhY2tncm91bmQ6ICNmMGYwZjA7XG5cdGJvcmRlci1yYWRpdXM6IDVweDtcblx0Ym9yZGVyOiAxcHggc29saWQgI2NjYztcblx0Y3Vyc29yOiBwb2ludGVyO1xuXHRmb250LWZhbWlseTogXCJSb2JvdG9cIiwgc2Fucy1zZXJpZjtcblx0Zm9udC1zaXplOiAxZW07XG5cdG1hcmdpbjogNXB4O1xuXHRwYWRkaW5nOiA1cHggMTBweDtcblx0dHJhbnNpdGlvbjogYm94LXNoYWRvdyAwLjI1cyBlYXNlLWluLW91dDtcblxuXHQmOmhvdmVyIHtcblx0XHRiYWNrZ3JvdW5kOiAjZTBlMGUwO1xuXHRcdGJveC1zaGFkb3c6IDAgMCA1cHggMCAjY2NjO1xuXHR9XG5cblx0JjphY3RpdmUge1xuXHRcdGJhY2tncm91bmQ6ICNkMGQwZDA7XG5cdFx0Ym94LXNoYWRvdzogMCAwIDVweCAwICNjY2MgaW5zZXQ7XG5cblx0fVxufVxuXG4ucmV2aXNpdF9ub3RlYm9va193aWRnZXQgaWZyYW1lIHtcblx0Ym9yZGVyOiAwO1xuXHRtYXJnaW46IDA7XG5cdHdpZHRoOiAxMDAlO1xufVxuXG4ucmV2aXNpdF9ub3RlYm9va193aWRnZXQge1xuXHQuc2VxdWVuY2Uge1xuXHRcdHdpZHRoOiAxMDAlO1xuXHRcdGRpc3BsYX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