Skip to content

Commit

Permalink
Merge pull request #11 from rewire5-io/feature/v1.9.0
Browse files Browse the repository at this point in the history
Feature/v1.9.0
  • Loading branch information
edersoncorbari authored Apr 1, 2023
2 parents d562b2d + 935118e commit 64f1955
Show file tree
Hide file tree
Showing 15 changed files with 287 additions and 99 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2022 Neural7
Copyright (c) 2022-2023 ReWire5

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 2 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ name = "pypi"
[dev-packages]
coverage = "*"
plotext = "*"
black = "*"
isort = "*"

[requires]
python_version = "3.10"
2 changes: 1 addition & 1 deletion RELEASES.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<img src="https://raw.githubusercontent.com/rewire5-io/five-factor-e/main/doc/rewire5-io.png" align="right" width="80" height="70"/>
<img src="https://raw.githubusercontent.com/rewire5-io/five-factor-e/main/doc/rewire5.png" align="right" width="80" height="70"/>

### Releases 🎈

Expand Down
2 changes: 1 addition & 1 deletion data/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,6 @@ from ipipneo import IpipNeo
IpipNeo(question=120, test=True).compute(sex="M", age=40, answers=answers120, compare=True)
```

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).
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).

Thanks!
Binary file modified doc/big-five-rewire5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
38 changes: 31 additions & 7 deletions ipipneo/facet.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@

from enum import IntEnum

from ipipneo.model import FacetLevel, FacetScale, NormCubic, NormScale, QuestionNumber
from ipipneo.model import (FacetLevel, FacetScale, NormCubic, NormScale,
QuestionNumber)
from ipipneo.utility import big5_ocean_is_valid, create_big5_dict


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

try:
for i in range(1, 7):
N[i] = 50 + (10 * (b5.get("N")[i] - norm.get("ns")[i + 10]) / norm.get("ns")[i + 16])
E[i] = 50 + (10 * (b5.get("E")[i] - norm.get("ns")[i + 22]) / norm.get("ns")[i + 28])
O[i] = 50 + (10 * (b5.get("O")[i] - norm.get("ns")[i + 34]) / norm.get("ns")[i + 40])
A[i] = 50 + (10 * (b5.get("A")[i] - norm.get("ns")[i + 46]) / norm.get("ns")[i + 52])
C[i] = 50 + (10 * (b5.get("C")[i] - norm.get("ns")[i + 58]) / norm.get("ns")[i + 64])
N[i] = 50 + (
10
* (b5.get("N")[i] - norm.get("ns")[i + 10])
/ norm.get("ns")[i + 16]
)
E[i] = 50 + (
10
* (b5.get("E")[i] - norm.get("ns")[i + 22])
/ norm.get("ns")[i + 28]
)
O[i] = 50 + (
10
* (b5.get("O")[i] - norm.get("ns")[i + 34])
/ norm.get("ns")[i + 40]
)
A[i] = 50 + (
10
* (b5.get("A")[i] - norm.get("ns")[i + 46])
/ norm.get("ns")[i + 52]
)
C[i] = 50 + (
10
* (b5.get("C")[i] - norm.get("ns")[i + 58])
/ norm.get("ns")[i + 64]
)
except IndexError as e:
raise BaseException(f"The number of questions setting is wrong: {str(e)}")

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

if traits[i] < FacetLevel.LOW.value:
Y[i] = "low"
if traits[i] >= FacetLevel.LOW.value and traits[i] <= FacetLevel.HIGH.value:
if (
traits[i] >= FacetLevel.LOW.value
and traits[i] <= FacetLevel.HIGH.value
):
Y[i] = "average"
if traits[i] > FacetLevel.HIGH.value:
Y[i] = "high"
Expand Down
11 changes: 4 additions & 7 deletions ipipneo/ipipneo.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,10 @@
from ipipneo.facet import Facet
from ipipneo.model import QuestionNumber
from ipipneo.norm import Norm
from ipipneo.reverse import ReverseScored120, ReverseScored300, ReverseScoredCustom
from ipipneo.utility import (
organize_list_json,
raise_if_age_is_invalid,
raise_if_sex_is_invalid,
add_dict_footer,
)
from ipipneo.reverse import (ReverseScored120, ReverseScored300,
ReverseScoredCustom)
from ipipneo.utility import (add_dict_footer, organize_list_json,
raise_if_age_is_invalid, raise_if_sex_is_invalid)


class IpipNeo(Facet):
Expand Down
81 changes: 66 additions & 15 deletions ipipneo/quiz.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
sys.path.insert(0, "../")
from ipipneo.ipipneo import IpipNeo

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


def load_ipip_questions(lang: int, question: int) -> dict:
Expand Down Expand Up @@ -55,7 +57,10 @@ def get_questions(lang: int, question: int) -> list:
- lang: The language ID.
- question: Inventory model 120 or 300.
"""
return [x for x in load_ipip_questions(lang=lang, question=question).get("questions", [])]
return [
x
for x in load_ipip_questions(lang=lang, question=question).get("questions", [])
]


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

result = IpipNeo(question=inventory).compute(sex=sex, age=age, answers={"answers": answers}, compare=True)
result = IpipNeo(question=inventory).compute(
sex=sex, age=age, answers={"answers": answers}, compare=True
)

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

print(
"\nInventory:",
str(result.get("model")) + "-" + str(result.get("question")) + " v" + str(result.get("version")),
str(result.get("model"))
+ "-"
+ str(result.get("question"))
+ " v"
+ str(result.get("version")),
)
print("Case:", result.get("id"))
print("Gender:", result.get("person").get("sex"))
Expand All @@ -164,7 +175,12 @@ def plot_results(result: dict) -> None:
int(big5[2].get("extraversion").get("traits")[1].get("gregariousness")),
int(big5[2].get("extraversion").get("traits")[2].get("assertiveness")),
int(big5[2].get("extraversion").get("traits")[3].get("activity_level")),
int(big5[2].get("extraversion").get("traits")[4].get("excitement_seeking")),
int(
big5[2]
.get("extraversion")
.get("traits")[4]
.get("excitement_seeking")
),
int(big5[2].get("extraversion").get("traits")[5].get("cheerfulness")),
],
width=100,
Expand Down Expand Up @@ -218,12 +234,36 @@ def plot_results(result: dict) -> None:
C,
[
int(big5[1].get("conscientiousness").get("C")),
int(big5[1].get("conscientiousness").get("traits")[0].get("self_efficacy")),
int(big5[1].get("conscientiousness").get("traits")[1].get("orderliness")),
int(big5[1].get("conscientiousness").get("traits")[2].get("dutifulness")),
int(big5[1].get("conscientiousness").get("traits")[3].get("achievement_striving")),
int(big5[1].get("conscientiousness").get("traits")[4].get("self_discipline")),
int(big5[1].get("conscientiousness").get("traits")[5].get("cautiousness")),
int(
big5[1]
.get("conscientiousness")
.get("traits")[0]
.get("self_efficacy")
),
int(
big5[1].get("conscientiousness").get("traits")[1].get("orderliness")
),
int(
big5[1].get("conscientiousness").get("traits")[2].get("dutifulness")
),
int(
big5[1]
.get("conscientiousness")
.get("traits")[3]
.get("achievement_striving")
),
int(
big5[1]
.get("conscientiousness")
.get("traits")[4]
.get("self_discipline")
),
int(
big5[1]
.get("conscientiousness")
.get("traits")[5]
.get("cautiousness")
),
],
width=100,
title="Big-Five | Consciousness",
Expand All @@ -250,7 +290,12 @@ def plot_results(result: dict) -> None:
int(big5[4].get("neuroticism").get("traits")[0].get("anxiety")),
int(big5[4].get("neuroticism").get("traits")[1].get("anger")),
int(big5[4].get("neuroticism").get("traits")[2].get("depression")),
int(big5[4].get("neuroticism").get("traits")[3].get("self_consciousness")),
int(
big5[4]
.get("neuroticism")
.get("traits")[3]
.get("self_consciousness")
),
int(big5[4].get("neuroticism").get("traits")[4].get("immoderation")),
int(big5[4].get("neuroticism").get("traits")[5].get("vulnerability")),
],
Expand Down Expand Up @@ -323,9 +368,13 @@ def main() -> None:

print("\n====================================================================")
if inventory == 120:
print("The following test contains 120 questions which is estimated to take you about 15 minutes to complete!")
print(
"The following test contains 120 questions which is estimated to take you about 15 minutes to complete!"
)
elif inventory == 300:
print("The following test contains 300 questions which is estimated to take you about 35 minutes to complete!")
print(
"The following test contains 300 questions which is estimated to take you about 35 minutes to complete!"
)

replies = map(
input,
Expand Down Expand Up @@ -364,7 +413,9 @@ def main() -> None:
input,
chain(
["\n> Choose the language of the questions above: "],
repeat("Please, only the numbers that are on the list are valid! Try again: "),
repeat(
"Please, only the numbers that are on the list are valid! Try again: "
),
),
)
lang = int(next(filter(set(map(str, range(0, 3))).__contains__, replies)))
Expand Down
34 changes: 28 additions & 6 deletions ipipneo/reverse.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,10 +252,16 @@ def __new__(self, answers: dict) -> dict or BaseException or AssertionError:
raise BaseException("The key named (reverse_scored) was not found!")

def is_reversed_custom(x: dict) -> dict:
x["id_select"] = reverse_scored(select=x["id_select"]) if x.get("reverse_scored") == 1 else x["id_select"]
x["id_select"] = (
reverse_scored(select=x["id_select"])
if x.get("reverse_scored") == 1
else x["id_select"]
)
return x

return {"answers": [is_reversed_custom(x=x) for x in answers.get("answers", [])]}
return {
"answers": [is_reversed_custom(x=x) for x in answers.get("answers", [])]
}


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

assert len(list(IPIP_NEO_ITEMS_REVERSED_120)) == 55, "The number of reverse items should be 55!"
assert (
len(list(IPIP_NEO_ITEMS_REVERSED_120)) == 55
), "The number of reverse items should be 55!"

def is_reversed_120(x: int, y: int) -> int:
for i in IPIP_NEO_ITEMS_REVERSED_120:
Expand All @@ -294,7 +302,13 @@ def is_reversed_120(x: int, y: int) -> int:
return y

update = map(
(lambda x: (x.__setitem__("id_select", is_reversed_120(x["id_question"], x["id_select"])))),
(
lambda x: (
x.__setitem__(
"id_select", is_reversed_120(x["id_question"], x["id_select"])
)
)
),
answers.get("answers"),
)
assert len(list(update)) == 120, "The update number should be 120!"
Expand Down Expand Up @@ -329,7 +343,9 @@ def __new__(self, answers: dict) -> dict or BaseException or AssertionError:
if not any("id_select" in x for x in answers.get("answers", [])):
raise BaseException("The key named (id_select) was not found!")

assert len(list(IPIP_NEO_ITEMS_REVERSED_300)) == 148, "The number of reverse items should be 148!"
assert (
len(list(IPIP_NEO_ITEMS_REVERSED_300)) == 148
), "The number of reverse items should be 148!"

def is_reversed_300(x: int, y: int) -> int:
for i in IPIP_NEO_ITEMS_REVERSED_300:
Expand All @@ -338,7 +354,13 @@ def is_reversed_300(x: int, y: int) -> int:
return y

update = map(
(lambda x: (x.__setitem__("id_select", is_reversed_300(x["id_question"], x["id_select"])))),
(
lambda x: (
x.__setitem__(
"id_select", is_reversed_300(x["id_question"], x["id_select"])
)
)
),
answers.get("answers"),
)
assert len(list(update)) == 300, "The update number should be 300!"
Expand Down
15 changes: 7 additions & 8 deletions ipipneo/utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,8 @@
from datetime import datetime
from enum import Enum

from ipipneo.model import (
Big5Agreeableness,
Big5Conscientiousness,
Big5Extraversion,
Big5Neuroticism,
Big5Openness,
)
from ipipneo.model import (Big5Agreeableness, Big5Conscientiousness,
Big5Extraversion, Big5Neuroticism, Big5Openness)


def raise_if_sex_is_invalid(sex: str) -> bool or AssertionError or BaseException:
Expand Down Expand Up @@ -155,7 +150,9 @@ def big5_target(label: str) -> Enum or BaseException:
Args:
- label: The acronym for the Big-Five standard O.C.E.A.N.
"""
if big5_ocean_is_valid(label=label):
big5_ocean_is_valid(label=label)

try:
if label == "O":
return Big5Openness
if label == "C":
Expand All @@ -166,6 +163,8 @@ def big5_target(label: str) -> Enum or BaseException:
return Big5Agreeableness
if label == "N":
return Big5Neuroticism
except BaseException:
raise BaseException("The Big-Five label is invalid!")


def create_big5_dict(label: str, big5: float, x: list, y: list) -> dict:
Expand Down
7 changes: 7 additions & 0 deletions run-build
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,15 @@ clean_pypi()
echo "Ok."
}

code_style()
{
black ipipneo/*.py && isort ipipneo/*.py
black test/*.py && isort test/*.py
}

while [[ "$#" -gt 0 ]]; do
case ${1} in
-s|--style) code_style;;
-p|--pypi) create_pypi;;
-c|--clean) clean_pypi;;
*) echo "Unknown parameter!"; exit 1;;
Expand Down
Loading

0 comments on commit 64f1955

Please sign in to comment.