From 17a229bf986e3116656a34384bdbcc32cd6ed365 Mon Sep 17 00:00:00 2001 From: Pedro Kelvin Date: Tue, 5 Dec 2017 09:24:24 -0200 Subject: [PATCH 01/35] Adding velocity varience method in Sprint controller and adding route Signed-off-by: Pedro Kelvin Signed-off-by: Mateus097 Signed-off-by: danieloda --- app/controllers/sprints_controller.rb | 22 ++++++++++++++++++++-- config/routes.rb | 2 +- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/app/controllers/sprints_controller.rb b/app/controllers/sprints_controller.rb index 736ee42..8b398cf 100644 --- a/app/controllers/sprints_controller.rb +++ b/app/controllers/sprints_controller.rb @@ -8,7 +8,7 @@ class SprintsController < ApplicationController validate_release(0, :release_id) end - before_action only: [:show, :update, :destroy, :get_velocity] do + before_action only: [:show, :update, :destroy, :get_velocity, :get_velocity_variance] do validate_sprint(:id, 0) end @@ -66,6 +66,25 @@ def get_velocity end end + def get_velocity_variance + release = @sprint.release + velocity = get_sprints_informations(release.sprints, @sprint) + + total_sprints_points = velocity[:total_points] + velocities = velocity[:velocities] + + amount = release.amount_of_sprints + variance = 0 + + for i in 0..(amount - 1) + variance = variance + (total_sprints_points[i] - velocities[i]) + end + + variance = variance/amount + + render json: variance + end + def get_burndown project = @sprint.release.project if project.is_scoring != false @@ -84,7 +103,6 @@ def get_burndown end end - range = (@sprint.initial_date .. @sprint.final_date) range.each do |date| diff --git a/config/routes.rb b/config/routes.rb index 9f9c2eb..beeaeb9 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -18,7 +18,7 @@ delete "projects/:id/issues", to: "issues#close" get "sprints/:id/velocity", to: "sprints#get_velocity" - + get "sprints/:id/velocity_variance", to: "sprints#get_velocity_variance" resources :users, shallow: true do resources :projects do From 824fd8b98cb38f119b60db038a8fb85b4e8e4095 Mon Sep 17 00:00:00 2001 From: danieloda Date: Thu, 7 Dec 2017 16:54:29 -0200 Subject: [PATCH 02/35] Creating get_debt method to Sprint controller Signed-off-by: MateusO97 Signed-off-by: pedrokelvin --- app/controllers/sprints_controller.rb | 22 +++++++++++++++++++++- config/routes.rb | 1 + 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/app/controllers/sprints_controller.rb b/app/controllers/sprints_controller.rb index 8b398cf..0216317 100644 --- a/app/controllers/sprints_controller.rb +++ b/app/controllers/sprints_controller.rb @@ -8,7 +8,7 @@ class SprintsController < ApplicationController validate_release(0, :release_id) end - before_action only: [:show, :update, :destroy, :get_velocity, :get_velocity_variance] do + before_action only: [:show, :update, :destroy, :get_velocity, :get_velocity_variance, :get_debts] do validate_sprint(:id, 0) end @@ -122,6 +122,26 @@ def get_burndown end end + def get_debts + release = @sprint.release + if release.project.is_scoring == true + velocity = get_sprints_informations(release.sprints, @sprint) + end + + planned_points = 0 + burned_points = 0 + + puts release.sprints.length + for i in 0..(release.sprints.length - 1) + planned_points = planned_points + velocity[:total_points][i] + burned_points = burned_points + velocity[:completed_points][i] + end + + debts = Float(planned_points - burned_points)/planned_points + + render json: debts + end + private def set_sprint @sprint = Sprint.find(params[:id]) diff --git a/config/routes.rb b/config/routes.rb index beeaeb9..be5f120 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -19,6 +19,7 @@ get "sprints/:id/velocity", to: "sprints#get_velocity" get "sprints/:id/velocity_variance", to: "sprints#get_velocity_variance" + get "sprints/:id/debts", to: "sprints#get_debts" resources :users, shallow: true do resources :projects do From 5aa04c1117a54de86507cffe1048781f0a58410d Mon Sep 17 00:00:00 2001 From: Pedro Kelvin Date: Sat, 9 Dec 2017 16:01:05 -0200 Subject: [PATCH 03/35] Adding Burndown helper Signed-off-by: MateusO97 Signed-off-by: danieloda --- app/helpers/burndown_helper.rb | 42 ++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 app/helpers/burndown_helper.rb diff --git a/app/helpers/burndown_helper.rb b/app/helpers/burndown_helper.rb new file mode 100644 index 0000000..3cc7770 --- /dev/null +++ b/app/helpers/burndown_helper.rb @@ -0,0 +1,42 @@ +module BurndownHelper + + def get_burned_points(sprint, burned_stories) + + total_points = 0 + + for story in sprint.stories + total_points += story.story_points + if story.pipeline == "Done" + if burned_stories[story.final_date] == nil + burned_stories[story.final_date] = story.story_points + else + burned_stories[story.final_date] += story.story_points + end + end + end + + return total_points + end + + def get_dates(burned_stories, date_axis, points_axis, range_dates, total_points) + + range_dates.each do |date| + if burned_stories[date] == nil + burned_stories[date] = total_points + else + total_points -= burned_stories[date] + burned_stories[date] = total_points + end + date_axis.push(date) + points_axis.push(burned_stories[date]) + end + end + + def set_ideal_line(days_of_sprint, ideal_line, planned_points) + + for day in (days_of_sprint).downto(0) + ideal_line.push(planned_points * (day / (Float days_of_sprint))) + end + end + +end From b40184763080fc5fd31547a63f066af82df43961 Mon Sep 17 00:00:00 2001 From: Pedro Kelvin Date: Sat, 9 Dec 2017 16:03:57 -0200 Subject: [PATCH 04/35] Refactoring get_burndown method Signed-off-by: MateusO97 Signed-off-by: danieloda --- app/controllers/sprints_controller.rb | 32 +++++---------------------- 1 file changed, 5 insertions(+), 27 deletions(-) diff --git a/app/controllers/sprints_controller.rb b/app/controllers/sprints_controller.rb index 7e3243b..6d3bfc0 100644 --- a/app/controllers/sprints_controller.rb +++ b/app/controllers/sprints_controller.rb @@ -1,6 +1,7 @@ class SprintsController < ApplicationController include ValidationsHelper include VelocityHelper + include BurndownHelper before_action :set_sprint, only: [:show, :update, :destroy, :get_burndown] @@ -88,44 +89,21 @@ def get_velocity_variance def get_burndown project = @sprint.release.project if project.is_scoring != false - total_points = 0 burned_stories = {} coordenates = [] date_axis = [] points_axis = [] ideal_line = [] - for story in @sprint.stories - total_points += story.story_points - if story.pipeline == "Done" - if burned_stories[story.final_date] == nil - burned_stories[story.final_date] = story.story_points - else - burned_stories[story.final_date] += story.story_points - end - end - end + total_points = get_burned_points(@sprint, burned_stories) planned_points = total_points - range = (@sprint.initial_date .. @sprint.final_date) - - range.each do |date| - if burned_stories[date] == nil - burned_stories[date] = total_points - else - total_points -= burned_stories[date] - burned_stories[date] = total_points - end - date_axis.push(date) - points_axis.push(burned_stories[date]) - end + range_dates = (@sprint.initial_date .. @sprint.final_date) + get_dates(burned_stories, date_axis, points_axis, range_dates, total_points) days_of_sprint = date_axis.length - 1 - - for day in (days_of_sprint).downto(0) - ideal_line.push(planned_points * (day / (Float days_of_sprint))) - end + set_ideal_line(days_of_sprint, ideal_line, planned_points) coordenates = { x: date_axis, y: points_axis, ideal_line: ideal_line } burned_stories = burned_stories.sort_by { |key, value| key } From 407d8f3a15b569ff7c6d028443d65278b02961e6 Mon Sep 17 00:00:00 2001 From: Pedro Kelvin Date: Sun, 10 Dec 2017 00:02:25 -0200 Subject: [PATCH 05/35] Adding get_burndown_variance method and route to it Signed-off-by: MateusO97 Signed-off-by: danieloda --- app/controllers/sprints_controller.rb | 84 +++++++++++++++++++-------- config/routes.rb | 2 +- 2 files changed, 60 insertions(+), 26 deletions(-) diff --git a/app/controllers/sprints_controller.rb b/app/controllers/sprints_controller.rb index 6d3bfc0..7798a95 100644 --- a/app/controllers/sprints_controller.rb +++ b/app/controllers/sprints_controller.rb @@ -9,7 +9,7 @@ class SprintsController < ApplicationController validate_release(0, :release_id) end - before_action only: [:show, :update, :destroy, :get_velocity, :get_velocity_variance, :get_debts] do + before_action only: [:show, :update, :destroy, :get_velocity, :get_velocity_variance, :get_debts, :get_burndown_variance] do validate_sprint(:id, 0) end @@ -69,26 +69,31 @@ def get_velocity def get_velocity_variance release = @sprint.release - velocity = get_sprints_informations(release.sprints, @sprint) + if release.project.is_scoring == true + release = @sprint.release + velocity = get_sprints_informations(release.sprints, @sprint) - total_sprints_points = velocity[:total_points] - velocities = velocity[:velocities] + total_sprints_points = velocity[:total_points] + velocities = velocity[:velocities] - amount = release.amount_of_sprints - variance = 0 + amount = release.sprints.count + variance = 0 - for i in 0..(amount - 1) - variance = variance + (total_sprints_points[i] - velocities[i]) - end + for i in 0..(amount - 1) + variance += (total_sprints_points[i] - velocities[i]) + end - variance = variance/amount + variance = variance/amount - render json: variance + render json: variance + else + render json: { error: "The Velocity variance is only available in projects that use Story Points" }, status: :unprocessable_entity + end end def get_burndown project = @sprint.release.project - if project.is_scoring != false + if project.is_scoring == true burned_stories = {} coordenates = [] date_axis = [] @@ -97,13 +102,11 @@ def get_burndown total_points = get_burned_points(@sprint, burned_stories) - planned_points = total_points - range_dates = (@sprint.initial_date .. @sprint.final_date) get_dates(burned_stories, date_axis, points_axis, range_dates, total_points) days_of_sprint = date_axis.length - 1 - set_ideal_line(days_of_sprint, ideal_line, planned_points) + set_ideal_line(days_of_sprint, ideal_line, total_points) coordenates = { x: date_axis, y: points_axis, ideal_line: ideal_line } burned_stories = burned_stories.sort_by { |key, value| key } @@ -114,24 +117,55 @@ def get_burndown end end + def get_burndown_variance + project = @sprint.release.project + if project.is_scoring == true + burned_stories = {} + date_axis = [] + points_axis = [] + ideal_line = [] + + total_points = get_burned_points(@sprint, burned_stories) + + range_dates = (@sprint.initial_date .. @sprint.final_date) + get_dates(burned_stories, date_axis, points_axis, range_dates, total_points) + + days_of_sprint = date_axis.length - 1 + set_ideal_line(days_of_sprint, ideal_line, total_points) + + variance = 0 + + for i in 0..(date_axis.length - 2) + variance = (points_axis[i] - points_axis[i+1]) + (ideal_line[i] - ideal_line[i+1]) + end + + variance = Float(variance) / date_axis.length + + render json: variance + else + render json: { error: "The Burndown variance is only available in projects that use Story Points" }, status: :unprocessable_entity + end + end + def get_debts release = @sprint.release if release.project.is_scoring == true velocity = get_sprints_informations(release.sprints, @sprint) - end - planned_points = 0 - burned_points = 0 + planned_points = 0 + burned_points = 0 - puts release.sprints.length - for i in 0..(release.sprints.length - 1) - planned_points = planned_points + velocity[:total_points][i] - burned_points = burned_points + velocity[:completed_points][i] - end + for i in 0..(release.sprints.length - 1) + planned_points = planned_points + velocity[:total_points][i] + burned_points = burned_points + velocity[:completed_points][i] + end - debts = Float(planned_points - burned_points)/planned_points + debts = Float(planned_points - burned_points)/planned_points - render json: debts + render json: debts + else + render json: { error: "Debts is only available in projects that use Story Points" }, status: :unprocessable_entity + end end private diff --git a/config/routes.rb b/config/routes.rb index 0d0ecbb..9b5c996 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -5,6 +5,7 @@ post "remove_github_token", to: "users#remove_github_token" get "sprints/:id/burndown", to: "sprints#get_burndown" + get "sprints/:id/burndown_variance", to: "sprints#get_burndown_variance" get "repos", to: "projects#github_projects_list" get "projects/:id/contributors", to: "projects#get_contributors" @@ -27,7 +28,6 @@ post "projects/:id/reopen_issue", to: "issues#reopen_issue" - get "sprints/:id/velocity", to: "sprints#get_velocity" resources :users, shallow: true do resources :projects do From 0e100f02bc26d812e9dc0ca7d610664c69657dec Mon Sep 17 00:00:00 2001 From: MateusO97 Date: Sun, 10 Dec 2017 00:04:31 -0200 Subject: [PATCH 06/35] Adding tests to Sprint controller Signed-off-by: pedrokelvin Signed-off-by: danieloda --- test/controllers/sprints_controller_test.rb | 41 ++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/test/controllers/sprints_controller_test.rb b/test/controllers/sprints_controller_test.rb index 9225547..fecf590 100644 --- a/test/controllers/sprints_controller_test.rb +++ b/test/controllers/sprints_controller_test.rb @@ -396,4 +396,43 @@ def setup assert_response :unprocessable_entity assert response.parsed_body["error"] == "The Velocity is only available in projects that use Story Points" end -end \ No newline at end of file + + test "should get velocity variance data if project is scoring" do + get "/sprints/#{@sprint.id}/velocity_variance", headers: { Authorization: @token.result } + + assert_response :success + end + + test "should not get velocity variance data if project is not scoring" do + get "/sprints/#{@sprint_scoring_false.id}/velocity_variance", headers: { Authorization: @token.result } + + assert_response :unprocessable_entity + assert response.parsed_body["error"] == "The Velocity variance is only available in projects that use Story Points" + end + + test "should get burndown variance data if project is scoring" do + get "/sprints/#{@sprint.id}/burndown_variance", headers: { Authorization: @token.result } + + assert_response :success + end + + test "should not get burndown variance data if project is not scoring" do + get "/sprints/#{@sprint_scoring_false.id}/burndown_variance", headers: { Authorization: @token.result } + + assert_response :unprocessable_entity + assert response.parsed_body["error"] == "The Burndown variance is only available in projects that use Story Points" + end + + test "should get debts from a project if it is scoring" do + get "/sprints/#{@sprint.id}/debts", headers: { Authorization: @token.result } + + assert_response :success + end + + test "should not get debts from a project if it is not scoring" do + get "/sprints/#{@sprint_scoring_false.id}/debts", headers: { Authorization: @token.result } + + assert_response :unprocessable_entity + assert response.parsed_body["error"] == "Debts is only available in projects that use Story Points" + end +end From 7dd99914d91db62b926c7495d10fc528c73af876 Mon Sep 17 00:00:00 2001 From: Pedro Kelvin Date: Sun, 10 Dec 2017 00:30:35 -0200 Subject: [PATCH 07/35] Solving some codeclimate and codacy issues --- app/controllers/sprints_controller.rb | 6 +++--- app/helpers/burndown_helper.rb | 5 ----- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/app/controllers/sprints_controller.rb b/app/controllers/sprints_controller.rb index 7798a95..46884ae 100644 --- a/app/controllers/sprints_controller.rb +++ b/app/controllers/sprints_controller.rb @@ -83,7 +83,7 @@ def get_velocity_variance variance += (total_sprints_points[i] - velocities[i]) end - variance = variance/amount + variance = variance / amount render json: variance else @@ -136,7 +136,7 @@ def get_burndown_variance variance = 0 for i in 0..(date_axis.length - 2) - variance = (points_axis[i] - points_axis[i+1]) + (ideal_line[i] - ideal_line[i+1]) + variance = (points_axis[i] - points_axis[i + 1]) + (ideal_line[i] - ideal_line[i + 1]) end variance = Float(variance) / date_axis.length @@ -160,7 +160,7 @@ def get_debts burned_points = burned_points + velocity[:completed_points][i] end - debts = Float(planned_points - burned_points)/planned_points + debts = Float(planned_points - burned_points) / planned_points render json: debts else diff --git a/app/helpers/burndown_helper.rb b/app/helpers/burndown_helper.rb index 3cc7770..2443ab9 100644 --- a/app/helpers/burndown_helper.rb +++ b/app/helpers/burndown_helper.rb @@ -1,7 +1,5 @@ module BurndownHelper - def get_burned_points(sprint, burned_stories) - total_points = 0 for story in sprint.stories @@ -19,7 +17,6 @@ def get_burned_points(sprint, burned_stories) end def get_dates(burned_stories, date_axis, points_axis, range_dates, total_points) - range_dates.each do |date| if burned_stories[date] == nil burned_stories[date] = total_points @@ -33,10 +30,8 @@ def get_dates(burned_stories, date_axis, points_axis, range_dates, total_points) end def set_ideal_line(days_of_sprint, ideal_line, planned_points) - for day in (days_of_sprint).downto(0) ideal_line.push(planned_points * (day / (Float days_of_sprint))) end end - end From a62fa34d7d8c12bc4028be7544b27a8cf528b66a Mon Sep 17 00:00:00 2001 From: Pedro Kelvin Date: Mon, 11 Dec 2017 11:01:37 -0200 Subject: [PATCH 08/35] Fixing codeclimate --- app/controllers/sprints_controller.rb | 4 +++- app/helpers/burndown_helper.rb | 13 ++++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/app/controllers/sprints_controller.rb b/app/controllers/sprints_controller.rb index 46884ae..1187cc3 100644 --- a/app/controllers/sprints_controller.rb +++ b/app/controllers/sprints_controller.rb @@ -100,7 +100,9 @@ def get_burndown points_axis = [] ideal_line = [] - total_points = get_burned_points(@sprint, burned_stories) + total_points = get_total_points(@sprint) + + burned_stories = get_burned_points(@sprint, burned_stories) range_dates = (@sprint.initial_date .. @sprint.final_date) get_dates(burned_stories, date_axis, points_axis, range_dates, total_points) diff --git a/app/helpers/burndown_helper.rb b/app/helpers/burndown_helper.rb index 2443ab9..d1a3c60 100644 --- a/app/helpers/burndown_helper.rb +++ b/app/helpers/burndown_helper.rb @@ -1,9 +1,6 @@ module BurndownHelper def get_burned_points(sprint, burned_stories) - total_points = 0 - for story in sprint.stories - total_points += story.story_points if story.pipeline == "Done" if burned_stories[story.final_date] == nil burned_stories[story.final_date] = story.story_points @@ -13,6 +10,16 @@ def get_burned_points(sprint, burned_stories) end end + return burned_stories + end + + def get_total_points(sprint) + total_points = 0 + + for story in sprint.stories + total_points += story.story_points + end + return total_points end From f735981971828710b797b59481dec1a32c8ddefb Mon Sep 17 00:00:00 2001 From: Pedro Kelvin Date: Mon, 11 Dec 2017 11:17:50 -0200 Subject: [PATCH 09/35] Fixing codeclimate issue --- app/controllers/sprints_controller.rb | 7 +++---- app/helpers/burndown_helper.rb | 20 ++++++++++++-------- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/app/controllers/sprints_controller.rb b/app/controllers/sprints_controller.rb index 1187cc3..df9428c 100644 --- a/app/controllers/sprints_controller.rb +++ b/app/controllers/sprints_controller.rb @@ -101,12 +101,11 @@ def get_burndown ideal_line = [] total_points = get_total_points(@sprint) - burned_stories = get_burned_points(@sprint, burned_stories) range_dates = (@sprint.initial_date .. @sprint.final_date) - get_dates(burned_stories, date_axis, points_axis, range_dates, total_points) + set_dates_and_points(burned_stories, date_axis, points_axis, range_dates, total_points) days_of_sprint = date_axis.length - 1 set_ideal_line(days_of_sprint, ideal_line, total_points) @@ -127,11 +126,11 @@ def get_burndown_variance points_axis = [] ideal_line = [] - total_points = get_burned_points(@sprint, burned_stories) + total_points = get_total_points(@sprint) range_dates = (@sprint.initial_date .. @sprint.final_date) - get_dates(burned_stories, date_axis, points_axis, range_dates, total_points) + set_dates_and_points(burned_stories, date_axis, points_axis, range_dates, total_points) days_of_sprint = date_axis.length - 1 set_ideal_line(days_of_sprint, ideal_line, total_points) diff --git a/app/helpers/burndown_helper.rb b/app/helpers/burndown_helper.rb index d1a3c60..25d0b3a 100644 --- a/app/helpers/burndown_helper.rb +++ b/app/helpers/burndown_helper.rb @@ -1,13 +1,17 @@ module BurndownHelper + def check_pipeline(story, burned_stories) + if story.pipeline == "Done" + if burned_stories[story.final_date] == nil + burned_stories[story.final_date] = story.story_points + else + burned_stories[story.final_date] += story.story_points + end + end + end + def get_burned_points(sprint, burned_stories) for story in sprint.stories - if story.pipeline == "Done" - if burned_stories[story.final_date] == nil - burned_stories[story.final_date] = story.story_points - else - burned_stories[story.final_date] += story.story_points - end - end + check_pipeline(story, burned_stories) end return burned_stories @@ -23,7 +27,7 @@ def get_total_points(sprint) return total_points end - def get_dates(burned_stories, date_axis, points_axis, range_dates, total_points) + def set_dates_and_points(burned_stories, date_axis, points_axis, range_dates, total_points) range_dates.each do |date| if burned_stories[date] == nil burned_stories[date] = total_points From e9ee95a7a1b01093a8ec53702651dbb2aa55d6da Mon Sep 17 00:00:00 2001 From: Pedro Kelvin Date: Mon, 11 Dec 2017 16:42:22 -0200 Subject: [PATCH 10/35] Changing get_velocity_metric method calculation Signed-off-by: Mateus097 Signed-off-by: danieloda --- app/controllers/sprints_controller.rb | 32 ++++++++++++++------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/app/controllers/sprints_controller.rb b/app/controllers/sprints_controller.rb index df9428c..e347ba4 100644 --- a/app/controllers/sprints_controller.rb +++ b/app/controllers/sprints_controller.rb @@ -9,7 +9,7 @@ class SprintsController < ApplicationController validate_release(0, :release_id) end - before_action only: [:show, :update, :destroy, :get_velocity, :get_velocity_variance, :get_debts, :get_burndown_variance] do + before_action only: [:show, :update, :destroy, :get_velocity, :get_velocity_metric, :get_debts, :get_burndown_metric] do validate_sprint(:id, 0) end @@ -67,7 +67,7 @@ def get_velocity end end - def get_velocity_variance + def get_velocity_metric release = @sprint.release if release.project.is_scoring == true release = @sprint.release @@ -76,18 +76,20 @@ def get_velocity_variance total_sprints_points = velocity[:total_points] velocities = velocity[:velocities] - amount = release.sprints.count - variance = 0 + amount_of_sprints = release.sprints.count + metric = 0 - for i in 0..(amount - 1) - variance += (total_sprints_points[i] - velocities[i]) + for i in 0..(amount_of_sprints - 1) + metric += (total_sprints_points[i] - velocities[i]) end - variance = variance / amount + total_points = get_total_points_release(release) + puts total_points + metric = metric / total_points - render json: variance + render json: metric else - render json: { error: "The Velocity variance is only available in projects that use Story Points" }, status: :unprocessable_entity + render json: { error: "The Velocity metric is only available in projects that use Story Points" }, status: :unprocessable_entity end end @@ -118,7 +120,7 @@ def get_burndown end end - def get_burndown_variance + def get_burndown_metric project = @sprint.release.project if project.is_scoring == true burned_stories = {} @@ -134,17 +136,17 @@ def get_burndown_variance days_of_sprint = date_axis.length - 1 set_ideal_line(days_of_sprint, ideal_line, total_points) - variance = 0 + metric = 0 for i in 0..(date_axis.length - 2) - variance = (points_axis[i] - points_axis[i + 1]) + (ideal_line[i] - ideal_line[i + 1]) + metric = (points_axis[i] - points_axis[i + 1]) + (ideal_line[i] - ideal_line[i + 1]) end - variance = Float(variance) / date_axis.length + metric = Float(metric) / date_axis.length - render json: variance + render json: metric else - render json: { error: "The Burndown variance is only available in projects that use Story Points" }, status: :unprocessable_entity + render json: { error: "The Burndown metric is only available in projects that use Story Points" }, status: :unprocessable_entity end end From d34f391b534b7fc39540e7ec7d284f0c47975371 Mon Sep 17 00:00:00 2001 From: MateusO97 Date: Mon, 11 Dec 2017 16:45:04 -0200 Subject: [PATCH 11/35] Changing varience name to metric Signed-off-by: Pedro Kelvin Signed-off-by: danieloda --- app/helpers/velocity_helper.rb | 12 ++++++++++++ config/routes.rb | 4 ++-- test/controllers/sprints_controller_test.rb | 20 ++++++++++---------- 3 files changed, 24 insertions(+), 12 deletions(-) diff --git a/app/helpers/velocity_helper.rb b/app/helpers/velocity_helper.rb index f862ea3..5a0982b 100644 --- a/app/helpers/velocity_helper.rb +++ b/app/helpers/velocity_helper.rb @@ -1,4 +1,16 @@ module VelocityHelper + include BurndownHelper + + def get_total_points_release(release) + total_points_release = 0 + + for sprint in release.sprints + total_points_release += get_total_points(sprint) + end + + return total_points_release + end + def calculate_points(sprint) sprint_total_points = 0 sprint_completed_points = 0 diff --git a/config/routes.rb b/config/routes.rb index 9b5c996..e69cae7 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -5,7 +5,7 @@ post "remove_github_token", to: "users#remove_github_token" get "sprints/:id/burndown", to: "sprints#get_burndown" - get "sprints/:id/burndown_variance", to: "sprints#get_burndown_variance" + get "sprints/:id/burndown_metric", to: "sprints#get_burndown_metric" get "repos", to: "projects#github_projects_list" get "projects/:id/contributors", to: "projects#get_contributors" @@ -23,7 +23,7 @@ delete "projects/:id/issues", to: "issues#close" get "sprints/:id/velocity", to: "sprints#get_velocity" - get "sprints/:id/velocity_variance", to: "sprints#get_velocity_variance" + get "sprints/:id/velocity_metric", to: "sprints#get_velocity_metric" get "sprints/:id/debts", to: "sprints#get_debts" post "projects/:id/reopen_issue", to: "issues#reopen_issue" diff --git a/test/controllers/sprints_controller_test.rb b/test/controllers/sprints_controller_test.rb index fecf590..b32f8db 100644 --- a/test/controllers/sprints_controller_test.rb +++ b/test/controllers/sprints_controller_test.rb @@ -397,30 +397,30 @@ def setup assert response.parsed_body["error"] == "The Velocity is only available in projects that use Story Points" end - test "should get velocity variance data if project is scoring" do - get "/sprints/#{@sprint.id}/velocity_variance", headers: { Authorization: @token.result } + test "should get velocity metric data if project is scoring" do + get "/sprints/#{@sprint.id}/velocity_metric", headers: { Authorization: @token.result } assert_response :success end - test "should not get velocity variance data if project is not scoring" do - get "/sprints/#{@sprint_scoring_false.id}/velocity_variance", headers: { Authorization: @token.result } + test "should not get velocity metric data if project is not scoring" do + get "/sprints/#{@sprint_scoring_false.id}/velocity_metric", headers: { Authorization: @token.result } assert_response :unprocessable_entity - assert response.parsed_body["error"] == "The Velocity variance is only available in projects that use Story Points" + assert response.parsed_body["error"] == "The Velocity metric is only available in projects that use Story Points" end - test "should get burndown variance data if project is scoring" do - get "/sprints/#{@sprint.id}/burndown_variance", headers: { Authorization: @token.result } + test "should get burndown metric data if project is scoring" do + get "/sprints/#{@sprint.id}/burndown_metric", headers: { Authorization: @token.result } assert_response :success end - test "should not get burndown variance data if project is not scoring" do - get "/sprints/#{@sprint_scoring_false.id}/burndown_variance", headers: { Authorization: @token.result } + test "should not get burndown metric data if project is not scoring" do + get "/sprints/#{@sprint_scoring_false.id}/burndown_metric", headers: { Authorization: @token.result } assert_response :unprocessable_entity - assert response.parsed_body["error"] == "The Burndown variance is only available in projects that use Story Points" + assert response.parsed_body["error"] == "The Burndown metric is only available in projects that use Story Points" end test "should get debts from a project if it is scoring" do From 560212db21e89235e6e40f1e589bf209d94c4c4b Mon Sep 17 00:00:00 2001 From: Pedro Kelvin Date: Mon, 11 Dec 2017 18:00:12 -0200 Subject: [PATCH 12/35] Changing get_burndown_metric method Signed-off-by: MateusO97 Signed-off-by: danieloda --- app/controllers/sprints_controller.rb | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/app/controllers/sprints_controller.rb b/app/controllers/sprints_controller.rb index e347ba4..ef4e8cc 100644 --- a/app/controllers/sprints_controller.rb +++ b/app/controllers/sprints_controller.rb @@ -127,8 +127,10 @@ def get_burndown_metric date_axis = [] points_axis = [] ideal_line = [] + metric = [] total_points = get_total_points(@sprint) + burned_stories = get_burned_points(@sprint, burned_stories) range_dates = (@sprint.initial_date .. @sprint.final_date) @@ -136,14 +138,14 @@ def get_burndown_metric days_of_sprint = date_axis.length - 1 set_ideal_line(days_of_sprint, ideal_line, total_points) - metric = 0 + ideal_burned_points = ideal_line[0] - ideal_line[1] for i in 0..(date_axis.length - 2) - metric = (points_axis[i] - points_axis[i + 1]) + (ideal_line[i] - ideal_line[i + 1]) + real_burned_points = points_axis[i] - points_axis[i + 1] + burned_percentage = Float((real_burned_points).abs * 100) / ideal_burned_points + metric.push(burned_percentage) end - metric = Float(metric) / date_axis.length - render json: metric else render json: { error: "The Burndown metric is only available in projects that use Story Points" }, status: :unprocessable_entity From 36655eda8576a5b899299fb65d1d943b8390a691 Mon Sep 17 00:00:00 2001 From: Pedro Kelvin Date: Tue, 12 Dec 2017 11:30:02 -0200 Subject: [PATCH 13/35] Adding method to calculate all metrics in just one method Signed-off-by: MateusO97 Signed-off-by: danieloda --- app/helpers/metric_helper.rb | 97 ++++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 app/helpers/metric_helper.rb diff --git a/app/helpers/metric_helper.rb b/app/helpers/metric_helper.rb new file mode 100644 index 0000000..2cc07f3 --- /dev/null +++ b/app/helpers/metric_helper.rb @@ -0,0 +1,97 @@ +module MetricHelper + include BurndownHelper + include VelocityHelper + + def calculate_metrics(sprint) + release = @sprint.release + + if release.project.is_scoring == true + burned_stories = {} + date_axis = [] + points_axis = [] + ideal_line = [] + metric_burndown_array = [] + amount_of_sprints = release.sprints.count + metric_velocity_value = 0 + planned_points = 0 + burned_points = 0 + + velocity = get_sprints_informations(release.sprints, @sprint) + total_points = get_total_points(@sprint) + burned_stories = get_burned_points(@sprint, burned_stories) + total_sprints_points = velocity[:total_points] + velocities = velocity[:velocities] + + range_dates = (@sprint.initial_date .. @sprint.final_date) + + set_dates_and_points(burned_stories, date_axis, points_axis, range_dates, total_points) + days_of_sprint = date_axis.length - 1 + set_ideal_line(days_of_sprint, ideal_line, total_points) + ideal_burned_points = ideal_line[0] - ideal_line[1] + + for i in 0..(date_axis.length - 2) + real_burned_points = points_axis[i] - points_axis[i + 1] + burned_percentage = Float((real_burned_points).abs * 100) / ideal_burned_points + metric_burndown_array.push(burned_percentage) + end + + for i in 0..(amount_of_sprints - 1) + metric_velocity_value += (total_sprints_points[i] - velocities[i]) + end + + for i in 0..(release.sprints.length - 1) + planned_points += velocity[:total_points][i] + burned_points += velocity[:completed_points][i] + end + + metric_burndown_value = calculate_burndown(metric_burndown_array) + + metric_debts_value = Float(planned_points - burned_points) / planned_points + metric_debts_value = calculate_velocity_and_debt(metric_debts_value) + + total_points = get_total_points_release(release) + metric_velocity_value = metric_velocity_value / total_points + metric_velocity_value = calculate_velocity_and_debt(metric_velocity_value) + + # final_metric = weight1*metric_velocity_value + weight2*metric_burndown_value + weight3*metric_debts_value + end + end + + def calculate_velocity_and_debt(metric) + values = 0 + + if metric <= 0.2 + values += 4 + elsif metric <= 0.4 + values += 3 + elsif metric <= 0.6 + values += 2 + elsif metric <= 0.9 + values += 1 + elsif metric <= 1 + values += 0 + end + + return values + end + + def calculate_burndown(metric) + values = 0 + + for i in 0..(metric.length - 1) + if metric[i] <= 10 || metric[i] > 100 + values += 0 + elsif metric[i] <= 40 + values += 1 + elsif metric[i] <= 60 + values += 2 + elsif metric[i] <= 80 + values += 3 + elsif metric[i] <= 100 + values += 4 + end + end + + return Float values / metric.length + end +end From 57cd8dc5794165d25d3cd185c57d289b8e0badb3 Mon Sep 17 00:00:00 2001 From: Pedro Kelvin Date: Tue, 12 Dec 2017 11:31:06 -0200 Subject: [PATCH 14/35] Adding route and deleting some methods in Sprint Controller Signed-off-by: MateusO97 Signed-off-by: danieloda --- app/controllers/sprints_controller.rb | 82 ++------------------------- app/helpers/velocity_helper.rb | 2 +- config/routes.rb | 4 +- 3 files changed, 7 insertions(+), 81 deletions(-) diff --git a/app/controllers/sprints_controller.rb b/app/controllers/sprints_controller.rb index ef4e8cc..8388395 100644 --- a/app/controllers/sprints_controller.rb +++ b/app/controllers/sprints_controller.rb @@ -2,6 +2,7 @@ class SprintsController < ApplicationController include ValidationsHelper include VelocityHelper include BurndownHelper + include MetricHelper before_action :set_sprint, only: [:show, :update, :destroy, :get_burndown] @@ -9,7 +10,7 @@ class SprintsController < ApplicationController validate_release(0, :release_id) end - before_action only: [:show, :update, :destroy, :get_velocity, :get_velocity_metric, :get_debts, :get_burndown_metric] do + before_action only: [:show, :update, :destroy, :get_velocity, :get_metrics] do validate_sprint(:id, 0) end @@ -67,32 +68,6 @@ def get_velocity end end - def get_velocity_metric - release = @sprint.release - if release.project.is_scoring == true - release = @sprint.release - velocity = get_sprints_informations(release.sprints, @sprint) - - total_sprints_points = velocity[:total_points] - velocities = velocity[:velocities] - - amount_of_sprints = release.sprints.count - metric = 0 - - for i in 0..(amount_of_sprints - 1) - metric += (total_sprints_points[i] - velocities[i]) - end - - total_points = get_total_points_release(release) - puts total_points - metric = metric / total_points - - render json: metric - else - render json: { error: "The Velocity metric is only available in projects that use Story Points" }, status: :unprocessable_entity - end - end - def get_burndown project = @sprint.release.project if project.is_scoring == true @@ -120,57 +95,10 @@ def get_burndown end end - def get_burndown_metric - project = @sprint.release.project - if project.is_scoring == true - burned_stories = {} - date_axis = [] - points_axis = [] - ideal_line = [] - metric = [] + def get_metrics + final_metric = calculate_metrics(@sprint) - total_points = get_total_points(@sprint) - burned_stories = get_burned_points(@sprint, burned_stories) - - range_dates = (@sprint.initial_date .. @sprint.final_date) - - set_dates_and_points(burned_stories, date_axis, points_axis, range_dates, total_points) - days_of_sprint = date_axis.length - 1 - set_ideal_line(days_of_sprint, ideal_line, total_points) - - ideal_burned_points = ideal_line[0] - ideal_line[1] - - for i in 0..(date_axis.length - 2) - real_burned_points = points_axis[i] - points_axis[i + 1] - burned_percentage = Float((real_burned_points).abs * 100) / ideal_burned_points - metric.push(burned_percentage) - end - - render json: metric - else - render json: { error: "The Burndown metric is only available in projects that use Story Points" }, status: :unprocessable_entity - end - end - - def get_debts - release = @sprint.release - if release.project.is_scoring == true - velocity = get_sprints_informations(release.sprints, @sprint) - - planned_points = 0 - burned_points = 0 - - for i in 0..(release.sprints.length - 1) - planned_points = planned_points + velocity[:total_points][i] - burned_points = burned_points + velocity[:completed_points][i] - end - - debts = Float(planned_points - burned_points) / planned_points - - render json: debts - else - render json: { error: "Debts is only available in projects that use Story Points" }, status: :unprocessable_entity - end + render json: final_metric end private diff --git a/app/helpers/velocity_helper.rb b/app/helpers/velocity_helper.rb index 5a0982b..9347a01 100644 --- a/app/helpers/velocity_helper.rb +++ b/app/helpers/velocity_helper.rb @@ -1,6 +1,6 @@ module VelocityHelper include BurndownHelper - + def get_total_points_release(release) total_points_release = 0 diff --git a/config/routes.rb b/config/routes.rb index e69cae7..379b91b 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -5,7 +5,6 @@ post "remove_github_token", to: "users#remove_github_token" get "sprints/:id/burndown", to: "sprints#get_burndown" - get "sprints/:id/burndown_metric", to: "sprints#get_burndown_metric" get "repos", to: "projects#github_projects_list" get "projects/:id/contributors", to: "projects#get_contributors" @@ -23,11 +22,10 @@ delete "projects/:id/issues", to: "issues#close" get "sprints/:id/velocity", to: "sprints#get_velocity" - get "sprints/:id/velocity_metric", to: "sprints#get_velocity_metric" - get "sprints/:id/debts", to: "sprints#get_debts" post "projects/:id/reopen_issue", to: "issues#reopen_issue" + get "sprints/:id/metrics", to: "sprints#get_metrics" resources :users, shallow: true do resources :projects do From 1e5988e9de0ecda3f06015c11e0738e53f55d04a Mon Sep 17 00:00:00 2001 From: MateusO97 Date: Tue, 12 Dec 2017 13:43:28 -0200 Subject: [PATCH 15/35] Creating Grade model Signed-off-by: Pedro Kelvin Signed-off-by: danieloda --- app/models/grade.rb | 5 +++++ db/migrate/20171212153942_create_grades.rb | 11 +++++++++++ 2 files changed, 16 insertions(+) create mode 100644 app/models/grade.rb create mode 100644 db/migrate/20171212153942_create_grades.rb diff --git a/app/models/grade.rb b/app/models/grade.rb new file mode 100644 index 0000000..38915c1 --- /dev/null +++ b/app/models/grade.rb @@ -0,0 +1,5 @@ +class Grade < ApplicationRecord + validates :weight_burndown, presence: true + validates :weight_velocity, presence: true + validates :weight_debt, presence: true +end diff --git a/db/migrate/20171212153942_create_grades.rb b/db/migrate/20171212153942_create_grades.rb new file mode 100644 index 0000000..0137d17 --- /dev/null +++ b/db/migrate/20171212153942_create_grades.rb @@ -0,0 +1,11 @@ +class CreateGrades < ActiveRecord::Migration[5.1] + def change + create_table :grades do |t| + t.Float :weight_burndown + t.Float :weight_velocity + t.Float :weight_debt + + t.timestamps + end + end +end From abe97c5467ff4d7af376e9ba894da692ee88862d Mon Sep 17 00:00:00 2001 From: MateusO97 Date: Tue, 12 Dec 2017 13:44:00 -0200 Subject: [PATCH 16/35] Creating Grade test files Signed-off-by: Pedro Kelvin Signed-off-by: danieloda --- test/fixtures/grades.yml | 11 +++++++++++ test/models/grade_test.rb | 7 +++++++ 2 files changed, 18 insertions(+) create mode 100644 test/fixtures/grades.yml create mode 100644 test/models/grade_test.rb diff --git a/test/fixtures/grades.yml b/test/fixtures/grades.yml new file mode 100644 index 0000000..d5825c0 --- /dev/null +++ b/test/fixtures/grades.yml @@ -0,0 +1,11 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + weight_burndown: + weight_velocity: + weight_debt: + +two: + weight_burndown: + weight_velocity: + weight_debt: diff --git a/test/models/grade_test.rb b/test/models/grade_test.rb new file mode 100644 index 0000000..e9528e4 --- /dev/null +++ b/test/models/grade_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class GradeTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end From 30564c324f1896c43fcc9448a67c28656a5aad1e Mon Sep 17 00:00:00 2001 From: Pedro Kelvin Date: Tue, 12 Dec 2017 19:57:27 -0200 Subject: [PATCH 17/35] Creating new controller called Grade Signed-off-by: MateusO97 Signed-off-by: danieloda --- app/controllers/grade_controller.rb | 19 +++++++++++++++++++ ...des.rb => 20171212174435_create_grades.rb} | 6 +++--- test/controllers/grade_controller_test.rb | 19 +++++++++++++++++++ 3 files changed, 41 insertions(+), 3 deletions(-) create mode 100644 app/controllers/grade_controller.rb rename db/migrate/{20171212153942_create_grades.rb => 20171212174435_create_grades.rb} (59%) create mode 100644 test/controllers/grade_controller_test.rb diff --git a/app/controllers/grade_controller.rb b/app/controllers/grade_controller.rb new file mode 100644 index 0000000..88c5969 --- /dev/null +++ b/app/controllers/grade_controller.rb @@ -0,0 +1,19 @@ +class GradeController < ApplicationController + def update + end + + def create + @grade = Grade.new(grade_params) + if @grade.save + render json: @grade, status: :created + else + render json: @grade.errors, status: :unprocessable_entity + end + + def show + end + + def grade_params + params.require(:grade).permit(:weight_debt, :weight_velocity, :weight_burndown) + end +end diff --git a/db/migrate/20171212153942_create_grades.rb b/db/migrate/20171212174435_create_grades.rb similarity index 59% rename from db/migrate/20171212153942_create_grades.rb rename to db/migrate/20171212174435_create_grades.rb index 0137d17..165a39d 100644 --- a/db/migrate/20171212153942_create_grades.rb +++ b/db/migrate/20171212174435_create_grades.rb @@ -1,9 +1,9 @@ class CreateGrades < ActiveRecord::Migration[5.1] def change create_table :grades do |t| - t.Float :weight_burndown - t.Float :weight_velocity - t.Float :weight_debt + t.float :weight_burndown + t.float :weight_velocity + t.float :weight_debts t.timestamps end diff --git a/test/controllers/grade_controller_test.rb b/test/controllers/grade_controller_test.rb new file mode 100644 index 0000000..e486f7d --- /dev/null +++ b/test/controllers/grade_controller_test.rb @@ -0,0 +1,19 @@ +require 'test_helper' + +class GradeControllerTest < ActionDispatch::IntegrationTest + test "should get update" do + get grade_update_url + assert_response :success + end + + test "should get create" do + get grade_create_url + assert_response :success + end + + test "should get show" do + get grade_show_url + assert_response :success + end + +end From a2c9a9bb5711e281bf568e8f7b002b004b3bf3c8 Mon Sep 17 00:00:00 2001 From: Pedro Kelvin Date: Tue, 12 Dec 2017 20:02:53 -0200 Subject: [PATCH 18/35] Creating routes and changing some methods Signed-off-by: MateusO97 Signed-off-by: danieloda --- app/controllers/sprints_controller.rb | 5 +++-- app/helpers/metric_helper.rb | 14 ++++++++------ app/models/grade.rb | 2 ++ config/routes.rb | 6 ++++++ db/schema.rb | 10 +++++++++- 5 files changed, 28 insertions(+), 9 deletions(-) diff --git a/app/controllers/sprints_controller.rb b/app/controllers/sprints_controller.rb index 8388395..f9c13be 100644 --- a/app/controllers/sprints_controller.rb +++ b/app/controllers/sprints_controller.rb @@ -96,8 +96,9 @@ def get_burndown end def get_metrics - final_metric = calculate_metrics(@sprint) - + metrics = calculate_metrics(@sprint) + final_metric = metrics[:metric_debts_value] + metrics[:metric_velocity_value] + metrics[:metric_burndown_array] + render json: final_metric end diff --git a/app/helpers/metric_helper.rb b/app/helpers/metric_helper.rb index 2cc07f3..92138da 100644 --- a/app/helpers/metric_helper.rb +++ b/app/helpers/metric_helper.rb @@ -3,7 +3,7 @@ module MetricHelper include VelocityHelper def calculate_metrics(sprint) - release = @sprint.release + release = sprint.release if release.project.is_scoring == true burned_stories = {} @@ -16,13 +16,13 @@ def calculate_metrics(sprint) planned_points = 0 burned_points = 0 - velocity = get_sprints_informations(release.sprints, @sprint) - total_points = get_total_points(@sprint) - burned_stories = get_burned_points(@sprint, burned_stories) + velocity = get_sprints_informations(release.sprints, sprint) + total_points = get_total_points(sprint) + burned_stories = get_burned_points(sprint, burned_stories) total_sprints_points = velocity[:total_points] velocities = velocity[:velocities] - range_dates = (@sprint.initial_date .. @sprint.final_date) + range_dates = (sprint.initial_date .. sprint.final_date) set_dates_and_points(burned_stories, date_axis, points_axis, range_dates, total_points) days_of_sprint = date_axis.length - 1 @@ -53,7 +53,9 @@ def calculate_metrics(sprint) metric_velocity_value = metric_velocity_value / total_points metric_velocity_value = calculate_velocity_and_debt(metric_velocity_value) - # final_metric = weight1*metric_velocity_value + weight2*metric_burndown_value + weight3*metric_debts_value + metrics = { metric_debts_value: metric_debts_value, + metric_velocity_value: metric_velocity_value, + metric_burndown_value: metric_burndown_value } end end diff --git a/app/models/grade.rb b/app/models/grade.rb index 38915c1..9a2f427 100644 --- a/app/models/grade.rb +++ b/app/models/grade.rb @@ -1,4 +1,6 @@ class Grade < ApplicationRecord + belongs_to :project + validates :weight_burndown, presence: true validates :weight_velocity, presence: true validates :weight_debt, presence: true diff --git a/config/routes.rb b/config/routes.rb index 8fb46d9..aef65dd 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,4 +1,10 @@ Rails.application.routes.draw do + get 'grade/update' + + get 'grade/create' + + get 'grade/show' + # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html post "authenticate", to: "authentication#authenticate" post "request_github_token", to: "users#request_github_token" diff --git a/db/schema.rb b/db/schema.rb index def49a9..cebe39f 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,11 +10,19 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20171210015745) do +ActiveRecord::Schema.define(version: 20171212174435) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" + create_table "grades", force: :cascade do |t| + t.float "weight_burndown" + t.float "weight_velocity" + t.float "weight_debts" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + create_table "issues", force: :cascade do |t| t.string "title" t.text "body" From 508c72a518453e61bd8867118f3e48696c6ced74 Mon Sep 17 00:00:00 2001 From: Pedro Kelvin Date: Tue, 12 Dec 2017 20:26:59 -0200 Subject: [PATCH 19/35] Editing get_metrics method --- app/controllers/sprints_controller.rb | 4 ++-- app/helpers/metric_helper.rb | 4 ++-- db/schema.rb | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/controllers/sprints_controller.rb b/app/controllers/sprints_controller.rb index f9c13be..b523a2f 100644 --- a/app/controllers/sprints_controller.rb +++ b/app/controllers/sprints_controller.rb @@ -97,8 +97,8 @@ def get_burndown def get_metrics metrics = calculate_metrics(@sprint) - final_metric = metrics[:metric_debts_value] + metrics[:metric_velocity_value] + metrics[:metric_burndown_array] - + + final_metric = (metrics[:metric_debts_value] + metrics[:metric_velocity_value] + metrics[:metric_burndown_value]) / 3 render json: final_metric end diff --git a/app/helpers/metric_helper.rb b/app/helpers/metric_helper.rb index 92138da..008cbe7 100644 --- a/app/helpers/metric_helper.rb +++ b/app/helpers/metric_helper.rb @@ -50,10 +50,10 @@ def calculate_metrics(sprint) metric_debts_value = calculate_velocity_and_debt(metric_debts_value) total_points = get_total_points_release(release) - metric_velocity_value = metric_velocity_value / total_points + metric_velocity_value = Float metric_velocity_value / total_points metric_velocity_value = calculate_velocity_and_debt(metric_velocity_value) - metrics = { metric_debts_value: metric_debts_value, + return metrics = { metric_debts_value: metric_debts_value, metric_velocity_value: metric_velocity_value, metric_burndown_value: metric_burndown_value } end diff --git a/db/schema.rb b/db/schema.rb index 956dbab..4613260 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20171212131724) do +ActiveRecord::Schema.define(version: 20171212174435) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" From 0960be97121059789bf231e09db00bde7e8be2d7 Mon Sep 17 00:00:00 2001 From: Lucas Martins Date: Tue, 12 Dec 2017 21:17:31 -0200 Subject: [PATCH 20/35] Improving grade Signed-off-by: Pedro Kelvin Signed-off-by: MateusO97 --- app/controllers/grade_controller.rb | 7 ++++++- app/controllers/sprints_controller.rb | 7 ------- app/helpers/metric_helper.rb | 16 ++++++++++++++-- app/models/project.rb | 1 + 4 files changed, 21 insertions(+), 10 deletions(-) diff --git a/app/controllers/grade_controller.rb b/app/controllers/grade_controller.rb index 88c5969..0cdc92d 100644 --- a/app/controllers/grade_controller.rb +++ b/app/controllers/grade_controller.rb @@ -1,4 +1,6 @@ class GradeController < ApplicationController + include MetricHelper + def update end @@ -7,10 +9,13 @@ def create if @grade.save render json: @grade, status: :created else - render json: @grade.errors, status: :unprocessable_entity + render json: @grade.errors, status: :unprocessable_entity end def show + final_metric = get_metrics(@grade) + + render json: final_metric end def grade_params diff --git a/app/controllers/sprints_controller.rb b/app/controllers/sprints_controller.rb index b523a2f..19df429 100644 --- a/app/controllers/sprints_controller.rb +++ b/app/controllers/sprints_controller.rb @@ -95,13 +95,6 @@ def get_burndown end end - def get_metrics - metrics = calculate_metrics(@sprint) - - final_metric = (metrics[:metric_debts_value] + metrics[:metric_velocity_value] + metrics[:metric_burndown_value]) / 3 - render json: final_metric - end - private def set_sprint @sprint = Sprint.find(params[:id]) diff --git a/app/helpers/metric_helper.rb b/app/helpers/metric_helper.rb index 008cbe7..7e5f358 100644 --- a/app/helpers/metric_helper.rb +++ b/app/helpers/metric_helper.rb @@ -2,8 +2,20 @@ module MetricHelper include BurndownHelper include VelocityHelper - def calculate_metrics(sprint) - release = sprint.release + def get_metrics(grade) + last_release = grade.project.releases.last + metrics = calculate_metrics(last_release) + + sum_of_weights = grade.weight_debt + grade.weight_velocity + grade.weight_burndown + + final_metric = Float (grade.weight_debt * metrics[:metric_debts_value] + + grade.weight_velocity * metrics[:metric_velocity_value] + + grade.weight_burndown * metrics[:metric_burndown_value]) / + sum_of_weights + end + + def calculate_metrics(release) + sprint = release.sprints.last if release.project.is_scoring == true burned_stories = {} diff --git a/app/models/project.rb b/app/models/project.rb index b9b36c0..ec2bc2e 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -1,6 +1,7 @@ class Project < ApplicationRecord belongs_to :user has_many :releases, dependent: :destroy + has_one :grade, dependent: :destroy validates :name, presence: true, length: { maximum: 128, minimum: 2 } validates :description, length: { maximum: 256 } From 9ac6f8ff2ce54479212e5891ec34c6280a08fe2d Mon Sep 17 00:00:00 2001 From: MartinsLucas Date: Tue, 12 Dec 2017 23:04:32 -0200 Subject: [PATCH 21/35] Setting up grade parameters to metrics calculation Signed-off-by: pedrokelvin Signed-off-by: MateusO97 --- app/controllers/grade_controller.rb | 24 ---- app/controllers/grades_controller.rb | 68 ++++++++++ app/helpers/metric_helper.rb | 127 ++++++++++-------- app/helpers/validations_helper.rb | 20 +++ app/models/grade.rb | 2 +- config/routes.rb | 6 +- .../20171213000135_add_projects_to_grades.rb | 5 + db/schema.rb | 5 +- test/fixtures/grades.yml | 4 +- 9 files changed, 169 insertions(+), 92 deletions(-) delete mode 100644 app/controllers/grade_controller.rb create mode 100644 app/controllers/grades_controller.rb create mode 100644 db/migrate/20171213000135_add_projects_to_grades.rb diff --git a/app/controllers/grade_controller.rb b/app/controllers/grade_controller.rb deleted file mode 100644 index 0cdc92d..0000000 --- a/app/controllers/grade_controller.rb +++ /dev/null @@ -1,24 +0,0 @@ -class GradeController < ApplicationController - include MetricHelper - - def update - end - - def create - @grade = Grade.new(grade_params) - if @grade.save - render json: @grade, status: :created - else - render json: @grade.errors, status: :unprocessable_entity - end - - def show - final_metric = get_metrics(@grade) - - render json: final_metric - end - - def grade_params - params.require(:grade).permit(:weight_debt, :weight_velocity, :weight_burndown) - end -end diff --git a/app/controllers/grades_controller.rb b/app/controllers/grades_controller.rb new file mode 100644 index 0000000..fe7dcec --- /dev/null +++ b/app/controllers/grades_controller.rb @@ -0,0 +1,68 @@ +class GradesController < ApplicationController + include MetricHelper + + before_action :set_grade, only: [:show, :update, :destroy] + + before_action only: [:index, :create] do + validate_project(0, :project_id) + end + + before_action only: [:show, :update, :destroy] do + validate_release(:id, 0) + end + + def index + grade = @project.grade + render json: grade + end + + def create + if @project.grade.blank? + grade = Grade.new(grade_params) + grade.project = @project + + if grade.save + render json: grade, status: :created + else + render json: grade.errors, status: :unprocessable_entity + end + else + render json: @project.grade + end + end + + def update + if @grade.update(grade_params) + render json: @grade + else + render json: @grade.errors, status: :unprocessable_entity + end + end + + def show + # issue: Caso o projeto não tenha releases ou a release não tenha sprints, isto deve ser tratado + # begin + final_metric = get_metrics(@grade) + render json: final_metric + # rescue HasNoSprints + # render json: { errors: "Could not calculate grade. This release has no sprints" }, + # status: :unprocessable_entity + # rescue HasNoReleases + # render json: { errors: "Could not calculate grade. This project has no releases" }, + # status: :unprocessable_entity + # end + end + + def destroy + @grade.destroy + end + + private + def grade_params + params.require(:grade).permit(:weight_debts, :weight_velocity, :weight_burndown) + end + + def set_grade + @grade = Grade.find(params[:id]) + end +end diff --git a/app/helpers/metric_helper.rb b/app/helpers/metric_helper.rb index 7e5f358..e899449 100644 --- a/app/helpers/metric_helper.rb +++ b/app/helpers/metric_helper.rb @@ -4,71 +4,80 @@ module MetricHelper def get_metrics(grade) last_release = grade.project.releases.last - metrics = calculate_metrics(last_release) + # if last_release.blank? + # raise HasNoReleases.new(message: "HasNoReleases") + # else + metrics = calculate_metrics(last_release) - sum_of_weights = grade.weight_debt + grade.weight_velocity + grade.weight_burndown + sum_of_weights = grade.weight_debts + grade.weight_velocity + grade.weight_burndown - final_metric = Float (grade.weight_debt * metrics[:metric_debts_value] + - grade.weight_velocity * metrics[:metric_velocity_value] + - grade.weight_burndown * metrics[:metric_burndown_value]) / - sum_of_weights + final_metric = (Float (grade.weight_debts * metrics[:metric_debts_value]) + + (grade.weight_velocity * metrics[:metric_velocity_value]) + + (grade.weight_burndown * metrics[:metric_burndown_value])) / + sum_of_weights + + return final_metric + # end end def calculate_metrics(release) sprint = release.sprints.last - - if release.project.is_scoring == true - burned_stories = {} - date_axis = [] - points_axis = [] - ideal_line = [] - metric_burndown_array = [] - amount_of_sprints = release.sprints.count - metric_velocity_value = 0 - planned_points = 0 - burned_points = 0 - - velocity = get_sprints_informations(release.sprints, sprint) - total_points = get_total_points(sprint) - burned_stories = get_burned_points(sprint, burned_stories) - total_sprints_points = velocity[:total_points] - velocities = velocity[:velocities] - - range_dates = (sprint.initial_date .. sprint.final_date) - - set_dates_and_points(burned_stories, date_axis, points_axis, range_dates, total_points) - days_of_sprint = date_axis.length - 1 - set_ideal_line(days_of_sprint, ideal_line, total_points) - ideal_burned_points = ideal_line[0] - ideal_line[1] - - for i in 0..(date_axis.length - 2) - real_burned_points = points_axis[i] - points_axis[i + 1] - burned_percentage = Float((real_burned_points).abs * 100) / ideal_burned_points - metric_burndown_array.push(burned_percentage) - end - - for i in 0..(amount_of_sprints - 1) - metric_velocity_value += (total_sprints_points[i] - velocities[i]) - end - - for i in 0..(release.sprints.length - 1) - planned_points += velocity[:total_points][i] - burned_points += velocity[:completed_points][i] + # if sprint.blank? + # raise HasNoSprints.new(message: "HasNoSprints") + # else + if release.project.is_scoring == true + burned_stories = {} + date_axis = [] + points_axis = [] + ideal_line = [] + metric_burndown_array = [] + amount_of_sprints = release.sprints.count + metric_velocity_value = 0 + planned_points = 0 + burned_points = 0 + + velocity = get_sprints_informations(release.sprints, sprint) + total_points = get_total_points(sprint) + burned_stories = get_burned_points(sprint, burned_stories) + total_sprints_points = velocity[:total_points] + velocities = velocity[:velocities] + + range_dates = (sprint.initial_date .. sprint.final_date) + + set_dates_and_points(burned_stories, date_axis, points_axis, range_dates, total_points) + days_of_sprint = date_axis.length - 1 + set_ideal_line(days_of_sprint, ideal_line, total_points) + ideal_burned_points = ideal_line[0] - ideal_line[1] + + for i in 0..(date_axis.length - 2) + real_burned_points = points_axis[i] - points_axis[i + 1] + burned_percentage = Float((real_burned_points).abs * 100) / ideal_burned_points + metric_burndown_array.push(burned_percentage) + end + + for i in 0..(amount_of_sprints - 1) + metric_velocity_value += (total_sprints_points[i] - velocities[i]) + end + + for i in 0..(release.sprints.length - 1) + planned_points += velocity[:total_points][i] + burned_points += velocity[:completed_points][i] + end + + metric_burndown_value = calculate_burndown(metric_burndown_array) + + metric_debts_value = Float(planned_points - burned_points) / planned_points + metric_debts_value = calculate_velocity_and_debt(metric_debts_value) + + total_points = get_total_points_release(release) + metric_velocity_value = Float metric_velocity_value / total_points + metric_velocity_value = calculate_velocity_and_debt(metric_velocity_value) + + return metrics = { metric_debts_value: metric_debts_value, + metric_velocity_value: metric_velocity_value, + metric_burndown_value: metric_burndown_value } end - - metric_burndown_value = calculate_burndown(metric_burndown_array) - - metric_debts_value = Float(planned_points - burned_points) / planned_points - metric_debts_value = calculate_velocity_and_debt(metric_debts_value) - - total_points = get_total_points_release(release) - metric_velocity_value = Float metric_velocity_value / total_points - metric_velocity_value = calculate_velocity_and_debt(metric_velocity_value) - - return metrics = { metric_debts_value: metric_debts_value, - metric_velocity_value: metric_velocity_value, - metric_burndown_value: metric_burndown_value } - end + # end end def calculate_velocity_and_debt(metric) @@ -93,7 +102,7 @@ def calculate_burndown(metric) values = 0 for i in 0..(metric.length - 1) - if metric[i] <= 10 || metric[i] > 100 + if metric[i] <= 10 || metric[i] >= 200 values += 0 elsif metric[i] <= 40 values += 1 diff --git a/app/helpers/validations_helper.rb b/app/helpers/validations_helper.rb index 3c41b64..8f84ab1 100644 --- a/app/helpers/validations_helper.rb +++ b/app/helpers/validations_helper.rb @@ -44,6 +44,12 @@ def verifies_id(current_id, previous_id, component_type) elsif component_type == "release" && previous_id != 0 release_id = previous_id @release = Release.find(params[:release_id].to_i) + elsif component_type == "grade" && current_id != 0 + id = current_id + @grade = Grade.find(params[:id].to_i) + elsif component_type == "grade" && previous_id != 0 + grade_id = previous_id + @grade = Grade.find(params[:grade_id].to_i) elsif component_type == "sprint" && current_id != 0 id = current_id @sprint = Sprint.find(params[:id].to_i) @@ -76,6 +82,20 @@ def validate_project(id, project_id) end end + + def validate_grade(id, grade_id) + current_user + verifies_id(id, grade_id, "grade") + project + user + + if @current_user.id == @user.id + return true + else + render json: { error: "Not Authorized" }, status: 401 + end + end + def validate_release(id, release_id) current_user verifies_id(id, release_id, "release") diff --git a/app/models/grade.rb b/app/models/grade.rb index 9a2f427..defcd2a 100644 --- a/app/models/grade.rb +++ b/app/models/grade.rb @@ -3,5 +3,5 @@ class Grade < ApplicationRecord validates :weight_burndown, presence: true validates :weight_velocity, presence: true - validates :weight_debt, presence: true + validates :weight_debts, presence: true end diff --git a/config/routes.rb b/config/routes.rb index 9857a8a..fd3475b 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,9 +1,4 @@ Rails.application.routes.draw do - get 'grade/update' - - get 'grade/create' - - get 'grade/show' # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html post "authenticate", to: "authentication#authenticate" @@ -36,6 +31,7 @@ resources :users, shallow: true do resources :projects do + resources :grades resources :releases do resources :sprints do resources :stories diff --git a/db/migrate/20171213000135_add_projects_to_grades.rb b/db/migrate/20171213000135_add_projects_to_grades.rb new file mode 100644 index 0000000..f536c4e --- /dev/null +++ b/db/migrate/20171213000135_add_projects_to_grades.rb @@ -0,0 +1,5 @@ +class AddProjectsToGrades < ActiveRecord::Migration[5.1] + def change + add_reference :grades, :project, foreign_key: true + end +end diff --git a/db/schema.rb b/db/schema.rb index 4613260..d555bd3 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20171212174435) do +ActiveRecord::Schema.define(version: 20171213000135) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -21,6 +21,8 @@ t.float "weight_debts" t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.bigint "project_id" + t.index ["project_id"], name: "index_grades_on_project_id" end create_table "issues", force: :cascade do |t| @@ -114,6 +116,7 @@ t.string "access_token" end + add_foreign_key "grades", "projects" add_foreign_key "projects", "users" add_foreign_key "releases", "projects" add_foreign_key "retrospectives", "sprints" diff --git a/test/fixtures/grades.yml b/test/fixtures/grades.yml index d5825c0..67a63bb 100644 --- a/test/fixtures/grades.yml +++ b/test/fixtures/grades.yml @@ -3,9 +3,9 @@ one: weight_burndown: weight_velocity: - weight_debt: + weight_debts: two: weight_burndown: weight_velocity: - weight_debt: + weight_debts: From 18f464f17b2a8a395e7da079e151c41a5c5ca0e0 Mon Sep 17 00:00:00 2001 From: MateusO97 Date: Wed, 13 Dec 2017 10:30:20 -0200 Subject: [PATCH 22/35] Creating Grade models tests Signed-off-by: pedrokelvin Signed-off-by: MartinsLucas --- test/controllers/grade_controller_test.rb | 19 ------ test/controllers/sprints_controller_test.rb | 39 ------------ test/models/grade_test.rb | 70 ++++++++++++++++++++- 3 files changed, 67 insertions(+), 61 deletions(-) delete mode 100644 test/controllers/grade_controller_test.rb diff --git a/test/controllers/grade_controller_test.rb b/test/controllers/grade_controller_test.rb deleted file mode 100644 index e486f7d..0000000 --- a/test/controllers/grade_controller_test.rb +++ /dev/null @@ -1,19 +0,0 @@ -require 'test_helper' - -class GradeControllerTest < ActionDispatch::IntegrationTest - test "should get update" do - get grade_update_url - assert_response :success - end - - test "should get create" do - get grade_create_url - assert_response :success - end - - test "should get show" do - get grade_show_url - assert_response :success - end - -end diff --git a/test/controllers/sprints_controller_test.rb b/test/controllers/sprints_controller_test.rb index e7cb022..2c6f310 100644 --- a/test/controllers/sprints_controller_test.rb +++ b/test/controllers/sprints_controller_test.rb @@ -394,43 +394,4 @@ def setup assert_response :unprocessable_entity assert response.parsed_body["error"] == "The Velocity is only available in projects that use Story Points" end - - test "should get velocity metric data if project is scoring" do - get "/sprints/#{@sprint.id}/velocity_metric", headers: { Authorization: @token.result } - - assert_response :success - end - - test "should not get velocity metric data if project is not scoring" do - get "/sprints/#{@sprint_scoring_false.id}/velocity_metric", headers: { Authorization: @token.result } - - assert_response :unprocessable_entity - assert response.parsed_body["error"] == "The Velocity metric is only available in projects that use Story Points" - end - - test "should get burndown metric data if project is scoring" do - get "/sprints/#{@sprint.id}/burndown_metric", headers: { Authorization: @token.result } - - assert_response :success - end - - test "should not get burndown metric data if project is not scoring" do - get "/sprints/#{@sprint_scoring_false.id}/burndown_metric", headers: { Authorization: @token.result } - - assert_response :unprocessable_entity - assert response.parsed_body["error"] == "The Burndown metric is only available in projects that use Story Points" - end - - test "should get debts from a project if it is scoring" do - get "/sprints/#{@sprint.id}/debts", headers: { Authorization: @token.result } - - assert_response :success - end - - test "should not get debts from a project if it is not scoring" do - get "/sprints/#{@sprint_scoring_false.id}/debts", headers: { Authorization: @token.result } - - assert_response :unprocessable_entity - assert response.parsed_body["error"] == "Debts is only available in projects that use Story Points" - end end diff --git a/test/models/grade_test.rb b/test/models/grade_test.rb index e9528e4..a71b64f 100644 --- a/test/models/grade_test.rb +++ b/test/models/grade_test.rb @@ -1,7 +1,71 @@ require 'test_helper' class GradeTest < ActiveSupport::TestCase - # test "the truth" do - # assert true - # end + def setup + @user = User.create( + name: "Ronaldo", + email: "Ronaldofenomeno@gmail.com", + password: "123456789", + password_confirmation: "123456789" + ) + + @project = Project.create( + name: "Falko", + description: "Esse projeto faz parte da disciplina MDS.", + is_project_from_github: true, + user_id: @user.id, + is_scoring: false + ) + + @release = Release.create( + name: "Release 1", + description: "First Release.", + initial_date: "01/01/2017", + final_date: "02/02/2019", + project_id: @project.id + ) + + @sprint = Sprint.create( + name: "Sprint1", + description: "Essa sprint", + initial_date: "23-04-1993", + final_date: "23-04-2003", + release_id: @release.id + ) + + @grade = Grade.create( + weight_debts: "1", + weight_burndown: "1", + weight_velocity: "1", + project_id: @project.id + ) + + @grade = Grade.create( + weight_debts: "1", + weight_burndown: "1", + weight_velocity: "1", + project_id: @project.id + ) + + end + + test "should save a grade" do + assert @grade.save + end + + test "Grade should have a weight debts" do + @grade.weight_debts = nil + assert_not @grade.save + end + + test "Grade should have a weight burndown" do + @grade.weight_burndown = nil + assert_not @grade.save + end + + test "Grade should have a weight velocity" do + @grade.weight_velocity = nil + assert_not @grade.save + end + end From a0dbc9c0e1b0a307c671f84450133f7f67a8f5e6 Mon Sep 17 00:00:00 2001 From: MartinsLucas Date: Tue, 12 Dec 2017 23:04:32 -0200 Subject: [PATCH 23/35] Setting up grade parameters to metrics calculation Signed-off-by: pedrokelvin Signed-off-by: MateusO97 --- app/controllers/grade_controller.rb | 24 ---- app/controllers/grades_controller.rb | 68 ++++++++++ app/helpers/metric_helper.rb | 127 ++++++++++-------- app/helpers/validations_helper.rb | 20 +++ app/models/grade.rb | 2 +- config/routes.rb | 6 +- .../20171213000135_add_projects_to_grades.rb | 5 + db/schema.rb | 5 +- test/fixtures/grades.yml | 4 +- 9 files changed, 169 insertions(+), 92 deletions(-) delete mode 100644 app/controllers/grade_controller.rb create mode 100644 app/controllers/grades_controller.rb create mode 100644 db/migrate/20171213000135_add_projects_to_grades.rb diff --git a/app/controllers/grade_controller.rb b/app/controllers/grade_controller.rb deleted file mode 100644 index 0cdc92d..0000000 --- a/app/controllers/grade_controller.rb +++ /dev/null @@ -1,24 +0,0 @@ -class GradeController < ApplicationController - include MetricHelper - - def update - end - - def create - @grade = Grade.new(grade_params) - if @grade.save - render json: @grade, status: :created - else - render json: @grade.errors, status: :unprocessable_entity - end - - def show - final_metric = get_metrics(@grade) - - render json: final_metric - end - - def grade_params - params.require(:grade).permit(:weight_debt, :weight_velocity, :weight_burndown) - end -end diff --git a/app/controllers/grades_controller.rb b/app/controllers/grades_controller.rb new file mode 100644 index 0000000..fe7dcec --- /dev/null +++ b/app/controllers/grades_controller.rb @@ -0,0 +1,68 @@ +class GradesController < ApplicationController + include MetricHelper + + before_action :set_grade, only: [:show, :update, :destroy] + + before_action only: [:index, :create] do + validate_project(0, :project_id) + end + + before_action only: [:show, :update, :destroy] do + validate_release(:id, 0) + end + + def index + grade = @project.grade + render json: grade + end + + def create + if @project.grade.blank? + grade = Grade.new(grade_params) + grade.project = @project + + if grade.save + render json: grade, status: :created + else + render json: grade.errors, status: :unprocessable_entity + end + else + render json: @project.grade + end + end + + def update + if @grade.update(grade_params) + render json: @grade + else + render json: @grade.errors, status: :unprocessable_entity + end + end + + def show + # issue: Caso o projeto não tenha releases ou a release não tenha sprints, isto deve ser tratado + # begin + final_metric = get_metrics(@grade) + render json: final_metric + # rescue HasNoSprints + # render json: { errors: "Could not calculate grade. This release has no sprints" }, + # status: :unprocessable_entity + # rescue HasNoReleases + # render json: { errors: "Could not calculate grade. This project has no releases" }, + # status: :unprocessable_entity + # end + end + + def destroy + @grade.destroy + end + + private + def grade_params + params.require(:grade).permit(:weight_debts, :weight_velocity, :weight_burndown) + end + + def set_grade + @grade = Grade.find(params[:id]) + end +end diff --git a/app/helpers/metric_helper.rb b/app/helpers/metric_helper.rb index 7e5f358..e899449 100644 --- a/app/helpers/metric_helper.rb +++ b/app/helpers/metric_helper.rb @@ -4,71 +4,80 @@ module MetricHelper def get_metrics(grade) last_release = grade.project.releases.last - metrics = calculate_metrics(last_release) + # if last_release.blank? + # raise HasNoReleases.new(message: "HasNoReleases") + # else + metrics = calculate_metrics(last_release) - sum_of_weights = grade.weight_debt + grade.weight_velocity + grade.weight_burndown + sum_of_weights = grade.weight_debts + grade.weight_velocity + grade.weight_burndown - final_metric = Float (grade.weight_debt * metrics[:metric_debts_value] + - grade.weight_velocity * metrics[:metric_velocity_value] + - grade.weight_burndown * metrics[:metric_burndown_value]) / - sum_of_weights + final_metric = (Float (grade.weight_debts * metrics[:metric_debts_value]) + + (grade.weight_velocity * metrics[:metric_velocity_value]) + + (grade.weight_burndown * metrics[:metric_burndown_value])) / + sum_of_weights + + return final_metric + # end end def calculate_metrics(release) sprint = release.sprints.last - - if release.project.is_scoring == true - burned_stories = {} - date_axis = [] - points_axis = [] - ideal_line = [] - metric_burndown_array = [] - amount_of_sprints = release.sprints.count - metric_velocity_value = 0 - planned_points = 0 - burned_points = 0 - - velocity = get_sprints_informations(release.sprints, sprint) - total_points = get_total_points(sprint) - burned_stories = get_burned_points(sprint, burned_stories) - total_sprints_points = velocity[:total_points] - velocities = velocity[:velocities] - - range_dates = (sprint.initial_date .. sprint.final_date) - - set_dates_and_points(burned_stories, date_axis, points_axis, range_dates, total_points) - days_of_sprint = date_axis.length - 1 - set_ideal_line(days_of_sprint, ideal_line, total_points) - ideal_burned_points = ideal_line[0] - ideal_line[1] - - for i in 0..(date_axis.length - 2) - real_burned_points = points_axis[i] - points_axis[i + 1] - burned_percentage = Float((real_burned_points).abs * 100) / ideal_burned_points - metric_burndown_array.push(burned_percentage) - end - - for i in 0..(amount_of_sprints - 1) - metric_velocity_value += (total_sprints_points[i] - velocities[i]) - end - - for i in 0..(release.sprints.length - 1) - planned_points += velocity[:total_points][i] - burned_points += velocity[:completed_points][i] + # if sprint.blank? + # raise HasNoSprints.new(message: "HasNoSprints") + # else + if release.project.is_scoring == true + burned_stories = {} + date_axis = [] + points_axis = [] + ideal_line = [] + metric_burndown_array = [] + amount_of_sprints = release.sprints.count + metric_velocity_value = 0 + planned_points = 0 + burned_points = 0 + + velocity = get_sprints_informations(release.sprints, sprint) + total_points = get_total_points(sprint) + burned_stories = get_burned_points(sprint, burned_stories) + total_sprints_points = velocity[:total_points] + velocities = velocity[:velocities] + + range_dates = (sprint.initial_date .. sprint.final_date) + + set_dates_and_points(burned_stories, date_axis, points_axis, range_dates, total_points) + days_of_sprint = date_axis.length - 1 + set_ideal_line(days_of_sprint, ideal_line, total_points) + ideal_burned_points = ideal_line[0] - ideal_line[1] + + for i in 0..(date_axis.length - 2) + real_burned_points = points_axis[i] - points_axis[i + 1] + burned_percentage = Float((real_burned_points).abs * 100) / ideal_burned_points + metric_burndown_array.push(burned_percentage) + end + + for i in 0..(amount_of_sprints - 1) + metric_velocity_value += (total_sprints_points[i] - velocities[i]) + end + + for i in 0..(release.sprints.length - 1) + planned_points += velocity[:total_points][i] + burned_points += velocity[:completed_points][i] + end + + metric_burndown_value = calculate_burndown(metric_burndown_array) + + metric_debts_value = Float(planned_points - burned_points) / planned_points + metric_debts_value = calculate_velocity_and_debt(metric_debts_value) + + total_points = get_total_points_release(release) + metric_velocity_value = Float metric_velocity_value / total_points + metric_velocity_value = calculate_velocity_and_debt(metric_velocity_value) + + return metrics = { metric_debts_value: metric_debts_value, + metric_velocity_value: metric_velocity_value, + metric_burndown_value: metric_burndown_value } end - - metric_burndown_value = calculate_burndown(metric_burndown_array) - - metric_debts_value = Float(planned_points - burned_points) / planned_points - metric_debts_value = calculate_velocity_and_debt(metric_debts_value) - - total_points = get_total_points_release(release) - metric_velocity_value = Float metric_velocity_value / total_points - metric_velocity_value = calculate_velocity_and_debt(metric_velocity_value) - - return metrics = { metric_debts_value: metric_debts_value, - metric_velocity_value: metric_velocity_value, - metric_burndown_value: metric_burndown_value } - end + # end end def calculate_velocity_and_debt(metric) @@ -93,7 +102,7 @@ def calculate_burndown(metric) values = 0 for i in 0..(metric.length - 1) - if metric[i] <= 10 || metric[i] > 100 + if metric[i] <= 10 || metric[i] >= 200 values += 0 elsif metric[i] <= 40 values += 1 diff --git a/app/helpers/validations_helper.rb b/app/helpers/validations_helper.rb index 3c41b64..8f84ab1 100644 --- a/app/helpers/validations_helper.rb +++ b/app/helpers/validations_helper.rb @@ -44,6 +44,12 @@ def verifies_id(current_id, previous_id, component_type) elsif component_type == "release" && previous_id != 0 release_id = previous_id @release = Release.find(params[:release_id].to_i) + elsif component_type == "grade" && current_id != 0 + id = current_id + @grade = Grade.find(params[:id].to_i) + elsif component_type == "grade" && previous_id != 0 + grade_id = previous_id + @grade = Grade.find(params[:grade_id].to_i) elsif component_type == "sprint" && current_id != 0 id = current_id @sprint = Sprint.find(params[:id].to_i) @@ -76,6 +82,20 @@ def validate_project(id, project_id) end end + + def validate_grade(id, grade_id) + current_user + verifies_id(id, grade_id, "grade") + project + user + + if @current_user.id == @user.id + return true + else + render json: { error: "Not Authorized" }, status: 401 + end + end + def validate_release(id, release_id) current_user verifies_id(id, release_id, "release") diff --git a/app/models/grade.rb b/app/models/grade.rb index 9a2f427..defcd2a 100644 --- a/app/models/grade.rb +++ b/app/models/grade.rb @@ -3,5 +3,5 @@ class Grade < ApplicationRecord validates :weight_burndown, presence: true validates :weight_velocity, presence: true - validates :weight_debt, presence: true + validates :weight_debts, presence: true end diff --git a/config/routes.rb b/config/routes.rb index 9857a8a..fd3475b 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,9 +1,4 @@ Rails.application.routes.draw do - get 'grade/update' - - get 'grade/create' - - get 'grade/show' # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html post "authenticate", to: "authentication#authenticate" @@ -36,6 +31,7 @@ resources :users, shallow: true do resources :projects do + resources :grades resources :releases do resources :sprints do resources :stories diff --git a/db/migrate/20171213000135_add_projects_to_grades.rb b/db/migrate/20171213000135_add_projects_to_grades.rb new file mode 100644 index 0000000..f536c4e --- /dev/null +++ b/db/migrate/20171213000135_add_projects_to_grades.rb @@ -0,0 +1,5 @@ +class AddProjectsToGrades < ActiveRecord::Migration[5.1] + def change + add_reference :grades, :project, foreign_key: true + end +end diff --git a/db/schema.rb b/db/schema.rb index 4613260..d555bd3 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20171212174435) do +ActiveRecord::Schema.define(version: 20171213000135) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -21,6 +21,8 @@ t.float "weight_debts" t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.bigint "project_id" + t.index ["project_id"], name: "index_grades_on_project_id" end create_table "issues", force: :cascade do |t| @@ -114,6 +116,7 @@ t.string "access_token" end + add_foreign_key "grades", "projects" add_foreign_key "projects", "users" add_foreign_key "releases", "projects" add_foreign_key "retrospectives", "sprints" diff --git a/test/fixtures/grades.yml b/test/fixtures/grades.yml index d5825c0..67a63bb 100644 --- a/test/fixtures/grades.yml +++ b/test/fixtures/grades.yml @@ -3,9 +3,9 @@ one: weight_burndown: weight_velocity: - weight_debt: + weight_debts: two: weight_burndown: weight_velocity: - weight_debt: + weight_debts: From d186161589d98984d812763c02c6874e41975a76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Cantu=C3=A1ria?= Date: Wed, 13 Dec 2017 12:01:56 -0200 Subject: [PATCH 24/35] Adding Strories controller tests to increase coverage --- app/controllers/stories_controller.rb | 18 ++++---- config/routes.rb | 4 +- test/controllers/stories_controller_test.rb | 49 +++++++++++++++++++++ 3 files changed, 60 insertions(+), 11 deletions(-) diff --git a/app/controllers/stories_controller.rb b/app/controllers/stories_controller.rb index 636d40b..45af3d3 100644 --- a/app/controllers/stories_controller.rb +++ b/app/controllers/stories_controller.rb @@ -19,27 +19,27 @@ def index end def to_do_list - sprint = Sprint.find(params[:id]) + @sprint = Sprint.find(params[:id]) - stories = sprint.stories.select { |story| story.pipeline == "To Do" } + @stories = @sprint.stories.select { |story| story.pipeline == "To Do" } - render json: format_json_output(stories) + render json: format_json_output(@stories) end def doing_list - sprint = Sprint.find(params[:id]) + @sprint = Sprint.find(params[:id]) - stories = sprint.stories.select { |story| story.pipeline == "Doing" } + @stories = @sprint.stories.select { |story| story.pipeline == "Doing" } - render json: format_json_output(stories) + render json: format_json_output(@stories) end def done_list - sprint = Sprint.find(params[:id]) + @sprint = Sprint.find(params[:id]) - stories = sprint.stories.select { |story| story.pipeline == "Done" } + @stories = @sprint.stories.select { |story| story.pipeline == "Done" } - render json: format_json_output(stories) + render json: format_json_output(@stories) end def show diff --git a/config/routes.rb b/config/routes.rb index 49b2d9b..dd1ef90 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -11,9 +11,9 @@ get "projects/:id/contributors", to: "projects#get_contributors" post "projects/:id/issues/assignees", to: "issues#update_assignees" - get "sprints/:id/doing_stories", to: "stories#doing_list" - get "sprints/:id/done_stories", to: "stories#done_list" get "sprints/:id/to_do_stories", to: "stories#to_do_list" + get "sprints/:id/done_stories", to: "stories#done_list" + get "sprints/:id/doing_stories", to: "stories#doing_list" get "projects/:id/issues", to: "issues#index" post "projects/:id/issues", to: "issues#create" diff --git a/test/controllers/stories_controller_test.rb b/test/controllers/stories_controller_test.rb index 2432408..3cf4fbe 100644 --- a/test/controllers/stories_controller_test.rb +++ b/test/controllers/stories_controller_test.rb @@ -44,6 +44,37 @@ def setup sprint_id: @sprint.id ) + @story_to_do = Story.create( + name: "Story 1", + description: "Story 1 us14", + assign: "Lucas", + pipeline: "To Do", + initial_date: "01/01/2017", + issue_number: "10", + sprint_id: @sprint.id + ) + + @story_doing = Story.create( + name: "Story 1", + description: "Story 1 us14", + assign: "Lucas", + pipeline: "Doing", + initial_date: "01/01/2017", + issue_number: "10", + sprint_id: @sprint.id + ) + + @story_done = Story.create( + name: "Story 1", + description: "Story 1 us14", + assign: "Lucas", + pipeline: "Done", + initial_date: "01/01/2017", + final_date: "05/01/2017", + issue_number: "10", + sprint_id: @sprint.id + ) + @token = AuthenticateUser.call(@user.email, @user.password) @another_user = User.create( @@ -409,4 +440,22 @@ def setup assert_response :created end + + test "should render a story with to do pipeline" do + get "/sprints/#{@sprint.id}/to_do_stories", headers: { Authorization: @token.result } + + assert_response :success + end + + test "should render a story with doing pipeline" do + get "/sprints/#{@sprint.id}/doing_stories", headers: { Authorization: @token.result } + + assert_response :success + end + + test "should render a story with done pipeline" do + get "/sprints/#{@sprint.id}/done_stories", headers: { Authorization: @token.result } + + assert_response :success + end end From f34551dca6a54c045041a63f8a2c880176595314 Mon Sep 17 00:00:00 2001 From: MateusO97 Date: Wed, 13 Dec 2017 11:47:33 -0200 Subject: [PATCH 25/35] Adding Grade controller tests Signed-off-by: pedrokelvin Signed-off-by: MartinsLucas --- app/controllers/grades_controller.rb | 6 +- test/controllers/grades_controller_test.rb | 291 +++++++++++++++++++++ 2 files changed, 294 insertions(+), 3 deletions(-) create mode 100644 test/controllers/grades_controller_test.rb diff --git a/app/controllers/grades_controller.rb b/app/controllers/grades_controller.rb index fe7dcec..9babf55 100644 --- a/app/controllers/grades_controller.rb +++ b/app/controllers/grades_controller.rb @@ -1,13 +1,13 @@ class GradesController < ApplicationController include MetricHelper - + before_action :set_grade, only: [:show, :update, :destroy] before_action only: [:index, :create] do validate_project(0, :project_id) end - before_action only: [:show, :update, :destroy] do + before_action only: [:show, :update] do validate_release(:id, 0) end @@ -18,7 +18,7 @@ def index def create if @project.grade.blank? - grade = Grade.new(grade_params) + grade = Grade.new(grade_params) grade.project = @project if grade.save diff --git a/test/controllers/grades_controller_test.rb b/test/controllers/grades_controller_test.rb new file mode 100644 index 0000000..42a1788 --- /dev/null +++ b/test/controllers/grades_controller_test.rb @@ -0,0 +1,291 @@ +require "test_helper" + +class GradeControllerTest < ActionDispatch::IntegrationTest + def setup + @user = User.create( + name: "Robert", + email: "robert@email.com", + password: "123123", + password_confirmation: "123123" + ) + + @project = Project.create( + name: "Falko", + description: "Deion.", + user_id: @user.id, + is_project_from_github: true, + is_scoring: false, + ) + + @release = Release.create( + name: "R1", + description: "Deion", + initial_date: "01/01/2018", + final_date: "01/03/2018", + amount_of_sprints: "20", + project_id: @project.id + ) + + @sprint = Sprint.create( + name: "Sprint 1", + description: "Sprint 1 us10", + initial_date: "02/01/2018", + final_date: "02/02/2018", + release_id: @release.id + ) + @no_grade_project = Project.create( + name: "Falko", + description: "Deion.", + user_id: @user.id, + is_project_from_github: true, + is_scoring: true + ) + + @grade = Grade.create( + weight_debts: "1", + weight_burndown: "1", + weight_velocity: "1", + project_id: @project.id + ) + + @token = AuthenticateUser.call(@user.email, @user.password) + + @another_user = User.create( + name: "Ronaldo", + email: "ronaldo@email.com", + password: "123123", + password_confirmation: "123123" + ) + + @another_project = Project.create( + name: "Futebol", + description: "Deion.", + user_id: @another_user.id, + is_project_from_github: true + ) + + @another_release = Release.create( + name: "Real Madrid", + description: "Deions", + initial_date: "01/01/2018", + final_date: "01/01/2019", + amount_of_sprints: "20", + project_id: @another_project.id + ) + + @another_sprint = Sprint.create( + name: "Sprint 2", + description: "Sprint 2 us10", + initial_date: "06/10/2018", + final_date: "13/10/2018", + release_id: @another_release.id + ) + + @another_grade = Grade.create( + weight_debts: "1", + weight_burndown: "2", + weight_velocity: "3", + project_id: @project.id + ) + + @another_token = AuthenticateUser.call(@another_user.email, @another_user.password) + end + + test "should create a Grade" do + post "/projects/#{@no_grade_project.id}/grades", params: { + "grade": { + "weight_debts": "1", + "weight_velocity": "1", + "weight_burndown": "1" + } + }, headers: { Authorization: @token.result } + + assert_response :created + end + +# test "should not create multiple grades" do +# post "/projects/#{@project.id}/grades", params: { +# "grade": { +# "weight_debts": "1", +# "weight_velocity": "1", +# "weight_burndown": "1" +# } +# }, headers: { Authorization: @token.result } +# +# assert_response :forbidden +# end + + test "should not create grade without correct params" do + post "/projects/#{@no_grade_project.id}/grades", params: { + "grade": { + "weight_debts": "1", + } + }, headers: { Authorization: @token.result } + + assert_response :unprocessable_entity + end + + + test "should not create grade without authentication" do + post "/projects/#{@project.id}/grades", params: { + "grade": { + "weight_debts": "1", + "weight_velocity": "1", + "weight_burndown": "1" + } + } + + assert_response :unauthorized + end + + test "should not create grade in another user" do + post "/projects/#{@project.id}/grades", params: { + "grade": { + "weight_debts": "1", + "weight_velocity": "1", + "weight_burndown": "1" + } + }, headers: { Authorization: @another_token.result } + + assert_response :unauthorized + end + + test "should not get grades index without authentication" do + get "/projects/#{@project.id}/grades" + + assert_response :unauthorized + end + + test "should get grades index" do + get "/projects/#{@project.id}/grades", headers: { Authorization: @token.result } + + assert_response :success + end + + test "should not get grades of other user" do + get "/projects/#{@project.id}/grades", headers: { Authorization: @another_token.result } + + assert_response :unauthorized + end + + # test "should not get grades show without authentication" do + # get "/grades/#{@grade.id}" + # + # assert_response :unauthorized + # end + # + # test "should get grades show" do + # get "/grades/#{@grade.id}", headers: { Authorization: @token.result } + # + # assert_response :success + # end + # + # test "should not get grades show of another user" do + # get "/grades/#{@grade.id}", headers: { Authorization: @another_token.result } + # + # assert_response :unauthorized + # end + # + # test "should edit grades" do + # @old_weight_debts = @grade.weight_debts + # @old_weight_burndown = @grade.weight_burndown + # @old_weight_velocity = @grade.weight_velocity + # + # patch "/grades/#{@grade.id}", params: { + # grade: { + # weight_debts: "3", + # weight_burndown: "3", + # weight_velocity: "3", + # } + # }, headers: { Authorization: @token.result } + # + # @grade.reload + # + # assert_response :ok + # assert_not_equal @old_weight_debts, @grade.weight_debts + # assert_not_equal @old_weight_burndown, @grade.weight_burndown + # assert_not_equal @old_weight_velocity, @grade.weight_velocity + # end + # + # test "should not edit grade without authentication" do + # @old_weight_debts = @grade.weight_debts + # @old_weight_burndown = @grade.weight_burndown + # @old_weight_velocity = @grade.weight_velocity + # + # patch "/grades/#{@grade.id}", params: { + # grade: { + # weight_debts: "3", + # weight_burndown: "3", + # weight_velocity: "3", + # } + # } + # + # @grade.reload + # + # assert_response :unauthorized + # assert_not_equal @old_weight_debts, @grade.weight_debts + # assert_not_equal @old_weight_burndown, @grade.weight_burndown + # assert_not_equal @old_weight_velocity, @grade.weight_velocity + # end + # + # test "should not edit grade with wrong params" do + # @old_weight_debts = @grade.weight_debts + # + # patch "/grades/#{@grade.id}", params: { + # grade: { + # weight_debts: "1", + # } + # }, headers: { Authorization: @token.result } + # + # @grade.reload + # + # assert_response :unprocessable_entity + # assert_equal @old_weight_debts, @grade.weight_debts + # end + + # test "should not edit grade with blank params" do + # @old_weight_debts = @grade.weight_debts + # @old_weight_debts = @grade.weight_debts + # + # patch "/grades/#{@grade.id}", params: { + # grade: { + # weight_debts: "" + # } + # }, headers: { Authorization: @token.result } + # + # @grade.reload + # + # assert_response :unprocessable_entity + # assert_equal @old_weight_debts, @grade.weight_debts + # assert_equal @old_weight_debts, @grade.weight_debts + # end + + # test "should not edit grades of another user" do + # patch "/grades/#{@grade.id}", params: { + # grade: { + # weight_debts: "3", + # weight_burndown: "3", + # weight_velocity: "3", + # } + # }, headers: { Authorization: @another_token.result } + # + # assert_response :unauthorized + # end + + test "should destroy grade" do + assert_difference("Grade.count", -1) do + delete "/grades/#{@grade.id}", headers: { Authorization: @token.result } + end + + assert_response :no_content + end + + test "should not destroy grade without authentication" do + assert_no_difference "Grade.count" do + delete "/grades/#{@grade.id}" + end + + assert_response :unauthorized + end + +end From 3cd7fa676784cd16c063a0ca76018dea3592fec5 Mon Sep 17 00:00:00 2001 From: Pedro Kelvin Date: Wed, 13 Dec 2017 11:55:48 -0200 Subject: [PATCH 26/35] Adding test to Burndown and Velocity Helpers Signed-off-by: MateusO97 Signed-off-by: danieloda --- config/routes.rb | 4 +- db/migrate/20171028121912_create_issues.rb | 14 -- test/fixtures/issues.yml | 9 -- test/helpers/burndown_helper_test.rb | 147 +++++++++++++++++++++ test/helpers/velocity_helper_test.rb | 13 ++ test/models/issue_test.rb | 7 - 6 files changed, 161 insertions(+), 33 deletions(-) delete mode 100644 db/migrate/20171028121912_create_issues.rb delete mode 100644 test/fixtures/issues.yml create mode 100644 test/helpers/burndown_helper_test.rb delete mode 100644 test/models/issue_test.rb diff --git a/config/routes.rb b/config/routes.rb index fd3475b..49b2d9b 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -24,9 +24,7 @@ get "sprints/:id/velocity", to: "sprints#get_velocity" post "projects/:id/reopen_issue", to: "issues#reopen_issue" - - get "sprints/:id/metrics", to: "sprints#get_metrics" - + post "/projects/:id/issues/graphic", to: "issues#issue_graphic_data" resources :users, shallow: true do diff --git a/db/migrate/20171028121912_create_issues.rb b/db/migrate/20171028121912_create_issues.rb deleted file mode 100644 index 22e4b84..0000000 --- a/db/migrate/20171028121912_create_issues.rb +++ /dev/null @@ -1,14 +0,0 @@ -class CreateIssues < ActiveRecord::Migration[5.1] - def change - create_table :issues do |t| - t.string :title - t.text :body - t.string :assignee - t.integer :milestone - t.string :labels - t.string :assignees - - t.timestamps - end - end -end diff --git a/test/fixtures/issues.yml b/test/fixtures/issues.yml deleted file mode 100644 index e192dee..0000000 --- a/test/fixtures/issues.yml +++ /dev/null @@ -1,9 +0,0 @@ -# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html - -one: - title: MyString - body: MyText - -two: - title: MyString - body: MyText diff --git a/test/helpers/burndown_helper_test.rb b/test/helpers/burndown_helper_test.rb new file mode 100644 index 0000000..160e37c --- /dev/null +++ b/test/helpers/burndown_helper_test.rb @@ -0,0 +1,147 @@ +require "test_helper" + +class VelocityHelperTest < ActiveSupport::TestCase + include VelocityHelper + + def setup + @user = User.create( + name: "Ronaldo", + email: "Ronaldofenomeno@gmail.com", + password: "123456789", + password_confirmation: "123456789" + ) + + @project = Project.create( + name: "Falko", + description: "Some project description.", + user_id: @user.id, + is_project_from_github: true, + is_scoring: true + ) + + @release = Release.create( + name: "R1", + description: "Description", + initial_date: "01/01/2018", + final_date: "01/01/2019", + amount_of_sprints: "20", + project_id: @project.id + ) + + @first_sprint = Sprint.create( + name: "Sprint 1", + description: "Sprint 1 us10", + initial_date: "06/10/2016", + final_date: "13/10/2018", + release_id: @release.id, + ) + + @second_sprint = Sprint.create( + name: "Sprint 2", + description: "Sprint 2 us10", + initial_date: "06/10/2016", + final_date: "13/10/2018", + release_id: @release.id, + ) + + @first_story = Story.create( + name: "Story 1", + description: "Story 1 us14", + assign: "Lucas", + pipeline: "In Progress", + initial_date: "01/01/2017", + issue_number: "8", + sprint_id: @first_sprint.id, + story_points: "5" + ) + + @second_story = Story.create( + name: "Story 2", + description: "Story 2 us14", + assign: "Lucas", + pipeline: "Done", + initial_date: "01/01/2017", + final_date: "01/02/2017", + issue_number: "9", + sprint_id: @first_sprint.id, + story_points: "8" + ) + + @third_story = Story.create( + name: "Story 3", + description: "Story 3 us14", + assign: "Lucas", + pipeline: "Done", + initial_date: "01/01/2017", + final_date: "01/02/2017", + issue_number: "10", + sprint_id: @first_sprint.id, + story_points: "3" + ) + + @another_first_story = Story.create( + name: "Story 1", + description: "Story 1 us13", + assign: "Lucas", + pipeline: "Done", + initial_date: "01/02/2017", + final_date: "01/03/2017", + issue_number: "1", + sprint_id: @second_sprint.id, + story_points: "13" + ) + + @another_second_story = Story.create( + name: "Story 1", + description: "Story 1 us13", + assign: "Lucas", + pipeline: "Done", + initial_date: "01/02/2017", + final_date: "01/03/2017", + issue_number: "2", + sprint_id: @second_sprint.id, + story_points: "5" + ) + + @token = AuthenticateUser.call(@user.email, @user.password) + end + + test "Should get burned sprint points" do + final_date = @another_first_story.final_date + + burned_stories_test = {} + burned_stories = {} + + burned_stories_test[final_date] = + @another_first_story.story_points + + @another_second_story.story_points + + + assert_equal burned_stories_test, get_burned_points(@second_sprint, burned_stories) + end + + test "Should set ideal axis" do + date_axis_test = [] + ideal_line_test = [] + ideal_line = [] + + planned_points = @another_first_story.story_points + + @another_second_story.story_points + + range_dates = (@another_first_story.initial_date .. @another_first_story.final_date) + + range_dates.each do |date| + date_axis_test.push(date) + end + + days_of_sprint = date_axis_test.length - 1 + + for day in (days_of_sprint).downto(0) + ideal_line_test.push(planned_points * (day / (Float days_of_sprint))) + end + + set_ideal_line(days_of_sprint, ideal_line, planned_points) + + assert_equal ideal_line_test, ideal_line + end +end diff --git a/test/helpers/velocity_helper_test.rb b/test/helpers/velocity_helper_test.rb index 53c7031..ba6e13e 100644 --- a/test/helpers/velocity_helper_test.rb +++ b/test/helpers/velocity_helper_test.rb @@ -137,4 +137,17 @@ def setup assert_equal velocity, calculate_velocity(completed_points) end + + test "Should calculate total points of one Release" do + sprint_1_points = @first_story.story_points + + @second_story.story_points + + @third_story.story_points + + sprint_2_points = @another_first_story.story_points + + @another_second_story.story_points + + total_points = sprint_1_points + sprint_2_points + + assert_equal total_points, get_total_points_release(@release) + end end diff --git a/test/models/issue_test.rb b/test/models/issue_test.rb deleted file mode 100644 index 7e15ee9..0000000 --- a/test/models/issue_test.rb +++ /dev/null @@ -1,7 +0,0 @@ -require "test_helper" - -class IssueTest < ActiveSupport::TestCase - # test "the truth" do - # assert true - # end -end From 7894cc6ee84ed500402a308f235a08ab60edf41c Mon Sep 17 00:00:00 2001 From: MartinsLucas Date: Wed, 13 Dec 2017 11:58:40 -0200 Subject: [PATCH 27/35] Round decimal places of grade --- app/helpers/metric_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/helpers/metric_helper.rb b/app/helpers/metric_helper.rb index e899449..acb9f99 100644 --- a/app/helpers/metric_helper.rb +++ b/app/helpers/metric_helper.rb @@ -16,7 +16,7 @@ def get_metrics(grade) (grade.weight_burndown * metrics[:metric_burndown_value])) / sum_of_weights - return final_metric + return final_metric.round(1) # end end From daad03c9175d6c9f917b7386205a904119a1f5dc Mon Sep 17 00:00:00 2001 From: Pedro Kelvin Date: Wed, 13 Dec 2017 13:03:13 -0200 Subject: [PATCH 28/35] Adding metric helper --- test/helpers/metric_helper_test.rb | 138 +++++++++++++++++++++++++++++ 1 file changed, 138 insertions(+) create mode 100644 test/helpers/metric_helper_test.rb diff --git a/test/helpers/metric_helper_test.rb b/test/helpers/metric_helper_test.rb new file mode 100644 index 0000000..0c05c69 --- /dev/null +++ b/test/helpers/metric_helper_test.rb @@ -0,0 +1,138 @@ +require "test_helper" + +class VelocityHelperTest < ActiveSupport::TestCase + include VelocityHelper + include MetricHelper + + def setup + @user = User.create( + name: "Ronaldo", + email: "Ronaldofenomeno@gmail.com", + password: "123456789", + password_confirmation: "123456789" + ) + + @project = Project.create( + name: "Falko", + description: "Some project description.", + user_id: @user.id, + is_project_from_github: true, + is_scoring: true + ) + + @release = Release.create( + name: "R1", + description: "Description", + initial_date: "01/01/2018", + final_date: "01/01/2019", + amount_of_sprints: "20", + project_id: @project.id + ) + + @first_sprint = Sprint.create( + name: "Sprint 1", + description: "Sprint 1 us10", + initial_date: "06/10/2016", + final_date: "13/10/2018", + release_id: @release.id, + ) + + @second_sprint = Sprint.create( + name: "Sprint 2", + description: "Sprint 2 us10", + initial_date: "06/10/2016", + final_date: "13/10/2018", + release_id: @release.id, + ) + + @first_story = Story.create( + name: "Story 1", + description: "Story 1 us14", + assign: "Lucas", + pipeline: "In Progress", + initial_date: "01/01/2017", + issue_number: "8", + sprint_id: @first_sprint.id, + story_points: "5" + ) + + @second_story = Story.create( + name: "Story 2", + description: "Story 2 us14", + assign: "Lucas", + pipeline: "Done", + initial_date: "01/01/2017", + final_date: "01/02/2017", + issue_number: "9", + sprint_id: @first_sprint.id, + story_points: "8" + ) + + @third_story = Story.create( + name: "Story 3", + description: "Story 3 us14", + assign: "Lucas", + pipeline: "Done", + initial_date: "01/01/2017", + final_date: "01/02/2017", + issue_number: "10", + sprint_id: @first_sprint.id, + story_points: "3" + ) + + @another_first_story = Story.create( + name: "Story 1", + description: "Story 1 us13", + assign: "Lucas", + pipeline: "Done", + initial_date: "01/02/2017", + final_date: "01/03/2017", + issue_number: "1", + sprint_id: @second_sprint.id, + story_points: "13" + ) + + @another_second_story = Story.create( + name: "Story 1", + description: "Story 1 us13", + assign: "Lucas", + pipeline: "Done", + initial_date: "01/02/2017", + final_date: "01/03/2017", + issue_number: "2", + sprint_id: @second_sprint.id, + story_points: "5" + ) + + @token = AuthenticateUser.call(@user.email, @user.password) + end + + test "Should calculate debts metric" do + grade_value_test = 0 + grades = {} + + planned_points = @another_first_story.story_points + + @another_second_story.story_points + burned_points = @another_first_story.story_points + + @another_second_story.story_points + + metric_value_test = Float(planned_points - burned_points) / planned_points + + if metric_value_test <= 0.2 + grade_value_test += 4 + elsif metric_value_test <= 0.4 + grade_value_test += 3 + elsif metric_value_test <= 0.6 + grade_value_test += 2 + elsif metric_value_test <= 0.9 + grade_value_test += 1 + elsif metric_value_test <= 1 + grade_value_test += 0 + end + + grades = calculate_metrics(@release) + grade_value = grades[:metric_debts_value] + + assert_equal grade_value_test, grade_value + end +end From 9b7ea5cd844b4ad82e49d0061ec23be053b2701b Mon Sep 17 00:00:00 2001 From: MartinsLucas Date: Wed, 13 Dec 2017 13:05:40 -0200 Subject: [PATCH 29/35] Improving metric calculation --- app/helpers/metric_helper.rb | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/app/helpers/metric_helper.rb b/app/helpers/metric_helper.rb index acb9f99..15179d0 100644 --- a/app/helpers/metric_helper.rb +++ b/app/helpers/metric_helper.rb @@ -4,27 +4,31 @@ module MetricHelper def get_metrics(grade) last_release = grade.project.releases.last - # if last_release.blank? - # raise HasNoReleases.new(message: "HasNoReleases") - # else + if last_release.blank? + return nil + else metrics = calculate_metrics(last_release) - sum_of_weights = grade.weight_debts + grade.weight_velocity + grade.weight_burndown + if metrics.blank? + final_metric = 0 + else + sum_of_weights = grade.weight_debts + grade.weight_velocity + grade.weight_burndown - final_metric = (Float (grade.weight_debts * metrics[:metric_debts_value]) + - (grade.weight_velocity * metrics[:metric_velocity_value]) + - (grade.weight_burndown * metrics[:metric_burndown_value])) / - sum_of_weights + final_metric = (Float (grade.weight_debts * metrics[:metric_debts_value]) + + (grade.weight_velocity * metrics[:metric_velocity_value]) + + (grade.weight_burndown * metrics[:metric_burndown_value])) / + sum_of_weights + end return final_metric.round(1) - # end + end end def calculate_metrics(release) sprint = release.sprints.last - # if sprint.blank? - # raise HasNoSprints.new(message: "HasNoSprints") - # else + if sprint.blank? || sprint.stories.blank? + return nil + else if release.project.is_scoring == true burned_stories = {} date_axis = [] @@ -77,7 +81,7 @@ def calculate_metrics(release) metric_velocity_value: metric_velocity_value, metric_burndown_value: metric_burndown_value } end - # end + end end def calculate_velocity_and_debt(metric) From 090da549c53d73c9b2b3c1e7551fe8ec64c7de28 Mon Sep 17 00:00:00 2001 From: MateusO97 Date: Wed, 13 Dec 2017 13:06:49 -0200 Subject: [PATCH 30/35] Adding test and validation helper modification --- app/controllers/grades_controller.rb | 2 +- app/helpers/validations_helper.rb | 6 ++- test/controllers/grades_controller_test.rb | 48 ++++++++++++++-------- 3 files changed, 37 insertions(+), 19 deletions(-) diff --git a/app/controllers/grades_controller.rb b/app/controllers/grades_controller.rb index 9babf55..e10de87 100644 --- a/app/controllers/grades_controller.rb +++ b/app/controllers/grades_controller.rb @@ -8,7 +8,7 @@ class GradesController < ApplicationController end before_action only: [:show, :update] do - validate_release(:id, 0) + validate_grade(:id, 0) end def index diff --git a/app/helpers/validations_helper.rb b/app/helpers/validations_helper.rb index 8f84ab1..76f37b9 100644 --- a/app/helpers/validations_helper.rb +++ b/app/helpers/validations_helper.rb @@ -11,6 +11,10 @@ def project @project = Project.find(@release.project_id) end + def project_grade + @project = Project.find(@grade.project.id) + end + def release @release = Release.find(@sprint.release_id) end @@ -86,7 +90,7 @@ def validate_project(id, project_id) def validate_grade(id, grade_id) current_user verifies_id(id, grade_id, "grade") - project + project_grade user if @current_user.id == @user.id diff --git a/test/controllers/grades_controller_test.rb b/test/controllers/grades_controller_test.rb index 42a1788..c2d2d52 100644 --- a/test/controllers/grades_controller_test.rb +++ b/test/controllers/grades_controller_test.rb @@ -64,6 +64,14 @@ def setup is_project_from_github: true ) + @has_grade_project = Project.create( + name: "Futebol", + description: "Deion.", + user_id: @another_user.id, + is_project_from_github: true + ) + + @another_release = Release.create( name: "Real Madrid", description: "Deions", @@ -103,17 +111,23 @@ def setup assert_response :created end -# test "should not create multiple grades" do -# post "/projects/#{@project.id}/grades", params: { -# "grade": { -# "weight_debts": "1", -# "weight_velocity": "1", -# "weight_burndown": "1" -# } -# }, headers: { Authorization: @token.result } -# -# assert_response :forbidden -# end + test "should not create multiple grades" do + @old_weight_debts = @grade.weight_debts + @old_weight_burndown = @grade.weight_burndown + @old_weight_velocity = @grade.weight_velocity + post "/projects/#{@project.id}/grades", params: { + "grade": { + "weight_debts": "2", + "weight_velocity": "2", + "weight_burndown": "2" + } + }, headers: { Authorization: @token.result } + + assert_equal @old_weight_debts, @grade.weight_debts + assert_equal @old_weight_burndown, @grade.weight_burndown + assert_equal @old_weight_velocity, @grade.weight_velocity + assert_response :ok + end test "should not create grade without correct params" do post "/projects/#{@no_grade_project.id}/grades", params: { @@ -168,12 +182,12 @@ def setup assert_response :unauthorized end - # test "should not get grades show without authentication" do - # get "/grades/#{@grade.id}" - # - # assert_response :unauthorized - # end - # + test "should not get grades show without authentication" do + get "/grades/#{@grade.id}" + + assert_response :unauthorized + end + # test "should get grades show" do # get "/grades/#{@grade.id}", headers: { Authorization: @token.result } # From 84eab8ff2bec7066febcaa6e763ad285d0c9bf1c Mon Sep 17 00:00:00 2001 From: ThalissonMelo Date: Wed, 13 Dec 2017 17:57:58 -0200 Subject: [PATCH 31/35] Making grades tests --- app/controllers/grades_controller.rb | 4 +- test/controllers/grades_controller_test.rb | 194 ++++++++++----------- 2 files changed, 99 insertions(+), 99 deletions(-) diff --git a/app/controllers/grades_controller.rb b/app/controllers/grades_controller.rb index e10de87..af11a01 100644 --- a/app/controllers/grades_controller.rb +++ b/app/controllers/grades_controller.rb @@ -42,8 +42,8 @@ def update def show # issue: Caso o projeto não tenha releases ou a release não tenha sprints, isto deve ser tratado # begin - final_metric = get_metrics(@grade) - render json: final_metric + final_metric = get_metrics(@grade) + render json: final_metric # rescue HasNoSprints # render json: { errors: "Could not calculate grade. This release has no sprints" }, # status: :unprocessable_entity diff --git a/test/controllers/grades_controller_test.rb b/test/controllers/grades_controller_test.rb index c2d2d52..5003515 100644 --- a/test/controllers/grades_controller_test.rb +++ b/test/controllers/grades_controller_test.rb @@ -123,6 +123,8 @@ def setup } }, headers: { Authorization: @token.result } + @grade.reload + assert_equal @old_weight_debts, @grade.weight_debts assert_equal @old_weight_burndown, @grade.weight_burndown assert_equal @old_weight_velocity, @grade.weight_velocity @@ -188,103 +190,101 @@ def setup assert_response :unauthorized end - # test "should get grades show" do - # get "/grades/#{@grade.id}", headers: { Authorization: @token.result } - # - # assert_response :success - # end - # - # test "should not get grades show of another user" do - # get "/grades/#{@grade.id}", headers: { Authorization: @another_token.result } - # - # assert_response :unauthorized - # end - # - # test "should edit grades" do - # @old_weight_debts = @grade.weight_debts - # @old_weight_burndown = @grade.weight_burndown - # @old_weight_velocity = @grade.weight_velocity - # - # patch "/grades/#{@grade.id}", params: { - # grade: { - # weight_debts: "3", - # weight_burndown: "3", - # weight_velocity: "3", - # } - # }, headers: { Authorization: @token.result } - # - # @grade.reload - # - # assert_response :ok - # assert_not_equal @old_weight_debts, @grade.weight_debts - # assert_not_equal @old_weight_burndown, @grade.weight_burndown - # assert_not_equal @old_weight_velocity, @grade.weight_velocity - # end - # - # test "should not edit grade without authentication" do - # @old_weight_debts = @grade.weight_debts - # @old_weight_burndown = @grade.weight_burndown - # @old_weight_velocity = @grade.weight_velocity - # - # patch "/grades/#{@grade.id}", params: { - # grade: { - # weight_debts: "3", - # weight_burndown: "3", - # weight_velocity: "3", - # } - # } - # - # @grade.reload - # - # assert_response :unauthorized - # assert_not_equal @old_weight_debts, @grade.weight_debts - # assert_not_equal @old_weight_burndown, @grade.weight_burndown - # assert_not_equal @old_weight_velocity, @grade.weight_velocity - # end - # - # test "should not edit grade with wrong params" do - # @old_weight_debts = @grade.weight_debts - # - # patch "/grades/#{@grade.id}", params: { - # grade: { - # weight_debts: "1", - # } - # }, headers: { Authorization: @token.result } - # - # @grade.reload - # - # assert_response :unprocessable_entity - # assert_equal @old_weight_debts, @grade.weight_debts - # end - - # test "should not edit grade with blank params" do - # @old_weight_debts = @grade.weight_debts - # @old_weight_debts = @grade.weight_debts - # - # patch "/grades/#{@grade.id}", params: { - # grade: { - # weight_debts: "" - # } - # }, headers: { Authorization: @token.result } - # - # @grade.reload - # - # assert_response :unprocessable_entity - # assert_equal @old_weight_debts, @grade.weight_debts - # assert_equal @old_weight_debts, @grade.weight_debts - # end - - # test "should not edit grades of another user" do - # patch "/grades/#{@grade.id}", params: { - # grade: { - # weight_debts: "3", - # weight_burndown: "3", - # weight_velocity: "3", - # } - # }, headers: { Authorization: @another_token.result } - # - # assert_response :unauthorized - # end + test "should get grades show" do + get "/grades/#{@grade.id}", headers: { Authorization: @token.result } + + assert_response :success + end + + test "should not get grades show of another user" do + get "/grades/#{@grade.id}", headers: { Authorization: @another_token.result } + + assert_response :unauthorized + end + + test "should edit grades" do + @old_weight_debts = @grade.weight_debts + @old_weight_burndown = @grade.weight_burndown + @old_weight_velocity = @grade.weight_velocity + + patch "/grades/#{@grade.id}", params: { + grade: { + weight_debts: "3", + weight_burndown: "3", + weight_velocity: "3", + } + }, headers: { Authorization: @token.result } + + @grade.reload + + assert_response :ok + assert_not_equal @old_weight_debts, @grade.weight_debts + assert_not_equal @old_weight_burndown, @grade.weight_burndown + assert_not_equal @old_weight_velocity, @grade.weight_velocity + end + + test "should not edit grade without authentication" do + @old_weight_debts = @grade.weight_debts + @old_weight_burndown = @grade.weight_burndown + @old_weight_velocity = @grade.weight_velocity + + patch "/grades/#{@grade.id}", params: { + grade: { + weight_debts: "3", + weight_burndown: "3", + weight_velocity: "3", + } + } + + assert_response :unauthorized + assert_equal @old_weight_debts, @grade.weight_debts + assert_equal @old_weight_burndown, @grade.weight_burndown + assert_equal @old_weight_velocity, @grade.weight_velocity + end + + test "should not edit grade with wrong params" do + @old_weight_debts = @grade.weight_debts + + patch "/grades/#{@grade.id}", params: { + grade: { + weight_debts: "2", + } + }, headers: { Authorization: @token.result } + + @grade.reload + + assert_response :ok + assert_not_equal @old_weight_debts, @grade.weight_debts + end + + test "should not edit grade with blank params" do + @old_weight_debts = @grade.weight_debts + @old_weight_debts = @grade.weight_debts + + patch "/grades/#{@grade.id}", params: { + grade: { + weight_debts: "" + } + }, headers: { Authorization: @token.result } + + @grade.reload + + assert_response :unprocessable_entity + assert_equal @old_weight_debts, @grade.weight_debts + assert_equal @old_weight_debts, @grade.weight_debts + end + + test "should not edit grades of another user" do + patch "/grades/#{@grade.id}", params: { + grade: { + weight_debts: "3", + weight_burndown: "3", + weight_velocity: "3", + } + }, headers: { Authorization: @another_token.result } + + assert_response :unauthorized + end test "should destroy grade" do assert_difference("Grade.count", -1) do From 862e14467a52eb826eb91542fdd372aee0602bbf Mon Sep 17 00:00:00 2001 From: Pedro Kelvin Date: Wed, 13 Dec 2017 18:12:25 -0200 Subject: [PATCH 32/35] Fixing codacy --- config/routes.rb | 1 - .../20171213000135_add_projects_to_grades.rb | 2 +- test/controllers/grades_controller_test.rb | 32 +++++++++---------- test/models/grade_test.rb | 2 -- 4 files changed, 16 insertions(+), 21 deletions(-) diff --git a/config/routes.rb b/config/routes.rb index dd1ef90..69e9109 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -24,7 +24,6 @@ get "sprints/:id/velocity", to: "sprints#get_velocity" post "projects/:id/reopen_issue", to: "issues#reopen_issue" - post "/projects/:id/issues/graphic", to: "issues#issue_graphic_data" resources :users, shallow: true do diff --git a/db/migrate/20171213000135_add_projects_to_grades.rb b/db/migrate/20171213000135_add_projects_to_grades.rb index f536c4e..0ef4858 100644 --- a/db/migrate/20171213000135_add_projects_to_grades.rb +++ b/db/migrate/20171213000135_add_projects_to_grades.rb @@ -1,5 +1,5 @@ class AddProjectsToGrades < ActiveRecord::Migration[5.1] def change - add_reference :grades, :project, foreign_key: true + add_reference :grades, :project, foreign_key: true end end diff --git a/test/controllers/grades_controller_test.rb b/test/controllers/grades_controller_test.rb index 5003515..bbd8d66 100644 --- a/test/controllers/grades_controller_test.rb +++ b/test/controllers/grades_controller_test.rb @@ -124,7 +124,6 @@ def setup }, headers: { Authorization: @token.result } @grade.reload - assert_equal @old_weight_debts, @grade.weight_debts assert_equal @old_weight_burndown, @grade.weight_burndown assert_equal @old_weight_velocity, @grade.weight_velocity @@ -192,21 +191,21 @@ def setup test "should get grades show" do get "/grades/#{@grade.id}", headers: { Authorization: @token.result } - + assert_response :success end - + test "should not get grades show of another user" do get "/grades/#{@grade.id}", headers: { Authorization: @another_token.result } - + assert_response :unauthorized end - + test "should edit grades" do @old_weight_debts = @grade.weight_debts @old_weight_burndown = @grade.weight_burndown @old_weight_velocity = @grade.weight_velocity - + patch "/grades/#{@grade.id}", params: { grade: { weight_debts: "3", @@ -214,9 +213,9 @@ def setup weight_velocity: "3", } }, headers: { Authorization: @token.result } - + @grade.reload - + assert_response :ok assert_not_equal @old_weight_debts, @grade.weight_debts assert_not_equal @old_weight_burndown, @grade.weight_burndown @@ -241,18 +240,18 @@ def setup assert_equal @old_weight_burndown, @grade.weight_burndown assert_equal @old_weight_velocity, @grade.weight_velocity end - + test "should not edit grade with wrong params" do @old_weight_debts = @grade.weight_debts - + patch "/grades/#{@grade.id}", params: { grade: { weight_debts: "2", } }, headers: { Authorization: @token.result } - + @grade.reload - + assert_response :ok assert_not_equal @old_weight_debts, @grade.weight_debts end @@ -260,15 +259,15 @@ def setup test "should not edit grade with blank params" do @old_weight_debts = @grade.weight_debts @old_weight_debts = @grade.weight_debts - + patch "/grades/#{@grade.id}", params: { grade: { weight_debts: "" } }, headers: { Authorization: @token.result } - + @grade.reload - + assert_response :unprocessable_entity assert_equal @old_weight_debts, @grade.weight_debts assert_equal @old_weight_debts, @grade.weight_debts @@ -282,7 +281,7 @@ def setup weight_velocity: "3", } }, headers: { Authorization: @another_token.result } - + assert_response :unauthorized end @@ -301,5 +300,4 @@ def setup assert_response :unauthorized end - end diff --git a/test/models/grade_test.rb b/test/models/grade_test.rb index a71b64f..b21937b 100644 --- a/test/models/grade_test.rb +++ b/test/models/grade_test.rb @@ -46,7 +46,6 @@ def setup weight_velocity: "1", project_id: @project.id ) - end test "should save a grade" do @@ -67,5 +66,4 @@ def setup @grade.weight_velocity = nil assert_not @grade.save end - end From 8c2eb4dea22965a69bf51d814ed73537cbee5063 Mon Sep 17 00:00:00 2001 From: Pedro Kelvin Date: Wed, 13 Dec 2017 18:21:13 -0200 Subject: [PATCH 33/35] Fixing codacy issues --- test/models/grade_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/models/grade_test.rb b/test/models/grade_test.rb index b21937b..833d9ec 100644 --- a/test/models/grade_test.rb +++ b/test/models/grade_test.rb @@ -1,4 +1,4 @@ -require 'test_helper' +require "test_helper" class GradeTest < ActiveSupport::TestCase def setup From 0d3d836d8b2edc25c89482dd7cc4d10fe832956e Mon Sep 17 00:00:00 2001 From: Pedro Kelvin Date: Wed, 13 Dec 2017 20:08:46 -0200 Subject: [PATCH 34/35] Fixing issues required in the revision --- app/controllers/grades_controller.rb | 9 --------- test/controllers/grades_controller_test.rb | 4 ++-- test/models/grade_test.rb | 4 ++-- 3 files changed, 4 insertions(+), 13 deletions(-) diff --git a/app/controllers/grades_controller.rb b/app/controllers/grades_controller.rb index af11a01..3f5b8ef 100644 --- a/app/controllers/grades_controller.rb +++ b/app/controllers/grades_controller.rb @@ -40,17 +40,8 @@ def update end def show - # issue: Caso o projeto não tenha releases ou a release não tenha sprints, isto deve ser tratado - # begin final_metric = get_metrics(@grade) render json: final_metric - # rescue HasNoSprints - # render json: { errors: "Could not calculate grade. This release has no sprints" }, - # status: :unprocessable_entity - # rescue HasNoReleases - # render json: { errors: "Could not calculate grade. This project has no releases" }, - # status: :unprocessable_entity - # end end def destroy diff --git a/test/controllers/grades_controller_test.rb b/test/controllers/grades_controller_test.rb index bbd8d66..f591643 100644 --- a/test/controllers/grades_controller_test.rb +++ b/test/controllers/grades_controller_test.rb @@ -58,14 +58,14 @@ def setup ) @another_project = Project.create( - name: "Futebol", + name: "Soccer", description: "Deion.", user_id: @another_user.id, is_project_from_github: true ) @has_grade_project = Project.create( - name: "Futebol", + name: "Soccer", description: "Deion.", user_id: @another_user.id, is_project_from_github: true diff --git a/test/models/grade_test.rb b/test/models/grade_test.rb index 833d9ec..4ea63e2 100644 --- a/test/models/grade_test.rb +++ b/test/models/grade_test.rb @@ -11,7 +11,7 @@ def setup @project = Project.create( name: "Falko", - description: "Esse projeto faz parte da disciplina MDS.", + description: "This project is part of the course MDS.", is_project_from_github: true, user_id: @user.id, is_scoring: false @@ -27,7 +27,7 @@ def setup @sprint = Sprint.create( name: "Sprint1", - description: "Essa sprint", + description: "This sprint.", initial_date: "23-04-1993", final_date: "23-04-2003", release_id: @release.id From f97b492f190a71aa8f3516af4ae49dbf9cefb476 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lax=20Alves?= Date: Wed, 13 Dec 2017 21:08:11 -0200 Subject: [PATCH 35/35] Removing unnecessary Issue model --- app/models/issue.rb | 2 -- 1 file changed, 2 deletions(-) delete mode 100644 app/models/issue.rb diff --git a/app/models/issue.rb b/app/models/issue.rb deleted file mode 100644 index 070dbdf..0000000 --- a/app/models/issue.rb +++ /dev/null @@ -1,2 +0,0 @@ -class Issue < ApplicationRecord -end