-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexplorer.py
3951 lines (3755 loc) · 135 KB
/
explorer.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
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
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
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
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
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import streamlit as st
import streamlit.components.v1 as components
import pandas as pd
import numpy as np
import plotly.graph_objects as go
import plotly.express as px
from string import Template
# ===========================================================================
# GUARDINT asset URL and color scheme
# ===========================================================================
asset_url = "https://guardint-assets.sehn.dev"
colors = [
"#600b0c",
"#C01518",
"#ff1c1f",
"#ff5557",
"#ff8e8f",
"#ffc7c7",
"#ffe3e3",
"#efefef",
]
# ===========================================================================
# Utility Functions to be cached
# ===========================================================================
@st.cache
def gen_px_pie(df, values, names, color_discrete_sequence=colors, **kwargs):
fig = px.pie(
df,
values=values,
names=names,
color_discrete_sequence=color_discrete_sequence,
color=kwargs.get("color", None),
color_discrete_map=kwargs.get("color_discrete_map", None),
custom_data=kwargs.get("custom_data", None),
)
# Update what is shown on the slices (on hover)
fig.update_traces(
texttemplate="<b>%{value}</b><br>%{percent}",
hovertemplate="""<b>Answer</b> %{label}
<br><br>given by <b>%{value}</b> respondents or <b>%{percent}</b>
<br>of all who answered the question
<br>given the current filter.
""",
)
# Update layout
fig.update_layout(
autosize=False,
width=700,
height=450,
margin=dict(l=0, r=0, b=100, t=30),
font={"size": 18, "family": "Roboto Mono, monospace"},
legend={
"font": {"size": kwargs.get("legend_font_size", 12)},
"orientation": kwargs.get("legend_orientation", "h"),
"bgcolor": "#efefef",
"x": -0.2,
"y": 1.1,
},
modebar={"orientation": "v"},
)
# Add logo
fig.add_layout_image(
dict(
source=f"{asset_url}/guardint_logo.png",
xref="paper",
yref="paper",
x=1.00,
y=0.00,
sizex=0.15,
sizey=0.15,
xanchor="right",
yanchor="bottom",
)
)
return fig
@st.cache
def gen_go_pie(labels, values, marker_colors=colors, **kwargs):
fig = go.Figure(
data=[
go.Pie(
labels=labels, values=values, marker_colors=marker_colors, sort=False
)
]
)
# Update what is shown on the slices (on hover)
fig.update_traces(
texttemplate="<b>%{value}</b><br>%{percent}",
hovertemplate="""<b>Answer</b> %{label}
<br><br>given by <b>%{value}</b> respondents or <b>%{percent}</b>
<br>of all who answered the question
<br>given the current filter.<extra></extra>
""",
)
# Update layout
fig.update_layout(
autosize=False,
width=700,
height=kwargs.get("height", 450),
margin=dict(l=0, r=0, b=50, t=30),
font={"size": kwargs.get("font_size", 18), "family": "Roboto Mono, monospace"},
legend={
"font": {"size": kwargs.get("legend_font_size", 12)},
"orientation": "v",
"bgcolor": "#efefef",
"x": kwargs.get("legend_x", -0.2),
"y": kwargs.get("legend_y", 1.1),
},
modebar={"orientation": "v"},
)
# Add logo
fig.add_layout_image(
dict(
source=f"{asset_url}/guardint_logo.png",
xref="paper",
yref="paper",
x=1.00,
y=0.00,
sizex=kwargs.get("image_sizex", 0.15),
sizey=kwargs.get("image_sizey", 0.15),
xanchor="right",
yanchor="bottom",
)
)
return fig
@st.cache
def gen_px_histogram(
df, x, y, nbins, color, labels, color_discrete_map=colors, **kwargs
):
fig = px.histogram(
df,
x=x,
y=y,
nbins=nbins,
color=color,
color_discrete_map=color_discrete_map,
labels=labels,
marginal=kwargs.get("marginal", "rug"),
)
# Update layout
fig.update_layout(
autosize=False,
width=700,
height=450,
margin=dict(l=0, r=0, b=100, t=30),
font={"size": kwargs.get("font_size", 13), "family": "Roboto Mono, monospace"},
legend={
"font": {"size": kwargs.get("legend_font_size", 10)},
},
modebar={"orientation": "h"},
)
# Add logo
fig.add_layout_image(
dict(
source="{asset_url}/guardint_logo.png",
xref="paper",
yref="paper",
x=1.18,
y=-0.005,
sizex=0.15,
sizey=0.15,
xanchor="right",
yanchor="bottom",
)
)
return fig
@st.cache
def gen_go_histogram_overlaid(traces, names, colors, **kwargs):
fig = go.Figure()
for trace, name, color in zip(traces, names, colors):
fig.add_trace(
go.Histogram(
x=trace,
name=name,
marker_color=color,
xbins={"size": 2},
cumulative_enabled=True,
)
)
fig.update_layout(barmode="overlay")
fig.update_traces(opacity=0.75)
# Update layout
fig.update_layout(
autosize=False,
width=700,
height=450,
margin=dict(l=0, r=0, b=100, t=30),
font={"size": kwargs.get("font_size", 13), "family": "Roboto Mono, monospace"},
legend={
"font": {"size": kwargs.get("legend_font_size", 10)},
},
modebar={"orientation": "h"},
)
# Add logo
fig.add_layout_image(
dict(
source="{asset_url}/guardint_logo.png",
xref="paper",
yref="paper",
x=1.18,
y=-0.005,
sizex=0.15,
sizey=0.15,
xanchor="right",
yanchor="bottom",
)
)
return fig
@st.cache
def gen_px_box(df, x, y, points, color, labels, color_discrete_map=colors, **kwargs):
fig = px.box(
df,
x=x,
y=y,
points=points,
color=color,
labels=labels,
color_discrete_map=color_discrete_map,
)
# Update layout
fig.update_layout(
autosize=False,
width=700,
height=450,
margin=dict(l=0, r=0, b=100, t=30),
font={"size": 13, "family": "Roboto Mono, monospace"},
legend={
"font": {"size": kwargs.get("legend_font_size", 10)},
},
modebar={"orientation": "h"},
)
# Add logo
fig.add_layout_image(
dict(
source="{asset_url}/guardint_logo.png",
xref="paper",
yref="paper",
x=1.18,
y=-0.005,
sizex=0.15,
sizey=0.15,
xanchor="right",
yanchor="bottom",
)
)
return fig
@st.cache
def gen_go_bar_stack(data, **kwargs):
fig = go.Figure(data=data)
# Update layout
fig.update_layout(
barmode="stack",
autosize=False,
width=700,
height=700,
margin=dict(l=0, r=0, b=100, t=30),
font={"size": 13, "family": "Roboto Mono, monospace"},
legend={
"font": {"size": kwargs.get("legend_font_size", 10)},
},
modebar={"orientation": "h"},
)
# Add logo
fig.add_layout_image(
dict(
source="{asset_url}/guardint_logo.png",
xref="paper",
yref="paper",
x=1.18,
y=-0.005,
sizex=0.15,
sizey=0.15,
xanchor="right",
yanchor="bottom",
)
)
return fig
@st.cache
def gen_rank_plt(input_col, options, **kwargs):
input_col_score = pd.Series(index=options)
for i in range(1, 7):
input_col_counts = df[filter][f"{input_col}[{i}]"].value_counts()
scores = input_col_counts.multiply(scoring[i])
input_col_score = input_col_score.add(scores, fill_value=0)
input_col_score = input_col_score.sort_values(ascending=False)
if i == 1:
ranked_first = df[filter][f"{input_col}[1]"].value_counts()
ranked_first_clean = pd.DataFrame(
{
"institution": ranked_first.index,
"No of times<br>ranked first": ranked_first.values,
}
)
input_col_df = pd.DataFrame(
{
"institution": input_col_score.index,
"score": input_col_score.values,
}
)
input_col_df = input_col_df.merge(
ranked_first_clean, on="institution", how="left"
).fillna(0)
input_col_df = input_col_df.sort_values(["score", "No of times<br>ranked first"])
fig = px.bar(
input_col_df.sort_values(by="score"),
y="institution",
x="score",
color="No of times<br>ranked first",
color_continuous_scale=[colors[5], colors[2]],
orientation="h",
)
# Update layout
fig.update_layout(
autosize=False,
width=700,
height=450,
margin=dict(l=0, r=0, b=100, t=30),
font={"size": 13, "family": "Roboto Mono, monospace"},
legend={
"font": {"size": kwargs.get("legend_font_size", 10)},
},
modebar={"orientation": "h"},
)
# Add logo
fig.add_layout_image(
dict(
source="{asset_url}/guardint_logo.png",
xref="paper",
yref="paper",
x=1.0,
y=0.0,
sizex=0.25,
sizey=0.25,
xanchor="right",
yanchor="bottom",
)
)
return fig
def print_total(number):
st.write(f"**{number}** respondents answered the question with the current filter")
def answered_by(group):
if group == "cso":
text = "CSO professionals"
else:
text = "journalists"
st.caption(f"This question was only answered by {text}")
chart_config = {
"displaylogo": False,
"modeBarButtonsToRemove": ["hoverClosestPie"],
"toImageButtonOptions": {
"width": 700,
"height": 450,
"scale": (210 / 25.4) / (700 / 300),
},
}
# ===========================================================================
# Import data from stored pickle
# ===========================================================================
df = pd.read_pickle("data/guardint_survey.pkl")
# ===========================================================================
# General configuration
# ===========================================================================
st.set_page_config(
page_title="GUARDINT Survey Data Explorer",
page_icon=f"{asset_url}/guardint_favicon.png",
)
def callback():
st.experimental_set_query_params(section=st.session_state.section)
sections = [
"Overview",
"Resources > HR",
"Resources > Expertise",
"Resources > Finance",
"Resources > FOI",
"Resources > Appreciation",
"Media Reporting",
"Public Campaigning",
"Policy Advocacy",
"Strategic Litigation",
"Protection",
"Constraints",
"Attitudes",
]
try:
query_params = st.experimental_get_query_params()
query_section = query_params["section"][0]
if "section" not in st.session_state:
st.session_state.section = query_section
except KeyError:
st.experimental_set_query_params(section=sections[0])
query_params = st.experimental_get_query_params()
query_section = query_params["section"][0]
if "section" not in st.session_state:
st.session_state.section = query_section
selected_section = st.sidebar.radio(
"Choose section",
sections,
index=sections.index(query_section),
key="section",
on_change=callback,
)
st.caption("GUARD//INT Survey > " + selected_section)
filters = {
"country": st.sidebar.selectbox(
"Country", ["All", "United Kingdom", "Germany", "France"]
),
"field": st.sidebar.selectbox("Field", ["All", "CSO Professionals", "Journalists"]),
}
filter = np.full(len(df.index), True)
for column_name, selectbox in filters.items():
if selectbox == "All":
continue
else:
filter = filter & (df[column_name] == selectbox)
# ===========================================================================
# Custom JS/CSS
# ===========================================================================
# This causes the page to scroll to top when section is changed
components.html(
f"""
<!--{st.session_state.section}-->
<script>
window.parent.document.querySelector('section.main').scrollTo(0, 0);
</script>
""",
height=0,
)
# Here, a custom font is loaded from the GitHub repo
css = Template(
""" <style>
@font-face {
font-family: 'Roboto Mono';
font-style: normal;
font-weight: 400;
font-display: swap;
src: url($asset_url/roboto_mono.woff2) format('woff2');
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
html, body, [class*="css"] {
font-family: 'Roboto Mono';
}
.st-bx {
font-family: 'Roboto Mono' !important;
}
.st-ae {
font-family: 'Roboto Mono' !important;
}
.css-1rh8hwn {
font-size: 0.8rem;
}
button {
border-width: 3px 3px 3px 3px !important;
border-radius: 0 !important;
}
h1 {
margin-top: -1em;
}
h3 {line-height: 1.3}
footer {
visibility: hidden;
}
.e8zbici2 {
visibility: hidden;
}
.custom-footer {
display: block;
padding-top: 150px;
margin-bottom: -400px;
color: rgba(38, 39, 48, 0.4);
flex: 0 1 0%;
font-size: 0.8rem !important;
max-width: 730px;
width: 100%;
}
strong {
font-style: bold;
font-weight: 700;
color: #000;
}
code {
color: #ff1c1f;
}
a {
color: #ff1c1f !important;
}
a:hover {
color: #ff5557 !important;
}
a:visited {
color: #600b0c !important;
}
</style>
"""
)
css = css.substitute({"asset_url": asset_url})
st.markdown(css, unsafe_allow_html=True)
# ===========================================================================
# Overview
# ===========================================================================
if selected_section == "Overview":
st.write("# Civic Intelligence Oversight Survey Data Explorer")
st.write(
"""
A better understanding of the democratic governance of intelligence
requires more detailed information about an increasingly important group
of actors outside the traditional corridors of power: Civic intelligence
oversight practitioners. As part of the
[GUARD//INT](https://guardint.org) research project, we conducted online
surveys with representatives of civil society organisations (CSOs) and
journalists in France, Germany and the United Kingdom.
This site provides open access to the anonymized data we gathered. It visualises
our empirical investigation of the perceptions of media and CSO
professionals specialised in intelligence and surveillance. The data is
meant to contribute to a better understanding of the potential and
limitations of civic intelligence oversight. We invite you to explore
the data using the sidebar on the left.
"""
)
col1, col2 = st.columns(2)
col1.metric("Respondents", len(df[filter].index))
col2.metric(
"Cumulative years spent working on SBIA",
int(df[filter]["expertise1"].sum()),
)
col1, col2 = st.columns(2)
col1.metric(
"Avg. years spent working on SBIA†",
"%.1f" % df[filter]["expertise1"].mean(),
)
col2.metric(
"Avg. No. of FOI requests in the past 5 years",
int(df[filter]["foi2"].mean()),
)
col1, col2 = st.columns(2)
col1.metric(
"Journalists",
len(df[filter & (df.field == "Journalists")].index),
)
col2.metric(
"Civil Society Organisation professionals",
len(df[filter & (df.field == "CSO Professionals")].index),
)
st.caption(
"""† For the calculation of the mean only valid numerical answers were
counted, excluding those who haven't specified their experience in years.
"""
)
st.write("## Understanding the data")
st.write(
"""The individuals who participated in the survey mostly engage in
civic oversight practices in their professional capacity. They were
invited to complete the survey based on their experience in working on
surveillance by intelligence agencies. We designed two different but
overlapping surveys: One for journalists and one for CSO professionals.
When we posed a question only to journalists, the question code is
prepended with `MS` (media scrutiny). When we put the question only to
CSO professionals, the code is prepended with `CS` (civil society
scrutiny). If the question was put to both groups, the prefix was
removed.
"""
)
st.write(
"""The questions and response options are structured in different
sections ranging from different kinds of resources (human resources,
expertise, use of freedom of information rights, financial resources,
journalistic appreciation) to different civic oversight activities
(media reporting, public campaigning, policy advocacy, strategic
litigation) as well as protections, constraints and attitudes. A
comprehensive overview of all questions and answer options can be found
in our two codebooks:
"""
)
with open("codebooks/guardint_survey_codebook_media.pdf", "rb") as file:
st.download_button(
label="Codebook Media Scrutiny (PDF)",
data=file,
file_name="guardint_survey_codebook_media.pdf",
)
with open("codebooks/guardint_survey_codebook_civil_society.pdf", "rb") as file:
st.download_button(
label="Codebook Civil Society Scrutiny (PDF)",
data=file,
file_name="guardint_survey_codebook_civil_society.pdf",
)
st.write(
"""If you want to have a look at the data yourself, you can also
download the entire dataset that this website is built on
below:
"""
)
with open("data/guardint_survey.csv", "rb") as file:
st.download_button(
label="Survey data (CSV)", data=file, file_name="guardint_survey_data.csv"
)
with open("data/guardint_survey.xlsx", "rb") as file:
st.download_button(
label="Survey data (Excel)",
data=file,
file_name="guardint_survey_data.xlsx",
)
st.write("## About this website")
st.write(
"""We initially built this website to give ourselves an easy way to
peruse and analyse the data. Since we found it helpful, we thought you
might find it helpful, too. Using the controls located in the sidebar on
the left you can filter by country (United Kingdom, France or Germany)
and by field (Journalists, CSO Professionals). For every question, the
data explorer indicates the total number of responses according to the
currently applied filter. By hoovering over the charts, further details
on the respective answer option appear. All charts can be downloaded as
.png files.
"""
)
st.write(
"""This website would not be remotely possible without the great
open-source software it's built with. We extend a big thank you to the
creators of the Streamlit library and all the other software libraries
that enable the functionality of this website. The code for this website
is freely available under a permissive license. If you find any errors
or room for improvement, don't hesitate to let us know.
"""
)
st.write("## Get in touch")
st.write(
"""If you have questions or comments about our research or the data
provided, you can contact the research team at the [Berlin Social Science
Center
(WZB)](https://www.wzb.eu/en/research/digitalization-and-societal-transformation/politics-of-digitalization/projects/oversight-and-intelligence-networks-who-guards-the-guardians-guardint)
and [Stiftung Neue Verantwortung (SNV)](https://www.stiftung-nv.de/en/project/digital-rights-surveillance-and-democracy) via email to
[[email protected]](mailto:[email protected]). You can also reach
out on Twitter [@guard_int](https://twitter.com/guard_int).
"""
)
st.write("## Summary statistics")
st.write(
"""Below you find some summary statistics, such as which countries the
respondents are primarily working in. You can always jump to a section
that interests you by using the outline in the left sidebar.
"""
)
country_counts = df[filter]["country"].value_counts()
st.write("### Country `[country]`")
print_total(country_counts.sum())
st.plotly_chart(
gen_px_pie(
df[filter],
values=country_counts,
names=country_counts.index,
color=country_counts.index,
color_discrete_map={
"Germany": colors[0],
"France": colors[2],
"United Kingdom": colors[5],
},
),
use_container_width=True,
config=chart_config,
)
st.write("### Field `[field]`")
field_counts = df[filter]["field"].value_counts()
print_total(field_counts.sum())
st.plotly_chart(
gen_px_pie(
df[filter],
values=field_counts,
names=field_counts.index,
),
use_container_width=True,
config=chart_config,
)
st.write("### Predominant activity of CSO professionals `[CSpreselection]`")
CSpreselection_counts = df[filter]["CSpreselection"].value_counts()
print_total(CSpreselection_counts.sum())
st.plotly_chart(
gen_px_pie(
df[filter],
values=CSpreselection_counts,
names=CSpreselection_counts.index,
),
use_container_width=True,
config=chart_config,
)
st.write("### Gender `[gender]`")
gender_counts = df[filter]["gender"].value_counts()
print_total(gender_counts.sum())
st.plotly_chart(
gen_px_pie(
df[filter],
values=gender_counts,
names=gender_counts.index,
color=gender_counts.index,
color_discrete_map={
"Not specified": colors[0],
"Male": colors[1],
"Female": colors[2],
"Other": colors[3],
},
),
use_container_width=True,
config=chart_config,
)
# TODO Privacy notice
# ===========================================================================
# Resources > HR
# ===========================================================================
if selected_section == "Resources > HR":
st.write("# Resources > HR")
st.write("### What is your employment status? `[hr1]`")
hr1_counts = df[filter]["hr1"].value_counts()
print_total(hr1_counts.sum())
st.plotly_chart(
gen_px_pie(
hr1_counts,
values=hr1_counts,
names=hr1_counts.index,
color=hr1_counts.index,
color_discrete_map={
"Full-time": colors[0],
"Part-time (>50%)": colors[1],
"Part-time (<50%)": colors[2],
"Freelance": colors[3],
"Other": colors[4],
},
),
use_container_width=True,
config=chart_config,
)
# =======================================================================
st.write(
"### How many days per month do you work on surveillance by intelligence agencies? `[hr2]`"
)
hr2_counts = df[filter]["hr2"].value_counts()
print_total(hr2_counts.sum())
st.plotly_chart(
gen_px_histogram(
df=df[filter],
x="hr2",
y=None,
nbins=None,
color="country",
color_discrete_map={
"Germany": colors[0],
"France": colors[2],
"United Kingdom": colors[5],
},
labels={"hr2": "days per month"},
),
use_container_width=True,
config=chart_config,
)
st.plotly_chart(
gen_px_box(
df=df[filter],
points="all",
x="country",
y="hr2",
color="country",
color_discrete_map={
"Germany": colors[0],
"France": colors[2],
"United Kingdom": colors[5],
},
labels={"hr2": "days per month"},
),
use_container_width=True,
config=chart_config,
)
df["hr2_more_than_five"] = np.where(df["hr2"] > 5, True, False)
df["hr2_more_than_five"] = df["hr2_more_than_five"].replace(
{True: "more than 5 days", False: "5 days or less"}
)
hr2_more_than_five_counts = df[filter]["hr2_more_than_five"].value_counts()
st.plotly_chart(
gen_px_pie(
hr2_more_than_five_counts,
values=hr2_more_than_five_counts,
names=hr2_more_than_five_counts.index,
color=hr2_more_than_five_counts.index,
),
use_container_width=True,
config=chart_config,
)
# =======================================================================
st.write("### Which type of medium do you work for? `[MShr3]`")
MShr3_df = pd.DataFrame(columns=("option", "count", "country"))
answered_by("media")
MShr3_options = [
"daily_newspaper",
"weekly_newspaper",
"magazine",
"tv",
"radio",
"news_agency",
"online_stand_alone",
"online_of_offline",
]
MShr3_options_clean = [
"Daily newspaper",
"Weekly newspaper",
"Magazine",
"TV",
"Radio",
"News agency",
"Online outlet<br>(standalone)",
"Online outlet<br>(of an offline publication)",
]
for option, option_clean in zip(MShr3_options, MShr3_options_clean):
MShr3_data = df[filter]["country"][df[f"MShr3[{option}]"] == 1].tolist()
for i in MShr3_data:
MShr3_df = MShr3_df.append(
{"option": option_clean, "count": MShr3_data.count(i), "country": i},
ignore_index=True,
)
MShr3_df = MShr3_df.drop_duplicates()
if filters["field"] == "CSO Professionals":
print_total(0)
else:
# If one respondent chose at least one medium it counts towards the total
MShr3_col_list = [col for col in df[filter].columns if col.startswith("MShr3")]
MShr3_df_total = df[filter][MShr3_col_list]
MShr3_df_total["answered"] = [
"Y" if x > 0 else "N" for x in np.sum(MShr3_df_total.values == True, 1)
]
print_total(MShr3_df_total["answered"].value_counts().sort_index()[1])
st.plotly_chart(
gen_px_histogram(
MShr3_df,
x="option",
y="count",
nbins=None,
color="country",
color_discrete_map={
"Germany": colors[0],
"United Kingdom": colors[2],
"France": colors[5],
},
labels={"count": "people who work<br>for this medium"},
marginal=None,
),
use_container_width=True,
config=chart_config,
)
# =======================================================================
st.write(
"### Within the past year, did you have enough time to cover surveillance by intelligence agencies? `[MShr4]`"
)
answered_by("media")
MShr4_counts = df[filter]["MShr4"].value_counts().sort_index()
print_total(MShr4_counts.sum())
st.plotly_chart(
gen_go_pie(
labels=MShr4_counts.sort_index().index,
values=MShr4_counts.sort_index().values,
),
use_container_width=True,
config=chart_config,
)
# ===========================================================================
# Resources > Expertise
# ===========================================================================
if selected_section == "Resources > Expertise":
st.write("# Resources > Expertise")
st.write(
"### How many years have you spent working on surveillance by intelligence agencies? `[expertise1]`"
)
expertise1_counts = df[filter]["expertise1"].value_counts()
print_total(expertise1_counts.sum())
st.plotly_chart(
gen_px_histogram(
df[filter],
x="expertise1",
y=None,
nbins=20,
color="country",
color_discrete_map={
"Germany": colors[0],
"France": colors[2],
"United Kingdom": colors[5],
},
labels={"expertise1": "years"},
),
use_container_width=True,
config=chart_config,
)
st.plotly_chart(
gen_px_box(
df=df[filter],
points="all",
x="country",
y="expertise1",
color="country",
color_discrete_map={
"Germany": colors[0],
"France": colors[2],
"United Kingdom": colors[5],
},
labels={"expertise1": "years"},
),
use_container_width=True,
config=chart_config,
)
# =======================================================================
st.write(
"### How do you assess your level of expertise concerning the **legal** aspects of surveillance by intelligence agencies? `[expertise2]`"
)
expertise2_counts = df[filter]["expertise2"].value_counts().sort_index()
print_total(expertise2_counts.sum())
st.plotly_chart(
gen_go_pie(
labels=expertise2_counts.sort_index().index,
values=expertise2_counts.sort_index().values,
),
use_container_width=True,
config=chart_config,
)
# =======================================================================
st.write(
"### How do you assess your level of expertise concerning the **political** aspects of surveillance by intelligence agencies `[expertise3]`?"
)
expertise3_counts = df[filter]["expertise3"].value_counts().sort_index()
print_total(expertise3_counts.sum())
st.plotly_chart(
gen_go_pie(
labels=expertise3_counts.sort_index().index,
values=expertise3_counts.sort_index().values,
),
use_container_width=True,