Skip to content

Commit 64f1955

Browse files
Merge pull request #11 from rewire5-io/feature/v1.9.0
Feature/v1.9.0
2 parents d562b2d + 935118e commit 64f1955

15 files changed

Lines changed: 287 additions & 99 deletions

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2022 Neural7
3+
Copyright (c) 2022-2023 ReWire5
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

Pipfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ name = "pypi"
88
[dev-packages]
99
coverage = "*"
1010
plotext = "*"
11+
black = "*"
12+
isort = "*"
1113

1214
[requires]
1315
python_version = "3.10"

RELEASES.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<img src="https://raw.githubusercontent.com/rewire5-io/five-factor-e/main/doc/rewire5-io.png" align="right" width="80" height="70"/>
1+
<img src="https://raw.githubusercontent.com/rewire5-io/five-factor-e/main/doc/rewire5.png" align="right" width="80" height="70"/>
22

33
### Releases 🎈
44

data/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,6 @@ from ipipneo import IpipNeo
5050
IpipNeo(question=120, test=True).compute(sex="M", age=40, answers=answers120, compare=True)
5151
```
5252

53-
If you have any questions, please send us an email to: (**e at neural.io**) or create an issue reporting the question of the problem in the repository of this project (https://github.com/rewire5-io/five-factor-e/issues).
53+
If you have any questions, please send us an email to: (**e at rewire5.io**) or create an issue reporting the question of the problem in the repository of this project (https://github.com/rewire5-io/five-factor-e/issues).
5454

5555
Thanks!

doc/big-five-rewire5.png

-16.5 KB
Loading

ipipneo/facet.py

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010

1111
from enum import IntEnum
1212

13-
from ipipneo.model import FacetLevel, FacetScale, NormCubic, NormScale, QuestionNumber
13+
from ipipneo.model import (FacetLevel, FacetScale, NormCubic, NormScale,
14+
QuestionNumber)
1415
from ipipneo.utility import big5_ocean_is_valid, create_big5_dict
1516

1617

@@ -113,11 +114,31 @@ def distrib(self, size: int, b5: dict, norm: dict) -> list:
113114

114115
try:
115116
for i in range(1, 7):
116-
N[i] = 50 + (10 * (b5.get("N")[i] - norm.get("ns")[i + 10]) / norm.get("ns")[i + 16])
117-
E[i] = 50 + (10 * (b5.get("E")[i] - norm.get("ns")[i + 22]) / norm.get("ns")[i + 28])
118-
O[i] = 50 + (10 * (b5.get("O")[i] - norm.get("ns")[i + 34]) / norm.get("ns")[i + 40])
119-
A[i] = 50 + (10 * (b5.get("A")[i] - norm.get("ns")[i + 46]) / norm.get("ns")[i + 52])
120-
C[i] = 50 + (10 * (b5.get("C")[i] - norm.get("ns")[i + 58]) / norm.get("ns")[i + 64])
117+
N[i] = 50 + (
118+
10
119+
* (b5.get("N")[i] - norm.get("ns")[i + 10])
120+
/ norm.get("ns")[i + 16]
121+
)
122+
E[i] = 50 + (
123+
10
124+
* (b5.get("E")[i] - norm.get("ns")[i + 22])
125+
/ norm.get("ns")[i + 28]
126+
)
127+
O[i] = 50 + (
128+
10
129+
* (b5.get("O")[i] - norm.get("ns")[i + 34])
130+
/ norm.get("ns")[i + 40]
131+
)
132+
A[i] = 50 + (
133+
10
134+
* (b5.get("A")[i] - norm.get("ns")[i + 46])
135+
/ norm.get("ns")[i + 52]
136+
)
137+
C[i] = 50 + (
138+
10
139+
* (b5.get("C")[i] - norm.get("ns")[i + 58])
140+
/ norm.get("ns")[i + 64]
141+
)
121142
except IndexError as e:
122143
raise BaseException(f"The number of questions setting is wrong: {str(e)}")
123144

@@ -146,7 +167,10 @@ def personality(self, size: int, big5: dict, traits: dict, label: str) -> dict:
146167

147168
if traits[i] < FacetLevel.LOW.value:
148169
Y[i] = "low"
149-
if traits[i] >= FacetLevel.LOW.value and traits[i] <= FacetLevel.HIGH.value:
170+
if (
171+
traits[i] >= FacetLevel.LOW.value
172+
and traits[i] <= FacetLevel.HIGH.value
173+
):
150174
Y[i] = "average"
151175
if traits[i] > FacetLevel.HIGH.value:
152176
Y[i] = "high"

ipipneo/ipipneo.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,10 @@
1414
from ipipneo.facet import Facet
1515
from ipipneo.model import QuestionNumber
1616
from ipipneo.norm import Norm
17-
from ipipneo.reverse import ReverseScored120, ReverseScored300, ReverseScoredCustom
18-
from ipipneo.utility import (
19-
organize_list_json,
20-
raise_if_age_is_invalid,
21-
raise_if_sex_is_invalid,
22-
add_dict_footer,
23-
)
17+
from ipipneo.reverse import (ReverseScored120, ReverseScored300,
18+
ReverseScoredCustom)
19+
from ipipneo.utility import (add_dict_footer, organize_list_json,
20+
raise_if_age_is_invalid, raise_if_sex_is_invalid)
2421

2522

2623
class IpipNeo(Facet):

ipipneo/quiz.py

Lines changed: 66 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@
2020
sys.path.insert(0, "../")
2121
from ipipneo.ipipneo import IpipNeo
2222

23-
URL_IPIP_QUESTIONS = "https://raw.githubusercontent.com/neural7/five-factor-e/main/data/IPIP-NEO"
23+
URL_IPIP_QUESTIONS = (
24+
"https://raw.githubusercontent.com/rewire5-io/five-factor-e/main/data/IPIP-NEO"
25+
)
2426

2527

2628
def load_ipip_questions(lang: int, question: int) -> dict:
@@ -55,7 +57,10 @@ def get_questions(lang: int, question: int) -> list:
5557
- lang: The language ID.
5658
- question: Inventory model 120 or 300.
5759
"""
58-
return [x for x in load_ipip_questions(lang=lang, question=question).get("questions", [])]
60+
return [
61+
x
62+
for x in load_ipip_questions(lang=lang, question=question).get("questions", [])
63+
]
5964

6065

6166
def get_select(lang: int, question: int) -> list:
@@ -113,7 +118,9 @@ def quiz(inventory: int, sex: str, age: int, shuffle: str, lang: int) -> None:
113118
option = int(next(filter({"1", "2", "3", "4", "5"}.__contains__, replies)))
114119
answers.append({"id_question": q.get("id"), "id_select": option})
115120

116-
result = IpipNeo(question=inventory).compute(sex=sex, age=age, answers={"answers": answers}, compare=True)
121+
result = IpipNeo(question=inventory).compute(
122+
sex=sex, age=age, answers={"answers": answers}, compare=True
123+
)
117124

118125
object = json.dumps(result, indent=4)
119126
fname = f"result-{str(inventory)}-{result.get('id', 'id')}.json"
@@ -140,7 +147,11 @@ def plot_results(result: dict) -> None:
140147

141148
print(
142149
"\nInventory:",
143-
str(result.get("model")) + "-" + str(result.get("question")) + " v" + str(result.get("version")),
150+
str(result.get("model"))
151+
+ "-"
152+
+ str(result.get("question"))
153+
+ " v"
154+
+ str(result.get("version")),
144155
)
145156
print("Case:", result.get("id"))
146157
print("Gender:", result.get("person").get("sex"))
@@ -164,7 +175,12 @@ def plot_results(result: dict) -> None:
164175
int(big5[2].get("extraversion").get("traits")[1].get("gregariousness")),
165176
int(big5[2].get("extraversion").get("traits")[2].get("assertiveness")),
166177
int(big5[2].get("extraversion").get("traits")[3].get("activity_level")),
167-
int(big5[2].get("extraversion").get("traits")[4].get("excitement_seeking")),
178+
int(
179+
big5[2]
180+
.get("extraversion")
181+
.get("traits")[4]
182+
.get("excitement_seeking")
183+
),
168184
int(big5[2].get("extraversion").get("traits")[5].get("cheerfulness")),
169185
],
170186
width=100,
@@ -218,12 +234,36 @@ def plot_results(result: dict) -> None:
218234
C,
219235
[
220236
int(big5[1].get("conscientiousness").get("C")),
221-
int(big5[1].get("conscientiousness").get("traits")[0].get("self_efficacy")),
222-
int(big5[1].get("conscientiousness").get("traits")[1].get("orderliness")),
223-
int(big5[1].get("conscientiousness").get("traits")[2].get("dutifulness")),
224-
int(big5[1].get("conscientiousness").get("traits")[3].get("achievement_striving")),
225-
int(big5[1].get("conscientiousness").get("traits")[4].get("self_discipline")),
226-
int(big5[1].get("conscientiousness").get("traits")[5].get("cautiousness")),
237+
int(
238+
big5[1]
239+
.get("conscientiousness")
240+
.get("traits")[0]
241+
.get("self_efficacy")
242+
),
243+
int(
244+
big5[1].get("conscientiousness").get("traits")[1].get("orderliness")
245+
),
246+
int(
247+
big5[1].get("conscientiousness").get("traits")[2].get("dutifulness")
248+
),
249+
int(
250+
big5[1]
251+
.get("conscientiousness")
252+
.get("traits")[3]
253+
.get("achievement_striving")
254+
),
255+
int(
256+
big5[1]
257+
.get("conscientiousness")
258+
.get("traits")[4]
259+
.get("self_discipline")
260+
),
261+
int(
262+
big5[1]
263+
.get("conscientiousness")
264+
.get("traits")[5]
265+
.get("cautiousness")
266+
),
227267
],
228268
width=100,
229269
title="Big-Five | Consciousness",
@@ -250,7 +290,12 @@ def plot_results(result: dict) -> None:
250290
int(big5[4].get("neuroticism").get("traits")[0].get("anxiety")),
251291
int(big5[4].get("neuroticism").get("traits")[1].get("anger")),
252292
int(big5[4].get("neuroticism").get("traits")[2].get("depression")),
253-
int(big5[4].get("neuroticism").get("traits")[3].get("self_consciousness")),
293+
int(
294+
big5[4]
295+
.get("neuroticism")
296+
.get("traits")[3]
297+
.get("self_consciousness")
298+
),
254299
int(big5[4].get("neuroticism").get("traits")[4].get("immoderation")),
255300
int(big5[4].get("neuroticism").get("traits")[5].get("vulnerability")),
256301
],
@@ -323,9 +368,13 @@ def main() -> None:
323368

324369
print("\n====================================================================")
325370
if inventory == 120:
326-
print("The following test contains 120 questions which is estimated to take you about 15 minutes to complete!")
371+
print(
372+
"The following test contains 120 questions which is estimated to take you about 15 minutes to complete!"
373+
)
327374
elif inventory == 300:
328-
print("The following test contains 300 questions which is estimated to take you about 35 minutes to complete!")
375+
print(
376+
"The following test contains 300 questions which is estimated to take you about 35 minutes to complete!"
377+
)
329378

330379
replies = map(
331380
input,
@@ -364,7 +413,9 @@ def main() -> None:
364413
input,
365414
chain(
366415
["\n> Choose the language of the questions above: "],
367-
repeat("Please, only the numbers that are on the list are valid! Try again: "),
416+
repeat(
417+
"Please, only the numbers that are on the list are valid! Try again: "
418+
),
368419
),
369420
)
370421
lang = int(next(filter(set(map(str, range(0, 3))).__contains__, replies)))

ipipneo/reverse.py

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -252,10 +252,16 @@ def __new__(self, answers: dict) -> dict or BaseException or AssertionError:
252252
raise BaseException("The key named (reverse_scored) was not found!")
253253

254254
def is_reversed_custom(x: dict) -> dict:
255-
x["id_select"] = reverse_scored(select=x["id_select"]) if x.get("reverse_scored") == 1 else x["id_select"]
255+
x["id_select"] = (
256+
reverse_scored(select=x["id_select"])
257+
if x.get("reverse_scored") == 1
258+
else x["id_select"]
259+
)
256260
return x
257261

258-
return {"answers": [is_reversed_custom(x=x) for x in answers.get("answers", [])]}
262+
return {
263+
"answers": [is_reversed_custom(x=x) for x in answers.get("answers", [])]
264+
}
259265

260266

261267
class ReverseScored120:
@@ -285,7 +291,9 @@ def __new__(self, answers: dict) -> dict or BaseException or AssertionError:
285291
if not any("id_select" in x for x in answers.get("answers", [])):
286292
raise BaseException("The key named (id_select) was not found!")
287293

288-
assert len(list(IPIP_NEO_ITEMS_REVERSED_120)) == 55, "The number of reverse items should be 55!"
294+
assert (
295+
len(list(IPIP_NEO_ITEMS_REVERSED_120)) == 55
296+
), "The number of reverse items should be 55!"
289297

290298
def is_reversed_120(x: int, y: int) -> int:
291299
for i in IPIP_NEO_ITEMS_REVERSED_120:
@@ -294,7 +302,13 @@ def is_reversed_120(x: int, y: int) -> int:
294302
return y
295303

296304
update = map(
297-
(lambda x: (x.__setitem__("id_select", is_reversed_120(x["id_question"], x["id_select"])))),
305+
(
306+
lambda x: (
307+
x.__setitem__(
308+
"id_select", is_reversed_120(x["id_question"], x["id_select"])
309+
)
310+
)
311+
),
298312
answers.get("answers"),
299313
)
300314
assert len(list(update)) == 120, "The update number should be 120!"
@@ -329,7 +343,9 @@ def __new__(self, answers: dict) -> dict or BaseException or AssertionError:
329343
if not any("id_select" in x for x in answers.get("answers", [])):
330344
raise BaseException("The key named (id_select) was not found!")
331345

332-
assert len(list(IPIP_NEO_ITEMS_REVERSED_300)) == 148, "The number of reverse items should be 148!"
346+
assert (
347+
len(list(IPIP_NEO_ITEMS_REVERSED_300)) == 148
348+
), "The number of reverse items should be 148!"
333349

334350
def is_reversed_300(x: int, y: int) -> int:
335351
for i in IPIP_NEO_ITEMS_REVERSED_300:
@@ -338,7 +354,13 @@ def is_reversed_300(x: int, y: int) -> int:
338354
return y
339355

340356
update = map(
341-
(lambda x: (x.__setitem__("id_select", is_reversed_300(x["id_question"], x["id_select"])))),
357+
(
358+
lambda x: (
359+
x.__setitem__(
360+
"id_select", is_reversed_300(x["id_question"], x["id_select"])
361+
)
362+
)
363+
),
342364
answers.get("answers"),
343365
)
344366
assert len(list(update)) == 300, "The update number should be 300!"

ipipneo/utility.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,8 @@
1111
from datetime import datetime
1212
from enum import Enum
1313

14-
from ipipneo.model import (
15-
Big5Agreeableness,
16-
Big5Conscientiousness,
17-
Big5Extraversion,
18-
Big5Neuroticism,
19-
Big5Openness,
20-
)
14+
from ipipneo.model import (Big5Agreeableness, Big5Conscientiousness,
15+
Big5Extraversion, Big5Neuroticism, Big5Openness)
2116

2217

2318
def raise_if_sex_is_invalid(sex: str) -> bool or AssertionError or BaseException:
@@ -155,7 +150,9 @@ def big5_target(label: str) -> Enum or BaseException:
155150
Args:
156151
- label: The acronym for the Big-Five standard O.C.E.A.N.
157152
"""
158-
if big5_ocean_is_valid(label=label):
153+
big5_ocean_is_valid(label=label)
154+
155+
try:
159156
if label == "O":
160157
return Big5Openness
161158
if label == "C":
@@ -166,6 +163,8 @@ def big5_target(label: str) -> Enum or BaseException:
166163
return Big5Agreeableness
167164
if label == "N":
168165
return Big5Neuroticism
166+
except BaseException:
167+
raise BaseException("The Big-Five label is invalid!")
169168

170169

171170
def create_big5_dict(label: str, big5: float, x: list, y: list) -> dict:

0 commit comments

Comments
 (0)