Skip to content

Commit 24a7606

Browse files
authored
Merging pull request #134 from fga-gpp-mds/us08_visualizar_burndown
2 parents a3cd01f + 4af0525 commit 24a7606

File tree

5 files changed

+159
-39
lines changed

5 files changed

+159
-39
lines changed

app/controllers/sprints_controller.rb

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
class SprintsController < ApplicationController
22
include ValidationsHelper
33

4-
before_action :set_sprint, only: [:show, :update, :destroy]
4+
before_action :set_sprint, only: [:show, :update, :destroy, :get_burndown]
55

66
before_action only: [:index, :create] do
77
validate_release(0, :release_id)
@@ -11,27 +11,22 @@ class SprintsController < ApplicationController
1111
validate_sprint(:id, 0)
1212
end
1313

14-
# GET /sprints
1514
def index
16-
# @release used from validate_previous_release(:release_id)
1715
@sprints = @release.sprints.reverse
1816
render json: @sprints
1917
end
2018

21-
# GET /sprints/1
2219
def show
2320
render json: @sprint
2421
end
2522

26-
# POST /sprints
2723
def create
2824
@sprint = Sprint.new(sprint_params)
2925
if validate_sprints_date("sprint", sprint_params)
3026
@sprint.release = @release
3127
update_amount_of_sprints
3228
if @sprint.save
3329
render json: @sprint, status: :created
34-
# @release used from validate_release
3530
@sprint.release = @release
3631
update_amount_of_sprints
3732
else
@@ -42,7 +37,6 @@ def create
4237
end
4338
end
4439

45-
# PATCH/PUT /sprints/1
4640
def update
4741
if validate_sprints_date("sprint", sprint_params)
4842
if @sprint.update(sprint_params)
@@ -55,19 +49,53 @@ def update
5549
end
5650
end
5751

58-
# DELETE /sprints/1
5952
def destroy
6053
@sprint.destroy
6154
update_amount_of_sprints
6255
end
6356

57+
def get_burndown
58+
project = @sprint.release.project
59+
if project.is_scoring != false
60+
total_points = 0
61+
burned_stories = {}
62+
coordenates = []
63+
64+
for story in @sprint.stories
65+
total_points += story.story_points
66+
if story.pipeline == "Done"
67+
if burned_stories[story.final_date] == nil
68+
burned_stories[story.final_date] = story.story_points
69+
else
70+
burned_stories[story.final_date] += story.story_points
71+
end
72+
end
73+
end
74+
75+
76+
range = (@sprint.initial_date .. @sprint.final_date)
77+
78+
range.each do |date|
79+
if burned_stories[date] == nil
80+
burned_stories[date] = total_points
81+
else
82+
total_points -= burned_stories[date]
83+
burned_stories[date] = total_points
84+
end
85+
coordanate = { x: date, y: burned_stories[date] }
86+
coordenates.push(coordanate)
87+
end
88+
burned_stories = burned_stories.sort_by { |key, value| key }
89+
render json: coordenates
90+
else
91+
render json: { error: "The Burndown Chart is only available in projects that use Story Points" }, status: :unprocessable_entity
92+
end
93+
end
6494
private
65-
# Use callbacks to share common setup or constraints between actions.
6695
def set_sprint
6796
@sprint = Sprint.find(params[:id])
6897
end
6998

70-
# Only allow a trusted parameter "white list" through.
7199
def sprint_params
72100
params.require(:sprint).permit(:name, :description, :initial_date, :final_date, :release_id)
73101
end

app/controllers/stories_controller.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ def create
3939

4040
def update
4141
if @story.update(story_params)
42+
if @story.pipeline == "Done"
43+
@story.final_date = Date.today
44+
end
4245
render json: @story
4346
else
4447
render json: @story.errors, status: :unprocessable_entity
@@ -55,6 +58,6 @@ def set_story
5558
end
5659

5760
def story_params
58-
params.require(:story).permit(:name, :description, :assign, :pipeline, :initial_date, :story_points, :issue_number)
61+
params.require(:story).permit(:name, :description, :assign, :pipeline, :initial_date, :story_points, :final_date, :issue_number)
5962
end
6063
end

config/routes.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
post "request_github_token", to: "users#request_github_token"
55
post "remove_github_token", to: "users#remove_github_token"
66

7+
get "sprints/:id/burndown", to: "sprints#get_burndown"
8+
79
get "repos", to: "projects#github_projects_list"
810
get "projects/:id/contributors", to: "projects#get_contributors"
911
post "projects/:id/issues/assignees", to: "issues#update_assignees"

