-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsurvey.py
715 lines (587 loc) · 16.8 KB
/
survey.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
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
import marimo
__generated_with = "0.9.16"
app = marimo.App(width="medium")
@app.cell
def __():
import marimo as mo
import polars as pl
import altair as alt
import random
import datetime
return alt, datetime, mo, pl, random
@app.cell
def __(mo, pl):
# Various constants
TECHNICAL_COLUMNS = ["StartDate", "EndDate", "Status", "Progress", "Duration (in seconds)", "Finished", "RecordedDate", "ResponseId", "DistributionChannel", "UserLanguage", "GDPR"]
# Helpers
def list_to_md(list_of_things, title=None):
text = f"### {title} \n" if title is not None else ""
for thing in list_of_things:
text += f" - {thing} \n"
return mo.md(text)
def mark(col_name, thing):
return pl.when(
pl.col(col_name).str.contains(thing)
).then(1).otherwise(0).alias(thing)
return TECHNICAL_COLUMNS, list_to_md, mark
@app.cell
def __(mo):
mo.md(r"""# Analysing Q2 group 2024 survey""")
return
@app.cell
def __(datetime, pl, random):
survey_start = datetime.datetime(2024, 10, 15)
df = pl.read_csv("survey-results.csv").filter(
pl.col("Status") != '{"ImportId":"status"}').filter(
pl.col("StartDate").str.to_datetime("%Y-%m-%d %H:%M:%S", strict=False) >= survey_start
)
random.seed(1234) # to get the same lines every run
#df.sample(50)
return df, survey_start
@app.cell
def __(mo):
mo.md(r"""To get a more advanced feeling:""")
return
@app.cell
def __(TECHNICAL_COLUMNS, df, pl):
df.select(pl.all().exclude(TECHNICAL_COLUMNS)).describe()
return
@app.cell
def __(df, pl):
answers = len(df)
finished = len(df.filter(pl.col("Finished") == "True"))
return answers, finished
@app.cell
def __(answers, mo):
mo.md(f"""## Total answers: {answers}""")
return
@app.cell
def __(alt, answers, finished, pl):
ddd = pl.DataFrame({"Status": ["Unfinished","Finished"],"y": [answers-finished, finished]})
base = alt.Chart(ddd, title="Finished questionnaires ratio").mark_arc().encode(theta="y", color="Status")
pie = base.mark_arc(outerRadius=120)
text = base.mark_text(radius=140, size=20).encode(text="y:N")
pie + text
return base, ddd, pie, text
@app.cell
def __(mo):
mo.md(
"""
## Where do people comes?
> Research Area
"""
)
return
@app.cell
def __(alt, df, pl):
_chart = (
alt.Chart(df.filter(pl.col("b1.q2").is_not_null()))
.transform_aggregate(count="count()", groupby=["b1\.q2"])
.transform_window(
rank="rank()",
sort=[
alt.SortField("count", order="descending"),
alt.SortField("b1\.q2", order="ascending"),
],
)
.transform_filter(alt.datum.rank <= 10)
.mark_bar()
.encode(
y=alt.Y("b1\.q2", type="nominal", sort="-x"),
x=alt.X("count", type="quantitative"),
)
.properties(title="Research Area", width="container")
)
_chart
return
@app.cell
def __(alt, df, pl):
_chart = (
alt.Chart(df.filter(pl.col("b1.q2_8_TEXT").is_not_null()))
.transform_aggregate(count="count()", groupby=["b1\.q2_8_TEXT"])
.transform_window(
rank="rank()",
sort=[
alt.SortField("count", order="descending"),
alt.SortField("b1\.q2_8_TEXT", order="ascending"),
],
)
.transform_filter(alt.datum.rank <= 10)
.mark_bar()
.encode(
y=alt.Y("b1\.q2_8_TEXT", type="nominal", sort="-x"),
x=alt.X("count", type="quantitative"),
)
.properties(title="Other research areas", width="container")
)
_chart
return
@app.cell
def __(mo):
mo.md("""> Organisation""")
return
@app.cell
def __(df, mo, pl):
orgs = df.select(
pl.col("b1.q3").alias("Organisation")
).filter(
pl.col("Organisation").is_not_null()
).group_by(
pl.col("Organisation")
).agg().sort(by="Organisation")
mo.ui.table(orgs)
return (orgs,)
@app.cell
def __(mo):
mo.md("""> Country""")
return
@app.cell
def __(df, pl):
df.select(
pl.col("b1.q4").str.to_lowercase().alias("Country")
).filter(
pl.col("Country").is_not_null()
).group_by("Country").agg(
pl.len().alias("count")
).sort("count", descending=True)
return
@app.cell
def __(mo):
mo.md("""## DDI use & knowledge""")
return
@app.cell
def __(mo):
mo.md("""### How would you rate your skill/knowledge on the following DDI products?""")
return
@app.cell
def __(alt, df, pl):
df_ddi_kl = df.select(
pl.col("b2.q1_1").alias("Codebook"),
pl.col("b2.q1_2").alias("Lifecycle"),
pl.col("b2.q1_3").alias("CDI"),
).unpivot(["Codebook", "Lifecycle", "CDI"]).group_by(
"variable", "value"
).len().sort("variable")
alt.Chart(df_ddi_kl, title="Skills and knowledge for DDI products").mark_bar().encode(
x="value:O",
y="len:Q",
color="value",
column="variable"
)
return (df_ddi_kl,)
@app.cell
def __(mo):
mo.md(r"""### What DDI products are you currently using in your activities?""")
return
@app.cell
def __(df, mo, pl):
mo.md("## Products used")
df_pu = df.select(
pl.col("b2.q2").alias("Products")
).filter(
pl.col("Products").is_not_null()
).group_by(
"Products"
).len().sort("len", descending=True)
mo.ui.table(df_pu)
return (df_pu,)
@app.cell
def __(mo):
mo.md(
r"""
### If you are using DDI, when are you using DDI regarding the data lifecycle schema below?
![Data lifecycle](https://ddialliance.org/sites/default/files/DDILifecycle.jpg)
"""
)
return
@app.cell
def __(df, mark, pl):
def markb2q3(thing):
return mark("b2.q3", thing)
df.select(
pl.col("b2.q3").alias("Lifecycle"),
markb2q3("Concept"),
markb2q3("Collection"),
markb2q3("Processing"),
markb2q3("Distribution"),
markb2q3("Discovery"),
markb2q3("Analysis"),
markb2q3("Repurposing"),
markb2q3("Archiving")
).unpivot(
["Concept", "Collection", "Processing", "Distribution", "Discovery", "Analysis", "Repurposing", "Archiving"]
).group_by(
"variable"
).agg(
pl.col("value").sum()
).select(
pl.col("variable").alias("Phase"),
pl.col("value").alias("Count")
).sort("Count", descending=True)
return (markb2q3,)
@app.cell
def __(mo):
mo.md("""### Are you documenting...""")
return
@app.cell
def __(alt, df, pl):
_chart = (
alt.Chart(
df.filter(pl.col("b2.q4_1").is_not_null()),
title="Datasets..."
)
.mark_bar()
.encode(
y=alt.Y("b2\.q4_1", type="nominal"),
x=alt.X("count()", type="quantitative"),
)
.properties(width="container")
)
_chart
return
@app.cell
def __(alt, df, pl):
_chart = (
alt.Chart(df.filter(pl.col("b2.q4_2").is_not_null()), title="Variables...")
.mark_bar()
.encode(
y=alt.Y("b2\.q4_2", type="nominal"),
x=alt.X("count()", type="quantitative"),
)
.properties(width="container")
)
_chart
return
@app.cell
def __(alt, df, pl):
_chart = (
alt.Chart(df.filter(pl.col("b2.q4_3").is_not_null()), title="Concepts...")
.mark_bar()
.encode(
y=alt.Y("b2\.q4_3", type="nominal"),
x=alt.X("count()", type="quantitative"),
)
.properties(width="container")
)
_chart
return
@app.cell
def __(alt, df, pl):
_chart = (
alt.Chart(df.filter(pl.col("b2.q4_4").is_not_null()), title="Questions wording...")
.mark_bar()
.encode(
y=alt.Y("b2\.q4_4", type="nominal"),
x=alt.X("count()", type="quantitative"),
)
.properties(width="container")
)
_chart
return
@app.cell
def __(alt, df, pl):
_chart = (
alt.Chart(df.filter(pl.col("b2.q4_5").is_not_null()), title="Responses & code lists...")
.mark_bar()
.encode(
y=alt.Y("b2\.q4_5", type="nominal"),
x=alt.X("count()", type="quantitative"),
)
.properties(width="container")
)
_chart
return
@app.cell
def __(mo):
mo.md("""### Which DDI elements are you using to describe the questionnaires?""")
return
@app.cell
def __(alt, df, pl):
_chart = (
alt.Chart(df.filter(pl.col("b2.q5").is_not_null()))
.transform_aggregate(count="count()", groupby=["b2\.q5"])
.transform_window(
rank="rank()",
sort=[
alt.SortField("count", order="descending"),
alt.SortField("b2\.q5", order="ascending"),
],
)
.transform_filter(alt.datum.rank <= 10)
.mark_bar()
.encode(
y=alt.Y("b2\.q5", type="nominal", sort="-x"),
x=alt.X("count", type="quantitative"),
)
.properties(title="Questionnaire documentation with...", width="container")
)
_chart
return
@app.cell
def __(mo):
mo.md(r"""### What survey tools are you using?""")
return
@app.cell
def __(alt, df, pl):
_chart = (
alt.Chart(df.filter(pl.col("b2.q6").is_not_null()))
.transform_aggregate(count="count()", groupby=["b2\.q6"])
.transform_window(
rank="rank()",
sort=[
alt.SortField("count", order="descending"),
alt.SortField("b2\.q6", order="ascending"),
],
)
.transform_filter(alt.datum.rank <= 10)
.mark_bar()
.encode(
y=alt.Y("b2\.q6", type="nominal", sort="-x"),
x=alt.X("count", type="quantitative"),
)
.properties(title="Survey tools", width="container")
)
_chart
return
@app.cell
def __(alt, df):
_chart = (
alt.Chart(df)
.transform_aggregate(count="count()", groupby=["b2\.q6_7_TEXT"])
.transform_window(
rank="rank()",
sort=[
alt.SortField("count", order="descending"),
alt.SortField("b2\.q6_7_TEXT", order="ascending"),
],
)
.transform_filter(alt.datum.rank <= 10)
.mark_bar()
.encode(
y=alt.Y("b2\.q6_7_TEXT", type="nominal", sort="-x"),
x=alt.X("count", type="quantitative"),
)
.properties(title="Other survey tools", width="container")
)
_chart
return
@app.cell
def __(mo):
mo.md("""### What tools are you using to document questions and questionnaires in DDI?""")
return
@app.cell
def __(alt, df, pl):
_chart = (
alt.Chart(df.filter(pl.col("b2.q7").is_not_null()))
.transform_aggregate(count="count()", groupby=["b2\.q7"])
.transform_window(
rank="rank()",
sort=[
alt.SortField("count", order="descending"),
alt.SortField("b2\.q7", order="ascending"),
],
)
.transform_filter(alt.datum.rank <= 10)
.mark_bar()
.encode(
y=alt.Y("b2\.q7", type="nominal", sort="-x"),
x=alt.X("count", type="quantitative"),
)
.properties(title="Documentation tools", width="container")
)
_chart
return
@app.cell
def __(alt, df, pl):
_chart = (
alt.Chart(df.filter(pl.col("b2.q7_4_TEXT").is_not_null()))
.mark_bar()
.encode(
y=alt.Y("b2\.q7_4_TEXT", type="nominal"),
x=alt.X("count()", type="quantitative"),
)
.properties(title="Internal documentation tools",width="container")
)
_chart
return
@app.cell
def __(alt, df, pl):
_chart = (
alt.Chart(df.filter(pl.col("b2.q7_5_TEXT").is_not_null()))
.mark_bar()
.encode(
y=alt.Y("b2\.q7_5_TEXT", type="nominal"),
x=alt.X("count()", type="quantitative"),
)
.properties(title="Other documentation tools ", width="container")
)
_chart
return
@app.cell
def __(mo):
mo.md("""### Are you satisfied with your current usage of DDI?""")
return
@app.cell
def __(alt, df, pl):
_chart = (
alt.Chart(df.filter(pl.col("b2.q10").is_not_null()))
.mark_bar()
.encode(
y=alt.Y("b2\.q10", type="nominal"),
x=alt.X("count()", type="quantitative"),
)
.properties(title="DDI satisfaction", width="container")
)
_chart
sat = df.filter(
pl.col("b2.q10").is_not_null()
).select(
pl.col("b2.q10").alias("Satisfaction")
).group_by("Satisfaction").len()
sat_base = alt.Chart(sat, title="Satisfaction").mark_arc().encode(theta="len:Q", color="Satisfaction")
sat_pie = sat_base.mark_arc(outerRadius=120)
sat_text = sat_base.mark_text(radius=140, size=20).encode(text="len:N")
sat_pie + sat_text
return sat, sat_base, sat_pie, sat_text
@app.cell
def __(mo):
mo.md("""> (If not) What enhancements would you like to make?""")
return
@app.cell
def __(df, pl):
df.filter(pl.col("b2.q11").is_not_null()).select(pl.col("b2.q11"))
return
@app.cell
def __(mo):
mo.md("""### Are you planning to document questionnaires using DDI?""")
return
@app.cell
def __(alt, df, pl):
_chart = (
alt.Chart(df.select(pl.col("b3.q1").alias("b3q1"))
.filter(pl.col("b3q1").is_not_null()))
.mark_bar()
.encode(
y=alt.Y("b3q1", type="nominal"),
x=alt.X("count()", type="quantitative"),
)
.properties(
title="Plans",
width="container"
)
)
_chart
return
@app.cell
def __(df, list_to_md, pl):
qddiyes = df.filter(
pl.col("b3.q1") == "Yes"
).select(
pl.col("b3.q2")
).filter(
pl.col("b3.q2").is_not_null()
).to_series()
list_to_md(qddiyes, "If _yes_, why?")
return (qddiyes,)
@app.cell
def __(df, list_to_md, pl):
qddino = df.filter(
pl.col("b3.q1") == "No"
).select(
pl.col("b3.q2")
).filter(
pl.col("b3.q2").is_not_null()
).to_series()
list_to_md(qddino, "If _no_, why?")
return (qddino,)
@app.cell
def __(df, list_to_md, pl):
qddiimprov = df.select(
pl.col("b3.q3")
).filter(pl.col("b3.q3").is_not_null()).to_series()
list_to_md(qddiimprov, "What improvements to DDI for questionnaires that you would like to see?")
return (qddiimprov,)
@app.cell
def __(mo):
mo.md(
"""
## DDI training and resources
### Have you ever taken part in a DDI training course, workshop or seminar?
"""
)
return
@app.cell
def __(df, mo, pl):
training = df.select("b4.q1").filter(pl.col("b4.q1").is_not_null()).group_by("b4.q1").len()
mo.ui.table(training)
return (training,)
@app.cell
def __(df, list_to_md, pl):
list_to_md(
df.select("b4.q2").filter(pl.col("b4.q2").is_not_null()).to_series(),
"Which one?"
)
return
@app.cell
def __(alt, df, pl):
_chart = (
alt.Chart(df.filter(pl.col("b4.q3").is_not_null()))
.mark_bar()
.encode(
y=alt.Y("b4\.q3", type="nominal"),
x=alt.X("count()", type="quantitative"),
)
.properties(width="container")
)
_chart
return
@app.cell
def __(mo):
mo.md("""### What resources do you usually use to help you in your questionnaire conception and documentation activities?""")
return
@app.cell
def __(df, mark, pl):
df.filter(
pl.col("b4.q4").is_not_null()
).select(
pl.col("b4.q4"),
mark("b4.q4", "DDI website"),
mark("b4.q4", "Specification"),
mark("b4.q4", "Model documentation"),
mark("b4.q4", "Codata"),
mark("b4.q4", "Zenodo"),
mark("b4.q4", "Youtube"),
mark("b4.q4", "Other")
).unpivot(
["DDI website", "Specification", "Model documentation", "Codata", "Zenodo", "Youtube", "Other"]
).group_by(
"variable"
).agg(
pl.col("value").sum()
).sort("value", descending=True)
return
@app.cell
def __(mo):
mo.md(r""" ### For you, what materials would meet your needs in terms of documenting questions and questionnaires?""")
return
@app.cell
def __(df, mark, pl):
df.filter(
pl.col("b4.q5").is_not_null()
).select(
pl.col("b4.q5"),
mark("b4.q5", "Best practices"),
mark("b4.q5", "Mentoring"),
mark("b4.q5", "Webinar"),
mark("b4.q5", "In person training"),
mark("b4.q5", "Other")
).unpivot(
["Best practices", "Mentoring", "Webinar", "In person training", "Other"]
).group_by(
"variable"
).agg(
pl.col("value").sum()
).sort("value", descending=True)
return
if __name__ == "__main__":
app.run()