-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sourcery refactored master branch #6
base: master
Are you sure you want to change the base?
Conversation
if question_type == 'shortanswer' or question_type == 'numerical' or question_type == 'multichoice' or question_type == 'truefalse': | ||
if question_type in [ | ||
'shortanswer', | ||
'numerical', | ||
'multichoice', | ||
'truefalse', | ||
]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function AnswersDB.add_user_answer
refactored with the following changes:
- Replace multiple comparisons of same variable with
in
operator [×2] (merge-comparisons
) - Merge else clause's nested if statement into elif (
merge-else-if-into-elif
) - Replace if statement with if expression (
assign-if-exp
)
This removes the following comments ( why? ):
# если пользователь не отпралял этот вариант ответа
if await AnswersDB.find_question_by_ans(conn, question, answer, session) is None: | ||
return await conn[DATABASE_NAME][QUESTIONS_COLLECTION_NAME].find_one_and_update( | ||
return ( | ||
await conn[DATABASE_NAME][ | ||
QUESTIONS_COLLECTION_NAME | ||
].find_one_and_update( | ||
{'question': question}, | ||
{'$push': {'answers': {'answer': answer, 'users': [], 'correct': [ | ||
user_info], 'not_correct': []}}}, {"_id": 0}, | ||
return_document=ReturnDocument.AFTER, session=session | ||
) | ||
else: | ||
return await conn[DATABASE_NAME][QUESTIONS_COLLECTION_NAME].find_one_and_update( | ||
{'question': question, 'answers.answer': answer}, | ||
{'$push': {'answers.$.correct': user_info}}, {"_id": 0}, | ||
return_document=ReturnDocument.AFTER, session=session | ||
{ | ||
'$push': { | ||
'answers': { | ||
'answer': answer, | ||
'users': [], | ||
'correct': [user_info], | ||
'not_correct': [], | ||
} | ||
} | ||
}, | ||
{"_id": 0}, | ||
return_document=ReturnDocument.AFTER, | ||
session=session, | ||
) | ||
else: | ||
if await AnswersDB.find_question_by_ans(conn, question, answer, session) is None: | ||
return await conn[DATABASE_NAME][QUESTIONS_COLLECTION_NAME].find_one_and_update( | ||
{'question': question}, | ||
{'$push': {'answers': {'answer': answer, 'users': [], | ||
'correct': [], 'not_correct': [user_info]}}}, {"_id": 0}, | ||
return_document=ReturnDocument.AFTER, session=session | ||
if await AnswersDB.find_question_by_ans( | ||
conn, question, answer, session | ||
) | ||
else: | ||
return await conn[DATABASE_NAME][QUESTIONS_COLLECTION_NAME].find_one_and_update( | ||
is None | ||
else await conn[DATABASE_NAME][ | ||
QUESTIONS_COLLECTION_NAME | ||
].find_one_and_update( | ||
{'question': question, 'answers.answer': answer}, | ||
{'$push': {'answers.$.not_correct': user_info}}, {"_id": 0}, | ||
return_document=ReturnDocument.AFTER, session=session | ||
{'$push': {'answers.$.correct': user_info}}, | ||
{"_id": 0}, | ||
return_document=ReturnDocument.AFTER, | ||
session=session, | ||
) | ||
) | ||
|
||
if await AnswersDB.find_question_by_ans(conn, question, answer, session) is None: | ||
return await conn[DATABASE_NAME][QUESTIONS_COLLECTION_NAME].find_one_and_update( | ||
{'question': question}, | ||
{'$push': {'answers': {'answer': answer, 'users': [], | ||
'correct': [], 'not_correct': [user_info]}}}, {"_id": 0}, | ||
return_document=ReturnDocument.AFTER, session=session | ||
) | ||
else: | ||
return await conn[DATABASE_NAME][QUESTIONS_COLLECTION_NAME].find_one_and_update( | ||
{'question': question, 'answers.answer': answer}, | ||
{'$push': {'answers.$.not_correct': user_info}}, {"_id": 0}, | ||
return_document=ReturnDocument.AFTER, session=session | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function AnswersDB.add_user_approve
refactored with the following changes:
- Remove unnecessary else after guard condition (
remove-unnecessary-else
) - Replace if statement with if expression (
assign-if-exp
)
if user_info not in question_db['viewers']: | ||
document = await conn[DATABASE_NAME][QUESTIONS_COLLECTION_NAME].find_one_and_update( | ||
{'question': question}, { | ||
'$push': {'viewers': user_info}}, | ||
{"_id": 0}, return_document=ReturnDocument.AFTER, session=session | ||
) | ||
return document | ||
else: | ||
if user_info in question_db['viewers']: | ||
return question_db | ||
document = await conn[DATABASE_NAME][QUESTIONS_COLLECTION_NAME].find_one_and_update( | ||
{'question': question}, { | ||
'$push': {'viewers': user_info}}, | ||
{"_id": 0}, return_document=ReturnDocument.AFTER, session=session | ||
) | ||
return document |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function AnswersDB.add_new_viewer
refactored with the following changes:
- Swap if/else branches (
swap-if-else-branches
) - Remove unnecessary else after guard condition (
remove-unnecessary-else
)
if answer_['subquestion'] == answer[0] and answer_['answer'] == answer[1]: | ||
if user_info in answer_['users']: | ||
if ( | ||
answer_['subquestion'] == answer[0] | ||
and answer_['answer'] == answer[1] | ||
and user_info in answer_['users'] | ||
): | ||
return True | ||
elif answer_['answer'] == answer: | ||
for user in answer_['users']: | ||
if user == user_info: | ||
return True | ||
else: | ||
if answer_['answer'] == answer: | ||
for user in answer_['users']: | ||
if user == user_info: | ||
return True |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function AnswersDB.is_user_send_answer
refactored with the following changes:
- Merge else clause's nested if statement into elif (
merge-else-if-into-elif
) - Merge nested if conditions (
merge-nested-ifs
)
if isinstance(data['answer'], list): | ||
if len(data['answer']) == 2: | ||
data['answer'] = 0 | ||
if isinstance(data['answer'], list) and len(data['answer']) == 2: | ||
data['answer'] = 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function add_approve
refactored with the following changes:
- Merge nested if conditions (
merge-nested-ifs
)
Branch
master
refactored by Sourcery.If you're happy with these changes, merge this Pull Request using the Squash and merge strategy.
See our documentation here.
Run Sourcery locally
Reduce the feedback loop during development by using the Sourcery editor plugin:
Review changes via command line
To manually merge these changes, make sure you're on the
master
branch, then run:Help us improve this pull request!