revisit 0.0.25__py2.py3-none-any.whl → 0.0.27__py2.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.
revisit/revisit.py CHANGED
@@ -169,7 +169,7 @@ class _WrappedComponentBlock(_JSONableBaseModel):
169
169
  order: rvt_models.Order,
170
170
  numSamples: Optional[int] = None,
171
171
  component_function=None
172
- ) -> None:
172
+ ) -> _WrappedComponentBlock:
173
173
 
174
174
  # Initialize components list with blank component if empty
175
175
  make_comp_block = True
@@ -510,8 +510,8 @@ def widget(study: _WrappedStudyConfig, revisitPath: str):
510
510
  uiConfig.logoPath = newPath
511
511
 
512
512
  # Copy all files
513
- # for item in extracted_paths:
514
- # _copy_file(item['src'], item['dest'])
513
+ for item in extracted_paths:
514
+ _copy_file(item['src'], item['dest'])
515
515
 
516
516
  w = _widget.Widget()
517
517
  w.config = json.loads(study.__str__())
@@ -732,7 +732,7 @@ def _recursive_json_permutation(
732
732
  if curr_comp.metadata__ is not None:
733
733
  metadata = {**curr_comp.metadata__, **entry}
734
734
  # Create new component
735
- comp_name = ":".join(f"{key}:{value}" for key, value in entry.items())
735
+ comp_name = "_".join(f"{key}:{value}" for key, value in entry.items())
736
736
  if component_function:
737
737
  new_comp = component_function(**metadata)
738
738
  else:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: revisit
3
- Version: 0.0.25
3
+ Version: 0.0.27
4
4
  Requires-Dist: anywidget
5
5
  Requires-Dist: pandas
6
6
  Requires-Dist: pydantic>=2.10.5
@@ -11,7 +11,7 @@ Description-Content-Type: text/markdown
11
11
 
12
12
  # revisit
13
13
 
14
- ## Installation
14
+ # Installation
15
15
 
16
16
  ```sh
17
17
  pip install revisit
@@ -23,34 +23,34 @@ or with [uv](https://github.com/astral-sh/uv):
23
23
  uv add revisit
24
24
  ```
25
25
 
26
- ## Usage
26
+ # Usage
27
27
 
28
28
  The reVISit python package wraps the standard items of the reVISit configuration file with readable, easy-to-use functions. We expose a factory function for each top-level item in the reVISit configuration: `studyMetadata`, `uiConfig`, `components`, `sequence`, and `studyMetadata`. Currently, we do not expose a `baseComponents` function. Instead, base components are still well-defined components and can be passed during the creation of another component. The final configuration will not include base components but will have the expected inherited output.
29
29
 
30
30
  Each factory function takes in the same parameters as the reVISit configuration file. For example, the `studyMetadata` function requires the author, organizations, title, version, and description parameters. Robust error output will help you, the user, understand what is required in each function. For the sake of brevity, we do not list every possible parameter since these are already defined in the current study configuration. Instead, we will show additional required/optional parameters as well as additional methods and other exposed functions.
31
31
 
32
- ### Functions
32
+ The individual classes (`Component`, `Response`, `Sequence`, `StudyMetadata`, `UIConfig`, and `StudyConfig`) should not be created directly. Instead, you should use the corresponding factory functions to insantiate them (`component()`, `response()`, `sequence()`, `studyMetadata()`, `uiConfig()`, and `studyConfig`).
33
33
 
34
- #### `component(component_name__: str, base__: Optional[component], **kwargs: dict) -> Component`
34
+ # Functions
35
35
 
36
- **Description**:
36
+ ## `component(component_name__: str, base__: Optional[component], **kwargs: dict) -> Component`
37
37
 
38
38
  Instantiates a Component class with the given input parameters.
39
39
 
40
- #### **Parameters**:
40
+ ### **Parameters**:
41
41
  | Parameter | Type | Description | Default Value |
42
42
  |-----------|--------|---------------------------------|---------------|
43
43
  | `component_name__` | `str` | Names the component for use in the final configuration file. | _None_ |
44
44
  | `base__` | `Optional[component]` | When a base component is passed, all properties of the base are inherited by the component. Any other specified property during input will override base properties. | _None_ |
45
45
  | `**kwargs` | `dict` | The component function requires any property that the component already requires, such as "type". Refer to the configuration documentation for required properties. | _None_ |
46
46
 
47
- #### **Returns**:
47
+ ### **Returns**:
48
48
  - `Component`: Returns an instantiation of the Component class.
49
49
 
50
- #### **Raises**:
50
+ ### **Raises**:
51
51
  - `RevisitError`: If the required properties are not specified, and exception will be raised.
52
52
 
53
- #### **Example**:
53
+ ### **Example**:
54
54
  ```python
55
55
  import revisit as rvt
56
56
 
@@ -71,24 +71,23 @@ my_other_component = rvt.component(
71
71
  ```
72
72
 
73
73
 
74
- #### `response(**kwargs: dict) -> Response`
74
+ ## `response(**kwargs: dict) -> Response`
75
75
 
76
- **Description**:
77
76
 
78
77
  Instantiates a Response class with the given input parameters.
79
78
 
80
- #### **Parameters**:
79
+ ### **Parameters**:
81
80
  | Parameter | Type | Description | Default Value |
82
81
  |-----------|--------|---------------------------------|---------------|
83
82
  | `**kwargs` | `dict` | The component function requires any property that the component already requires, such as "type". Refer to the configuration documentation for required properties. | _None_ |
84
83
 
85
- #### **Returns**:
84
+ ### **Returns**:
86
85
  - `Response`: Returns an instantiation of the Response class.
87
86
 
88
- #### **Raises**:
87
+ ### **Raises**:
89
88
  - `RevisitError`: If the required properties are not specified, and exception will be raised.
90
89
 
91
- #### **Example**:
90
+ ### **Example**:
92
91
  ```python
93
92
  import revisit as rvt
94
93
 
@@ -102,22 +101,22 @@ my_response = rvt.response(
102
101
  )
103
102
  ```
104
103
 
105
- ### Classes
104
+ # Classes
106
105
 
107
- #### `Component`
106
+ ## `Component`
108
107
 
109
- **Description**:
110
108
  A brief summary of the class's purpose and functionality.
111
109
 
112
- #### **Attributes**:
110
+ ### **Attributes**:
113
111
  | Attribute | Type | Description | Default Value |
114
112
  |-------------|----------|-------------------------------------|---------------|
115
- | `component_name__` | `type` | Description of attribute 1. | `default` |
116
- | `base__` | `type` | Description of attribute 2. | _None_ |
113
+ | `component_name__` | `str` | Name of the component to be used as the key in the study config. | _None_ |
114
+ | `base__` | `Optional[Component]` | The base component which is inherited by this component. | _None_ |
115
+ | `metadata__` | `Optional[dict]` | A dictionary specifying metadata of the object. This is purely used for additional properties which are not written to the config and may be used to attach arbitrary data to the component without affecting the final output. | _None_ |
117
116
 
117
+ ### **Methods**:
118
118
 
119
- #### **Methods**:
120
- ##### `responses(responses: List[Response]) -> self`
119
+ #### `responses(responses: List[Response]) -> self`
121
120
 
122
121
  **Description**:
123
122
  Sets responses for the component
@@ -133,7 +132,7 @@ Sets responses for the component
133
132
  **Raises**:
134
133
  - `RevisitError`: If the list is not a valid list of responses, raises and exception.
135
134
 
136
- #### **Example**:
135
+ **Example**:
137
136
  ```python
138
137
  my_response=rvt.response(
139
138
  id='my_response',
@@ -163,7 +162,7 @@ Returns the response of the component with the given ID. If the Response does no
163
162
  **Returns**:
164
163
  - `Response`: The response with the given ID.
165
164
 
166
- #### **Examples**:
165
+ **Example**:
167
166
  ```python
168
167
  the_response = my_component.get_response(id='the_response')
169
168
 
@@ -184,7 +183,7 @@ Edits the Response in the Component with the given ID. This is done by creating
184
183
  **Returns**:
185
184
  - `self`: Returns self for method chaining.
186
185
 
187
- #### **Examples**:
186
+ **Example**:
188
187
  ```python
189
188
  test_response = rvt.response(
190
189
  id='test_response',
@@ -246,10 +245,11 @@ Clones the component with the given new component name.
246
245
  |-------------|----------|-------------------------------------|---------------|
247
246
  | `component_name__` | `str` | New component name to assign to cloned component. | _None_ |
248
247
 
248
+
249
249
  **Returns**:
250
250
  - `self`: Returns self for method chaining.
251
251
 
252
- #### **Examples**:
252
+ **Example**:
253
253
  ```python
254
254
  test_response = rvt.response(
255
255
  id='test_response',
@@ -297,19 +297,15 @@ print(component_two)
297
297
  '''
298
298
  ```
299
299
 
300
- #### `Response`
300
+ ## `Response`
301
301
 
302
- **Description**:
303
- A brief summary of the class's purpose and functionality.
302
+ This is the `Responsse` class. When calling the `response` factory function, an instantiation of this class is returned.
304
303
 
305
- #### **Attributes**:
306
- | Attribute | Type | Description | Default Value |
307
- |-------------|----------|-------------------------------------|---------------|
308
- | `component_name__` | `type` | Description of attribute 1. | `default` |
309
- | `base__` | `type` | Description of attribute 2. | _None_ |
304
+ ### **Attributes**:
305
+ _No attributes_
310
306
 
311
307
 
312
- #### **Methods**:
308
+ ### **Methods**:
313
309
 
314
310
  #### `set(**kwargs: dict) -> self`
315
311
 
@@ -325,10 +321,10 @@ Sets the values of the response to the input dictionary. The `type` cannot be ch
325
321
  **Returns**:
326
322
  - `self`: Returns self for method chaining.
327
323
 
328
- #### **Raises**:
324
+ **Raises**:
329
325
  - `RevisitError`: If the user attempts to change the `type` attribute of the response, an exception will be raised. Any invalid inputs for the instantiated response type will also raise an exception.
330
326
 
331
- #### **Examples**:
327
+ **Examples**:
332
328
  ```python
333
329
  response_one = rvt.response(
334
330
  id='r-1',
@@ -369,7 +365,7 @@ _No parameters_
369
365
  **Returns**:
370
366
  - `self`: Returns self for method chaining.
371
367
 
372
- #### **Examples**:
368
+ **Examples**:
373
369
  ```python
374
370
  import random
375
371
  question_1 = rvt.response(
@@ -432,6 +428,279 @@ Expected Output:
432
428
  '''
433
429
  ```
434
430
 
431
+
432
+ ## `ComponentBlock`
433
+
434
+ **Description**:
435
+ The `ComponentBlock` class (also referred to as a "Sequence"). A well-defined sequence simply contains an order and a set of components, with other optional properties. Just as in the nested structure of component blocks in the reVISit study configuration, `ComponentBlock` classes can be added together.
436
+
437
+ A `ComponentBlock` automatically tracks all of its existing `Component` classes. When the `ComponentBlock` is added to the study configuration, all components will automatically be added to the high-level components element of the study config.
438
+
439
+ ### **Attributes**:
440
+ _No attributes_
441
+
442
+
443
+ ### **Methods**:
444
+
445
+ #### `__add__(other: Union[ComponentBlock, Component]) -> self:`
446
+
447
+ **Description**:
448
+
449
+ Adds two `ComponentBlock` or `Component` to the input sequence. When adding two sequences together, the right sequence gets added as a `ComponentBlock` to the list of components of the left sequence. When the right object is an instance of the `Component` class, the component is added to the `ComponentBlock`'s list of components.
450
+
451
+
452
+ **Parameters**:
453
+ | Parameter | Type | Description | Default Value |
454
+ |-------------|----------|-------------------------------------|---------------|
455
+ | `other` | `Union[ComponentBlock, Component]` | Other item adding to left sequence. | _None_ |
456
+
457
+ **Returns**:
458
+ - `self`: Returns self for method chaining.
459
+
460
+ **Raises**:
461
+ - `NotImplemented`: If the right item is not a `Component` or `ComponentBlock`, raises a `NotImplemented` exception.
462
+
463
+ **Examples**:
464
+ ```python
465
+ first_sequence = rvt.sequence(
466
+ order='fixed',
467
+ components=[introduction]
468
+ )
469
+ second_sequence = rvt.sequence(
470
+ order='random',
471
+ components=[comp_one, comp_two]
472
+ )
473
+
474
+ first_sequence = first_sequence + second_sequence
475
+
476
+ print(first_sequence)
477
+ '''
478
+ Expected Output:
479
+ {
480
+ "order": "fixed",
481
+ "components" : [
482
+ "introduction",
483
+ {
484
+ "order": "random"
485
+ "components" : [
486
+ "comp_one",
487
+ "comp_two"
488
+ ]
489
+ }
490
+ ]
491
+ }
492
+ '''
493
+ post_study = rvt.component(
494
+ component_name__='post-study',
495
+ type='markdown',
496
+ path='./post-study.md'
497
+ )
498
+
499
+ first_sequence = first_sequence + post_study
500
+ print(first_sequence)
501
+ '''
502
+ Expected Output:
503
+ {
504
+ "order": "fixed",
505
+ "components" : [
506
+ "introduction",
507
+ {
508
+ "order": "random"
509
+ "components" : [
510
+ "comp_one",
511
+ "comp_two"
512
+ ]
513
+ },
514
+ "post-study"
515
+ ]
516
+ }
517
+ '''
518
+ ```
519
+
520
+ #### `get_component(name: str) -> Component:`
521
+
522
+ **Description**:
523
+
524
+ Fetches the `Component` with the given component name from the sequence.
525
+
526
+
527
+ **Parameters**:
528
+ | Parameter | Type | Description | Default Value |
529
+ |-------------|----------|-------------------------------------|---------------|
530
+ | `name` | `str` | string matching the `component_name__` attribute of the desired `Component`. | _None_ |
531
+
532
+ **Returns**:
533
+ - `Component`: Returns desired `Component`. If no component with specified name is found, returns `None`.
534
+
535
+
536
+ **Examples**:
537
+ ```python
538
+
539
+ sequence = rvt.sequence(
540
+ order='random',
541
+ components=[comp_one, comp_two]
542
+ )
543
+
544
+ print(sequence.get_component(name='comp_two'))
545
+ '''
546
+ {
547
+ "type": "markdown",
548
+ "path": "my_markdown_file.md",
549
+ "response": []
550
+ }
551
+ '''
552
+ ```
553
+
554
+ #### `permute(factors: List[dict], order: 'fixed' | 'latinSquare' | 'random', numSamples: Optional[int], component_function: Optional[Callable]) -> self`
555
+
556
+ **Description**:
557
+ Permutes the the existing components of the sequence over the given `factors`. The permute method can be chained to complex study sequences. By default, the factors are attached as `metadata__` attributes to each component created. If a `component_function` is passed in as an argument, all current factors and `metadata__` of the component will be passed into the component function. The component function must return a valid `Component` instance.
558
+
559
+ **Parameters**:
560
+ | Parameter | Type | Description | Default Value |
561
+ |-------------|----------|-------------------------------------|---------------|
562
+ | `factors` | `List[dict]` | A list of single-key dictionaries to permute over. | _None_ |
563
+ | `order` | `'fixed' \| 'latinSquare' \| 'random' ` |The order to assign to the current permuted component block. | _None_ |
564
+ | `numSamples` | `Optional[int]` | The `numSamples` value to assign to the current permuted block. | _None_ |
565
+ | `component_function` | `Optional[Callable]` | A function defining what component should be generated during permutation. If not provided, the permutation function inherits the existing components in the sequence as new components and applies the factors as metadata. If given, the metadata is passed into the component function as arguments. | _None_ |
566
+
567
+ **Returns**:
568
+ - `self`: Returns self for method chaining.
569
+
570
+ **Raises**:
571
+ - `TypeError`: The `component_function` must be able to take in all metadata of the sequence's existing components as well as the current factors. For example, if you start with a component with no metadata and permute over the factors `[{'key_1':'value_1'}, {'key_1': 'value_2'}]`, the component function should be defined to take in the parameter `key_1`. Otherwise, this will most likely result in a `TypeError` being raised. If you are chaining multiple permute methods after one another, please note that the the set of factors that are passed into the permute function are applied as metadata to the resulting components. Thus, your function must be able to take in all factors as arguments. To avoid this, you can simply use `**kwargs` as your parameter input of your component function.
572
+
573
+ #### **Examples**:
574
+
575
+ **Simple Permutation**
576
+ ```python
577
+
578
+ comp_one = rvt.component(component_name__='my-base', type='markdown', path='./my-markdown.md')
579
+
580
+ sequence = rvt.component(order='fixed',components=[comp_one])
581
+
582
+ sequence.permute(
583
+ factors=[{'condition':'A'}, {'condition':'B'}],
584
+ order='random'
585
+ )
586
+
587
+ print(sequence)
588
+ '''
589
+ Expected Output:
590
+ {
591
+ "order": "random", <--- Since there was only one component in the original sequence, order gets overwritten.
592
+ "components": [
593
+ "my-base_condition:A",
594
+ "my-base_condition:B" <--- Note that the default behavior appends the factors to the name
595
+ ]
596
+ }
597
+
598
+ The two components generated are inherently identical, except with different metadata__ attributes.
599
+ These metadata__ attributes are not outputed into the final JSON study config or seen when printing out
600
+ the individual components.
601
+ '''
602
+
603
+ sequence.permute(
604
+ factors=[{'type':'1'}, {'type': '2'}]
605
+ order='fixed',
606
+ numSamples=1
607
+ )
608
+
609
+ print(sequence)
610
+ '''
611
+ Expected Output:
612
+ {
613
+ "order": "random",
614
+ "components": [
615
+ {
616
+ "order": "fixed", <--- New order gets added to inner most component blocks.
617
+ "components": [
618
+ "my-base_condition:A_type:1",
619
+ "my-base_condition:A_type:2",
620
+ ],
621
+ "numSamples": 1
622
+ },
623
+ {
624
+ "order": "fixed",
625
+ "components": [
626
+ "my-base_condition:B_type:1",
627
+ "my-base_condition:B_type:2",
628
+ ],
629
+ "numSamples": 1
630
+ },
631
+ ]
632
+
633
+ }
634
+ '''
635
+ ```
636
+
637
+ **Using the `component_function`**
638
+
639
+ ```python
640
+ # Defining component function.
641
+ # Takes in kwargs to prevent conflicts with any existing metadata.
642
+ def my_comp_function(**kwargs):
643
+ condition = kwargs.get('condition')
644
+ type_ = kwargs.get('type')
645
+ # If condition and type_ are both defined, return new component.
646
+ if condition is not None and type_ is not None:
647
+ rvt.component(
648
+ type='website'
649
+ component_name__=f"{condition}__{type_}"
650
+ parameters={
651
+ 'condition': condition,
652
+ 'type': type_
653
+ },
654
+ response=[
655
+ rvt.response(
656
+ id=f"response_{condition}_{type_}",
657
+ type="longText",
658
+ prompt=f"How do you feel about condition {condition} and type {type_}?",
659
+ required=True
660
+ )
661
+ ]
662
+ )
663
+
664
+ # If not both defined, return a blank component with "BAD-COMPONENT" name.
665
+ # Useful for debugging
666
+ return rvt.component(type='questionnaire',component_name__="BAD-COMPONENT")
667
+
668
+ sequence = rvt.sequence(order='fixed').permute(
669
+ factors=[{'condition':'A'}, {'condition':'B'}],
670
+ order='random'
671
+ ).permute(
672
+ factors=[{'type':'1'}, {'type': '2'}]
673
+ order='fixed',
674
+ numSamples=1,
675
+ component_function=my_comp_function
676
+ )
677
+ print(sequence)
678
+ '''
679
+ Expected Output:
680
+ {
681
+ "order": "random",
682
+ "components": [
683
+ {
684
+ "order": "fixed", <--- New order gets added to inner most component blocks.
685
+ "components": [
686
+ "A__1",
687
+ "A__2",
688
+ ],
689
+ "numSamples": 1
690
+ },
691
+ {
692
+ "order": "fixed",
693
+ "components": [
694
+ "B__1",
695
+ "B__2"
696
+ ],
697
+ "numSamples": 1
698
+ },
699
+ ]
700
+
701
+ }
702
+ '''
703
+ ```
435
704
  ## Development
436
705
 
437
706
  We recommend using [uv](https://github.com/astral-sh/uv) for development.
@@ -1,10 +1,10 @@
1
1
  revisit/StudyConfigSchema.json,sha256=xtzwZifuPJoiHASx0o8PHqBuh5L30mjBlhQ5eqsYm10,132168
2
2
  revisit/__init__.py,sha256=QCvYt8m9QwpjcK4dv6GlLMUDCzRXGy16cua1r2biNCg,255
3
3
  revisit/models.py,sha256=FRy8IlUAtDS3gdmZwwvqR935lbViTPnnr7k0CAkDkzI,134084
4
- revisit/revisit.py,sha256=VaHcbySp18VjpIJ3z-_XfQN93RbS4_ZMQs50Vs7feuA,27776
4
+ revisit/revisit.py,sha256=DMbT_B-vFf55V6kDKz-Th3FE-qKk3GHk4aq2-Buf2j4,27790
5
5
  revisit/widget.py,sha256=VvFqRvvvn86fW8ASe1pxaAvh5ZLvvSRThI5XtlCdgcg,915
6
6
  revisit/static/widget.css,sha256=TLu5F6k0CvowQtmApPswG-JZUXYszo7a10dVWKnZsIg,647
7
7
  revisit/static/widget.js,sha256=jjc-RvauEnU8dHCR7oGSjg0y1CRXtAlw1-4yDeSbdKE,186472
8
- revisit-0.0.25.dist-info/METADATA,sha256=nsZQ-i0vAB_kwBEMV4YbaF6W4F1k0s5XsY0p-KltFf0,13510
9
- revisit-0.0.25.dist-info/WHEEL,sha256=tkmg4JIqwd9H8mL30xA7crRmoStyCtGp0VWshokd1Jc,105
10
- revisit-0.0.25.dist-info/RECORD,,
8
+ revisit-0.0.27.dist-info/METADATA,sha256=0b818mZVHJeCp7P4plpU3J1Hr4KVMsPCoTsvLo4FZfA,22846
9
+ revisit-0.0.27.dist-info/WHEEL,sha256=tkmg4JIqwd9H8mL30xA7crRmoStyCtGp0VWshokd1Jc,105
10
+ revisit-0.0.27.dist-info/RECORD,,