db/seeds.rb

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,16 @@
3131
Project.find_or_create_by(
3232
name: "Owla",
3333
description: "This project helps improving classes",
34-
is_project_from_github: false,
35-
github_slug: nil,
36-
is_scoring: false,
37-
user_id: "1"
34+
user_id: "1",
35+
is_project_from_github: true,
36+
is_scoring: true
3837
),
3938
Project.find_or_create_by(
4039
name: "Falko",
4140
description: "Agile Projects Manager",
42-
is_project_from_github: false,
43-
github_slug: nil,
44-
is_scoring: false,
45-
user_id: "2"
41+
user_id: "2",
42+
is_project_from_github: true,
43+
is_scoring: true
4644
)
4745
]
4846

@@ -73,7 +71,7 @@
7371
Release.find_or_create_by(
7472
name: "R - 02",
7573
description: "Second Release",
76-
initial_date: "01-10-2016",
74+
initial_date: "01-01-2016",
7775
final_date: "01-12-2016",
7876
project_id: "2"
7977
)
@@ -91,8 +89,8 @@
9189
Sprint.find_or_create_by(
9290
name: "Sprint 2 - P1",
9391
description: "Second Sprint",
94-
initial_date: "01-10-2016",
95-
final_date: "01-12-2016",
92+
initial_date: "01-01-2017",
93+
final_date: "07-01-2017",
9694
release_id: "1"
9795
),
9896
Sprint.find_or_create_by(
@@ -120,8 +118,9 @@
120118
pipeline: "Backlog",
121119
initial_date: "01/01/2017",
122120
final_date: "02/01/2017",
123-
sprint_id: "1",
121+
story_points: "10",
124122
issue_number: "1",
123+
sprint_id: "1"
125124
),
126125
Story.find_or_create_by(
127126
name: "Story 2",
@@ -130,35 +129,42 @@
130129
pipeline: "Done",
131130
initial_date: "01/01/2017",
132131
final_date: "08/01/2017",
133-
sprint_id: "1",
132+
story_points: "10",
134133
issue_number: "2",
134+
sprint_id: "1"
135135
),
136136
Story.find_or_create_by(
137137
name: "Story 1",
138138
description: "Story 1 us14",
139139
assign: "Matheus B",
140-
pipeline: "In Progress",
141-
initial_date: "03/01/2017",
142-
sprint_id: "2",
140+
pipeline: "Done",
141+
initial_date: "01/01/2017",
142+
final_date: "04/01/2017",
143+
story_points: "10",
143144
issue_number: "3",
145+
sprint_id: "2"
144146
),
145147
Story.find_or_create_by(
146148
name: "Story 2",
147149
description: "Story 2 us14",
148150
assign: "Matheus R",
149-
pipeline: "Backlog",
151+
pipeline: "Done",
150152
initial_date: "01/01/2017",
153+
final_date: "04/01/2017",
151154
sprint_id: "2",
155+
story_points: "10",
152156
issue_number: "4",
157+
sprint_id: "2"
153158
),
154159
Story.find_or_create_by(
155160
name: "Story 1",
156161
description: "Story 1 us14",
157162
assign: "Matheus Roberto",
158163
pipeline: "In Progress",
159164
initial_date: "01/01/2017",
160-
sprint_id: "3",
165+
story_points: "10",
161166
issue_number: "5",
167+
sprint_id: "3"
162168
),
163169
Story.find_or_create_by(
164170
name: "Story 2",
@@ -167,25 +173,27 @@
167173
pipeline: "Done",
168174
initial_date: "07/01/2017",
169175
final_date: "15/01/2017",
170-
sprint_id: "3",
176+
story_points: "10",
171177
issue_number: "6",
178+
sprint_id: "3"
172179
),
173180
Story.find_or_create_by(
174181
name: "Story 1",
175182
description: "Story 1 us14",
176183
assign: "Vinícius",
177184
pipeline: "In Progress",
178185
initial_date: "01/01/2017",
179-
sprint_id: "4",
186+
story_points: "10",
180187
issue_number: "7",
188+
sprint_id: "4"
181189
),
182190
Story.find_or_create_by(
183191
name: "Story 2",
184192
description: "Story 2 us14",
185193
assign: "Adrianne",
186194
pipeline: "In Progress",
187195
initial_date: "01/01/2017",
188-
sprint_id: "4",
196+
story_points: "10",
189197
issue_number: "8",
190198
)
191199
]

0 commit comments

Comments
 (0)