{"action":"created","comment":{"url":"https://api.github.com/repos/RandoApp/Rando-exchanger/pulls/comments/76945265","id":76945265,"diff_hunk":"@@ -3,90 +3,43 @@ var config = require(\"config\");\n var logger = require(\"./log/logger\");\n var async = require(\"async\");\n var metrics = require(\"./metrics\");\n-var firebase = require(\"./firebase/firebase\");\n+var printService = require(\"./service/printService\");\n+var randoService = require(\"./service/randoService\");\n+var dbService = require(\"./service/dbService\");\n+var firebaseService = require(\"./service/firebaseService\");\n \n-function fetchAllRandosAsync (callback) {\n-  db.rando.getFirstN(config.exch.fetchRandosNumber, function (err, randos) {\n-    if (err) {\n-      logger.warn(\"[exchanger.fetchAllRandosAsync]\", \"Exchanger.pair: Can't get all randos: \", err);\n-      callback(err);\n-      return;\n-    }\n-\n-    logger.trace(\"[exchanger.fetchAllRandosAsync]\", \"Is randos null?\");\n-    if (!randos) {\n-      logger.debug(\"[exchanger.fetchAllRandosAsync]\", \"Randos are null. Throw Randos not found error\");\n-      callback(new Error(\"Randos not found\"));\n-      return;\n-    }\n-\n-    logger.info(\"[exchanger.fetchAllRandosAsync]\", \"Exchanger.pair: Get \", randos.length, \" randos\");\n-\n-    async.eachLimit(randos, 30, function (rando, callback) {\n-      logger.trace(\"[exchanger.fetchAllRandosAsync]\", \" Process rando: \", rando.randoId);\n-      attachUserToRando(rando, function (err) {\n-        logger.trace(\"[exchanger.fetchAllRandosAsync.attachUserToRando callback] \", \"Done\");\n-        callback(err);\n-      });\n-    }, function (err) {\n-      if (err) {\n-        logger.warn(\"[exchanger.fetchAllRandosAsync]\", \"Each done with error: \", err);\n-      } else {\n-        logger.warn(\"[exchanger.fetchAllRandosAsync]\", \"Each done successfully\");\n-      }\n-      callback(err, randos);\n-    });\n-  });\n-}\n-\n-function attachUserToRando (rando, callback) {\n-  db.user.getByEmail(rando.email, function (err, user) {\n-    if (err) {\n-      logger.debug(\"[exchanger.attachUserToRando] \", \"Error on attachUserToRando: \" + err);\n-      callback(err);\n-      return;\n-    }\n-\n-    if (user) {\n-      logger.trace(\"[exchanger.attachUserToRando] \", \"Fetched user with email: \", user.email);\n-      rando.user = user;\n-      callback(err);\n-    } else {\n-      logger.debug(\"[exchanger.attachUserToRando] \", \"User with email: \" + rando.email + \" not found\");\n-      callback(new Error(\"not found\"));\n-    }\n-  });\n-}\n+global.users = {};\n+global.randos = [];\n \n-function exchangeRandos (randos, callback) {\n+function exchangeRandos (callback) {\n   logger.info(\"[exchanger.exchangeRandos]\", \"Trying exchange randos\");\n \n-  var choosers = findAllChoosers(randos);\n-  printChooser(choosers);\n+  var choosers = randoService.findAllChoosers(global.randos);\n+  printService.printChooser(choosers);\n \n   async.eachSeries(choosers, function (chooser, done) {\n     //chooser is rando that will search other rando and put it to rando.user.in\n     logger.debug(\"[exchanger.exchangeRandos]\", \"Chooser is:\", chooser.randoId, \"of [\", chooser.email, \"]\");\n \n     logger.trace(\"[exchanger.exchangeRandos]\", \"Start calculating by metrics\");\n-    metrics.calculate(chooser, randos);\n+    metrics.calculate(chooser, global.randos);\n \n     logger.trace(\"[exchanger.exchangeRandos]\", \"Calculation is done. Print metrics\");\n-    printMetrics(randos, chooser);\n+    printService.printMetrics(global.randos, chooser);\n \n     logger.trace(\"[exchanger.exchangeRandos]\", \"Trying to select best rando\");\n-    var bestRando = selectBestRando(randos);\n+    var bestRando = randoService.selectBestRando(global.randos);\n \n-    logger.debug(\"[exchanger.exchangeRandos]\", \"Best rando:\", bestRando.randoId, \"of\", bestRando.user.email);\n+    logger.debug(\"[exchanger.exchangeRandos]\", \"Best rando:\", bestRando.randoId, \"of\", bestRando.email);\n \n     if (bestRando.mark < 0) {\n       logger.trace(\"[exchanger.exchangeRandos]\", \"Continue, because bestRando.mark < 0\");","path":"src/exchanger.js","position":94,"original_position":94,"commit_id":"a275f5aecdd7f1cae8964722bcad7dd660a81ed5","original_commit_id":"a275f5aecdd7f1cae8964722bcad7dd660a81ed5","user":{"login":"dimhold","id":977022,"avatar_url":"https://avatars.githubusercontent.com/u/977022?v=3","gravatar_id":"","url":"https://api.github.com/users/dimhold","html_url":"https://github.com/dimhold","followers_url":"https://api.github.com/users/dimhold/followers","following_url":"https://api.github.com/users/dimhold/following{/other_user}","gists_url":"https://api.github.com/users/dimhold/gists{/gist_id}","starred_url":"https://api.github.com/users/dimhold/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dimhold/subscriptions","organizations_url":"https://api.github.com/users/dimhold/orgs","repos_url":"https://api.github.com/users/dimhold/repos","events_url":"https://api.github.com/users/dimhold/events{/privacy}","received_events_url":"https://api.github.com/users/dimhold/received_events","type":"User","site_admin":false},"body":"We don't stop exchange we just skip current `chooser` and go to next. this line is a body of `eachSeries`:\r\n\r\n```\r\n20: async.eachSeries(choosers, function (chooser, done) {\r\n```","created_at":"2016-08-31T08:31:39Z","updated_at":"2016-08-31T08:31:39Z","html_url":"https://github.com/RandoApp/Rando-exchanger/pull/3#discussion_r76945265","pull_request_url":"https://api.github.com/repos/RandoApp/Rando-exchanger/pulls/3","_links":{"self":{"href":"https://api.github.com/repos/RandoApp/Rando-exchanger/pulls/comments/76945265"},"html":{"href":"https://github.com/RandoApp/Rando-exchanger/pull/3#discussion_r76945265"},"pull_request":{"href":"https://api.github.com/repos/RandoApp/Rando-exchanger/pulls/3"}}},"pull_request":{"url":"https://api.github.com/repos/RandoApp/Rando-exchanger/pulls/3","id":82735452,"html_url":"https://github.com/RandoApp/Rando-exchanger/pull/3","diff_url":"https://github.com/RandoApp/Rando-exchanger/pull/3.diff","patch_url":"https://github.com/RandoApp/Rando-exchanger/pull/3.patch","issue_url":"https://api.github.com/repos/RandoApp/Rando-exchanger/issues/3","number":3,"state":"open","locked":false,"title":"Add stranger map","user":{"login":"dimhold","id":977022,"avatar_url":"https://avatars.githubusercontent.com/u/977022?v=3","gravatar_id":"","url":"https://api.github.com/users/dimhold","html_url":"https://github.com/dimhold","followers_url":"https://api.github.com/users/dimhold/followers","following_url":"https://api.github.com/users/dimhold/following{/other_user}","gists_url":"https://api.github.com/users/dimhold/gists{/gist_id}","starred_url":"https://api.github.com/users/dimhold/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dimhold/subscriptions","organizations_url":"https://api.github.com/users/dimhold/orgs","repos_url":"https://api.github.com/users/dimhold/repos","events_url":"https://api.github.com/users/dimhold/events{/privacy}","received_events_url":"https://api.github.com/users/dimhold/received_events","type":"User","site_admin":false},"body":"","created_at":"2016-08-25T14:56:53Z","updated_at":"2016-08-31T08:31:39Z","closed_at":null,"merged_at":null,"merge_commit_sha":"b427b18f496b2dcc7dc7351675a5f24de356ca38","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/RandoApp/Rando-exchanger/pulls/3/commits","review_comments_url":"https://api.github.com/repos/RandoApp/Rando-exchanger/pulls/3/comments","review_comment_url":"https://api.github.com/repos/RandoApp/Rando-exchanger/pulls/comments{/number}","comments_url":"https://api.github.com/repos/RandoApp/Rando-exchanger/issues/3/comments","statuses_url":"https://api.github.com/repos/RandoApp/Rando-exchanger/statuses/a275f5aecdd7f1cae8964722bcad7dd660a81ed5","head":{"label":"RandoApp:add-stranger-map","ref":"add-stranger-map","sha":"a275f5aecdd7f1cae8964722bcad7dd660a81ed5","user":{"login":"RandoApp","id":7382647,"avatar_url":"https://avatars.githubusercontent.com/u/7382647?v=3","gravatar_id":"","url":"https://api.github.com/users/RandoApp","html_url":"https://github.com/RandoApp","followers_url":"https://api.github.com/users/RandoApp/followers","following_url":"https://api.github.com/users/RandoApp/following{/other_user}","gists_url":"https://api.github.com/users/RandoApp/gists{/gist_id}","starred_url":"https://api.github.com/users/RandoApp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/RandoApp/subscriptions","organizations_url":"https://api.github.com/users/RandoApp/orgs","repos_url":"https://api.github.com/users/RandoApp/repos","events_url":"https://api.github.com/users/RandoApp/events{/privacy}","received_events_url":"https://api.github.com/users/RandoApp/received_events","type":"Organization","site_admin":false},"repo":{"id":23073961,"name":"Rando-exchanger","full_name":"RandoApp/Rando-exchanger","owner":{"login":"RandoApp","id":7382647,"avatar_url":"https://avatars.githubusercontent.com/u/7382647?v=3","gravatar_id":"","url":"https://api.github.com/users/RandoApp","html_url":"https://github.com/RandoApp","followers_url":"https://api.github.com/users/RandoApp/followers","following_url":"https://api.github.com/users/RandoApp/following{/other_user}","gists_url":"https://api.github.com/users/RandoApp/gists{/gist_id}","starred_url":"https://api.github.com/users/RandoApp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/RandoApp/subscriptions","organizations_url":"https://api.github.com/users/RandoApp/orgs","repos_url":"https://api.github.com/users/RandoApp/repos","events_url":"https://api.github.com/users/RandoApp/events{/privacy}","received_events_url":"https://api.github.com/users/RandoApp/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/RandoApp/Rando-exchanger","description":"Background service for exchange randos","fork":false,"url":"https://api.github.com/repos/RandoApp/Rando-exchanger","forks_url":"https://api.github.com/repos/RandoApp/Rando-exchanger/forks","keys_url":"https://api.github.com/repos/RandoApp/Rando-exchanger/keys{/key_id}","collaborators_url":"https://api.github.com/repos/RandoApp/Rando-exchanger/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/RandoApp/Rando-exchanger/teams","hooks_url":"https://api.github.com/repos/RandoApp/Rando-exchanger/hooks","issue_events_url":"https://api.github.com/repos/RandoApp/Rando-exchanger/issues/events{/number}","events_url":"https://api.github.com/repos/RandoApp/Rando-exchanger/events","assignees_url":"https://api.github.com/repos/RandoApp/Rando-exchanger/assignees{/user}","branches_url":"https://api.github.com/repos/RandoApp/Rando-exchanger/branches{/branch}","tags_url":"https://api.github.com/repos/RandoApp/Rando-exchanger/tags","blobs_url":"https://api.github.com/repos/RandoApp/Rando-exchanger/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/RandoApp/Rando-exchanger/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/RandoApp/Rando-exchanger/git/refs{/sha}","trees_url":"https://api.github.com/repos/RandoApp/Rando-exchanger/git/trees{/sha}","statuses_url":"https://api.github.com/repos/RandoApp/Rando-exchanger/statuses/{sha}","languages_url":"https://api.github.com/repos/RandoApp/Rando-exchanger/languages","stargazers_url":"https://api.github.com/repos/RandoApp/Rando-exchanger/stargazers","contributors_url":"https://api.github.com/repos/RandoApp/Rando-exchanger/contributors","subscribers_url":"https://api.github.com/repos/RandoApp/Rando-exchanger/subscribers","subscription_url":"https://api.github.com/repos/RandoApp/Rando-exchanger/subscription","commits_url":"https://api.github.com/repos/RandoApp/Rando-exchanger/commits{/sha}","git_commits_url":"https://api.github.com/repos/RandoApp/Rando-exchanger/git/commits{/sha}","comments_url":"https://api.github.com/repos/RandoApp/Rando-exchanger/comments{/number}","issue_comment_url":"https://api.github.com/repos/RandoApp/Rando-exchanger/issues/comments{/number}","contents_url":"https://api.github.com/repos/RandoApp/Rando-exchanger/contents/{+path}","compare_url":"https://api.github.com/repos/RandoApp/Rando-exchanger/compare/{base}...{head}","merges_url":"https://api.github.com/repos/RandoApp/Rando-exchanger/merges","archive_url":"https://api.github.com/repos/RandoApp/Rando-exchanger/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/RandoApp/Rando-exchanger/downloads","issues_url":"https://api.github.com/repos/RandoApp/Rando-exchanger/issues{/number}","pulls_url":"https://api.github.com/repos/RandoApp/Rando-exchanger/pulls{/number}","milestones_url":"https://api.github.com/repos/RandoApp/Rando-exchanger/milestones{/number}","notifications_url":"https://api.github.com/repos/RandoApp/Rando-exchanger/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/RandoApp/Rando-exchanger/labels{/name}","releases_url":"https://api.github.com/repos/RandoApp/Rando-exchanger/releases{/id}","deployments_url":"https://api.github.com/repos/RandoApp/Rando-exchanger/deployments","created_at":"2014-08-18T14:20:06Z","updated_at":"2016-08-19T14:08:45Z","pushed_at":"2016-08-30T15:05:25Z","git_url":"git://github.com/RandoApp/Rando-exchanger.git","ssh_url":"git@github.com:RandoApp/Rando-exchanger.git","clone_url":"https://github.com/RandoApp/Rando-exchanger.git","svn_url":"https://github.com/RandoApp/Rando-exchanger","homepage":"https://rando4.me","size":85,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"base":{"label":"RandoApp:master","ref":"master","sha":"96a673fb9d923616f39fc2f94b6146288fe331a8","user":{"login":"RandoApp","id":7382647,"avatar_url":"https://avatars.githubusercontent.com/u/7382647?v=3","gravatar_id":"","url":"https://api.github.com/users/RandoApp","html_url":"https://github.com/RandoApp","followers_url":"https://api.github.com/users/RandoApp/followers","following_url":"https://api.github.com/users/RandoApp/following{/other_user}","gists_url":"https://api.github.com/users/RandoApp/gists{/gist_id}","starred_url":"https://api.github.com/users/RandoApp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/RandoApp/subscriptions","organizations_url":"https://api.github.com/users/RandoApp/orgs","repos_url":"https://api.github.com/users/RandoApp/repos","events_url":"https://api.github.com/users/RandoApp/events{/privacy}","received_events_url":"https://api.github.com/users/RandoApp/received_events","type":"Organization","site_admin":false},"repo":{"id":23073961,"name":"Rando-exchanger","full_name":"RandoApp/Rando-exchanger","owner":{"login":"RandoApp","id":7382647,"avatar_url":"https://avatars.githubusercontent.com/u/7382647?v=3","gravatar_id":"","url":"https://api.github.com/users/RandoApp","html_url":"https://github.com/RandoApp","followers_url":"https://api.github.com/users/RandoApp/followers","following_url":"https://api.github.com/users/RandoApp/following{/other_user}","gists_url":"https://api.github.com/users/RandoApp/gists{/gist_id}","starred_url":"https://api.github.com/users/RandoApp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/RandoApp/subscriptions","organizations_url":"https://api.github.com/users/RandoApp/orgs","repos_url":"https://api.github.com/users/RandoApp/repos","events_url":"https://api.github.com/users/RandoApp/events{/privacy}","received_events_url":"https://api.github.com/users/RandoApp/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/RandoApp/Rando-exchanger","description":"Background service for exchange randos","fork":false,"url":"https://api.github.com/repos/RandoApp/Rando-exchanger","forks_url":"https://api.github.com/repos/RandoApp/Rando-exchanger/forks","keys_url":"https://api.github.com/repos/RandoApp/Rando-exchanger/keys{/key_id}","collaborators_url":"https://api.github.com/repos/RandoApp/Rando-exchanger/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/RandoApp/Rando-exchanger/teams","hooks_url":"https://api.github.com/repos/RandoApp/Rando-exchanger/hooks","issue_events_url":"https://api.github.com/repos/RandoApp/Rando-exchanger/issues/events{/number}","events_url":"https://api.github.com/repos/RandoApp/Rando-exchanger/events","assignees_url":"https://api.github.com/repos/RandoApp/Rando-exchanger/assignees{/user}","branches_url":"https://api.github.com/repos/RandoApp/Rando-exchanger/branches{/branch}","tags_url":"https://api.github.com/repos/RandoApp/Rando-exchanger/tags","blobs_url":"https://api.github.com/repos/RandoApp/Rando-exchanger/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/RandoApp/Rando-exchanger/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/RandoApp/Rando-exchanger/git/refs{/sha}","trees_url":"https://api.github.com/repos/RandoApp/Rando-exchanger/git/trees{/sha}","statuses_url":"https://api.github.com/repos/RandoApp/Rando-exchanger/statuses/{sha}","languages_url":"https://api.github.com/repos/RandoApp/Rando-exchanger/languages","stargazers_url":"https://api.github.com/repos/RandoApp/Rando-exchanger/stargazers","contributors_url":"https://api.github.com/repos/RandoApp/Rando-exchanger/contributors","subscribers_url":"https://api.github.com/repos/RandoApp/Rando-exchanger/subscribers","subscription_url":"https://api.github.com/repos/RandoApp/Rando-exchanger/subscription","commits_url":"https://api.github.com/repos/RandoApp/Rando-exchanger/commits{/sha}","git_commits_url":"https://api.github.com/repos/RandoApp/Rando-exchanger/git/commits{/sha}","comments_url":"https://api.github.com/repos/RandoApp/Rando-exchanger/comments{/number}","issue_comment_url":"https://api.github.com/repos/RandoApp/Rando-exchanger/issues/comments{/number}","contents_url":"https://api.github.com/repos/RandoApp/Rando-exchanger/contents/{+path}","compare_url":"https://api.github.com/repos/RandoApp/Rando-exchanger/compare/{base}...{head}","merges_url":"https://api.github.com/repos/RandoApp/Rando-exchanger/merges","archive_url":"https://api.github.com/repos/RandoApp/Rando-exchanger/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/RandoApp/Rando-exchanger/downloads","issues_url":"https://api.github.com/repos/RandoApp/Rando-exchanger/issues{/number}","pulls_url":"https://api.github.com/repos/RandoApp/Rando-exchanger/pulls{/number}","milestones_url":"https://api.github.com/repos/RandoApp/Rando-exchanger/milestones{/number}","notifications_url":"https://api.github.com/repos/RandoApp/Rando-exchanger/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/RandoApp/Rando-exchanger/labels{/name}","releases_url":"https://api.github.com/repos/RandoApp/Rando-exchanger/releases{/id}","deployments_url":"https://api.github.com/repos/RandoApp/Rando-exchanger/deployments","created_at":"2014-08-18T14:20:06Z","updated_at":"2016-08-19T14:08:45Z","pushed_at":"2016-08-30T15:05:25Z","git_url":"git://github.com/RandoApp/Rando-exchanger.git","ssh_url":"git@github.com:RandoApp/Rando-exchanger.git","clone_url":"https://github.com/RandoApp/Rando-exchanger.git","svn_url":"https://github.com/RandoApp/Rando-exchanger","homepage":"https://rando4.me","size":85,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/RandoApp/Rando-exchanger/pulls/3"},"html":{"href":"https://github.com/RandoApp/Rando-exchanger/pull/3"},"issue":{"href":"https://api.github.com/repos/RandoApp/Rando-exchanger/issues/3"},"comments":{"href":"https://api.github.com/repos/RandoApp/Rando-exchanger/issues/3/comments"},"review_comments":{"href":"https://api.github.com/repos/RandoApp/Rando-exchanger/pulls/3/comments"},"review_comment":{"href":"https://api.github.com/repos/RandoApp/Rando-exchanger/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/RandoApp/Rando-exchanger/pulls/3/commits"},"statuses":{"href":"https://api.github.com/repos/RandoApp/Rando-exchanger/statuses/a275f5aecdd7f1cae8964722bcad7dd660a81ed5"}}}}
{"actor":{"display_login":"dimhold"}}