Skip to content
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

Generalised Review System Milestone 2: Cron job to automatically accept suggestions after a threshold #5155

Merged
merged 8 commits into from
Jul 12, 2018

Conversation

nithusha21
Copy link
Contributor

@nithusha21 nithusha21 commented Jun 26, 2018

Explanation

This PR implements a cron job that will accept all suggestions which were last updated before a threshold time (i.e. no activity has occurred on them).

PTAL @anmolshkl. Thanks!

Checklist

  • The PR title starts with "Fix #bugnum: ", followed by a short, clear summary of the changes.
  • The PR explanation includes the words "Fixes #bugnum: ...".
  • The linter/Karma presubmit checks have passed.
    • These should run automatically, but if not, you can manually trigger them locally using python scripts/pre_commit_linter.py and bash scripts/run_frontend_tests.sh.
  • The PR is made from a branch that's not called "develop".
  • The PR follows the style guide.
  • The PR is assigned to an appropriate reviewer.
    • If you're a new contributor, please ask on Gitter for someone to assign a reviewer.
    • If you're not sure who the appropriate reviewer is, please assign to the issue's "owner" -- see the "talk-to" label on the issue.

@nithusha21 nithusha21 requested a review from anmolshkl June 26, 2018 12:51
Copy link
Contributor

@anmolshkl anmolshkl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nithusha21 added a few comments, PTAL!

@@ -178,6 +183,19 @@ def create_message(
new_status = thread.status
thread.put()

# We do a put on the suggestion linked to the thread, if any so that the
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps - We do a put on the suggestion linked (if it exists) to the thread so that the....

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@@ -178,6 +183,19 @@ def create_message(
new_status = thread.status
thread.put()

# We do a put on the suggestion linked to the thread, if any so that the
# last_updated time changes to show that there is activity in the thread.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How would registering an activity on the thread help?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So my idea was that we accept suggestions which have no activity on them. By activity I mean any conversation basically. So if someone messages on a feedback thread linked to a suggestion, I want to update the last updated time of the suggestion too. Does this clarify the question?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding on... If people are discussing about a suggestion, we don't want to auto-approve it right? If no one is discussing, and no action is being taken, then we can safely assume no activity is there and then we can accept the suggestion.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, that makes sense. Thanks!

@@ -225,3 +225,9 @@ def test_get_suggestions_by_target_id(self):
.get_suggestions_by_target_id(
suggestion_models.TARGET_TYPE_EXPLORATION, 'exp_invalid')),
0)

def test_get_all_stale_suggestions(self):
with self.swap(suggestion_models, 'THRESHOLD_TIME_BEFORE_ACCEPT', 0):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Um we can do better. When we say 0, we are actually not testing the logic which takes a time delta and subtracts it from the current time. It is also fine if the delay is a few msecs only.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so you mean put about 10 msec or something like that instead of 0?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a separate test that checks with the actual value and returns an empty list. This makes sure that the subtraction logic works fine. Is this fine?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, unless you are asserting the actual time calculated, you won't know if it is correct or not. One way to verify could be to retrieve a suggestion just before that calculated time or you could abstract that functionality into a method and test that method separately.

@@ -72,6 +74,12 @@
# The delimiter to be used in score category field.
SCORE_CATEGORY_DELIMITER = '.'

