Templates¶
Neon +1.3.0 +2.8.25
You can access the response data entered into the template questionnaire on the phone and also set those responses remotely. If the template is properly configured, this allows you to also define the recording name.
Get Template Definition¶
Using the device.get_template method, you can receive the definition of the template containing all questions and sections.
template = device.get_template()
Template
Template
¶
Template Class for data collection.
Methods:
-
convert_from_api_to_simple_format–Convert data from API format to simple format.
-
convert_from_simple_to_api_format–Convert data from simple format to API format.
-
get_question_by_id–Get a template item by ID.
-
validate_answers–Validate answers for this Template.
Attributes:
-
archived_at(datetime | None) –Archival timestamp (if archived).
-
created_at(datetime) –Creation timestamp.
-
description(str | None) –Template description.
-
id(UUID) –Unique identifier.
-
is_default_template(bool) –Whether this is the default template for the Workspace
-
items(list[TemplateItem]) –List of template items.
-
label_ids(list[UUID]) –Associated label IDs.
-
name(str) –Template name.
-
published_at(datetime | None) –Publication timestamp.
-
recording_ids(list[UUID] | None) –Associated recording IDs.
-
recording_name_format(list[str]) –Format for recording name.
-
updated_at(datetime) –Last update timestamp.
archived_at
class-attribute
instance-attribute
¶
archived_at: datetime | None = None
Archival timestamp (if archived).
description
class-attribute
instance-attribute
¶
description: str | None = None
Template description.
is_default_template
class-attribute
instance-attribute
¶
is_default_template: bool = True
Whether this is the default template for the Workspace
items
class-attribute
instance-attribute
¶
items: list[TemplateItem] = field(default_factory=list)
List of template items.
label_ids
class-attribute
instance-attribute
¶
Associated label IDs.
published_at
class-attribute
instance-attribute
¶
published_at: datetime | None = None
Publication timestamp.
recording_ids
class-attribute
instance-attribute
¶
Associated recording IDs.
recording_name_format
instance-attribute
¶
Format for recording name.
convert_from_api_to_simple_format
¶
Convert data from API format to simple format.
Parameters:
Returns:
Source code in src/pupil_labs/realtime_api/models.py
755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 | |
convert_from_simple_to_api_format
¶
Convert data from simple format to API format.
Parameters:
Returns:
Source code in src/pupil_labs/realtime_api/models.py
733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 | |
get_question_by_id
¶
get_question_by_id(question_id: str | UUID) -> TemplateItem | None
Get a template item by ID.
Parameters:
Returns:
-
TemplateItem | None–TemplateItem | None: The template item, or None if not found.
Source code in src/pupil_labs/realtime_api/models.py
801 802 803 804 805 806 807 808 809 810 811 812 813 814 | |
validate_answers
¶
validate_answers(answers: dict[str, list[str]], template_format: TemplateDataFormat, raise_exception: bool = True) -> list[ErrorDetails]
Validate answers for this Template.
Parameters:
-
answers(dict[str, list[str]]) –Answers to validate.
-
raise_exception(bool, default:True) –Whether to raise an exception on validation failure.
-
template_format(TemplateDataFormat) –Format of the answers ("simple" or "api").
Returns:
-
list(list[ErrorDetails]) –List of validation errors, or empty list if validation succeeded.
Raises:
-
InvalidTemplateAnswersError–If validation fails and raise_exception is
Source code in src/pupil_labs/realtime_api/models.py
844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 | |
Get Template Data¶
Using the device.get_template_data method, you can receive the responses currently saved in the template.
data = device.get_template_data()
Set Template Data¶
And using the device.post_template_data method, you can set the template responses remotely.
device.post_template_data(questionnaire)
Get Template Questions & Validate them¶
You can also retrieve individual questions by their ID using the template.get_question_by_id method and check the validity of a response using the template.validate_answer method.
See it in action¶
Check the whole example code here
| templates.py | |
|---|---|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 | |