Skip to content
This repository

Ruby 1.8.7 compatibilty #7

Merged
merged 5 commits into from over 1 year ago

2 participants

Toshi MARUYAMA Tiago Franco
Toshi MARUYAMA
Collaborator

No description provided.

Tiago Franco gamafranco merged commit a2ca33f into from January 02, 2013
Tiago Franco gamafranco closed this January 02, 2013
Tiago Franco
Owner

@marutosi, thanks for this. We had this patch on the TODO list, but were not able to deliver yet. Well done.

I'll create an issue for us to monkey patch the Float class and add the round(int) method to it. This will make the code a bit more DRYer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
1  .gitignore
@@ -29,3 +29,4 @@
29 29
 /Gemfile.local
30 30
 /.idea
31 31
 .svn
  32
+.hg
19  app/controllers/ratios_controller.rb
... ...
@@ -1,17 +1,10 @@
1 1
 class RatiosController < ApplicationController
2  
-  	unloadable
  2
+	unloadable
3 3
 	include IndicatorsLogic
4 4
 
5  
-  def index
6  
-  
7  
-  	@project = Project.find(params[:id])
8  
-  	@proj_or_vers_data = IndicatorsLogic::retrive_data(@project)
9  
-	@proj_or_vers_indicators = IndicatorsLogic::calc_indicators(@project, @proj_or_vers_data[0], @proj_or_vers_data[1])
10  
-		
11  
-  end
12  
-
13  
- 
  5
+	def index
  6
+		@project = Project.find(params[:id])
  7
+		@proj_or_vers_data = IndicatorsLogic::retrive_data(@project)
  8
+		@proj_or_vers_indicators = IndicatorsLogic::calc_indicators(@project, @proj_or_vers_data[0], @proj_or_vers_data[1])
  9
+	end
14 10
 end
15  
-
16  
-
17  
-
3  app/helpers/ratios_helper.rb
... ...
@@ -1,5 +1,2 @@
1 1
 module RatiosHelper
2  
-
3  
-
4  
-
5 2
 end
21  app/views/ratios/_bottom_js.html.erb
... ...
@@ -1,16 +1,14 @@
1  
-
2 1
 <div id="chart <%= name %>" class="goocharts"></div>
3 2
 <div id="gauge_cpi <%= name %>" class="googauges"></div>
4 3
 <div id="gauge_spi <%= name %>" class="googauges"></div>
5 4
 <div style="clear:both;"></div>
6 5
 <script type="text/javascript">
7  
-    drawChart();
8  
-    drawCpi();
9  
-    drawSpi();
  6
+	drawChart();
  7
+	drawCpi();
  8
+	drawSpi();
10 9
 
11 10
 	function drawChart() {
12  
-		var data = new google.visualization.arrayToDataTable(<%=raw @proj_or_vers_indicators[0] %>);
13  
-
  11
+		var data = new google.visualization.arrayToDataTable(<%=raw @proj_or_vers_indicators[0].to_json %>);
14 12
 		var options = {
15 13
 		title: 'EVM Indicators - <%= name %>',
16 14
 		series: {0:{color: 'red'},
@@ -18,7 +16,6 @@
18 16
 		       2:{color: 'green'}},
19 17
 		vAxis: {title: 'Hours',  titleTextStyle: {color: 'red'}}
20 18
 		};
21  
-
22 19
 		var chart = new google.visualization.LineChart(document.getElementById("chart <%= name %>"));
23 20
 		chart.draw(data, options);
24 21
 	}
@@ -27,10 +24,8 @@
27 24
 		// Create and populate the data table.
28 25
 		var data_gauge = new google.visualization.arrayToDataTable([
29 26
 		  ['Label', 'Value'],
30  
-		  ['CPI', <%=raw @proj_or_vers_indicators[1].round(3) %>]
  27
+		  ['CPI', <%= raw (@proj_or_vers_indicators[1] * 1000).to_f.round / 1000 %>]
31 28
 		]);