# Threshold time after which suggestion is considered stale and auto-accepted.
THRESHOLD_TIME_BEFORE_ACCEPT = 14 * 24 * 60 * 60 * 1000
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we running this weekly or bi-weekly?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am actually not sure.. Open for your opinion here. It feels weird that I put the threshold as 14 days while the cron job runs weekly. I think weekly is good? (If so i'll make this 7*....) What do you say?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made it weekly. If you feel otherwise, we'll change it.

@codecov-io
Copy link

codecov-io commented Jun 26, 2018

Codecov Report

Merging #5155 into develop will decrease coverage by 0.21%.
The diff coverage is n/a.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #5155      +/-   ##
===========================================
- Coverage    47.49%   47.27%   -0.22%     
===========================================
  Files          441      457      +16     
  Lines        25537    26671    +1134     
  Branches      4019     4162     +143     
===========================================
+ Hits         12129    12609     +480     
- Misses       13408    14062     +654
Impacted Files Coverage Δ
...mplates/dev/head/pages/story_editor/StoryEditor.js 15.38% <0%> (-59.62%) ⬇️
...re/templates/dev/head/services/RteHelperService.js 67.5% <0%> (-18.22%) ⬇️
...s/schema_editors/SchemaBasedHtmlEditorDirective.js 16.66% <0%> (-16.67%) ⬇️
...ead/domain/topic/EditableTopicBackendApiService.js 61.29% <0%> (-13.22%) ⬇️
...templates/dev/head/components/forms/FormBuilder.js 37.19% <0%> (-12.81%) ⬇️
...r/editor_tab/UnresolvedAnswersOverviewDirective.js 2.15% <0%> (-11.19%) ⬇️
...ead/domain/story/EditableStoryBackendApiService.js 92.5% <0%> (-7.5%) ⬇️
...head/pages/topic_editor/TopicEditorStateService.js 86.45% <0%> (-6.31%) ⬇️
core/templates/dev/head/filters.js 66.91% <0%> (-2.44%) ⬇️
...ploration_editor/feedback_tab/ThreadDataService.js 23.57% <0%> (-1.16%) ⬇️
... and 52 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 70a244a...d4ae46e. Read the comment docs.

def get(self):
"""Handles get requests."""
suggestions = suggestion_services.get_all_stale_suggestions()
print suggestions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should drop this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -72,6 +74,12 @@
# The delimiter to be used in score category field.
SCORE_CATEGORY_DELIMITER = '.'

# Threshold time after which suggestion is considered stale and auto-accepted.
THRESHOLD_TIME_BEFORE_ACCEPT = 7 * 24 * 60 * 60 * 1000
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Name of constant should include units.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. I added MSECS. I checked other locations and they had it in the short form too. MILLISECONDS would make the variable name too big I feel :)

THRESHOLD_TIME_BEFORE_ACCEPT = 7 * 24 * 60 * 60 * 1000

# The default message to be shown when accepting stale suggestions.
DEFAULT_SUGGESTION_ACCEPT_MESSAGE = 'Accepting suggestion due to inactivity.'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Message is not clear -- whose inactivity?

"Automatically accepting suggestion after X days." would be better. Make sure X is a named constant which gets interpolated and that it is also used in THRESHOLD_TIME_BEFORE_ACCEPT.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@@ -63,7 +63,7 @@ def create_suggestion(
if target_type == suggestion_models.TARGET_TYPE_EXPLORATION:
thread_id = feedback_services.create_thread(
target_id, None, author_id, description,
DEFAULT_SUGGESTION_THREAD_SUBJECT)
DEFAULT_SUGGESTION_THREAD_SUBJECT, True)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If an arg has a default value, the name of the arg should be specified in caller functions. /cc @apb7 @kevinlee12

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@acl_decorators.can_perform_cron_tasks
def get(self):
"""Handles get requests."""
suggestions = suggestion_services.get_all_stale_suggestions()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a boolean flag in feconf (ENABLE_AUTO_ACCEPT_OF_SUGGESTIONS) that's set to False by default. We'll turn it on to True for the deployment. But I think we should have a mechanism to turn this off easily if we see issues in practice.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@nithusha21
Copy link
Contributor Author

Hi @seanlip, could you take another pass on this PR?

Copy link
Member

@seanlip seanlip left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Looks fine from codeowner perspective.

@@ -112,6 +112,12 @@ indexes:
- name: exploration_id
- name: last_updated

- kind: GeneralSuggestionModel
properties:
- name: deleted
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure why "deleted" is in here? If you remove this stanza and rerun on dev server, does this get autogenerated exactly the way it is now?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was auto generated. Will try again and let you know.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just confirmed. So I deleted these lines, and ran the cron job and these lines got added back. Looking around this file a few of the other models also had "deleted". But I have no idea on why "deleted" is being added here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm OK, no idea either. But happy to merge! Thanks for confirming.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@seanlip seanlip merged commit bd31875 into oppia:develop Jul 12, 2018
@nithusha21 nithusha21 deleted the suggestions-cron-job branch July 12, 2018 04:52
seanlip pushed a commit that referenced this pull request Jul 12, 2018
…pt suggestions after a threshold (#5155)

* added cron job to accept suggestions weekly

* fixed linting

* updated last_updated field whenever a message is sent to the thread

* linting fixed

* review changes

* linting fixes and minor change

* remove print

* review changes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants