{"action":"created","comment":{"url":"https://api.github.com/repos/usgo/online-ratings/pulls/comments/94280322","pull_request_review_id":14810170,"id":94280322,"diff_hunk":"@@ -22,42 +23,59 @@ def sanitized_games(games):\n     print(\"Cleaning games...\")\n     for g in games:\n         if g.white.user_id is None or g.black.user_id is None:\n-            print('  ', g) #should probably strip them.\n+            print('No ids        :  ', g) #should probably strip them from the db.\n+            pass\n         elif g.handicap > 1 and (-1 > g.komi > 1):\n-            print('  ', g)\n+            #print('bad komi      :  ', g)\n+            pass\n         elif g.handicap > 6:\n             continue\n         elif g.komi < 0 or g.komi > 8.6:\n-            print('  ', g)\n-        elif not (g.result.startswith('W+') or g.result.startswith('B+')):\n-            print('  ', g)\n+            #print('bad komi      :  ', g)\n+            pass\n+        elif not (g.result.startswith('W') or g.result.startswith('B')):\n+            print('unknown result:  ', g)\n+            pass\n         else:\n-            # Vector of result_tuples.  Just what we need to compute stuff...\n-            g_vec.append( (g.white.user_id, \n-                         g.black.user_id,\n+            # Vector of result_tuples.  Just what we need to compute ratings...\n+            g_vec.append( (g.white.id, \n+                         g.black.id,\n                          1.0 if g.result.startswith('W') else 0.0,\n                          g.date_played,\n                          g.handicap,\n                          g.komi)) \n     return g_vec \n \n-def rate_all():\n-    games = Game.query.all() \n-    users = sanitized_users(games)\n+def rate_all(t_from=None, t_to=None, iters=200, lam=.22):\n+    \"\"\"\n+    t_from -- datetime obj, rate all games after this \n+    t_to -- datetime obj, rate all games up to this\n+    iters -- number of iterations\n+    lam -- 'neighborhood pull' parameter.  higher = more error from moving a rank away from ranks in its neighborhood\n+    \"\"\"\n+    if t_to is None:\n+        t_to = datetime.datetime.now()\n+    if t_from is None:\n+        t_from = datetime.datetime.utcfromtimestamp(1.0)\n+    games = Game.query.filter(Game.date_played < t_to, Game.date_played > t_from) \n     g_vec = sanitized_games(games)\n+    users = sanitized_users(g_vec)\n+\n+    aga_ids_to_uids = dict([(u.aga_id, u.id) for u in users])\n+\n+    print(\"found %d users with %d valid games\" % (len(users), len(g_vec)) )\n \n-    ratings = {u.id: u.last_rating() for u in users}\n-    rating_prior = {u: v.rating if (v and v.rating) else 0 for u,v in ratings.items()} \n+    ratings = {int(u.aga_id): u.last_rating() for u in users}\n+    rating_prior = {id: v.rating if (v and v.rating) else 20 for id,v in ratings.items()} \n \n-    neighbors = rm.neighbors(games)\n-    neighbor_avgs = rm.compute_avgs(games, rating_prior) \n+    neighbors = rm.neighbors(g_vec)\n+    neighbor_avgs = rm.compute_avgs(g_vec, rating_prior) \n \n-    t_min = min(games, key=lambda g: g.date_played or datetime.datetime.now()).date_played\n-    t_max = max(games, key=lambda g: g.date_played or datetime.datetime.now()).date_played\n+    t_min = min(g_vec, key=lambda g: g[3] or datetime.datetime.now())[3]","path":"web/scripts/rate_all.py","position":93,"original_position":93,"commit_id":"bf00e5c89ecf586b898417036577928bde642785","original_commit_id":"bf00e5c89ecf586b898417036577928bde642785","user":{"login":"brilee","id":1320214,"avatar_url":"https://avatars.githubusercontent.com/u/1320214?v=3","gravatar_id":"","url":"https://api.github.com/users/brilee","html_url":"https://github.com/brilee","followers_url":"https://api.github.com/users/brilee/followers","following_url":"https://api.github.com/users/brilee/following{/other_user}","gists_url":"https://api.github.com/users/brilee/gists{/gist_id}","starred_url":"https://api.github.com/users/brilee/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/brilee/subscriptions","organizations_url":"https://api.github.com/users/brilee/orgs","repos_url":"https://api.github.com/users/brilee/repos","events_url":"https://api.github.com/users/brilee/events{/privacy}","received_events_url":"https://api.github.com/users/brilee/received_events","type":"User","site_admin":false},"body":"move the default datetime.datetime.now() up into `sanitize_games`?","created_at":"2017-01-01T06:10:08Z","updated_at":"2017-01-01T06:27:09Z","html_url":"https://github.com/usgo/online-ratings/pull/80#discussion_r94280322","pull_request_url":"https://api.github.com/repos/usgo/online-ratings/pulls/80","_links":{"self":{"href":"https://api.github.com/repos/usgo/online-ratings/pulls/comments/94280322"},"html":{"href":"https://github.com/usgo/online-ratings/pull/80#discussion_r94280322"},"pull_request":{"href":"https://api.github.com/repos/usgo/online-ratings/pulls/80"}}},"pull_request":{"url":"https://api.github.com/repos/usgo/online-ratings/pulls/80","id":99817911,"html_url":"https://github.com/usgo/online-ratings/pull/80","diff_url":"https://github.com/usgo/online-ratings/pull/80.diff","patch_url":"https://github.com/usgo/online-ratings/pull/80.patch","issue_url":"https://api.github.com/repos/usgo/online-ratings/issues/80","number":80,"state":"closed","locked":false,"title":"Rate command","user":{"login":"brilee","id":1320214,"avatar_url":"https://avatars.githubusercontent.com/u/1320214?v=3","gravatar_id":"","url":"https://api.github.com/users/brilee","html_url":"https://github.com/brilee","followers_url":"https://api.github.com/users/brilee/followers","following_url":"https://api.github.com/users/brilee/following{/other_user}","gists_url":"https://api.github.com/users/brilee/gists{/gist_id}","starred_url":"https://api.github.com/users/brilee/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/brilee/subscriptions","organizations_url":"https://api.github.com/users/brilee/orgs","repos_url":"https://api.github.com/users/brilee/repos","events_url":"https://api.github.com/users/brilee/events{/privacy}","received_events_url":"https://api.github.com/users/brilee/received_events","type":"User","site_admin":false},"body":"","created_at":"2017-01-01T05:09:20Z","updated_at":"2017-01-01T06:27:09Z","closed_at":"2017-01-01T06:22:14Z","merged_at":"2017-01-01T06:22:14Z","merge_commit_sha":"cdf2b6914482c3022439409bc98b463ea09b11f0","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/usgo/online-ratings/pulls/80/commits","review_comments_url":"https://api.github.com/repos/usgo/online-ratings/pulls/80/comments","review_comment_url":"https://api.github.com/repos/usgo/online-ratings/pulls/comments{/number}","comments_url":"https://api.github.com/repos/usgo/online-ratings/issues/80/comments","statuses_url":"https://api.github.com/repos/usgo/online-ratings/statuses/bf00e5c89ecf586b898417036577928bde642785","head":{"label":"usgo:rate-command","ref":"rate-command","sha":"bf00e5c89ecf586b898417036577928bde642785","user":{"login":"usgo","id":510953,"avatar_url":"https://avatars.githubusercontent.com/u/510953?v=3","gravatar_id":"","url":"https://api.github.com/users/usgo","html_url":"https://github.com/usgo","followers_url":"https://api.github.com/users/usgo/followers","following_url":"https://api.github.com/users/usgo/following{/other_user}","gists_url":"https://api.github.com/users/usgo/gists{/gist_id}","starred_url":"https://api.github.com/users/usgo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/usgo/subscriptions","organizations_url":"https://api.github.com/users/usgo/orgs","repos_url":"https://api.github.com/users/usgo/repos","events_url":"https://api.github.com/users/usgo/events{/privacy}","received_events_url":"https://api.github.com/users/usgo/received_events","type":"Organization","site_admin":false},"repo":{"id":22080451,"name":"online-ratings","full_name":"usgo/online-ratings","owner":{"login":"usgo","id":510953,"avatar_url":"https://avatars.githubusercontent.com/u/510953?v=3","gravatar_id":"","url":"https://api.github.com/users/usgo","html_url":"https://github.com/usgo","followers_url":"https://api.github.com/users/usgo/followers","following_url":"https://api.github.com/users/usgo/following{/other_user}","gists_url":"https://api.github.com/users/usgo/gists{/gist_id}","starred_url":"https://api.github.com/users/usgo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/usgo/subscriptions","organizations_url":"https://api.github.com/users/usgo/orgs","repos_url":"https://api.github.com/users/usgo/repos","events_url":"https://api.github.com/users/usgo/events{/privacy}","received_events_url":"https://api.github.com/users/usgo/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/usgo/online-ratings","description":"AGA Online Ratings protocol and implementation","fork":false,"url":"https://api.github.com/repos/usgo/online-ratings","forks_url":"https://api.github.com/repos/usgo/online-ratings/forks","keys_url":"https://api.github.com/repos/usgo/online-ratings/keys{/key_id}","collaborators_url":"https://api.github.com/repos/usgo/online-ratings/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/usgo/online-ratings/teams","hooks_url":"https://api.github.com/repos/usgo/online-ratings/hooks","issue_events_url":"https://api.github.com/repos/usgo/online-ratings/issues/events{/number}","events_url":"https://api.github.com/repos/usgo/online-ratings/events","assignees_url":"https://api.github.com/repos/usgo/online-ratings/assignees{/user}","branches_url":"https://api.github.com/repos/usgo/online-ratings/branches{/branch}","tags_url":"https://api.github.com/repos/usgo/online-ratings/tags","blobs_url":"https://api.github.com/repos/usgo/online-ratings/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/usgo/online-ratings/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/usgo/online-ratings/git/refs{/sha}","trees_url":"https://api.github.com/repos/usgo/online-ratings/git/trees{/sha}","statuses_url":"https://api.github.com/repos/usgo/online-ratings/statuses/{sha}","languages_url":"https://api.github.com/repos/usgo/online-ratings/languages","stargazers_url":"https://api.github.com/repos/usgo/online-ratings/stargazers","contributors_url":"https://api.github.com/repos/usgo/online-ratings/contributors","subscribers_url":"https://api.github.com/repos/usgo/online-ratings/subscribers","subscription_url":"https://api.github.com/repos/usgo/online-ratings/subscription","commits_url":"https://api.github.com/repos/usgo/online-ratings/commits{/sha}","git_commits_url":"https://api.github.com/repos/usgo/online-ratings/git/commits{/sha}","comments_url":"https://api.github.com/repos/usgo/online-ratings/comments{/number}","issue_comment_url":"https://api.github.com/repos/usgo/online-ratings/issues/comments{/number}","contents_url":"https://api.github.com/repos/usgo/online-ratings/contents/{+path}","compare_url":"https://api.github.com/repos/usgo/online-ratings/compare/{base}...{head}","merges_url":"https://api.github.com/repos/usgo/online-ratings/merges","archive_url":"https://api.github.com/repos/usgo/online-ratings/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/usgo/online-ratings/downloads","issues_url":"https://api.github.com/repos/usgo/online-ratings/issues{/number}","pulls_url":"https://api.github.com/repos/usgo/online-ratings/pulls{/number}","milestones_url":"https://api.github.com/repos/usgo/online-ratings/milestones{/number}","notifications_url":"https://api.github.com/repos/usgo/online-ratings/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/usgo/online-ratings/labels{/name}","releases_url":"https://api.github.com/repos/usgo/online-ratings/releases{/id}","deployments_url":"https://api.github.com/repos/usgo/online-ratings/deployments","created_at":"2014-07-21T21:13:44Z","updated_at":"2016-12-21T16:32:41Z","pushed_at":"2017-01-01T06:22:15Z","git_url":"git://github.com/usgo/online-ratings.git","ssh_url":"git@github.com:usgo/online-ratings.git","clone_url":"https://github.com/usgo/online-ratings.git","svn_url":"https://github.com/usgo/online-ratings","homepage":null,"size":499,"stargazers_count":18,"watchers_count":18,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":11,"mirror_url":null,"open_issues_count":16,"forks":11,"open_issues":16,"watchers":18,"default_branch":"master"}},"base":{"label":"usgo:master","ref":"master","sha":"251c43ba51ec038c7884fdf978e58fffb0ca205d","user":{"login":"usgo","id":510953,"avatar_url":"https://avatars.githubusercontent.com/u/510953?v=3","gravatar_id":"","url":"https://api.github.com/users/usgo","html_url":"https://github.com/usgo","followers_url":"https://api.github.com/users/usgo/followers","following_url":"https://api.github.com/users/usgo/following{/other_user}","gists_url":"https://api.github.com/users/usgo/gists{/gist_id}","starred_url":"https://api.github.com/users/usgo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/usgo/subscriptions","organizations_url":"https://api.github.com/users/usgo/orgs","repos_url":"https://api.github.com/users/usgo/repos","events_url":"https://api.github.com/users/usgo/events{/privacy}","received_events_url":"https://api.github.com/users/usgo/received_events","type":"Organization","site_admin":false},"repo":{"id":22080451,"name":"online-ratings","full_name":"usgo/online-ratings","owner":{"login":"usgo","id":510953,"avatar_url":"https://avatars.githubusercontent.com/u/510953?v=3","gravatar_id":"","url":"https://api.github.com/users/usgo","html_url":"https://github.com/usgo","followers_url":"https://api.github.com/users/usgo/followers","following_url":"https://api.github.com/users/usgo/following{/other_user}","gists_url":"https://api.github.com/users/usgo/gists{/gist_id}","starred_url":"https://api.github.com/users/usgo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/usgo/subscriptions","organizations_url":"https://api.github.com/users/usgo/orgs","repos_url":"https://api.github.com/users/usgo/repos","events_url":"https://api.github.com/users/usgo/events{/privacy}","received_events_url":"https://api.github.com/users/usgo/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/usgo/online-ratings","description":"AGA Online Ratings protocol and implementation","fork":false,"url":"https://api.github.com/repos/usgo/online-ratings","forks_url":"https://api.github.com/repos/usgo/online-ratings/forks","keys_url":"https://api.github.com/repos/usgo/online-ratings/keys{/key_id}","collaborators_url":"https://api.github.com/repos/usgo/online-ratings/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/usgo/online-ratings/teams","hooks_url":"https://api.github.com/repos/usgo/online-ratings/hooks","issue_events_url":"https://api.github.com/repos/usgo/online-ratings/issues/events{/number}","events_url":"https://api.github.com/repos/usgo/online-ratings/events","assignees_url":"https://api.github.com/repos/usgo/online-ratings/assignees{/user}","branches_url":"https://api.github.com/repos/usgo/online-ratings/branches{/branch}","tags_url":"https://api.github.com/repos/usgo/online-ratings/tags","blobs_url":"https://api.github.com/repos/usgo/online-ratings/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/usgo/online-ratings/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/usgo/online-ratings/git/refs{/sha}","trees_url":"https://api.github.com/repos/usgo/online-ratings/git/trees{/sha}","statuses_url":"https://api.github.com/repos/usgo/online-ratings/statuses/{sha}","languages_url":"https://api.github.com/repos/usgo/online-ratings/languages","stargazers_url":"https://api.github.com/repos/usgo/online-ratings/stargazers","contributors_url":"https://api.github.com/repos/usgo/online-ratings/contributors","subscribers_url":"https://api.github.com/repos/usgo/online-ratings/subscribers","subscription_url":"https://api.github.com/repos/usgo/online-ratings/subscription","commits_url":"https://api.github.com/repos/usgo/online-ratings/commits{/sha}","git_commits_url":"https://api.github.com/repos/usgo/online-ratings/git/commits{/sha}","comments_url":"https://api.github.com/repos/usgo/online-ratings/comments{/number}","issue_comment_url":"https://api.github.com/repos/usgo/online-ratings/issues/comments{/number}","contents_url":"https://api.github.com/repos/usgo/online-ratings/contents/{+path}","compare_url":"https://api.github.com/repos/usgo/online-ratings/compare/{base}...{head}","merges_url":"https://api.github.com/repos/usgo/online-ratings/merges","archive_url":"https://api.github.com/repos/usgo/online-ratings/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/usgo/online-ratings/downloads","issues_url":"https://api.github.com/repos/usgo/online-ratings/issues{/number}","pulls_url":"https://api.github.com/repos/usgo/online-ratings/pulls{/number}","milestones_url":"https://api.github.com/repos/usgo/online-ratings/milestones{/number}","notifications_url":"https://api.github.com/repos/usgo/online-ratings/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/usgo/online-ratings/labels{/name}","releases_url":"https://api.github.com/repos/usgo/online-ratings/releases{/id}","deployments_url":"https://api.github.com/repos/usgo/online-ratings/deployments","created_at":"2014-07-21T21:13:44Z","updated_at":"2016-12-21T16:32:41Z","pushed_at":"2017-01-01T06:22:15Z","git_url":"git://github.com/usgo/online-ratings.git","ssh_url":"git@github.com:usgo/online-ratings.git","clone_url":"https://github.com/usgo/online-ratings.git","svn_url":"https://github.com/usgo/online-ratings","homepage":null,"size":499,"stargazers_count":18,"watchers_count":18,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":11,"mirror_url":null,"open_issues_count":16,"forks":11,"open_issues":16,"watchers":18,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/usgo/online-ratings/pulls/80"},"html":{"href":"https://github.com/usgo/online-ratings/pull/80"},"issue":{"href":"https://api.github.com/repos/usgo/online-ratings/issues/80"},"comments":{"href":"https://api.github.com/repos/usgo/online-ratings/issues/80/comments"},"review_comments":{"href":"https://api.github.com/repos/usgo/online-ratings/pulls/80/comments"},"review_comment":{"href":"https://api.github.com/repos/usgo/online-ratings/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/usgo/online-ratings/pulls/80/commits"},"statuses":{"href":"https://api.github.com/repos/usgo/online-ratings/statuses/bf00e5c89ecf586b898417036577928bde642785"}}}}
{"actor":{"display_login":"brilee"}}