32  
-	
33  
-	 
34 29
 		var options_g = {
35 30
 		  redFrom: 0, redTo: 0.85,
36 31
 		  yellowFrom:0.85, yellowTo: 1,
@@ -38,7 +33,6 @@
38 33
 		  minorTicks:5,
39 34
 		  min:0, max:2
40 35
 		};
41  
-
42 36
 		// Create and draw the visualization.
43 37
 		var gauge= new google.visualization.Gauge(document.getElementById("gauge_cpi <%= name %>"));
44 38
 		gauge.draw(data_gauge, options_g);
@@ -48,10 +42,8 @@
48 42
 		// Create and populate the data table.
49 43
 		var data_gauges = new google.visualization.arrayToDataTable([
50 44
 		  ['Label', 'Value'],
51  
-		  ['SPI', <%=raw @proj_or_vers_indicators[2].round(3) %>]
  45
+		  ['SPI', <%= raw (@proj_or_vers_indicators[2] * 1000).to_f.round / 1000 %>]
52 46
 		]);
53  
-	
54  
-	 
55 47
 		var options_gs = {
56 48
 		  redFrom: 0, redTo: 0.85,
57 49
 		  yellowFrom:0.85, yellowTo: 1,
@@ -59,7 +51,6 @@
59 51
 		  minorTicks:5,
60 52
 		  min:0, max:2
61 53
 		};
62  
-
63 54
 		// Create and draw the visualization.
64 55
 		var gauge= new google.visualization.Gauge(document.getElementById("gauge_spi <%= name %>"));
65 56
 		gauge.draw(data_gauges, options_gs);
43  lib/indicators_logic.rb
@@ -4,67 +4,57 @@ def self.retrive_data(project_or_version)
4 4
 		if project_or_version.instance_of? Version
5 5
 			my_project = project_or_version.project
6 6
 			my_version = project_or_version
7  
-		
  7
+
8 8
 			ary_reported_time_week_year = my_project.time_entries.where(:issue_id=>Issue.where(:fixed_version_id=>my_version.id)).sum(:hours, :group =>[:tweek, :tyear], :order=> [:tyear, :tweek])
9 9
 			ary_all_issues = my_version.fixed_issues
10  
-			
11 10
 		else
12 11
 			my_project = project_or_version
13 12
 			ary_reported_time_week_year = my_project.time_entries.sum(:hours, :group =>[:tweek, :tyear], :order=> [:tyear, :tweek])
14 13
 			ary_all_issues = my_project.issues
15 14
 		end
16  
-
17 15
 		return [ary_reported_time_week_year, ary_all_issues]
18 16
 	end
19  
-	
20  
-		
21  
-	def self.calc_indicators(my_project_or_version, ary_reported_time_week_year, ary_all_issues)
22 17
 
  18
+	def self.calc_indicators(my_project_or_version, ary_reported_time_week_year, ary_all_issues)
23 19
 		check_end_date = my_project_or_version.due_date || Time.now.to_date
24 20
 		check_ary_reported_time_week_year = ary_reported_time_week_year.empty? ? Time.now.to_date : Date.ordinal(ary_reported_time_week_year.keys.last[1], ary_reported_time_week_year.keys.last[0]*7-3)
25 21
 		check_ary_all_issues = ary_all_issues.empty? ? Time.now.to_date : ary_all_issues.maximum(:start_date)
26 22
 		my_project_or_version_end_date = [check_end_date,check_ary_reported_time_week_year, check_ary_all_issues].max
27  
-		
  23
+
28 24
 		ary_weeks_years = []
29  
-		
  25
+
30 26
 		real_start_date = [(my_project_or_version.start_date.nil? ? (Time.now.to_date - 1.day): my_project_or_version.start_date.beginning_of_week), (ary_reported_time_week_year.empty? ? Time.now.to_date : Date.ordinal(ary_reported_time_week_year.keys.first[1], ary_reported_time_week_year.keys.first[0]*7-3))].min
