revisit 0.0.11__py2.py3-none-any.whl → 0.0.13__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
@@ -10,7 +10,8 @@ import re
10
10
  import os
11
11
  import shutil
12
12
  from . import widget as _widget
13
-
13
+ import ast
14
+ import time
14
15
 
15
16
  __all__ = [
16
17
  "component",
@@ -59,7 +60,7 @@ class _WrappedResponse(_JSONableBaseModel):
59
60
  return self
60
61
 
61
62
  def clone(self):
62
- return response(**self.root.__dict__)
63
+ return __response__(**self.root.__dict__)
63
64
 
64
65
 
65
66
  # Private
@@ -67,6 +68,7 @@ class _WrappedComponent(_JSONableBaseModel):
67
68
  component_name__: str
68
69
  base__: Optional[_WrappedComponent] = None
69
70
  context__: Optional[dict] = None
71
+ metadata__: Optional[dict] = None
70
72
  root: rvt_models.IndividualComponent
71
73
 
72
74
  def model_post_init(self, __context: Any) -> None:
@@ -77,7 +79,7 @@ class _WrappedComponent(_JSONableBaseModel):
77
79
  def responses(self, responses: List[_WrappedResponse]) -> _WrappedComponent:
78
80
  for item in responses:
79
81
  if not isinstance(item, _WrappedResponse):
80
- raise ValueError(f'Expecting type Response got {type(item)}')
82
+ raise RevisitError(message=f'Expecting type Response but got {type(item)}')
81
83
  self.root.response = responses
82
84
  return self
83
85
 
@@ -93,7 +95,7 @@ class _WrappedComponent(_JSONableBaseModel):
93
95
  # Get dict
94
96
  response_dict = r.root.__dict__
95
97
  # Create new response
96
- new_response = response(**response_dict)
98
+ new_response = __response__(**response_dict)
97
99
  # Set with new values
98
100
  new_response.set(**kwargs)
99
101
  # Filter out old response
@@ -119,7 +121,7 @@ class _WrappedComponent(_JSONableBaseModel):
119
121
  return self
120
122
 
121
123
  def clone(self, component_name__):
122
- return component(**self.root.__dict__, component_name__=component_name__)
124
+ return __component__(**self.root.__dict__, component_name__=component_name__)
123
125
 
124
126
 
125
127
  class _WrappedStudyMetadata(_JSONableBaseModel):
@@ -156,6 +158,37 @@ class _WrappedComponentBlock(_JSONableBaseModel):
156
158
  )
157
159
  return DataIterator(data_list, self)
158
160
 
161
+ def get_component(self, name: str) -> _WrappedComponent:
162
+ for entry in self.component_objects__:
163
+ if entry.component_name__ == name:
164
+ return entry
165
+
166
+ def permute(
167
+ self,
168
+ factors: List[str],
169
+ order: rvt_models.Order,
170
+ numSamples: Optional[int] = None,
171
+ component_function=None
172
+ ) -> None:
173
+ # Convert to JSON
174
+ self_json = json.loads(self.__str__())
175
+ # Get all current component dictionaries
176
+ components_dict = {c.component_name__: c for c in self.component_objects__}
177
+ # Recursively start permutation function
178
+ new_permuted_component_block = _recursive_json_permutation(
179
+ self_json,
180
+ factors=factors,
181
+ order=order,
182
+ numSamples=numSamples,
183
+ input_components=components_dict,
184
+ component_function=component_function
185
+ )
186
+ # Set new objects
187
+ self.component_objects__ = new_permuted_component_block.component_objects__
188
+ # Set new root
189
+ self.root = new_permuted_component_block.root
190
+ return self
191
+
159
192
 
160
193
  class _WrappedStudyConfig(_JSONableBaseModel):
161
194
  root: rvt_models.StudyConfig
@@ -198,7 +231,7 @@ class DataIterator:
198
231
  current_dict[key] = value
199
232
  else:
200
233
  current_dict[key] = value
201
- curr_component = component(**current_dict)
234
+ curr_component = __component__(**current_dict)
202
235
  self.parent_class = self.parent_class + curr_component
203
236
  # Return the parent class calling iterator when component is finished.
204
237
  return self.parent_class
@@ -276,6 +309,10 @@ def component(**kwargs) -> _WrappedComponent:
276
309
  raise RevisitError(e.errors())
277
310
 
278
311
 
312
+ # Shadowing
313
+ __component__ = component
314
+
315
+
279
316
  # Response factory function
280
317
  @overload
281
318
  def response(**kwargs: Unpack[rvt_models.NumericalResponseType]) -> _WrappedResponse: ...
