{"action":"created","comment":{"url":"https://api.github.com/repos/department-of-veterans-affairs/caseflow-efolder/pulls/comments/83885479","pull_request_review_id":4694837,"id":83885479,"diff_hunk":"@@ -32,8 +41,46 @@ def type_name\n     TYPES[doc_type.to_i] || vbms_filename\n   end\n \n+  def self.historical_average_download_rate\n+    time_floor = TimeUtil.floor(AVERAGE_DOWNLOAD_RATE_CACHE_EXPIRATION)\n+    cache = Rails.cache.read(AVERAGE_DOWNLOAD_RATE_CACHE_KEY)\n+\n+    return cache[:value] if cache && cache[:updated_at] == time_floor\n+\n+    calculate_and_save_historical_average_download_rate!\n+  end\n+\n   private\n \n+  class << self\n+    def calculate_and_save_historical_average_download_rate!\n+      value = calculate_historical_average_download_rate\n+      obj = {\n+        updated_at: TimeUtil.floor(AVERAGE_DOWNLOAD_RATE_CACHE_EXPIRATION),\n+        value: value\n+      }\n+\n+      Rails.cache.write(AVERAGE_DOWNLOAD_RATE_CACHE_KEY, obj)\n+      value\n+    end\n+\n+    # This calculates the historical average rate at which files are downloaded\n+    # This takes the time spend downloading all files over the past hour and\n+    # divides by the total number of files in that period\n+    def calculate_historical_average_download_rate\n+      documents = ordered_by_completed_at.limit(AVERAGE_DOWNLOAD_RATE_LIMIT)\n+\n+      count = documents.count\n+      return nil unless count\n+\n+      total_time = documents.inject(0) do |total, document|","path":"app/models/document.rb","position":56,"original_position":56,"commit_id":"a0277ce84750dd0bb8542709bc09e3d1d89e58ec","original_commit_id":"8f453032d0539620078cef17544d5b258ab2970b","user":{"login":"shanear","id":1596259,"avatar_url":"https://avatars.githubusercontent.com/u/1596259?v=3","gravatar_id":"","url":"https://api.github.com/users/shanear","html_url":"https://github.com/shanear","followers_url":"https://api.github.com/users/shanear/followers","following_url":"https://api.github.com/users/shanear/following{/other_user}","gists_url":"https://api.github.com/users/shanear/gists{/gist_id}","starred_url":"https://api.github.com/users/shanear/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/shanear/subscriptions","organizations_url":"https://api.github.com/users/shanear/orgs","repos_url":"https://api.github.com/users/shanear/repos","events_url":"https://api.github.com/users/shanear/events{/privacy}","received_events_url":"https://api.github.com/users/shanear/received_events","type":"User","site_admin":false},"body":"`#inject` is so pro 😎 ","created_at":"2016-10-18T15:45:23Z","updated_at":"2016-10-18T15:46:43Z","html_url":"https://github.com/department-of-veterans-affairs/caseflow-efolder/pull/256#discussion_r83885479","pull_request_url":"https://api.github.com/repos/department-of-veterans-affairs/caseflow-efolder/pulls/256","_links":{"self":{"href":"https://api.github.com/repos/department-of-veterans-affairs/caseflow-efolder/pulls/comments/83885479"},"html":{"href":"https://github.com/department-of-veterans-affairs/caseflow-efolder/pull/256#discussion_r83885479"},"pull_request":{"href":"https://api.github.com/repos/department-of-veterans-affairs/caseflow-efolder/pulls/256"}}},"pull_request":{"url":"https://api.github.com/repos/department-of-veterans-affairs/caseflow-efolder/pulls/256","id":89706519,"html_url":"https://github.com/department-of-veterans-affairs/caseflow-efolder/pull/256","diff_url":"https://github.com/department-of-veterans-affairs/caseflow-efolder/pull/256.diff","patch_url":"https://github.com/department-of-veterans-affairs/caseflow-efolder/pull/256.patch","issue_url":"https://api.github.com/repos/department-of-veterans-affairs/caseflow-efolder/issues/256","number":256,"state":"open","locked":false,"title":"Improve time estimation for reamining downloads","user":{"login":"joofsh","id":2256237,"avatar_url":"https://avatars.githubusercontent.com/u/2256237?v=3","gravatar_id":"","url":"https://api.github.com/users/joofsh","html_url":"https://github.com/joofsh","followers_url":"https://api.github.com/users/joofsh/followers","following_url":"https://api.github.com/users/joofsh/following{/other_user}","gists_url":"https://api.github.com/users/joofsh/gists{/gist_id}","starred_url":"https://api.github.com/users/joofsh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/joofsh/subscriptions","organizations_url":"https://api.github.com/users/joofsh/orgs","repos_url":"https://api.github.com/users/joofsh/repos","events_url":"https://api.github.com/users/joofsh/events{/privacy}","received_events_url":"https://api.github.com/users/joofsh/received_events","type":"User","site_admin":false},"body":"- Update logic for calculating remaining time for downloading files to\r\n  reference the latest 100 downloads\r\n- Cache calculation of average download rate to redis. Update\r\n  calculations on the 30sec mark\r\n- Add TimeUtil with floor method for calculating closest window for\r\n  caching values\r\n\r\nFixes #221\r\n\r\nTesting:\r\n- Updating download unit tests\r\n- Added document unit tests\r\n- All existing tests pass\r\n- Manually tested in browser and works as expected. In the gif below, the historical average download rate is set to ~1 minute. This way you can see it quickly updating as it downloads. Notice the steady rate that the estimation changes:\r\n![document_time_estimates](https://cloud.githubusercontent.com/assets/2256237/19457272/8c65f0bc-9493-11e6-9d5c-c98c0fe2cce7.gif)\r\n","created_at":"2016-10-17T21:26:41Z","updated_at":"2016-10-18T15:46:43Z","closed_at":null,"merged_at":null,"merge_commit_sha":"becbbefe1532614cb9c5990791cb989299bcc157","assignee":{"login":"shanear","id":1596259,"avatar_url":"https://avatars.githubusercontent.com/u/1596259?v=3","gravatar_id":"","url":"https://api.github.com/users/shanear","html_url":"https://github.com/shanear","followers_url":"https://api.github.com/users/shanear/followers","following_url":"https://api.github.com/users/shanear/following{/other_user}","gists_url":"https://api.github.com/users/shanear/gists{/gist_id}","starred_url":"https://api.github.com/users/shanear/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/shanear/subscriptions","organizations_url":"https://api.github.com/users/shanear/orgs","repos_url":"https://api.github.com/users/shanear/repos","events_url":"https://api.github.com/users/shanear/events{/privacy}","received_events_url":"https://api.github.com/users/shanear/received_events","type":"User","site_admin":false},"assignees":[{"login":"shanear","id":1596259,"avatar_url":"https://avatars.githubusercontent.com/u/1596259?v=3","gravatar_id":"","url":"https://api.github.com/users/shanear","html_url":"https://github.com/shanear","followers_url":"https://api.github.com/users/shanear/followers","following_url":"https://api.github.com/users/shanear/following{/other_user}","gists_url":"https://api.github.com/users/shanear/gists{/gist_id}","starred_url":"https://api.github.com/users/shanear/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/shanear/subscriptions","organizations_url":"https://api.github.com/users/shanear/orgs","repos_url":"https://api.github.com/users/shanear/repos","events_url":"https://api.github.com/users/shanear/events{/privacy}","received_events_url":"https://api.github.com/users/shanear/received_events","type":"User","site_admin":false}],"milestone":null,"commits_url":"https://api.github.com/repos/department-of-veterans-affairs/caseflow-efolder/pulls/256/commits","review_comments_url":"https://api.github.com/repos/department-of-veterans-affairs/caseflow-efolder/pulls/256/comments","review_comment_url":"https://api.github.com/repos/department-of-veterans-affairs/caseflow-efolder/pulls/comments{/number}","comments_url":"https://api.github.com/repos/department-of-veterans-affairs/caseflow-efolder/issues/256/comments","statuses_url":"https://api.github.com/repos/department-of-veterans-affairs/caseflow-efolder/statuses/a0277ce84750dd0bb8542709bc09e3d1d89e58ec","head":{"label":"department-of-veterans-affairs:jd-issue-221","ref":"jd-issue-221","sha":"a0277ce84750dd0bb8542709bc09e3d1d89e58ec","user":{"login":"department-of-veterans-affairs","id":5421563,"avatar_url":"https://avatars.githubusercontent.com/u/5421563?v=3","gravatar_id":"","url":"https://api.github.com/users/department-of-veterans-affairs","html_url":"https://github.com/department-of-veterans-affairs","followers_url":"https://api.github.com/users/department-of-veterans-affairs/followers","following_url":"https://api.github.com/users/department-of-veterans-affairs/following{/other_user}","gists_url":"https://api.github.com/users/department-of-veterans-affairs/gists{/gist_id}","starred_url":"https://api.github.com/users/department-of-veterans-affairs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/department-of-veterans-affairs/subscriptions","organizations_url":"https://api.github.com/users/department-of-veterans-affairs/orgs","repos_url":"https://api.github.com/users/department-of-veterans-affairs/repos","events_url":"https://api.github.com/users/department-of-veterans-affairs/events{/privacy}","received_events_url":"https://api.github.com/users/department-of-veterans-affairs/received_events","type":"Organization","site_admin":false},"repo":{"id":50130088,"name":"caseflow-efolder","full_name":"department-of-veterans-affairs/caseflow-efolder","owner":{"login":"department-of-veterans-affairs","id":5421563,"avatar_url":"https://avatars.githubusercontent.com/u/5421563?v=3","gravatar_id":"","url":"https://api.github.com/users/department-of-veterans-affairs","html_url":"https://github.com/department-of-veterans-affairs","followers_url":"https://api.github.com/users/department-of-veterans-affairs/followers","following_url":"https://api.github.com/users/department-of-veterans-affairs/following{/other_user}","gists_url":"https://api.github.com/users/department-of-veterans-affairs/gists{/gist_id}","starred_url":"https://api.github.com/users/department-of-veterans-affairs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/department-of-veterans-affairs/subscriptions","organizations_url":"https://api.github.com/users/department-of-veterans-affairs/orgs","repos_url":"https://api.github.com/users/department-of-veterans-affairs/repos","events_url":"https://api.github.com/users/department-of-veterans-affairs/events{/privacy}","received_events_url":"https://api.github.com/users/department-of-veterans-affairs/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/department-of-veterans-affairs/caseflow-efolder","description":"Tool for bulk download of efolder claim files","fork":false,"url":"https://api.github.com/repos/department-of-veterans-affairs/caseflow-efolder","forks_url":"https://api.github.com/repos/department-of-veterans-affairs/caseflow-efolder/forks","keys_url":"https://api.github.com/repos/department-of-veterans-affairs/caseflow-efolder/keys{/key_id}","collaborators_url":"https://api.github.com/repos/department-of-veterans-affairs/caseflow-efolder/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/department-of-veterans-affairs/caseflow-efolder/teams","hooks_url":"https://api.github.com/repos/department-of-veterans-affairs/caseflow-efolder/hooks","issue_events_url":"https://api.github.com/repos/department-of-veterans-affairs/caseflow-efolder/issues/events{/number}","events_url":"https://api.github.com/repos/department-of-veterans-affairs/caseflow-efolder/events","assignees_url":"https://api.github.com/repos/department-of-veterans-affairs/caseflow-efolder/assignees{/user}","branches_url":"https://api.github.com/repos/department-of-veterans-affairs/caseflow-efolder/branches{/branch}","tags_url":"https://api.github.com/repos/department-of-veterans-affairs/caseflow-efolder/tags","blobs_url":"https://api.github.com/repos/department-of-veterans-affairs/caseflow-efolder/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/department-of-veterans-affairs/caseflow-efolder/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/department-of-veterans-affairs/caseflow-efolder/git/refs{/sha}","trees_url":"https://api.github.com/repos/department-of-veterans-affairs/caseflow-efolder/git/trees{/sha}","statuses_url":"https://api.github.com/repos/department-of-veterans-affairs/caseflow-efolder/statuses/{sha}","languages_url":"https://api.github.com/repos/department-of-veterans-affairs/caseflow-efolder/languages","stargazers_url":"https://api.github.com/repos/department-of-veterans-affairs/caseflow-efolder/stargazers","contributors_url":"https://api.github.com/repos/department-of-veterans-affairs/caseflow-efolder/contributors","subscribers_url":"https://api.github.com/repos/department-of-veterans-affairs/caseflow-efolder/subscribers","subscription_url":"https://api.github.com/repos/department-of-veterans-affairs/caseflow-efolder/subscription","commits_url":"https://api.github.com/repos/department-of-veterans-affairs/caseflow-efolder/commits{/sha}","git_commits_url":"https://api.github.com/repos/department-of-veterans-affairs/caseflow-efolder/git/commits{/sha}","comments_url":"https://api.github.com/repos/department-of-veterans-affairs/caseflow-efolder/comments{/number}","issue_comment_url":"https://api.github.com/repos/department-of-veterans-affairs/caseflow-efolder/issues/comments{/number}","contents_url":"https://api.github.com/repos/department-of-veterans-affairs/caseflow-efolder/contents/{+path}","compare_url":"https://api.github.com/repos/department-of-veterans-affairs/caseflow-efolder/compare/{base}...{head}","merges_url":"https://api.github.com/repos/department-of-veterans-affairs/caseflow-efolder/merges","archive_url":"https://api.github.com/repos/department-of-veterans-affairs/caseflow-efolder/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/department-of-veterans-affairs/caseflow-efolder/downloads","issues_url":"https://api.github.com/repos/department-of-veterans-affairs/caseflow-efolder/issues{/number}","pulls_url":"https://api.github.com/repos/department-of-veterans-affairs/caseflow-efolder/pulls{/number}","milestones_url":"https://api.github.com/repos/department-of-veterans-affairs/caseflow-efolder/milestones{/number}","notifications_url":"https://api.github.com/repos/department-of-veterans-affairs/caseflow-efolder/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/department-of-veterans-affairs/caseflow-efolder/labels{/name}","releases_url":"https://api.github.com/repos/department-of-veterans-affairs/caseflow-efolder/releases{/id}","deployments_url":"https://api.github.com/repos/department-of-veterans-affairs/caseflow-efolder/deployments","created_at":"2016-01-21T19:08:28Z","updated_at":"2016-08-26T06:33:34Z","pushed_at":"2016-10-18T14:20:48Z","git_url":"git://github.com/department-of-veterans-affairs/caseflow-efolder.git","ssh_url":"git@github.com:department-of-veterans-affairs/caseflow-efolder.git","clone_url":"https://github.com/department-of-veterans-affairs/caseflow-efolder.git","svn_url":"https://github.com/department-of-veterans-affairs/caseflow-efolder","homepage":null,"size":3909,"stargazers_count":1,"watchers_count":1,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2,"mirror_url":null,"open_issues_count":19,"forks":2,"open_issues":19,"watchers":1,"default_branch":"master"}},"base":{"label":"department-of-veterans-affairs:master","ref":"master","sha":"137ff6463555967a455826b2d053c4a9b73adf00","user":{"login":"department-of-veterans-affairs","id":5421563,"avatar_url":"https://avatars.githubusercontent.com/u/5421563?v=3","gravatar_id":"","url":"https://api.github.com/users/department-of-veterans-affairs","html_url":"https://github.com/department-of-veterans-affairs","followers_url":"https://api.github.com/users/department-of-veterans-affairs/followers","following_url":"https://api.github.com/users/department-of-veterans-affairs/following{/other_user}","gists_url":"https://api.github.com/users/department-of-veterans-affairs/gists{/gist_id}","starred_url":"https://api.github.com/users/department-of-veterans-affairs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/department-of-veterans-affairs/subscriptions","organizations_url":"https://api.github.com/users/department-of-veterans-affairs/orgs","repos_url":"https://api.github.com/users/department-of-veterans-affairs/repos","events_url":"https://api.github.com/users/department-of-veterans-affairs/events{/privacy}","received_events_url":"https://api.github.com/users/department-of-veterans-affairs/received_events","type":"Organization","site_admin":false},"repo":{"id":50130088,"name":"caseflow-efolder","full_name":"department-of-veterans-affairs/caseflow-efolder","owner":{"login":"department-of-veterans-affairs","id":5421563,"avatar_url":"https://avatars.githubusercontent.com/u/5421563?v=3","gravatar_id":"","url":"https://api.github.com/users/department-of-veterans-affairs","html_url":"https://github.com/department-of-veterans-affairs","followers_url":"https://api.github.com/users/department-of-veterans-affairs/followers","following_url":"https://api.github.com/users/department-of-veterans-affairs/following{/other_user}","gists_url":"https://api.github.com/users/department-of-veterans-affairs/gists{/gist_id}","starred_url":"https://api.github.com/users/department-of-veterans-affairs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/department-of-veterans-affairs/subscriptions","organizations_url":"https://api.github.com/users/department-of-veterans-affairs/orgs","repos_url":"https://api.github.com/users/department-of-veterans-affairs/repos","events_url":"https://api.github.com/users/department-of-veterans-affairs/events{/privacy}","received_events_url":"https://api.github.com/users/department-of-veterans-affairs/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/department-of-veterans-affairs/caseflow-efolder","description":"Tool for bulk download of efolder claim files","fork":false,"url":"https://api.github.com/repos/department-of-veterans-affairs/caseflow-efolder","forks_url":"https://api.github.com/repos/department-of-veterans-affairs/caseflow-efolder/forks","keys_url":"https://api.github.com/repos/department-of-veterans-affairs/caseflow-efolder/keys{/key_id}","collaborators_url":"https://api.github.com/repos/department-of-veterans-affairs/caseflow-efolder/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/department-of-veterans-affairs/caseflow-efolder/teams","hooks_url":"https://api.github.com/repos/department-of-veterans-affairs/caseflow-efolder/hooks","issue_events_url":"https://api.github.com/repos/department-of-veterans-affairs/caseflow-efolder/issues/events{/number}","events_url":"https://api.github.com/repos/department-of-veterans-affairs/caseflow-efolder/events","assignees_url":"https://api.github.com/repos/department-of-veterans-affairs/caseflow-efolder/assignees{/user}","branches_url":"https://api.github.com/repos/department-of-veterans-affairs/caseflow-efolder/branches{/branch}","tags_url":"https://api.github.com/repos/department-of-veterans-affairs/caseflow-efolder/tags","blobs_url":"https://api.github.com/repos/department-of-veterans-affairs/caseflow-efolder/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/department-of-veterans-affairs/caseflow-efolder/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/department-of-veterans-affairs/caseflow-efolder/git/refs{/sha}","trees_url":"https://api.github.com/repos/department-of-veterans-affairs/caseflow-efolder/git/trees{/sha}","statuses_url":"https://api.github.com/repos/department-of-veterans-affairs/caseflow-efolder/statuses/{sha}","languages_url":"https://api.github.com/repos/department-of-veterans-affairs/caseflow-efolder/languages","stargazers_url":"https://api.github.com/repos/department-of-veterans-affairs/caseflow-efolder/stargazers","contributors_url":"https://api.github.com/repos/department-of-veterans-affairs/caseflow-efolder/contributors","subscribers_url":"https://api.github.com/repos/department-of-veterans-affairs/caseflow-efolder/subscribers","subscription_url":"https://api.github.com/repos/department-of-veterans-affairs/caseflow-efolder/subscription","commits_url":"https://api.github.com/repos/department-of-veterans-affairs/caseflow-efolder/commits{/sha}","git_commits_url":"https://api.github.com/repos/department-of-veterans-affairs/caseflow-efolder/git/commits{/sha}","comments_url":"https://api.github.com/repos/department-of-veterans-affairs/caseflow-efolder/comments{/number}","issue_comment_url":"https://api.github.com/repos/department-of-veterans-affairs/caseflow-efolder/issues/comments{/number}","contents_url":"https://api.github.com/repos/department-of-veterans-affairs/caseflow-efolder/contents/{+path}","compare_url":"https://api.github.com/repos/department-of-veterans-affairs/caseflow-efolder/compare/{base}...{head}","merges_url":"https://api.github.com/repos/department-of-veterans-affairs/caseflow-efolder/merges","archive_url":"https://api.github.com/repos/department-of-veterans-affairs/caseflow-efolder/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/department-of-veterans-affairs/caseflow-efolder/downloads","issues_url":"https://api.github.com/repos/department-of-veterans-affairs/caseflow-efolder/issues{/number}","pulls_url":"https://api.github.com/repos/department-of-veterans-affairs/caseflow-efolder/pulls{/number}","milestones_url":"https://api.github.com/repos/department-of-veterans-affairs/caseflow-efolder/milestones{/number}","notifications_url":"https://api.github.com/repos/department-of-veterans-affairs/caseflow-efolder/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/department-of-veterans-affairs/caseflow-efolder/labels{/name}","releases_url":"https://api.github.com/repos/department-of-veterans-affairs/caseflow-efolder/releases{/id}","deployments_url":"https://api.github.com/repos/department-of-veterans-affairs/caseflow-efolder/deployments","created_at":"2016-01-21T19:08:28Z","updated_at":"2016-08-26T06:33:34Z","pushed_at":"2016-10-18T14:20:48Z","git_url":"git://github.com/department-of-veterans-affairs/caseflow-efolder.git","ssh_url":"git@github.com:department-of-veterans-affairs/caseflow-efolder.git","clone_url":"https://github.com/department-of-veterans-affairs/caseflow-efolder.git","svn_url":"https://github.com/department-of-veterans-affairs/caseflow-efolder","homepage":null,"size":3909,"stargazers_count":1,"watchers_count":1,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2,"mirror_url":null,"open_issues_count":19,"forks":2,"open_issues":19,"watchers":1,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/department-of-veterans-affairs/caseflow-efolder/pulls/256"},"html":{"href":"https://github.com/department-of-veterans-affairs/caseflow-efolder/pull/256"},"issue":{"href":"https://api.github.com/repos/department-of-veterans-affairs/caseflow-efolder/issues/256"},"comments":{"href":"https://api.github.com/repos/department-of-veterans-affairs/caseflow-efolder/issues/256/comments"},"review_comments":{"href":"https://api.github.com/repos/department-of-veterans-affairs/caseflow-efolder/pulls/256/comments"},"review_comment":{"href":"https://api.github.com/repos/department-of-veterans-affairs/caseflow-efolder/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/department-of-veterans-affairs/caseflow-efolder/pulls/256/commits"},"statuses":{"href":"https://api.github.com/repos/department-of-veterans-affairs/caseflow-efolder/statuses/a0277ce84750dd0bb8542709bc09e3d1d89e58ec"}}}}
{"actor":{"display_login":"shanear"}}