-
Notifications
You must be signed in to change notification settings - Fork 45
Add meta-review to gamification #190
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,12 +4,14 @@ | |
MergeRequest, | ||
Issue, | ||
) | ||
from data.newcomers import active_newcomers | ||
from gamification.process.activity_points import ( | ||
get_activity_with_points | ||
) | ||
from gamification.labels import NEGATIVE_POINT_LABELS | ||
from gamification.data.points import MERGE_REQUEST_CLOSED_WITHOUT_MERGE | ||
from gamification.models import Participant | ||
from meta_review.models import Reaction, Participant as meta_review_participants | ||
|
||
|
||
def get_mr_objects(): | ||
|
@@ -135,6 +137,45 @@ def get_participant_objects(): | |
return participants | ||
|
||
|
||
def get_meta_review_participant_objects(): | ||
return meta_review_participants.objects.all() | ||
|
||
|
||
meta_review_completed_list = [] | ||
|
||
|
||
def update_participants_data_with_meta_review(meta_review_participant): | ||
""" | ||
Update participants based on meta-review | ||
|
||
This method updates every participant based on the meta-review | ||
received or given. If the meta-review participant is | ||
in the active newcomers list then it will check if the meta-review | ||
is complete or not and update the activity accordingly. | ||
""" | ||
active_newcomers_list = active_newcomers() | ||
if (meta_review_participant.login in active_newcomers_list and | ||
meta_review_participant.login not in meta_review_completed_list): | ||
# Get the corresponding gamification participant | ||
gamification_participant = Participant.objects.get( | ||
username=meta_review_participant.login) | ||
reaction = Reaction.objects.get(id=meta_review_participant.login) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is definitely wrong. I checked the output you print out https://pastebin.com/6X6y5Kfx. You have the illusion that this works, because your test is wrong. In your test, both participant and reaction share the same id (primary_key), which gives you the wrong belief that you are correct. That's why I said you should run There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @li-boxuan Thanks for your valuable input. Can you please tell me what do I need to do in order to fix this? This thing is taking way much more time than I expected to. 😞 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. First you need to fix the test case. See #190 (comment) so that your test won't pass (which is good coz now you know your code is wrong). Then read the definition of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In order to test things, I used my user handle test_meta_review_participant = meta_review_participant.objects.get(login='shikharvaish28')
reaction = Reaction.objects.get(id=test_meta_review_participant.login) Instead, I am getting Since PS: I'm running these commands in django shell to get a gist of things. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Your assumption is wrong. Django does not work like that. I strongly recommend you to read https://docs.djangoproject.com/en/2.1/topics/db/queries/, esepecially understand how Foreign Key works. |
||
if (meta_review_participant.pos_in > 0 or | ||
meta_review_participant.pos_out > 0 or | ||
meta_review_participant.neg_in > 0 or | ||
meta_review_participant.neg_out > 0): | ||
# Add a meta-review activity to the participant | ||
activity = 'Did a meta-review or received a meta-review' | ||
created_at = reaction.created_at | ||
updated_at = None | ||
gamification_participant.add_activity(0, activity, created_at, | ||
updated_at) | ||
shikharvaish28 marked this conversation as resolved.
Show resolved
Hide resolved
shikharvaish28 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
meta_review_completed_list.append(meta_review_participant.login) | ||
logger = logging.getLogger(__name__) | ||
logger.info(meta_review_participant.login, | ||
' has completed the meta-review activity') | ||
|
||
|
||
def award_badges(participant): | ||
activities = participant.activities.values('name') | ||
participant.add_badges(activities) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
from django.test import TestCase | ||
|
||
from data.newcomers import active_newcomers | ||
|
||
from gamification.models import ( | ||
Activity, | ||
Level, | ||
|
@@ -8,6 +10,12 @@ | |
Participant, | ||
) | ||
|
||
from gamification.process.update import ( | ||
update_participants_data_with_meta_review | ||
) | ||
|
||
from meta_review.models import Reaction, Participant as meta_review_participant | ||
|
||
|
||
class ActivityModelTest(TestCase): | ||
|
||
|
@@ -341,3 +349,64 @@ def test_add_badges_method(self): | |
|
||
# After applying add_badge method | ||
self.assertEquals(test_participant.badges.count(), 0) | ||
|
||
def test_update_participants_data_with_meta_review_complete(self): | ||
# Test the participant who has completed the meta-review activity | ||
active_newcomers_list = active_newcomers() | ||
active_newcomers_list.extend(['test2', 'test3']) | ||
# meta-review participant | ||
meta_review_participant.objects.create(login='test2') | ||
test_meta_review_participant = meta_review_participant.objects.get( | ||
shikharvaish28 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
login='test2') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unnecessary. |
||
|
||
Reaction.objects.create(id='test2') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well, this is definitely inappropriate and prone to error. You are creating a reaction with id also equals to |
||
reaction = Reaction.objects.get( | ||
id=test_meta_review_participant.login) | ||
# corresponding gamification participant for 'test2' | ||
Participant.objects.create(username='test2') | ||
test_gamification_participant = Participant.objects.get( | ||
username='test2') | ||
|
||
test_meta_review_participant.pos_in = 2 | ||
reaction.created_at = '2018-10-25 14:30:59' | ||
# Before applying update_participants_data_with_meta_review method | ||
self.assertEquals(test_gamification_participant.activities.count(), 0) | ||
# After applying update_participants_data_with_meta_review method | ||
update_participants_data_with_meta_review(test_meta_review_participant) | ||
self.assertEquals(test_gamification_participant.activities.count(), 1) | ||
shikharvaish28 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
self.assertEquals( | ||
test_gamification_participant.activities.all()[0].name, | ||
'Did a meta-review or received a meta-review') | ||
# Check if multiple activities are not adding up for the same | ||
# participant 'test2' already has meta-review added so check | ||
# if activity is not added again | ||
update_participants_data_with_meta_review(test_meta_review_participant) | ||
self.assertEquals(test_gamification_participant.activities.count(), 1) | ||
|
||
def test_update_participants_data_with_meta_review_incomplete(self): | ||
# Test the participant who has zero meta-review activity | ||
meta_review_participant.objects.create(login='test3') | ||
test_meta_review_participant = meta_review_participant.objects.get( | ||
login='test3') | ||
Reaction.objects.create(id='test3') | ||
reaction = Reaction.objects.get( | ||
id=test_meta_review_participant.login) | ||
# The corresponding gamification participant | ||
Participant.objects.create(username='test3') | ||
test_gamification_participant = Participant.objects.get( | ||
username='test3') | ||
|
||
reaction.created_at = '2018-10-25 14:30:59' | ||
update_participants_data_with_meta_review(test_meta_review_participant) | ||
self.assertEquals(test_gamification_participant.activities.count(), 0) | ||
|
||
# if (meta_review_participant.login in active_newcomers_list): is false | ||
meta_review_participant.objects.create(login='test4') | ||
test_meta_review_participant = meta_review_participant.objects.get( | ||
login='test4') | ||
# The corresponding gamification participant for 'test4' | ||
Participant.objects.create(username='test4') | ||
test_gamification_participant = Participant.objects.get( | ||
username='test4') | ||
update_participants_data_with_meta_review(test_meta_review_participant) | ||
self.assertEquals(test_gamification_participant.activities.count(), 0) |
Uh oh!
There was an error while loading. Please reload this page.