-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathutils.py
65 lines (52 loc) · 3.24 KB
/
utils.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
from collections import OrderedDict
free_and_fair_key_order = ["Don't know", "Not free and fair",
"Free and fair, with major problems",
"Free and fair, but with minor problems",
"Completely free and fair",
"Do not understand the question",
"metadata"]
elections_key_order = ["Don't know", "Not at all well", "Not very well",
"Well", "Very well", "metadata"]
chinas_influence_key_order = ["Don't know / Haven't heard enough",
"Very negative", "Somewhat negative",
"Neither positive nor negative",
"Somewhat positive", "Very positive",
"metadata"]
china_influence_on_economy_key_order = ["Don't know / Haven't heard enough",
"None", "Some", "A little", "A lot",
"metadata"]
mobile_phone_usage_key_order = ["Don't know", "Never",
"A few times a month", "A few times a week",
"Less than once a month", "Everyday",
"metadata"]
internet_usage_key_order = mobile_phone_usage_key_order
corruption_amongst_key_order = ["Don't know/ Haven't heard enough", "None",
"Some of them", "Most of them",
"All of them", "metadata"]
corruption_level_key_order = ["Don't know", "Decreased a lot",
"Decreased somewhat", "Stayed the same",
"Increased somewhat", "Increased a lot",
"metadata"]
pay_bribes_key_order = ["Don't know", "No contact", "Never",
"Once or Twice", "A Few times", "Often", "metadata"]
difficulty_key_order = ["Don't Know", "No contact", "Very Easy", "Easy",
"Difficult", "Very Difficult", "metadata"]
education_of_respondent_key_order = ["No formal schooling",
"Some primary schooling",
"Primary school completed",
"Some secondary school/high school",
"Secondary school/high school completed",
"Post-secondary qualifications, other than university",
"Some university", "University completed", "metadata"]
employment_status_key_order = ["No (not looking)", "No (looking)",
"Yes, part time", "Yes, full time", "metadata"]
can_people_fight_corruption_key_order = ["Don't know","Strongly Disagree", "Neither Agree Nor Diagree", "Agree", "Strongly Agree", "metadata"]
courts_make_binding_decisions_key_order = can_people_fight_corruption_key_order
people_must_obey_the_law_key_order = ["Disagree", "Neither Agree Nor Disagree", "Agree", "Strongly Agree", "metadata"]
pay_taxes_key_order = people_must_obey_the_law_key_order
def sort_keys(key_order, d):
try:
return OrderedDict(
sorted(d.items(), key=lambda i: key_order.index(i[0])))
except ValueError:
return d