{"action":"created","comment":{"url":"https://api.github.com/repos/thoughtbot/FOMObot/pulls/comments/61992861","id":61992861,"diff_hunk":"@@ -1,44 +1,56 @@\n module FOMObot.Helpers.Algorithm\n-    ( shiftInTime\n+    ( shiftInHistory\n     , shiftInEvent\n-    , calcDensity\n     , detectFOMOEvent\n     ) where\n \n-import Control.Lens ((^.))\n+import Control.Lens ((^.), (^?), (^?!), (&), (.~), (%~), _head, _last, views)\n+import Data.List (nub)\n import qualified Web.Slack as Slack\n \n import FOMObot.Types.Bot\n import FOMObot.Types.BotConfig\n import FOMObot.Types.ChannelState\n+import FOMObot.Types.HistoryItem\n \n type Density = Double\n \n calcDensity :: ChannelState -> Bot Density\n-calcDensity ChannelState{stateHistory} = do\n+calcDensity s = do\n     BotConfig{configHistorySize} <- getConfig\n-    return $ if isArrayFull stateHistory configHistorySize\n+    return $ if isArrayFull (s ^. stateHistory) configHistorySize\n         then calc $ fromIntegral configHistorySize\n         else 0\n   where\n     calc historySize = 60 * historySize / timeOverHistory\n-    timeOverHistory = realToFrac $ (head stateHistory ^. Slack.slackTime) - (last stateHistory ^. Slack.slackTime)\n-\n-detectFOMOEvent :: Density -> Bot Bool\n-detectFOMOEvent density = do\n-    BotConfig{configThreshold} <- getConfig\n-    return $ density > configThreshold\n+    timeOverHistory = realToFrac $ latestTimeStamp - earliestTimeStamp\n+    latestTimeStamp = s ^?! stateHistory . _head . historyTimeStamp . Slack.slackTime\n+    earliestTimeStamp  = s ^?! stateHistory . _last . historyTimeStamp . Slack.slackTime\n+\n+detectFOMOEvent :: ChannelState -> Bot Bool\n+detectFOMOEvent state = do\n+    densitySurpassesThreshold <- (>) <$> calcDensity state <*> (configThreshold <$> getConfig)\n+    return $ and\n+        [ densitySurpassesThreshold\n+        , atLeastThreeUniqueUsers state\n+        ]\n+  where\n+    atLeastThreeUniqueUsers = views stateHistory ((>=3) . length . nub . (map (^. historyUserId)))\n \n-shiftInTime :: BotConfig -> Slack.SlackTimeStamp -> ChannelState -> ChannelState\n-shiftInTime BotConfig{configHistorySize} timestamp s@ChannelState{stateHistory} =\n-    s { stateHistory = shiftIn configHistorySize stateHistory timestamp }\n+shiftInHistory :: BotConfig -> HistoryItem -> ChannelState -> ChannelState\n+shiftInHistory BotConfig{configHistorySize} historyItem s =\n+    if (s ^? stateHistory . _head . historyUserId) == Just (historyItem ^. historyUserId)","path":"src/FOMObot/Helpers/Algorithm.hs","position":56,"original_position":56,"commit_id":"40fe60927749ae8d5aa21de0eaff7ced3b082371","original_commit_id":"40fe60927749ae8d5aa21de0eaff7ced3b082371","user":{"login":"gabebw","id":257678,"avatar_url":"https://avatars.githubusercontent.com/u/257678?v=3","gravatar_id":"","url":"https://api.github.com/users/gabebw","html_url":"https://github.com/gabebw","followers_url":"https://api.github.com/users/gabebw/followers","following_url":"https://api.github.com/users/gabebw/following{/other_user}","gists_url":"https://api.github.com/users/gabebw/gists{/gist_id}","starred_url":"https://api.github.com/users/gabebw/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gabebw/subscriptions","organizations_url":"https://api.github.com/users/gabebw/orgs","repos_url":"https://api.github.com/users/gabebw/repos","events_url":"https://api.github.com/users/gabebw/events{/privacy}","received_events_url":"https://api.github.com/users/gabebw/received_events","type":"User","site_admin":false},"body":"That sounds great!","created_at":"2016-05-04T06:01:55Z","updated_at":"2016-05-04T06:01:55Z","html_url":"https://github.com/thoughtbot/FOMObot/pull/23#discussion_r61992861","pull_request_url":"https://api.github.com/repos/thoughtbot/FOMObot/pulls/23","_links":{"self":{"href":"https://api.github.com/repos/thoughtbot/FOMObot/pulls/comments/61992861"},"html":{"href":"https://github.com/thoughtbot/FOMObot/pull/23#discussion_r61992861"},"pull_request":{"href":"https://api.github.com/repos/thoughtbot/FOMObot/pulls/23"}}},"pull_request":{"url":"https://api.github.com/repos/thoughtbot/FOMObot/pulls/23","id":68793588,"html_url":"https://github.com/thoughtbot/FOMObot/pull/23","diff_url":"https://github.com/thoughtbot/FOMObot/pull/23.diff","patch_url":"https://github.com/thoughtbot/FOMObot/pull/23.patch","issue_url":"https://api.github.com/repos/thoughtbot/FOMObot/issues/23","number":23,"state":"open","locked":false,"title":"Enhance the algorithm","user":{"login":"tonyd256","id":1169797,"avatar_url":"https://avatars.githubusercontent.com/u/1169797?v=3","gravatar_id":"","url":"https://api.github.com/users/tonyd256","html_url":"https://github.com/tonyd256","followers_url":"https://api.github.com/users/tonyd256/followers","following_url":"https://api.github.com/users/tonyd256/following{/other_user}","gists_url":"https://api.github.com/users/tonyd256/gists{/gist_id}","starred_url":"https://api.github.com/users/tonyd256/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tonyd256/subscriptions","organizations_url":"https://api.github.com/users/tonyd256/orgs","repos_url":"https://api.github.com/users/tonyd256/repos","events_url":"https://api.github.com/users/tonyd256/events{/privacy}","received_events_url":"https://api.github.com/users/tonyd256/received_events","type":"User","site_admin":false},"body":"This adds 2 specific enhancements to the algorithm. The first will prevent\nusers from triggering an event themselves by sending many messages in a row.\nThe second requires at least 3 people involved in a conversation for an event\nto occur.","created_at":"2016-05-03T23:50:49Z","updated_at":"2016-05-04T06:01:55Z","closed_at":null,"merged_at":null,"merge_commit_sha":"b4f3e34e4b0a2b25a1145e71ed6df3ef10ceb930","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/thoughtbot/FOMObot/pulls/23/commits","review_comments_url":"https://api.github.com/repos/thoughtbot/FOMObot/pulls/23/comments","review_comment_url":"https://api.github.com/repos/thoughtbot/FOMObot/pulls/comments{/number}","comments_url":"https://api.github.com/repos/thoughtbot/FOMObot/issues/23/comments","statuses_url":"https://api.github.com/repos/thoughtbot/FOMObot/statuses/40fe60927749ae8d5aa21de0eaff7ced3b082371","head":{"label":"thoughtbot:td-algorithm-2","ref":"td-algorithm-2","sha":"40fe60927749ae8d5aa21de0eaff7ced3b082371","user":{"login":"thoughtbot","id":6183,"avatar_url":"https://avatars.githubusercontent.com/u/6183?v=3","gravatar_id":"","url":"https://api.github.com/users/thoughtbot","html_url":"https://github.com/thoughtbot","followers_url":"https://api.github.com/users/thoughtbot/followers","following_url":"https://api.github.com/users/thoughtbot/following{/other_user}","gists_url":"https://api.github.com/users/thoughtbot/gists{/gist_id}","starred_url":"https://api.github.com/users/thoughtbot/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thoughtbot/subscriptions","organizations_url":"https://api.github.com/users/thoughtbot/orgs","repos_url":"https://api.github.com/users/thoughtbot/repos","events_url":"https://api.github.com/users/thoughtbot/events{/privacy}","received_events_url":"https://api.github.com/users/thoughtbot/received_events","type":"Organization","site_admin":false},"repo":{"id":47729662,"name":"FOMObot","full_name":"thoughtbot/FOMObot","owner":{"login":"thoughtbot","id":6183,"avatar_url":"https://avatars.githubusercontent.com/u/6183?v=3","gravatar_id":"","url":"https://api.github.com/users/thoughtbot","html_url":"https://github.com/thoughtbot","followers_url":"https://api.github.com/users/thoughtbot/followers","following_url":"https://api.github.com/users/thoughtbot/following{/other_user}","gists_url":"https://api.github.com/users/thoughtbot/gists{/gist_id}","starred_url":"https://api.github.com/users/thoughtbot/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thoughtbot/subscriptions","organizations_url":"https://api.github.com/users/thoughtbot/orgs","repos_url":"https://api.github.com/users/thoughtbot/repos","events_url":"https://api.github.com/users/thoughtbot/events{/privacy}","received_events_url":"https://api.github.com/users/thoughtbot/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/thoughtbot/FOMObot","description":"A slack bot to help with FOMO.","fork":false,"url":"https://api.github.com/repos/thoughtbot/FOMObot","forks_url":"https://api.github.com/repos/thoughtbot/FOMObot/forks","keys_url":"https://api.github.com/repos/thoughtbot/FOMObot/keys{/key_id}","collaborators_url":"https://api.github.com/repos/thoughtbot/FOMObot/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/thoughtbot/FOMObot/teams","hooks_url":"https://api.github.com/repos/thoughtbot/FOMObot/hooks","issue_events_url":"https://api.github.com/repos/thoughtbot/FOMObot/issues/events{/number}","events_url":"https://api.github.com/repos/thoughtbot/FOMObot/events","assignees_url":"https://api.github.com/repos/thoughtbot/FOMObot/assignees{/user}","branches_url":"https://api.github.com/repos/thoughtbot/FOMObot/branches{/branch}","tags_url":"https://api.github.com/repos/thoughtbot/FOMObot/tags","blobs_url":"https://api.github.com/repos/thoughtbot/FOMObot/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/thoughtbot/FOMObot/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/thoughtbot/FOMObot/git/refs{/sha}","trees_url":"https://api.github.com/repos/thoughtbot/FOMObot/git/trees{/sha}","statuses_url":"https://api.github.com/repos/thoughtbot/FOMObot/statuses/{sha}","languages_url":"https://api.github.com/repos/thoughtbot/FOMObot/languages","stargazers_url":"https://api.github.com/repos/thoughtbot/FOMObot/stargazers","contributors_url":"https://api.github.com/repos/thoughtbot/FOMObot/contributors","subscribers_url":"https://api.github.com/repos/thoughtbot/FOMObot/subscribers","subscription_url":"https://api.github.com/repos/thoughtbot/FOMObot/subscription","commits_url":"https://api.github.com/repos/thoughtbot/FOMObot/commits{/sha}","git_commits_url":"https://api.github.com/repos/thoughtbot/FOMObot/git/commits{/sha}","comments_url":"https://api.github.com/repos/thoughtbot/FOMObot/comments{/number}","issue_comment_url":"https://api.github.com/repos/thoughtbot/FOMObot/issues/comments{/number}","contents_url":"https://api.github.com/repos/thoughtbot/FOMObot/contents/{+path}","compare_url":"https://api.github.com/repos/thoughtbot/FOMObot/compare/{base}...{head}","merges_url":"https://api.github.com/repos/thoughtbot/FOMObot/merges","archive_url":"https://api.github.com/repos/thoughtbot/FOMObot/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/thoughtbot/FOMObot/downloads","issues_url":"https://api.github.com/repos/thoughtbot/FOMObot/issues{/number}","pulls_url":"https://api.github.com/repos/thoughtbot/FOMObot/pulls{/number}","milestones_url":"https://api.github.com/repos/thoughtbot/FOMObot/milestones{/number}","notifications_url":"https://api.github.com/repos/thoughtbot/FOMObot/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/thoughtbot/FOMObot/labels{/name}","releases_url":"https://api.github.com/repos/thoughtbot/FOMObot/releases{/id}","deployments_url":"https://api.github.com/repos/thoughtbot/FOMObot/deployments","created_at":"2015-12-10T01:22:39Z","updated_at":"2016-05-02T21:23:15Z","pushed_at":"2016-05-03T23:50:49Z","git_url":"git://github.com/thoughtbot/FOMObot.git","ssh_url":"git@github.com:thoughtbot/FOMObot.git","clone_url":"https://github.com/thoughtbot/FOMObot.git","svn_url":"https://github.com/thoughtbot/FOMObot","homepage":"","size":58,"stargazers_count":1,"watchers_count":1,"language":"Haskell","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":6,"forks":0,"open_issues":6,"watchers":1,"default_branch":"master"}},"base":{"label":"thoughtbot:master","ref":"master","sha":"12b43515b7f01baf274a692dfb083a9cc3dcd2b4","user":{"login":"thoughtbot","id":6183,"avatar_url":"https://avatars.githubusercontent.com/u/6183?v=3","gravatar_id":"","url":"https://api.github.com/users/thoughtbot","html_url":"https://github.com/thoughtbot","followers_url":"https://api.github.com/users/thoughtbot/followers","following_url":"https://api.github.com/users/thoughtbot/following{/other_user}","gists_url":"https://api.github.com/users/thoughtbot/gists{/gist_id}","starred_url":"https://api.github.com/users/thoughtbot/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thoughtbot/subscriptions","organizations_url":"https://api.github.com/users/thoughtbot/orgs","repos_url":"https://api.github.com/users/thoughtbot/repos","events_url":"https://api.github.com/users/thoughtbot/events{/privacy}","received_events_url":"https://api.github.com/users/thoughtbot/received_events","type":"Organization","site_admin":false},"repo":{"id":47729662,"name":"FOMObot","full_name":"thoughtbot/FOMObot","owner":{"login":"thoughtbot","id":6183,"avatar_url":"https://avatars.githubusercontent.com/u/6183?v=3","gravatar_id":"","url":"https://api.github.com/users/thoughtbot","html_url":"https://github.com/thoughtbot","followers_url":"https://api.github.com/users/thoughtbot/followers","following_url":"https://api.github.com/users/thoughtbot/following{/other_user}","gists_url":"https://api.github.com/users/thoughtbot/gists{/gist_id}","starred_url":"https://api.github.com/users/thoughtbot/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thoughtbot/subscriptions","organizations_url":"https://api.github.com/users/thoughtbot/orgs","repos_url":"https://api.github.com/users/thoughtbot/repos","events_url":"https://api.github.com/users/thoughtbot/events{/privacy}","received_events_url":"https://api.github.com/users/thoughtbot/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/thoughtbot/FOMObot","description":"A slack bot to help with FOMO.","fork":false,"url":"https://api.github.com/repos/thoughtbot/FOMObot","forks_url":"https://api.github.com/repos/thoughtbot/FOMObot/forks","keys_url":"https://api.github.com/repos/thoughtbot/FOMObot/keys{/key_id}","collaborators_url":"https://api.github.com/repos/thoughtbot/FOMObot/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/thoughtbot/FOMObot/teams","hooks_url":"https://api.github.com/repos/thoughtbot/FOMObot/hooks","issue_events_url":"https://api.github.com/repos/thoughtbot/FOMObot/issues/events{/number}","events_url":"https://api.github.com/repos/thoughtbot/FOMObot/events","assignees_url":"https://api.github.com/repos/thoughtbot/FOMObot/assignees{/user}","branches_url":"https://api.github.com/repos/thoughtbot/FOMObot/branches{/branch}","tags_url":"https://api.github.com/repos/thoughtbot/FOMObot/tags","blobs_url":"https://api.github.com/repos/thoughtbot/FOMObot/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/thoughtbot/FOMObot/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/thoughtbot/FOMObot/git/refs{/sha}","trees_url":"https://api.github.com/repos/thoughtbot/FOMObot/git/trees{/sha}","statuses_url":"https://api.github.com/repos/thoughtbot/FOMObot/statuses/{sha}","languages_url":"https://api.github.com/repos/thoughtbot/FOMObot/languages","stargazers_url":"https://api.github.com/repos/thoughtbot/FOMObot/stargazers","contributors_url":"https://api.github.com/repos/thoughtbot/FOMObot/contributors","subscribers_url":"https://api.github.com/repos/thoughtbot/FOMObot/subscribers","subscription_url":"https://api.github.com/repos/thoughtbot/FOMObot/subscription","commits_url":"https://api.github.com/repos/thoughtbot/FOMObot/commits{/sha}","git_commits_url":"https://api.github.com/repos/thoughtbot/FOMObot/git/commits{/sha}","comments_url":"https://api.github.com/repos/thoughtbot/FOMObot/comments{/number}","issue_comment_url":"https://api.github.com/repos/thoughtbot/FOMObot/issues/comments{/number}","contents_url":"https://api.github.com/repos/thoughtbot/FOMObot/contents/{+path}","compare_url":"https://api.github.com/repos/thoughtbot/FOMObot/compare/{base}...{head}","merges_url":"https://api.github.com/repos/thoughtbot/FOMObot/merges","archive_url":"https://api.github.com/repos/thoughtbot/FOMObot/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/thoughtbot/FOMObot/downloads","issues_url":"https://api.github.com/repos/thoughtbot/FOMObot/issues{/number}","pulls_url":"https://api.github.com/repos/thoughtbot/FOMObot/pulls{/number}","milestones_url":"https://api.github.com/repos/thoughtbot/FOMObot/milestones{/number}","notifications_url":"https://api.github.com/repos/thoughtbot/FOMObot/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/thoughtbot/FOMObot/labels{/name}","releases_url":"https://api.github.com/repos/thoughtbot/FOMObot/releases{/id}","deployments_url":"https://api.github.com/repos/thoughtbot/FOMObot/deployments","created_at":"2015-12-10T01:22:39Z","updated_at":"2016-05-02T21:23:15Z","pushed_at":"2016-05-03T23:50:49Z","git_url":"git://github.com/thoughtbot/FOMObot.git","ssh_url":"git@github.com:thoughtbot/FOMObot.git","clone_url":"https://github.com/thoughtbot/FOMObot.git","svn_url":"https://github.com/thoughtbot/FOMObot","homepage":"","size":58,"stargazers_count":1,"watchers_count":1,"language":"Haskell","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":6,"forks":0,"open_issues":6,"watchers":1,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/thoughtbot/FOMObot/pulls/23"},"html":{"href":"https://github.com/thoughtbot/FOMObot/pull/23"},"issue":{"href":"https://api.github.com/repos/thoughtbot/FOMObot/issues/23"},"comments":{"href":"https://api.github.com/repos/thoughtbot/FOMObot/issues/23/comments"},"review_comments":{"href":"https://api.github.com/repos/thoughtbot/FOMObot/pulls/23/comments"},"review_comment":{"href":"https://api.github.com/repos/thoughtbot/FOMObot/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/thoughtbot/FOMObot/pulls/23/commits"},"statuses":{"href":"https://api.github.com/repos/thoughtbot/FOMObot/statuses/40fe60927749ae8d5aa21de0eaff7ced3b082371"}}}}