@@ -312,6 +349,10 @@ def response(**kwargs) -> _WrappedResponse:
312
349
  raise RevisitError(e.errors())
313
350
 
314
351
 
352
+ # Shadowing
353
+ __response__ = response
354
+
355
+
315
356
  def studyMetadata(**kwargs: Unpack[rvt_models.StudyMetadataType]):
316
357
  filter_kwargs = _get_filtered_kwargs(rvt_models.StudyMetadata, kwargs)
317
358
  base_model = rvt_models.StudyMetadata(**filter_kwargs)
@@ -350,6 +391,10 @@ def sequence(**kwargs: Unpack[rvt_models.ComponentBlockType]):
350
391
  return _WrappedComponentBlock(**kwargs, root=base_model, component_objects__=valid_components)
351
392
 
352
393
 
394
+ # Shadowing
395
+ __sequence__ = sequence
396
+
397
+
353
398
  @overload
354
399
  def studyConfig(**kwargs: Unpack[_StudyConfigType]) -> _WrappedStudyConfig: ...
355
400
  @overload
@@ -646,3 +691,60 @@ def _copy_file(src: str, dest: str):
646
691
 
647
692
  print(f'Copying file from {src} to {dest}')
648
693
  shutil.copyfile(src, dest)
694
+
695
+
696
+ def _recursive_json_permutation(
697
+ input_json: dict,
698
+ factors: List[str],
699
+ order: rvt_models.Order,
700
+ numSamples: int,
701
+ input_components: dict,
702
+ component_function=None
703
+ ):
704
+ new_seq = __sequence__(order=order, numSamples=numSamples)
705
+ while input_json['components']:
706
+ c = input_json['components'].pop()
707
+ # If component name
708
+ if isinstance(c, str):
709
+ # Get orig component
710
+ curr_comp = input_components[c]
711
+ # Create new comp block for permuting this component across all factors
712
+ curr_seq = __sequence__(order=order, numSamples=numSamples)
713
+ # Generate new comp for each
714
+ for entry in factors:
715
+ # Assign params
716
+ metadata = entry
717
+ if curr_comp.metadata__ is not None:
718
+ metadata = {**curr_comp.metadata__, **entry}
719
+ # Create new component
720
+ comp_name = ":".join(f"{key}:{value}" for key, value in entry.items())
721
+ if component_function:
722
+ new_comp = component_function(**metadata)
723
+ else:
724
+ new_comp = __component__(
725
+ base__=curr_comp,
726
+ component_name__=f"{c}__{comp_name}",
727
+ metadata__=metadata
728
+ )
729
+ # Add to curr seq block
730
+ curr_seq = curr_seq + new_comp
731
+ # Add seq block to outer seq block
732
+ else:
733
+ new_input_json = c
734
+ temp_num_samples = None
735
+ if new_input_json.get('numSamples') is not None:
736
+ temp_num_samples = new_input_json['numSamples']
737
+
738
+ curr_seq = _recursive_json_permutation(
739
+ input_json=new_input_json,
740
+ order=order,
741
+ numSamples=numSamples,
742
+ input_components=input_components,
743
+ factors=factors,
744
+ component_function=component_function
745
+ )
746
+ curr_seq.root.order = new_input_json['order']
747
+ curr_seq.root.numSamples = temp_num_samples
748
+ new_seq = new_seq + curr_seq
749
+ return new_seq
750
+
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,ewogICJ2ZXJzaW9uIjogMywKICAic291cmNlcyI6IFsiLi4vLi4vLi4vanMvd2lkZ2V0LmNzcyJdLAogICJzb3VyY2VzQ29udGVudCI6IFsiLnJldmlzaXRfbm90ZWJvb2tfd2lkZ2V0IGJ1dHRvbiB7XG5cdGJhY2tncm91bmQ6ICNmMGYwZjA7XG5cdGJvcmRlci1yYWRpdXM6IDVweDtcblx0Ym9yZGVyOiAxcHggc29saWQgI2NjYztcblx0Y3Vyc29yOiBwb2ludGVyO1xuXHRmb250LWZhbWlseTogXCJSb2JvdG9cIiwgc2Fucy1zZXJpZjtcblx0Zm9udC1zaXplOiAxZW07XG5cdG1hcmdpbjogNXB4O1xuXHRwYWRkaW5nOiA1cHggMTBweDtcblx0dHJhbnNpdGlvbjogYm94LXNoYWRvdyAwLjI1cyBlYXNlLWluLW91dDtcblxuXHQmOmhvdmVyIHtcblx0XHRiYWNrZ3JvdW5kOiAjZTBlMGUwO1xuXHR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