{"action":"created","comment":{"url":"https://api.github.com/repos/coopdevs/timeoverflow/pulls/comments/61668296","id":61668296,"diff_hunk":"@@ -1,88 +1,31 @@\n class StatisticsController < ApplicationController\n-  AGE_GROUP_LABELS = {\n-    0..17 => \" -17\",\n-    18..24 => \"18-24\",\n-    25..34 => \"25-34\",\n-    35..44 => \"35-44\",\n-    45..54 => \"45-54\",\n-    55..64 => \"55-64\",\n-    65..100 => \"65+\",\n-  }\n-\n   before_filter :authenticate_user!\n+  before_action :load_members, except: [:statistics_type_swaps,\n+                                        :statistics_all_transfers]\n+  before_action :load_transfers, only: [:statistics_global_activity,\n+                                        :statistics_all_transfers]\n \n   def statistics_global_activity\n-    @members = current_organization.members\n-    @active_members = @members.active\n-    @total_hours = num_movements = 0\n-    @members.each do |m|\n-      num_movements += m.account.movements.count\n-      @total_hours += m.account.movements.map do\n-        |a| (a.amount > 0) ? a.amount : 0\n-      end.inject(0, :+)\n-    end\n-    # cada intercambio implica dos movimientos\n-    @num_swaps = (num_movements +\n-                  current_organization.account.movements.count) / 2\n-    # intercambios con el banco\n-    @total_hours += current_organization.account.movements.\n-                    map { |a| (a.amount > 0) ? a.amount : 0 }.inject(0, :+)\n-    # periodo a mostrar actividades globales, por defecto 6 meses\n-    ini = params[:ini].presence.try(:to_date) || DateTime.now.to_date - 5.month\n-    fin = params[:fin].presence.try(:to_date) || DateTime.now.to_date\n-    if ini.present?\n-      # calculo numero de meses\n-      num_months = (fin.year * 12 + fin.month) - (ini.year * 12 + ini.month) + 1\n-      date = ini\n-      # vector para los meses de la gráfica [\"Enero\", \"Febrero\",...]\n-      @months_names = []\n-      # y vectores con los datos para la gráfica\n-      @user_reg_months = []\n-      @num_swaps_months = []\n-      @hours_swaps_months = []\n-      # valores por cada mes\n-      num_months.times do\n-        @months_names.push(l(date, format: \"%B %Y\"))\n-        @user_reg_months.push(@members.by_month(date).count)\n-        # movimientos de los miembros en dicho mes\n-        swaps_members = @members.map { |a| a.account.movements.by_month(date) }\n-        # movimimentos del banco\n-        swaps_organization = current_organization.account.\n-                             movements.by_month(date)\n-        # numero de movimientos totales\n-        sum_swaps = (swaps_members.flatten.count + swaps_organization.count) / 2\n-        @num_swaps_months.push(sum_swaps)\n-        # horas intercambiadas\n-        sum_hours = 0\n-        swaps_members.flatten.each do |s|\n-          sum_hours += (s.amount > 0) ? s.amount : 0\n-        end\n-        sum_hours += swaps_organization.map do\n-          |a| (a.amount > 0) ? a.amount : 0\n-        end.inject(0, :+)\n-        sum_hours = sum_hours / 3600.0 if sum_hours > 0\n-        @hours_swaps_months.push(sum_hours)\n-        date = date.next_month\n-      end\n-    end\n+    @data = StatsCalculator.new.global_activity(@members, @transfers,\n+                                                params[:from], params[:to])\n   end\n \n   def statistics_inactive_users\n-    @members = current_organization.members.active\n+    @members = @members.active.includes(:account).sort_by(&:days_without_swaps).\n+               reverse.map { |a| a unless a.days_without_swaps.zero? }.compact","path":"app/controllers/statistics_controller.rb","position":79,"original_position":79,"commit_id":"416f6b152c73446b4750b4ab727a76d18b9f8277","original_commit_id":"416f6b152c73446b4750b4ab727a76d18b9f8277","user":{"login":"enricostano","id":748971,"avatar_url":"https://avatars.githubusercontent.com/u/748971?v=3","gravatar_id":"","url":"https://api.github.com/users/enricostano","html_url":"https://github.com/enricostano","followers_url":"https://api.github.com/users/enricostano/followers","following_url":"https://api.github.com/users/enricostano/following{/other_user}","gists_url":"https://api.github.com/users/enricostano/gists{/gist_id}","starred_url":"https://api.github.com/users/enricostano/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/enricostano/subscriptions","organizations_url":"https://api.github.com/users/enricostano/orgs","repos_url":"https://api.github.com/users/enricostano/repos","events_url":"https://api.github.com/users/enricostano/events{/privacy}","received_events_url":"https://api.github.com/users/enricostano/received_events","type":"User","site_admin":false},"body":"@PatriRor esta logica ha cambiado en https://github.com/coopdevs/timeoverflow/pull/207 \r\n\r\nPodrias hacer review de ese PR y llevarte esos cambios aqui?\r\n\r\nGracias!!! :smile: ","created_at":"2016-04-30T11:14:44Z","updated_at":"2016-04-30T11:14:44Z","html_url":"https://github.com/coopdevs/timeoverflow/pull/184#discussion_r61668296","pull_request_url":"https://api.github.com/repos/coopdevs/timeoverflow/pulls/184","_links":{"self":{"href":"https://api.github.com/repos/coopdevs/timeoverflow/pulls/comments/61668296"},"html":{"href":"https://github.com/coopdevs/timeoverflow/pull/184#discussion_r61668296"},"pull_request":{"href":"https://api.github.com/repos/coopdevs/timeoverflow/pulls/184"}}},"pull_request":{"url":"https://api.github.com/repos/coopdevs/timeoverflow/pulls/184","id":56975336,"html_url":"https://github.com/coopdevs/timeoverflow/pull/184","diff_url":"https://github.com/coopdevs/timeoverflow/pull/184.diff","patch_url":"https://github.com/coopdevs/timeoverflow/pull/184.patch","issue_url":"https://api.github.com/repos/coopdevs/timeoverflow/issues/184","number":184,"state":"open","locked":false,"title":"refactor global activity statistics","user":{"login":"PatriRor","id":5472707,"avatar_url":"https://avatars.githubusercontent.com/u/5472707?v=3","gravatar_id":"","url":"https://api.github.com/users/PatriRor","html_url":"https://github.com/PatriRor","followers_url":"https://api.github.com/users/PatriRor/followers","following_url":"https://api.github.com/users/PatriRor/following{/other_user}","gists_url":"https://api.github.com/users/PatriRor/gists{/gist_id}","starred_url":"https://api.github.com/users/PatriRor/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/PatriRor/subscriptions","organizations_url":"https://api.github.com/users/PatriRor/orgs","repos_url":"https://api.github.com/users/PatriRor/repos","events_url":"https://api.github.com/users/PatriRor/events{/privacy}","received_events_url":"https://api.github.com/users/PatriRor/received_events","type":"User","site_admin":false},"body":"","created_at":"2016-01-23T12:34:50Z","updated_at":"2016-04-30T11:14:44Z","closed_at":null,"merged_at":null,"merge_commit_sha":"660f95b3ae1165d19683466cb0accb39ea6a1325","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/coopdevs/timeoverflow/pulls/184/commits","review_comments_url":"https://api.github.com/repos/coopdevs/timeoverflow/pulls/184/comments","review_comment_url":"https://api.github.com/repos/coopdevs/timeoverflow/pulls/comments{/number}","comments_url":"https://api.github.com/repos/coopdevs/timeoverflow/issues/184/comments","statuses_url":"https://api.github.com/repos/coopdevs/timeoverflow/statuses/416f6b152c73446b4750b4ab727a76d18b9f8277","head":{"label":"coopdevs:refactor_global_stats","ref":"refactor_global_stats","sha":"416f6b152c73446b4750b4ab727a76d18b9f8277","user":{"login":"coopdevs","id":4038308,"avatar_url":"https://avatars.githubusercontent.com/u/4038308?v=3","gravatar_id":"","url":"https://api.github.com/users/coopdevs","html_url":"https://github.com/coopdevs","followers_url":"https://api.github.com/users/coopdevs/followers","following_url":"https://api.github.com/users/coopdevs/following{/other_user}","gists_url":"https://api.github.com/users/coopdevs/gists{/gist_id}","starred_url":"https://api.github.com/users/coopdevs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/coopdevs/subscriptions","organizations_url":"https://api.github.com/users/coopdevs/orgs","repos_url":"https://api.github.com/users/coopdevs/repos","events_url":"https://api.github.com/users/coopdevs/events{/privacy}","received_events_url":"https://api.github.com/users/coopdevs/received_events","type":"Organization","site_admin":false},"repo":{"id":6365733,"name":"timeoverflow","full_name":"coopdevs/timeoverflow","owner":{"login":"coopdevs","id":4038308,"avatar_url":"https://avatars.githubusercontent.com/u/4038308?v=3","gravatar_id":"","url":"https://api.github.com/users/coopdevs","html_url":"https://github.com/coopdevs","followers_url":"https://api.github.com/users/coopdevs/followers","following_url":"https://api.github.com/users/coopdevs/following{/other_user}","gists_url":"https://api.github.com/users/coopdevs/gists{/gist_id}","starred_url":"https://api.github.com/users/coopdevs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/coopdevs/subscriptions","organizations_url":"https://api.github.com/users/coopdevs/orgs","repos_url":"https://api.github.com/users/coopdevs/repos","events_url":"https://api.github.com/users/coopdevs/events{/privacy}","received_events_url":"https://api.github.com/users/coopdevs/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/coopdevs/timeoverflow","description":"A time banking system","fork":false,"url":"https://api.github.com/repos/coopdevs/timeoverflow","forks_url":"https://api.github.com/repos/coopdevs/timeoverflow/forks","keys_url":"https://api.github.com/repos/coopdevs/timeoverflow/keys{/key_id}","collaborators_url":"https://api.github.com/repos/coopdevs/timeoverflow/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/coopdevs/timeoverflow/teams","hooks_url":"https://api.github.com/repos/coopdevs/timeoverflow/hooks","issue_events_url":"https://api.github.com/repos/coopdevs/timeoverflow/issues/events{/number}","events_url":"https://api.github.com/repos/coopdevs/timeoverflow/events","assignees_url":"https://api.github.com/repos/coopdevs/timeoverflow/assignees{/user}","branches_url":"https://api.github.com/repos/coopdevs/timeoverflow/branches{/branch}","tags_url":"https://api.github.com/repos/coopdevs/timeoverflow/tags","blobs_url":"https://api.github.com/repos/coopdevs/timeoverflow/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/coopdevs/timeoverflow/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/coopdevs/timeoverflow/git/refs{/sha}","trees_url":"https://api.github.com/repos/coopdevs/timeoverflow/git/trees{/sha}","statuses_url":"https://api.github.com/repos/coopdevs/timeoverflow/statuses/{sha}","languages_url":"https://api.github.com/repos/coopdevs/timeoverflow/languages","stargazers_url":"https://api.github.com/repos/coopdevs/timeoverflow/stargazers","contributors_url":"https://api.github.com/repos/coopdevs/timeoverflow/contributors","subscribers_url":"https://api.github.com/repos/coopdevs/timeoverflow/subscribers","subscription_url":"https://api.github.com/repos/coopdevs/timeoverflow/subscription","commits_url":"https://api.github.com/repos/coopdevs/timeoverflow/commits{/sha}","git_commits_url":"https://api.github.com/repos/coopdevs/timeoverflow/git/commits{/sha}","comments_url":"https://api.github.com/repos/coopdevs/timeoverflow/comments{/number}","issue_comment_url":"https://api.github.com/repos/coopdevs/timeoverflow/issues/comments{/number}","contents_url":"https://api.github.com/repos/coopdevs/timeoverflow/contents/{+path}","compare_url":"https://api.github.com/repos/coopdevs/timeoverflow/compare/{base}...{head}","merges_url":"https://api.github.com/repos/coopdevs/timeoverflow/merges","archive_url":"https://api.github.com/repos/coopdevs/timeoverflow/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/coopdevs/timeoverflow/downloads","issues_url":"https://api.github.com/repos/coopdevs/timeoverflow/issues{/number}","pulls_url":"https://api.github.com/repos/coopdevs/timeoverflow/pulls{/number}","milestones_url":"https://api.github.com/repos/coopdevs/timeoverflow/milestones{/number}","notifications_url":"https://api.github.com/repos/coopdevs/timeoverflow/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/coopdevs/timeoverflow/labels{/name}","releases_url":"https://api.github.com/repos/coopdevs/timeoverflow/releases{/id}","deployments_url":"https://api.github.com/repos/coopdevs/timeoverflow/deployments","created_at":"2012-10-24T06:48:53Z","updated_at":"2016-03-18T17:26:56Z","pushed_at":"2016-04-30T11:10:30Z","git_url":"git://github.com/coopdevs/timeoverflow.git","ssh_url":"git@github.com:coopdevs/timeoverflow.git","clone_url":"https://github.com/coopdevs/timeoverflow.git","svn_url":"https://github.com/coopdevs/timeoverflow","homepage":null,"size":3961,"stargazers_count":37,"watchers_count":37,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":28,"mirror_url":null,"open_issues_count":9,"forks":28,"open_issues":9,"watchers":37,"default_branch":"master"}},"base":{"label":"coopdevs:master","ref":"master","sha":"84484beb33c7a17c4d86f5fc30da91cc49159140","user":{"login":"coopdevs","id":4038308,"avatar_url":"https://avatars.githubusercontent.com/u/4038308?v=3","gravatar_id":"","url":"https://api.github.com/users/coopdevs","html_url":"https://github.com/coopdevs","followers_url":"https://api.github.com/users/coopdevs/followers","following_url":"https://api.github.com/users/coopdevs/following{/other_user}","gists_url":"https://api.github.com/users/coopdevs/gists{/gist_id}","starred_url":"https://api.github.com/users/coopdevs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/coopdevs/subscriptions","organizations_url":"https://api.github.com/users/coopdevs/orgs","repos_url":"https://api.github.com/users/coopdevs/repos","events_url":"https://api.github.com/users/coopdevs/events{/privacy}","received_events_url":"https://api.github.com/users/coopdevs/received_events","type":"Organization","site_admin":false},"repo":{"id":6365733,"name":"timeoverflow","full_name":"coopdevs/timeoverflow","owner":{"login":"coopdevs","id":4038308,"avatar_url":"https://avatars.githubusercontent.com/u/4038308?v=3","gravatar_id":"","url":"https://api.github.com/users/coopdevs","html_url":"https://github.com/coopdevs","followers_url":"https://api.github.com/users/coopdevs/followers","following_url":"https://api.github.com/users/coopdevs/following{/other_user}","gists_url":"https://api.github.com/users/coopdevs/gists{/gist_id}","starred_url":"https://api.github.com/users/coopdevs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/coopdevs/subscriptions","organizations_url":"https://api.github.com/users/coopdevs/orgs","repos_url":"https://api.github.com/users/coopdevs/repos","events_url":"https://api.github.com/users/coopdevs/events{/privacy}","received_events_url":"https://api.github.com/users/coopdevs/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/coopdevs/timeoverflow","description":"A time banking system","fork":false,"url":"https://api.github.com/repos/coopdevs/timeoverflow","forks_url":"https://api.github.com/repos/coopdevs/timeoverflow/forks","keys_url":"https://api.github.com/repos/coopdevs/timeoverflow/keys{/key_id}","collaborators_url":"https://api.github.com/repos/coopdevs/timeoverflow/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/coopdevs/timeoverflow/teams","hooks_url":"https://api.github.com/repos/coopdevs/timeoverflow/hooks","issue_events_url":"https://api.github.com/repos/coopdevs/timeoverflow/issues/events{/number}","events_url":"https://api.github.com/repos/coopdevs/timeoverflow/events","assignees_url":"https://api.github.com/repos/coopdevs/timeoverflow/assignees{/user}","branches_url":"https://api.github.com/repos/coopdevs/timeoverflow/branches{/branch}","tags_url":"https://api.github.com/repos/coopdevs/timeoverflow/tags","blobs_url":"https://api.github.com/repos/coopdevs/timeoverflow/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/coopdevs/timeoverflow/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/coopdevs/timeoverflow/git/refs{/sha}","trees_url":"https://api.github.com/repos/coopdevs/timeoverflow/git/trees{/sha}","statuses_url":"https://api.github.com/repos/coopdevs/timeoverflow/statuses/{sha}","languages_url":"https://api.github.com/repos/coopdevs/timeoverflow/languages","stargazers_url":"https://api.github.com/repos/coopdevs/timeoverflow/stargazers","contributors_url":"https://api.github.com/repos/coopdevs/timeoverflow/contributors","subscribers_url":"https://api.github.com/repos/coopdevs/timeoverflow/subscribers","subscription_url":"https://api.github.com/repos/coopdevs/timeoverflow/subscription","commits_url":"https://api.github.com/repos/coopdevs/timeoverflow/commits{/sha}","git_commits_url":"https://api.github.com/repos/coopdevs/timeoverflow/git/commits{/sha}","comments_url":"https://api.github.com/repos/coopdevs/timeoverflow/comments{/number}","issue_comment_url":"https://api.github.com/repos/coopdevs/timeoverflow/issues/comments{/number}","contents_url":"https://api.github.com/repos/coopdevs/timeoverflow/contents/{+path}","compare_url":"https://api.github.com/repos/coopdevs/timeoverflow/compare/{base}...{head}","merges_url":"https://api.github.com/repos/coopdevs/timeoverflow/merges","archive_url":"https://api.github.com/repos/coopdevs/timeoverflow/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/coopdevs/timeoverflow/downloads","issues_url":"https://api.github.com/repos/coopdevs/timeoverflow/issues{/number}","pulls_url":"https://api.github.com/repos/coopdevs/timeoverflow/pulls{/number}","milestones_url":"https://api.github.com/repos/coopdevs/timeoverflow/milestones{/number}","notifications_url":"https://api.github.com/repos/coopdevs/timeoverflow/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/coopdevs/timeoverflow/labels{/name}","releases_url":"https://api.github.com/repos/coopdevs/timeoverflow/releases{/id}","deployments_url":"https://api.github.com/repos/coopdevs/timeoverflow/deployments","created_at":"2012-10-24T06:48:53Z","updated_at":"2016-03-18T17:26:56Z","pushed_at":"2016-04-30T11:10:30Z","git_url":"git://github.com/coopdevs/timeoverflow.git","ssh_url":"git@github.com:coopdevs/timeoverflow.git","clone_url":"https://github.com/coopdevs/timeoverflow.git","svn_url":"https://github.com/coopdevs/timeoverflow","homepage":null,"size":3961,"stargazers_count":37,"watchers_count":37,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":28,"mirror_url":null,"open_issues_count":9,"forks":28,"open_issues":9,"watchers":37,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/coopdevs/timeoverflow/pulls/184"},"html":{"href":"https://github.com/coopdevs/timeoverflow/pull/184"},"issue":{"href":"https://api.github.com/repos/coopdevs/timeoverflow/issues/184"},"comments":{"href":"https://api.github.com/repos/coopdevs/timeoverflow/issues/184/comments"},"review_comments":{"href":"https://api.github.com/repos/coopdevs/timeoverflow/pulls/184/comments"},"review_comment":{"href":"https://api.github.com/repos/coopdevs/timeoverflow/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/coopdevs/timeoverflow/pulls/184/commits"},"statuses":{"href":"https://api.github.com/repos/coopdevs/timeoverflow/statuses/416f6b152c73446b4750b4ab727a76d18b9f8277"}}}}