-
Notifications
You must be signed in to change notification settings - Fork 25
/
props.py
259 lines (193 loc) · 6.3 KB
/
props.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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
from dataclasses import dataclass
from typing import Optional, TypedDict
import pandas as pd
class Translations(TypedDict):
"""Typed dict containing text that is display in a speficic language
Attributes:
en: English string to display
nl: Dutch string to display
"""
en: str
nl: str
@dataclass
class Translatable:
"""Wrapper class for Translations"""
translations: Translations
def toDict(self):
return self.__dict__.copy()
@dataclass
class PropsUIHeader:
"""Page header
Attributes:
title: title of the page
"""
title: Translatable
def toDict(self):
dict = {}
dict["__type__"] = "PropsUIHeader"
dict["title"] = self.title.toDict()
return dict
@dataclass
class PropsUIFooter:
"""Page footer
Attributes:
progressPercentage: float indicating the progress in the flow
"""
progressPercentage: float
def toDict(self):
dict = {}
dict["__type__"] = "PropsUIFooter"
dict["progressPercentage"] = self.progressPercentage
return dict
@dataclass
class PropsUIPromptConfirm:
"""Retry submitting a file page
Prompt the user if they want to submit a new file.
This can be used in case a file could not be processed.
Attributes:
text: message to display
ok: message to display if the user wants to try again
cancel: message to display if the user wants to continue regardless
"""
text: Translatable
ok: Translatable
cancel: Translatable
def toDict(self):
dict = {}
dict["__type__"] = "PropsUIPromptConfirm"
dict["text"] = self.text.toDict()
dict["ok"] = self.ok.toDict()
dict["cancel"] = self.cancel.toDict()
return dict
@dataclass
class PropsUIPromptConsentFormTable:
"""Table to be shown to the participant prior to donation
Attributes:
id: a unique string to itentify the table after donation
title: title of the table
data_frame: table to be shown
"""
id: str
title: Translatable
data_frame: pd.DataFrame
def toDict(self):
dict = {}
dict["__type__"] = "PropsUIPromptConsentFormTable"
dict["id"] = self.id
dict["title"] = self.title.toDict()
dict["data_frame"] = self.data_frame.to_json()
return dict
@dataclass
class PropsUIPromptConsentForm:
"""Tables to be shown to the participant prior to donation
Attributes:
tables: a list of tables
meta_tables: a list of optional tables, for example for logging data
"""
tables: list[PropsUIPromptConsentFormTable]
meta_tables: list[PropsUIPromptConsentFormTable]
description: Optional[Translatable] = None
donate_question: Optional[Translatable] = None
donate_button: Optional[Translatable] = None
def translate_tables(self):
output = []
for table in self.tables:
output.append(table.toDict())
return output
def translate_meta_tables(self):
output = []
for table in self.meta_tables:
output.append(table.toDict())
return output
def toDict(self):
dict = {}
dict["__type__"] = "PropsUIPromptConsentForm"
dict["tables"] = self.translate_tables()
dict["metaTables"] = self.translate_meta_tables()
dict["description"] = self.description and self.description.toDict()
dict["donateQuestion"] = self.donate_question and self.donate_question.toDict()
dict["donateButton"] = self.donate_button and self.donate_button.toDict()
return dict
@dataclass
class PropsUIPromptFileInput:
"""Prompt the user to submit a file
Attributes:
description: text with an explanation
extensions: accepted mime types, example: "application/zip, text/plain"
"""
description: Translatable
extensions: str
def toDict(self):
dict = {}
dict["__type__"] = "PropsUIPromptFileInput"
dict["description"] = self.description.toDict()
dict["extensions"] = self.extensions
return dict
@dataclass
class PropsUIPromptProgress:
"""Prompt the user information during the extraction
Attributes:
description: text with an explanation
message: can be used to show extraction progress
"""
description: Translatable
message: str
percentage: Optional[int] = None
def toDict(self):
dict = {}
dict["__type__"] = "PropsUIPromptProgress"
dict["description"] = self.description.toDict()
dict["message"] = self.message
dict["percentage"] = self.percentage
return dict
class RadioItem(TypedDict):
"""Radio button
Attributes:
id: id of radio button
value: text to be displayed
"""
id: int
value: str
@dataclass
class PropsUIPromptRadioInput:
"""Radio group
This radio group can be used get a mutiple choice answer from a user
Attributes:
title: title of the radio group
description: short description of the radio group
items: a list of radio buttons
"""
title: Translatable
description: Translatable
items: list[RadioItem]
def toDict(self):
dict = {}
dict["__type__"] = "PropsUIPromptRadioInput"
dict["title"] = self.title.toDict()
dict["description"] = self.description.toDict()
dict["items"] = self.items
return dict
@dataclass
class PropsUIPageDonation:
"""A multi-purpose page that gets shown to the user
Attributes:
platform: the platform name the user is curently in the process of donating data from
header: page header
body: main body of the page, see the individual classes for an explanation
"""
platform: str
header: PropsUIHeader
body: PropsUIPromptRadioInput | PropsUIPromptConsentForm | PropsUIPromptFileInput | PropsUIPromptConfirm
def toDict(self):
dict = {}
dict["__type__"] = "PropsUIPageDonation"
dict["platform"] = self.platform
dict["header"] = self.header.toDict()
dict["body"] = self.body.toDict()
return dict
class PropsUIPageEnd:
"""An ending page to show the user they are done"""
def toDict(self):
dict = {}
dict["__type__"] = "PropsUIPageEnd"
return dict