{"action":"created","comment":{"url":"https://api.github.com/repos/ubc/ubcpi/pulls/comments/38777849","id":38777849,"diff_hunk":"@@ -0,0 +1,240 @@\n+import random\n+import persistence as sas_api\n+\n+\n+class UnknownChooseAnswerAlgorithm(Exception):\n+    pass\n+\n+\n+def offer_answer(pool, answer, rationale, student_id, algo):\n+    \"\"\"\n+    Answers format:\n+    {\n+        option1_index: {\n+            'student_id': { can store algorithm specific info here },\n+            ...\n+        }\n+        option2_index: ...\n+    }\n+    \"\"\"\n+    if algo['name'] == 'simple':\n+        offer_simple(pool, answer, rationale, student_id)\n+    elif algo['name'] == 'random':\n+        offer_random(pool, answer, rationale, student_id)\n+    else:\n+        raise UnknownChooseAnswerAlgorithm()\n+\n+\n+def offer_simple(pool, answer, rationale, student_id):\n+    existing = pool.setdefault(answer, {})\n+    if len(existing) >= 50:\n+        student_id_to_remove = random.choice(existing.keys())\n+        del existing[student_id_to_remove]\n+    existing[student_id] = {}\n+    pool[answer] = existing\n+\n+\n+def offer_random(pool, answer, rationale, student_id):\n+    offer_simple(pool, answer, rationale, student_id)\n+\n+\n+def validate_seeded_answers_simple(answers, options, algo):\n+    \"\"\"\n+    This validator checks if the answers includes all possible options\n+    :param answers: the answers to be checked\n+    :param options: all options that should exist in the answers\n+    :return: None if everything is good. Otherwise, the missing option error message.\n+    \"\"\"\n+    seen_options = {}\n+    for answer in answers:\n+        if answer:\n+            key = options[answer['answer']].get('text')\n+            if options[answer['answer']].get('image_url'):\n+                key += options[answer['answer']].get('image_url')\n+            seen_options.setdefault(key, 0)\n+            seen_options[key] += 1\n+\n+    missing_options = []\n+    index = 1\n+    for option in options:\n+        key = option.get('text') + option.get('image_url') if option.get('image_url') else option.get('text')\n+        if seen_options.get(key, 0) == 0:\n+            missing_options.append('Option ' + str(index))\n+        index += 1\n+\n+    if missing_options:\n+        return {'seed_error': 'Missing option seed(s): ' + ', '.join(missing_options)}\n+\n+    return None\n+\n+\n+def validate_seeded_answers_random(answers):\n+    \"\"\"\n+    This validator checks if there are a minimum of one answer\n+    :param answers: the answers to be checked\n+    :return: None if everything is good. Otherwise, the missing option error messag.\n+    \"\"\"\n+    if len(answers) < 1:\n+        return {'seed_error': 'Missing 1 option seed'}\n+\n+    return None\n+\n+\n+def validate_seeded_answers(answers, options, algo):","path":"ubcpi/answer_pool.py","position":83,"original_position":83,"commit_id":"3788422bc2c6a62513d3961f4148482a0df641e4","original_commit_id":"3788422bc2c6a62513d3961f4148482a0df641e4","user":{"login":"sarina","id":1985317,"avatar_url":"https://avatars.githubusercontent.com/u/1985317?v=3","gravatar_id":"","url":"https://api.github.com/users/sarina","html_url":"https://github.com/sarina","followers_url":"https://api.github.com/users/sarina/followers","following_url":"https://api.github.com/users/sarina/following{/other_user}","gists_url":"https://api.github.com/users/sarina/gists{/gist_id}","starred_url":"https://api.github.com/users/sarina/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sarina/subscriptions","organizations_url":"https://api.github.com/users/sarina/orgs","repos_url":"https://api.github.com/users/sarina/repos","events_url":"https://api.github.com/users/sarina/events{/privacy}","received_events_url":"https://api.github.com/users/sarina/received_events","type":"User","site_admin":false},"body":"more to the point, we don't call this when removing answers from the pool, so potentially you can end up with a pool that fails this validation check, no?","created_at":"2015-09-04T18:00:33Z","updated_at":"2015-09-04T18:00:33Z","html_url":"https://github.com/ubc/ubcpi/pull/27#discussion_r38777849","pull_request_url":"https://api.github.com/repos/ubc/ubcpi/pulls/27","_links":{"self":{"href":"https://api.github.com/repos/ubc/ubcpi/pulls/comments/38777849"},"html":{"href":"https://github.com/ubc/ubcpi/pull/27#discussion_r38777849"},"pull_request":{"href":"https://api.github.com/repos/ubc/ubcpi/pulls/27"}}},"pull_request":{"url":"https://api.github.com/repos/ubc/ubcpi/pulls/27","id":43791274,"html_url":"https://github.com/ubc/ubcpi/pull/27","diff_url":"https://github.com/ubc/ubcpi/pull/27.diff","patch_url":"https://github.com/ubc/ubcpi/pull/27.patch","issue_url":"https://api.github.com/repos/ubc/ubcpi/issues/27","number":27,"state":"open","locked":false,"title":"For Edx Review","user":{"login":"xcompass","id":465548,"avatar_url":"https://avatars.githubusercontent.com/u/465548?v=3","gravatar_id":"","url":"https://api.github.com/users/xcompass","html_url":"https://github.com/xcompass","followers_url":"https://api.github.com/users/xcompass/followers","following_url":"https://api.github.com/users/xcompass/following{/other_user}","gists_url":"https://api.github.com/users/xcompass/gists{/gist_id}","starred_url":"https://api.github.com/users/xcompass/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/xcompass/subscriptions","organizations_url":"https://api.github.com/users/xcompass/orgs","repos_url":"https://api.github.com/users/xcompass/repos","events_url":"https://api.github.com/users/xcompass/events{/privacy}","received_events_url":"https://api.github.com/users/xcompass/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-08-31T18:02:21Z","updated_at":"2015-09-04T18:00:33Z","closed_at":null,"merged_at":null,"merge_commit_sha":"27de32e126f8242f35da2b1d38e12bd4138fb220","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/ubc/ubcpi/pulls/27/commits","review_comments_url":"https://api.github.com/repos/ubc/ubcpi/pulls/27/comments","review_comment_url":"https://api.github.com/repos/ubc/ubcpi/pulls/comments{/number}","comments_url":"https://api.github.com/repos/ubc/ubcpi/issues/27/comments","statuses_url":"https://api.github.com/repos/ubc/ubcpi/statuses/3788422bc2c6a62513d3961f4148482a0df641e4","head":{"label":"ubc:master","ref":"master","sha":"3788422bc2c6a62513d3961f4148482a0df641e4","user":{"login":"ubc","id":1396118,"avatar_url":"https://avatars.githubusercontent.com/u/1396118?v=3","gravatar_id":"","url":"https://api.github.com/users/ubc","html_url":"https://github.com/ubc","followers_url":"https://api.github.com/users/ubc/followers","following_url":"https://api.github.com/users/ubc/following{/other_user}","gists_url":"https://api.github.com/users/ubc/gists{/gist_id}","starred_url":"https://api.github.com/users/ubc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ubc/subscriptions","organizations_url":"https://api.github.com/users/ubc/orgs","repos_url":"https://api.github.com/users/ubc/repos","events_url":"https://api.github.com/users/ubc/events{/privacy}","received_events_url":"https://api.github.com/users/ubc/received_events","type":"Organization","site_admin":false},"repo":{"id":30939095,"name":"ubcpi","full_name":"ubc/ubcpi","owner":{"login":"ubc","id":1396118,"avatar_url":"https://avatars.githubusercontent.com/u/1396118?v=3","gravatar_id":"","url":"https://api.github.com/users/ubc","html_url":"https://github.com/ubc","followers_url":"https://api.github.com/users/ubc/followers","following_url":"https://api.github.com/users/ubc/following{/other_user}","gists_url":"https://api.github.com/users/ubc/gists{/gist_id}","starred_url":"https://api.github.com/users/ubc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ubc/subscriptions","organizations_url":"https://api.github.com/users/ubc/orgs","repos_url":"https://api.github.com/users/ubc/repos","events_url":"https://api.github.com/users/ubc/events{/privacy}","received_events_url":"https://api.github.com/users/ubc/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/ubc/ubcpi","description":"Peer Instruction XBlock","fork":false,"url":"https://api.github.com/repos/ubc/ubcpi","forks_url":"https://api.github.com/repos/ubc/ubcpi/forks","keys_url":"https://api.github.com/repos/ubc/ubcpi/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ubc/ubcpi/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ubc/ubcpi/teams","hooks_url":"https://api.github.com/repos/ubc/ubcpi/hooks","issue_events_url":"https://api.github.com/repos/ubc/ubcpi/issues/events{/number}","events_url":"https://api.github.com/repos/ubc/ubcpi/events","assignees_url":"https://api.github.com/repos/ubc/ubcpi/assignees{/user}","branches_url":"https://api.github.com/repos/ubc/ubcpi/branches{/branch}","tags_url":"https://api.github.com/repos/ubc/ubcpi/tags","blobs_url":"https://api.github.com/repos/ubc/ubcpi/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ubc/ubcpi/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ubc/ubcpi/git/refs{/sha}","trees_url":"https://api.github.com/repos/ubc/ubcpi/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ubc/ubcpi/statuses/{sha}","languages_url":"https://api.github.com/repos/ubc/ubcpi/languages","stargazers_url":"https://api.github.com/repos/ubc/ubcpi/stargazers","contributors_url":"https://api.github.com/repos/ubc/ubcpi/contributors","subscribers_url":"https://api.github.com/repos/ubc/ubcpi/subscribers","subscription_url":"https://api.github.com/repos/ubc/ubcpi/subscription","commits_url":"https://api.github.com/repos/ubc/ubcpi/commits{/sha}","git_commits_url":"https://api.github.com/repos/ubc/ubcpi/git/commits{/sha}","comments_url":"https://api.github.com/repos/ubc/ubcpi/comments{/number}","issue_comment_url":"https://api.github.com/repos/ubc/ubcpi/issues/comments{/number}","contents_url":"https://api.github.com/repos/ubc/ubcpi/contents/{+path}","compare_url":"https://api.github.com/repos/ubc/ubcpi/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ubc/ubcpi/merges","archive_url":"https://api.github.com/repos/ubc/ubcpi/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ubc/ubcpi/downloads","issues_url":"https://api.github.com/repos/ubc/ubcpi/issues{/number}","pulls_url":"https://api.github.com/repos/ubc/ubcpi/pulls{/number}","milestones_url":"https://api.github.com/repos/ubc/ubcpi/milestones{/number}","notifications_url":"https://api.github.com/repos/ubc/ubcpi/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ubc/ubcpi/labels{/name}","releases_url":"https://api.github.com/repos/ubc/ubcpi/releases{/id}","created_at":"2015-02-17T21:37:02Z","updated_at":"2015-08-10T05:46:07Z","pushed_at":"2015-08-31T18:02:21Z","git_url":"git://github.com/ubc/ubcpi.git","ssh_url":"git@github.com:ubc/ubcpi.git","clone_url":"https://github.com/ubc/ubcpi.git","svn_url":"https://github.com/ubc/ubcpi","homepage":null,"size":1248,"stargazers_count":1,"watchers_count":1,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":11,"forks":0,"open_issues":11,"watchers":1,"default_branch":"master"}},"base":{"label":"ubc:init","ref":"init","sha":"731496e08215a895c5e808db08a46b7889fbf290","user":{"login":"ubc","id":1396118,"avatar_url":"https://avatars.githubusercontent.com/u/1396118?v=3","gravatar_id":"","url":"https://api.github.com/users/ubc","html_url":"https://github.com/ubc","followers_url":"https://api.github.com/users/ubc/followers","following_url":"https://api.github.com/users/ubc/following{/other_user}","gists_url":"https://api.github.com/users/ubc/gists{/gist_id}","starred_url":"https://api.github.com/users/ubc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ubc/subscriptions","organizations_url":"https://api.github.com/users/ubc/orgs","repos_url":"https://api.github.com/users/ubc/repos","events_url":"https://api.github.com/users/ubc/events{/privacy}","received_events_url":"https://api.github.com/users/ubc/received_events","type":"Organization","site_admin":false},"repo":{"id":30939095,"name":"ubcpi","full_name":"ubc/ubcpi","owner":{"login":"ubc","id":1396118,"avatar_url":"https://avatars.githubusercontent.com/u/1396118?v=3","gravatar_id":"","url":"https://api.github.com/users/ubc","html_url":"https://github.com/ubc","followers_url":"https://api.github.com/users/ubc/followers","following_url":"https://api.github.com/users/ubc/following{/other_user}","gists_url":"https://api.github.com/users/ubc/gists{/gist_id}","starred_url":"https://api.github.com/users/ubc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ubc/subscriptions","organizations_url":"https://api.github.com/users/ubc/orgs","repos_url":"https://api.github.com/users/ubc/repos","events_url":"https://api.github.com/users/ubc/events{/privacy}","received_events_url":"https://api.github.com/users/ubc/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/ubc/ubcpi","description":"Peer Instruction XBlock","fork":false,"url":"https://api.github.com/repos/ubc/ubcpi","forks_url":"https://api.github.com/repos/ubc/ubcpi/forks","keys_url":"https://api.github.com/repos/ubc/ubcpi/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ubc/ubcpi/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ubc/ubcpi/teams","hooks_url":"https://api.github.com/repos/ubc/ubcpi/hooks","issue_events_url":"https://api.github.com/repos/ubc/ubcpi/issues/events{/number}","events_url":"https://api.github.com/repos/ubc/ubcpi/events","assignees_url":"https://api.github.com/repos/ubc/ubcpi/assignees{/user}","branches_url":"https://api.github.com/repos/ubc/ubcpi/branches{/branch}","tags_url":"https://api.github.com/repos/ubc/ubcpi/tags","blobs_url":"https://api.github.com/repos/ubc/ubcpi/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ubc/ubcpi/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ubc/ubcpi/git/refs{/sha}","trees_url":"https://api.github.com/repos/ubc/ubcpi/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ubc/ubcpi/statuses/{sha}","languages_url":"https://api.github.com/repos/ubc/ubcpi/languages","stargazers_url":"https://api.github.com/repos/ubc/ubcpi/stargazers","contributors_url":"https://api.github.com/repos/ubc/ubcpi/contributors","subscribers_url":"https://api.github.com/repos/ubc/ubcpi/subscribers","subscription_url":"https://api.github.com/repos/ubc/ubcpi/subscription","commits_url":"https://api.github.com/repos/ubc/ubcpi/commits{/sha}","git_commits_url":"https://api.github.com/repos/ubc/ubcpi/git/commits{/sha}","comments_url":"https://api.github.com/repos/ubc/ubcpi/comments{/number}","issue_comment_url":"https://api.github.com/repos/ubc/ubcpi/issues/comments{/number}","contents_url":"https://api.github.com/repos/ubc/ubcpi/contents/{+path}","compare_url":"https://api.github.com/repos/ubc/ubcpi/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ubc/ubcpi/merges","archive_url":"https://api.github.com/repos/ubc/ubcpi/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ubc/ubcpi/downloads","issues_url":"https://api.github.com/repos/ubc/ubcpi/issues{/number}","pulls_url":"https://api.github.com/repos/ubc/ubcpi/pulls{/number}","milestones_url":"https://api.github.com/repos/ubc/ubcpi/milestones{/number}","notifications_url":"https://api.github.com/repos/ubc/ubcpi/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ubc/ubcpi/labels{/name}","releases_url":"https://api.github.com/repos/ubc/ubcpi/releases{/id}","created_at":"2015-02-17T21:37:02Z","updated_at":"2015-08-10T05:46:07Z","pushed_at":"2015-08-31T18:02:21Z","git_url":"git://github.com/ubc/ubcpi.git","ssh_url":"git@github.com:ubc/ubcpi.git","clone_url":"https://github.com/ubc/ubcpi.git","svn_url":"https://github.com/ubc/ubcpi","homepage":null,"size":1248,"stargazers_count":1,"watchers_count":1,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":11,"forks":0,"open_issues":11,"watchers":1,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/ubc/ubcpi/pulls/27"},"html":{"href":"https://github.com/ubc/ubcpi/pull/27"},"issue":{"href":"https://api.github.com/repos/ubc/ubcpi/issues/27"},"comments":{"href":"https://api.github.com/repos/ubc/ubcpi/issues/27/comments"},"review_comments":{"href":"https://api.github.com/repos/ubc/ubcpi/pulls/27/comments"},"review_comment":{"href":"https://api.github.com/repos/ubc/ubcpi/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/ubc/ubcpi/pulls/27/commits"},"statuses":{"href":"https://api.github.com/repos/ubc/ubcpi/statuses/3788422bc2c6a62513d3961f4148482a0df641e4"}}}}