revisit 0.0.26__tar.gz → 0.0.28__tar.gz

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.
@@ -1,9 +1,10 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: revisit
3
- Version: 0.0.26
3
+ Version: 0.0.28
4
4
  Requires-Dist: anywidget
5
5
  Requires-Dist: pandas
6
6
  Requires-Dist: pydantic>=2.10.5
7
+ Requires-Dist: revisit-server>=0.0.1
7
8
  Provides-Extra: dev
8
9
  Requires-Dist: jupyterlab; extra == 'dev'
9
10
  Requires-Dist: watchfiles; extra == 'dev'
@@ -11,7 +12,7 @@ Description-Content-Type: text/markdown
11
12
 
12
13
  # revisit
13
14
 
14
- ## Installation
15
+ # Installation
15
16
 
16
17
  ```sh
17
18
  pip install revisit
@@ -23,34 +24,34 @@ or with [uv](https://github.com/astral-sh/uv):
23
24
  uv add revisit
24
25
  ```
25
26
 
26
- ## Usage
27
+ # Usage
27
28
 
28
29
  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
30
 
30
31
  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
32
 
32
- ### Functions
33
+ 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
34
 
34
- #### `component(component_name__: str, base__: Optional[component], **kwargs: dict) -> Component`
35
+ # Functions
35
36
 
36
- **Description**:
37
+ ## `component(component_name__: str, base__: Optional[component], **kwargs: dict) -> Component`
37
38
 
38
39
  Instantiates a Component class with the given input parameters.
39
40
 
40
- #### **Parameters**:
41
+ ### **Parameters**:
41
42
  | Parameter | Type | Description | Default Value |
42
43
  |-----------|--------|---------------------------------|---------------|
43
44
  | `component_name__` | `str` | Names the component for use in the final configuration file. | _None_ |
44
45
  | `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
46
  | `**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
47
 
47
- #### **Returns**:
48
+ ### **Returns**:
48
49
  - `Component`: Returns an instantiation of the Component class.
49
50
 
50
- #### **Raises**:
51
+ ### **Raises**:
51
52
  - `RevisitError`: If the required properties are not specified, and exception will be raised.
52
53
 
53
- #### **Example**:
54
+ ### **Example**:
54
55
  ```python
55
56
  import revisit as rvt
56
57
 
@@ -71,24 +72,23 @@ my_other_component = rvt.component(
71
72
  ```
72
73
 
73
74
 
74
- #### `response(**kwargs: dict) -> Response`
75
+ ## `response(**kwargs: dict) -> Response`
75
76
 
76
- **Description**:
77
77
 
78
78
  Instantiates a Response class with the given input parameters.
79
79
 
80
- #### **Parameters**:
80
+ ### **Parameters**:
81
81
  | Parameter | Type | Description | Default Value |
82
82
  |-----------|--------|---------------------------------|---------------|
83
83
  | `**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
84
 
85
- #### **Returns**:
85
+ ### **Returns**:
86
86
  - `Response`: Returns an instantiation of the Response class.
87
87
 
88
- #### **Raises**:
88
+ ### **Raises**:
89
89
  - `RevisitError`: If the required properties are not specified, and exception will be raised.
90
90
 
91
- #### **Example**:
91
+ ### **Example**:
92
92
  ```python
93
93
  import revisit as rvt
94
94
 
@@ -102,22 +102,51 @@ my_response = rvt.response(
102
102
  )
