Permalink
Browse files

avg hours per day for gecko board

  • Loading branch information...
bernardo committed Nov 19, 2011
1 parent 56b5966 commit 67d3134bfd90abc13cbf35ef96106486f81db463
Showing with 48 additions and 39 deletions.
  1. +5 −14 .idea/workspace.xml
  2. +42 −25 app/controllers/stats_controller.rb
  3. +1 −0 config/routes.rb
View
@@ -33,16 +33,7 @@
<file leaf-file-name="routes.rb" pinned="false" current="true" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/config/routes.rb">
<provider selected="true" editor-type-id="text-editor">
- <state line="12" column="0" selection-start="469" selection-end="469" vertical-scroll-proportion="0.29675424">
- <folding />
- </state>
- </provider>
- </entry>
- </file>
- <file leaf-file-name="stats_controller.rb" pinned="false" current="false" current-in-tab="false">
- <entry file="file://$PROJECT_DIR$/app/controllers/stats_controller.rb">
- <provider selected="true" editor-type-id="text-editor">
- <state line="69" column="43" selection-start="2084" selection-end="2084" vertical-scroll-proportion="0.0">
+ <state line="7" column="13" selection-start="161" selection-end="161" vertical-scroll-proportion="0.17310664">
<folding />
</state>
</provider>
@@ -76,8 +67,8 @@
<option value="$PROJECT_DIR$/app/controllers/users_controller.rb" />
<option value="$PROJECT_DIR$/config/locales/will_paginate.yml" />
<option value="$PROJECT_DIR$/db/migrate/20111119190729_add_indexes.rb" />
- <option value="$PROJECT_DIR$/app/controllers/stats_controller.rb" />
<option value="$PROJECT_DIR$/config/routes.rb" />
+ <option value="$PROJECT_DIR$/app/controllers/stats_controller.rb" />
</list>
</option>
</component>
@@ -590,7 +581,7 @@
</todo-panel>
</component>
<component name="ToolWindowManager">
- <frame x="306" y="176" width="1385" height="783" extended-state="0" />
+ <frame x="304" y="215" width="1385" height="783" extended-state="0" />
<editor active="true" />
<layout>
<window_info id="Data Sources" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="3" side_tool="false" content_ui="tabs" />
@@ -755,14 +746,14 @@
</entry>
<entry file="file://$PROJECT_DIR$/app/controllers/stats_controller.rb">
<provider selected="true" editor-type-id="text-editor">
- <state line="69" column="43" selection-start="2084" selection-end="2084" vertical-scroll-proportion="0.0">
+ <state line="47" column="16" selection-start="1480" selection-end="1480" vertical-scroll-proportion="0.5054096">
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/config/routes.rb">
<provider selected="true" editor-type-id="text-editor">
- <state line="12" column="0" selection-start="469" selection-end="469" vertical-scroll-proportion="0.29675424">
+ <state line="7" column="13" selection-start="161" selection-end="161" vertical-scroll-proportion="0.17310664">
<folding />
</state>
</provider>
@@ -1,22 +1,22 @@
class StatsController < ApplicationController
-
+
COLORS = %w(8DD3C7 FFFFB3 BEBADA FB8072 80B1D3 FDB462 B3DE69 FCCDE5 D9D9D9 BC80BD CCEBC5 FFED6F)
-
+
def index
month_names = %w(JAN FEV MAR ABR MAI JUN JUL AGO SET OUT NOV DEZ)
-
+
@users = User.by_name
start = Time.parse('2011-11-14')
finish = Time.now
number_of_weeks = ((finish - start) / 60 / 60 / 24 / 7).ceil
-
+
@week_ranges = []
last_week = start
(1..number_of_weeks).each do
@week_ranges.push last_week..(1.week.since(last_week))
last_week += 1.week
end
-
+
@week_names = @week_ranges.map do |week_range|
#o ano em que o primeiro dia da semana começa
year = week_range.begin.at_beginning_of_week.year - 2000
@@ -26,41 +26,58 @@ def index
week_number = ((week_range.begin.at_beginning_of_week - week_range.begin.at_beginning_of_month) / 60 / 60 / 24 / 7).ceil
"%1d%3s%2.2d" % [week_number, month_names[month-1], year]
end
-
+
@series = @users.map do |u|
hours = @week_ranges.map do |week_range|
u.hours_worked(week_range).round
end
{:name => u.name, :data => hours}
end
-
- @pie_series = @users.map{ |u|
- { :y => u.hours_worked(start..finish).round, :name => u.name}
+
+ @pie_series = @users.map { |u|
+ {:y => u.hours_worked(start..finish).round, :name => u.name}
}
-
+
end
-
- def gecko_this_week_pie
+
+ def gecko_daily_avg_30_days
users = User.by_name
- start = 1.week.ago
- finish = Time.now
-
- render :text => pie_data(users, start, finish).to_json
+
+ count = -1
+ data = users.map do |u|
+ count += 1
+ days_worked = 0
+ total_hours = 0
+ (1..30).each do |n|
+ day = n.days.ago
+ start = day.beginning_of_day
+ finish = day.end_of_day
+ hours = u.hours_worked(start..finish)
+ if hours > 2 #only days with more than 2 hours worked count
+ days_worked += 1
+ total_hours += hours
+ end
+ end
+ avg = total_hours.to_f/days_worked
+ {:value => avg, :label => "#{u.name} (#{"%2.1f" % avg}h)", :colour=> COLORS[count]}
+ end
+
+ render :text => {:item => data}.to_json
end
-
+
def gecko_last_week_pie
users = User.by_name
start = 1.week.ago.at_beginning_of_week
finish = Time.now.at_beginning_of_week
-
+
render :text => pie_data(users, start, finish).to_json
end
def gecko_this_month_pie
users = User.by_name
start = 1.month.ago
finish = Time.now
-
+
render :text => pie_data(users, start, finish).to_json
end
@@ -71,25 +88,25 @@ def gecko_last_month_pie
render :text => pie_data(users, start, finish).to_json
end
-
+
def gecko_from_checkpoint_pie
users = User.by_name
start = Time.parse('2011-11-14')
finish = Time.now
-
+
render :text => pie_data(users, start, finish).to_json
end
-
+
protected
-
+
def pie_data(users, start, finish)
count = -1
data = users.map do |u|
count += 1
value = u.hours_worked(start..finish).round
- { :value => value, :label => "#{u.name} (#{value}h)", :colour=> COLORS[count]}
+ {:value => value, :label => "#{u.name} (#{value}h)", :colour=> COLORS[count]}
end
return_data = {:item => data}
end
-
+
end
View
@@ -5,6 +5,7 @@
resources :punches
match "stats" => 'stats#index'
+ match "gecko_daily_avg_30_days" => 'stats#gecko_daily_avg_30_days'
match "gecko_last_week_pie" => 'stats#gecko_last_week_pie'
match "gecko_last_month_pie" => 'stats#gecko_last_month_pie'
match "gecko_this_week_pie" => 'stats#gecko_this_week_pie'

0 comments on commit 67d3134

Please sign in to comment.