31  
-		
  27
+
32 28
 		while real_start_date < my_project_or_version_end_date + 1.week
33 29
 			ary_weeks_years << [real_start_date.cweek, real_start_date.cwyear]
34 30
 			real_start_date += 1.week
35  
-		end	
36  
-		
  31
+		end
  32
+
37 33
 		hash_weeks_years = {}
38 34
 		ary_weeks_years.each{|e| hash_weeks_years[e] = [0,0,0]}
39 35
 		@done_ratio = 0
40  
-		
41  
-		ary_all_issues.each do |issue|
42 36
 
  37
+		ary_all_issues.each do |issue|
43 38
 				start_issue_date = issue.start_date? ? issue.start_date : my_project_or_version.start_date
44 39
 				end_issue_date = issue.due_date? ? issue.due_date : my_project_or_version_end_date
45 40
 				estimated_time = issue.estimated_hours? ? issue.estimated_hours : 0
46 41
 				@done_ratio = (issue.done_ratio / 100.0)
47 42
 				ary_dates = (start_issue_date..end_issue_date).to_a
48  
-				ary_dates.delete_if{|x| x.saturday? || x.sunday?}
49  
-				
  43
+				ary_dates.delete_if{|x| x.wday == 5 || x.wday == 6}
50 44
 				if ary_dates.any? && estimated_time != 0
51  
-					hoursPerDay = estimated_time / ary_dates.size		
  45
+					hoursPerDay = estimated_time / ary_dates.size
52 46
 					ary_dates.each do |day|
53  
-						week = day.cweek				
  47
+						week = day.cweek
54 48
 						year = day.cwyear
55 49
 						hash_weeks_years[[week,year]][1] += hoursPerDay
56 50
 						hash_weeks_years[[week,year]][2] += hoursPerDay * @done_ratio
57 51
 					end
58  
-					
59 52
 				end
60  
-				
61 53
 		end
62  
-
63 54
 		@ary_data_week_years = [Array['week', 'ActualCost', 'PlannedCost', 'EarnedValue']]
64 55
 		sum_real = 0
65 56
 		sum_planned = 0
66 57
 		sum_earned = 0
67  
-		
68 58
 		hash_weeks_years.each do |k,v|
69 59
 			sum_real += ary_reported_time_week_year.has_key?(k)? ary_reported_time_week_year[k] : 0
70 60
 			v[0] = sum_real
@@ -72,19 +62,18 @@ def self.calc_indicators(my_project_or_version, ary_reported_time_week_year, ary
72 62
 			v[1] = sum_planned
73 63
 			sum_earned += v[2]
74 64
 			v[2] = sum_earned
75  
-			@ary_data_week_years.push(Array[k[0].to_s + "/" + k[1].to_s, v[0].round(2), v[1].round(2), v[2].round(2)])
  65
+			@ary_data_week_years.push(
  66
+				Array[k[0].to_s + "/" + k[1].to_s,
  67
+							 ((v[0] * 100).to_f).round / 100,
  68
+							 ((v[1] * 100).to_f).round / 100,
  69
+							 ((v[2] * 100).to_f).round / 100])
76 70
 		end
77  
-
78 71
 		@cpi = hash_weeks_years.values.last[0].zero? ? 0 : hash_weeks_years.values.last[2]/hash_weeks_years.values.last[0]
79 72
 		@spi = hash_weeks_years.values.last[1].zero? ? 0 : hash_weeks_years.values.last[2]/hash_weeks_years.values.last[1]
80 73
 		return [@ary_data_week_years, @cpi, @spi]
81  
-	
82 74
 	end
83 75
 
84  
-
85  
-
86 76
 	def self.included(base)
87 77
 		base.send :helper_method, :calc_indicators, :retrive_data if base.respond_to? :helper_method
88 78
 	end
89  
-
90 79
 end
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.