103
103
  ```
104
104
 
105
- ### Classes
105
+ ## `studyMetadata(**kwargs: dict) -> StudyMetadata`
106
106
 
107
- #### `Component`
107
+ ## `uiConfig(**kwargs: dict) -> UIConfig`
108
108
 
109
- **Description**:
110
- A brief summary of the class's purpose and functionality.
109
+ ### `studyConfig(studyMetadata: StudyMetadata, uiConfig: UIConfig, sequence: ComponentBlock, schema: str, components: Optional[List[Component]]) -> StudyConfig`
110
+
111
+ Instantiates a the final `StudyConfig` based on the `UIConfig`, `StudyMetadata`, `Sequence`, and `Components` input. Note that the components list is completely optional: using the `studyConfig` factory function automatically populates all components based on their presence in the sequence.
112
+
113
+ ### **Parameters**:
114
+ | Parameter | Type | Description | Default Value |
115
+ |-----------|--------|---------------------------------|---------------|
116
+ | `studyMetadata` | `StudyMetadata` | An instance of the `StudyMetadata` class | _None_ |
117
+ | `uiConfig` | `UIConfig` | An instance of the `UIConfig` class | _None_ |
118
+ | `sequence` | `ComponentBlock` | The top level member of your sequence. | _None_ |
119
+ | `components` | `Optional[List[Component]]` | The list of `Component`s to be added to the config. This is automatically populated based on the inputted sequence | `[]` |
120
+ | `schema` | `str` |The valid `$schema` value for the config | _None_ |
121
+
122
+ ### **Returns**:
123
+ - `StudyConfig`: Returns an instantiation of the StudyConfig class.
124
+
125
+ ### **Raises**:
126
+ - `RevisitError`: If the required properties are not specified, and exception will be raised.
111
127
 
112
- #### **Attributes**:
128
+ ### **Example**:
129
+
130
+ ```python
131
+
132
+ ```
133
+
134
+ # Classes
135
+
136
+ ## `Component`
137
+
138
+ The class that is instantiated when calling the `component` factory function. Used to define the components in the study configuration file.
139
+
140
+ ### **Attributes**:
113
141
  | Attribute | Type | Description | Default Value |
114
142
  |-------------|----------|-------------------------------------|---------------|
115
- | `component_name__` | `type` | Description of attribute 1. | `default` |
116
- | `base__` | `type` | Description of attribute 2. | _None_ |
143
+ | `component_name__` | `str` | Name of the component to be used as the key in the study config. | _None_ |
144
+ | `base__` | `Optional[Component]` | The base component which is inherited by this component. | _None_ |
145
+ | `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
146
 
147
+ ### **Methods**:
118
148
 
119
- #### **Methods**:
120
- ##### `responses(responses: List[Response]) -> self`
149
+ #### `responses(responses: List[Response]) -> self`
121
150
 
122
151
  **Description**:
123
152
  Sets responses for the component
@@ -133,7 +162,7 @@ Sets responses for the component
133
162
  **Raises**:
134
163
  - `RevisitError`: If the list is not a valid list of responses, raises and exception.
135
164
 
136
- #### **Example**:
165
+ **Example**:
137
166
  ```python
138
167
  my_response=rvt.response(
139
168
  id='my_response',
@@ -163,7 +192,7 @@ Returns the response of the component with the given ID. If the Response does no
163
192
  **Returns**:
164
193
  - `Response`: The response with the given ID.
165
194
 
166
- #### **Examples**:
195
+ **Example**:
167
196
  ```python
168
197
  the_response = my_component.get_response(id='the_response')
169
198
 
@@ -184,7 +213,7 @@ Edits the Response in the Component with the given ID. This is done by creating
184
213
  **Returns**:
185
214
  - `self`: Returns self for method chaining.
186
215
 
187
- #### **Examples**:
216
+ **Example**:
188
217
  ```python
189
218
  test_response = rvt.response(
190
219
  id='test_response',
@@ -246,10 +275,11 @@ Clones the component with the given new component name.
246
275
  |-------------|----------|-------------------------------------|---------------|
247
276
  | `component_name__` | `str` | New component name to assign to cloned component. | _None_ |
248
277
 
278
+
249
279
  **Returns**:
250
280
  - `self`: Returns self for method chaining.
251
281
 
252
- #### **Examples**:
282
+ **Example**:
253
283
  ```python
254
284
  test_response = rvt.response(
255
285
  id='test_response',
@@ -297,19 +327,15 @@ print(component_two)
297
327
  '''
298
328
  ```
299
329
 
300
- #### `Response`
330
+ ## `Response`
301
331
 
302
- **Description**:
303
- A brief summary of the class's purpose and functionality.
332
+ This is the `Responsse` class. When calling the `response` factory function, an instantiation of this class is returned.
304
333
 
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_ |
334
+ ### **Attributes**:
335
+ _No attributes_
310
336
 
311
337
 
312
- #### **Methods**:
338
+ ### **Methods**:
313
339
 
314
340
  #### `set(**kwargs: dict) -> self`
315
341
 
@@ -325,10 +351,10 @@ Sets the values of the response to the input dictionary. The `type` cannot be ch
325
351
  **Returns**:
326
352
  - `self`: Returns self for method chaining.
327
353
 
328
- #### **Raises**:
354
+ **Raises**:
329
355
  - `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
356
 
331
- #### **Examples**:
357
+ **Examples**:
332
358
  ```python
333
359
  response_one = rvt.response(
334
360
  id='r-1',
@@ -369,7 +395,7 @@ _No parameters_
369
395
  **Returns**:
370
396
  - `self`: Returns self for method chaining.
371
397
 
372
- #### **Examples**:
398
+ **Examples**:
373
399
  ```python
374
400
  import random
375
401
  question_1 = rvt.response(
@@ -432,6 +458,279 @@ Expected Output:
432
458
  '''
433
459
  ```
434
460
 
461
+
462
+ ## `ComponentBlock`
463
+
464
+ **Description**:
465
+ 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.
466
+
467
+ 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.
468
+
469
+ ### **Attributes**:
470
+ _No attributes_
471
+
472
+
473
+ ### **Methods**:
474
+
475
+ #### `__add__(other: Union[ComponentBlock, Component]) -> self:`
476
+
477
+ **Description**:
478
+
479
+ 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.
480
+
481
+
482
+ **Parameters**:
483
+ | Parameter | Type | Description | Default Value |
484
+ |-------------|----------|-------------------------------------|---------------|
485
+ | `other` | `Union[ComponentBlock, Component]` | Other item adding to left sequence. | _None_ |
486
+
487
+ **Returns**:
488
+ - `self`: Returns self for method chaining.
489
+
490
+ **Raises**:
491
+ - `NotImplemented`: If the right item is not a `Component` or `ComponentBlock`, raises a `NotImplemented` exception.
492
+
493
+ **Examples**:
494
+ ```python
495
+ first_sequence = rvt.sequence(
496
+ order='fixed',
497
+ components=[introduction]
498
+ )
499
+ second_sequence = rvt.sequence(
500
+ order='random',
501
+ components=[comp_one, comp_two]
502
+ )
503
+
504
+ first_sequence = first_sequence + second_sequence
505
+
506
+ print(first_sequence)
507
+ '''
508
+ Expected Output:
509
+ {
510
+ "order": "fixed",
511
+ "components" : [
512
+ "introduction",
513
+ {
514
+ "order": "random"
515
+ "components" : [
516
+ "comp_one",
517
+ "comp_two"
518
+ ]
519
+ }
520
+ ]
521
+ }
522
+ '''
523
+ post_study = rvt.component(
524
+ component_name__='post-study',
525
+ type='markdown',
526
+ path='./post-study.md'
527
+ )
528
+
529
+ first_sequence = first_sequence + post_study
530
+ print(first_sequence)
531
+ '''
532
+ Expected Output:
533
+ {
534
+ "order": "fixed",
535
+ "components" : [
536
+ "introduction",
537
+ {
538
+ "order": "random"
539
+ "components" : [
540
+ "comp_one",
541
+ "comp_two"
542
+ ]
543
+ },
544
+ "post-study"
545
+ ]
546
+ }
547
+ '''
548
+ ```
549
+
550
+ #### `get_component(name: str) -> Component:`
551
+
552
+ **Description**:
553
+
554
+ Fetches the `Component` with the given component name from the sequence.
555
+
556
+
557
+ **Parameters**:
558
+ | Parameter | Type | Description | Default Value |
559
+ |-------------|----------|-------------------------------------|---------------|
560
+ | `name` | `str` | string matching the `component_name__` attribute of the desired `Component`. | _None_ |
561
+
562
+ **Returns**:
563
+ - `Component`: Returns desired `Component`. If no component with specified name is found, returns `None`.
564
+
565
+
566
+ **Examples**:
567
+ ```python
568
+
569
+ sequence = rvt.sequence(
570
+ order='random',
571
+ components=[comp_one, comp_two]
572
+ )
573
+
574
+ print(sequence.get_component(name='comp_two'))
575
+ '''
576
+ {
577
+ "type": "markdown",
578
+ "path": "my_markdown_file.md",
579
+ "response": []
580
+ }
581
+ '''
582
+ ```
583
+
584
+ #### `permute(factors: List[dict], order: 'fixed' | 'latinSquare' | 'random', numSamples: Optional[int], component_function: Optional[Callable]) -> self`
585
+
586
+ **Description**:
587
+ 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.
588
+
589
+ **Parameters**:
590
+ | Parameter | Type | Description | Default Value |
591
+ |-------------|----------|-------------------------------------|---------------|
592
+ | `factors` | `List[dict]` | A list of single-key dictionaries to permute over. | _None_ |
593
+ | `order` | `'fixed' \| 'latinSquare' \| 'random' ` |The order to assign to the current permuted component block. | _None_ |
594
+ | `numSamples` | `Optional[int]` | The `numSamples` value to assign to the current permuted block. | _None_ |
595
+ | `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_ |
596
+
597
+ **Returns**:
598
+ - `self`: Returns self for method chaining.
599
+
600
+ **Raises**:
601
+ - `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.
602
+
603
+ #### **Examples**:
604
+
605
+ **Simple Permutation**
606
+ ```python
607
+
608
+ comp_one = rvt.component(component_name__='my-base', type='markdown', path='./my-markdown.md')
609
+
610
+ sequence = rvt.component(order='fixed',components=[comp_one])
611
+
612
+ sequence.permute(
613
+ factors=[{'condition':'A'}, {'condition':'B'}],
614
+ order='random'
615
+ )
616
+
617
+ print(sequence)
618
+ '''
619
+ Expected Output:
620
+ {
621
+ "order": "random", <--- Since there was only one component in the original sequence, order gets overwritten.
622
+ "components": [
623
+ "my-base_condition:A",
624
+ "my-base_condition:B" <--- Note that the default behavior appends the factors to the name
625
+ ]
626
+ }
627
+
628
+ The two components generated are inherently identical, except with different metadata__ attributes.
629
+ These metadata__ attributes are not outputed into the final JSON study config or seen when printing out
630
+ the individual components.
631
+ '''
632
+
633
+ sequence.permute(
634
+ factors=[{'type':'1'}, {'type': '2'}]
635
+ order='fixed',
636
+ numSamples=1
637
+ )
638
+
639
+ print(sequence)
640
+ '''
641
+ Expected Output:
642
+ {
643
+ "order": "random",
644
+ "components": [
645
+ {
646
+ "order": "fixed", <--- New order gets added to inner most component blocks.
647
+ "components": [
648
+ "my-base_condition:A_type:1",
649
+ "my-base_condition:A_type:2",
650
+ ],
651
+ "numSamples": 1
652
+ },
653
+ {
654
+ "order": "fixed",
655
+ "components": [
656
+ "my-base_condition:B_type:1",
657
+ "my-base_condition:B_type:2",
658
+ ],
659
+ "numSamples": 1
660
+ },
661
+ ]
662
+
663
+ }
664
+ '''
665
+ ```
666
+
667
+ **Using the `component_function`**
668
+
669
+ ```python
670
+ # Defining component function.
671
+ # Takes in kwargs to prevent conflicts with any existing metadata.
672
+ def my_comp_function(**kwargs):
673
+ condition = kwargs.get('condition')
674
+ type_ = kwargs.get('type')
675
+ # If condition and type_ are both defined, return new component.
676
+ if condition is not None and type_ is not None:
677
+ rvt.component(
678
+ type='website'
679
+ component_name__=f"{condition}__{type_}"
680
+ parameters={
681
+ 'condition': condition,
682
+ 'type': type_
683
+ },
684
+ response=[
685
+ rvt.response(
686
+ id=f"response_{condition}_{type_}",
687
+ type="longText",
688
+ prompt=f"How do you feel about condition {condition} and type {type_}?",
689
+ required=True
690
+ )
691
+ ]
692
+ )
693
+
694
+ # If not both defined, return a blank component with "BAD-COMPONENT" name.
695
+ # Useful for debugging
696
+ return rvt.component(type='questionnaire',component_name__="BAD-COMPONENT")
697
+
698
+ sequence = rvt.sequence(order='fixed').permute(
699
+ factors=[{'condition':'A'}, {'condition':'B'}],
700
+ order='random'
701
+ ).permute(
702
+ factors=[{'type':'1'}, {'type': '2'}]
703
+ order='fixed',
704
+ numSamples=1,
705
+ component_function=my_comp_function
706
+ )
707
+ print(sequence)
708
+ '''
709
+ Expected Output:
710
+ {
711
+ "order": "random",
712
+ "components": [
713
+ {
714
+ "order": "fixed", <--- New order gets added to inner most component blocks.
715
+ "components": [
716
+ "A__1",
717
+ "A__2",
718
+ ],
719
+ "numSamples": 1
720
+ },
721
+ {
722
+ "order": "fixed",
723
+ "components": [
724
+ "B__1",
725
+ "B__2"
726
+ ],
727
+ "numSamples": 1
728
+ },
729
+ ]
730
+
731
+ }
732
+ '''
733
+ ```
435
734
  ## Development
436
735
 
437
736
  We recommend using [uv](https://github.com/astral-sh/uv) for development.