Skip to content

Commit

Permalink
Merging pull request #134 from fga-gpp-mds/us08_visualizar_burndown
Browse files Browse the repository at this point in the history
  • Loading branch information
MatheusRich authored Nov 21, 2017
2 parents a3cd01f + 4af0525 commit 24a7606
Show file tree
Hide file tree
Showing 5 changed files with 159 additions and 39 deletions.
48 changes: 38 additions & 10 deletions app/controllers/sprints_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class SprintsController < ApplicationController
include ValidationsHelper

before_action :set_sprint, only: [:show, :update, :destroy]
before_action :set_sprint, only: [:show, :update, :destroy, :get_burndown]

before_action only: [:index, :create] do
validate_release(0, :release_id)
Expand All @@ -11,27 +11,22 @@ class SprintsController < ApplicationController
validate_sprint(:id, 0)
end

# GET /sprints
def index
# @release used from validate_previous_release(:release_id)
@sprints = @release.sprints.reverse
render json: @sprints
end

# GET /sprints/1
def show
render json: @sprint
end

# POST /sprints
def create
@sprint = Sprint.new(sprint_params)
if validate_sprints_date("sprint", sprint_params)
@sprint.release = @release
update_amount_of_sprints
if @sprint.save
render json: @sprint, status: :created
# @release used from validate_release
@sprint.release = @release
update_amount_of_sprints
else
Expand All @@ -42,7 +37,6 @@ def create
end
end

# PATCH/PUT /sprints/1
def update
if validate_sprints_date("sprint", sprint_params)
if @sprint.update(sprint_params)
Expand All @@ -55,19 +49,53 @@ def update
end
end

# DELETE /sprints/1
def destroy
@sprint.destroy
update_amount_of_sprints
end

def get_burndown
project = @sprint.release.project
if project.is_scoring != false
total_points = 0
burned_stories = {}
coordenates = []

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


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
coordanate = { x: date, y: burned_stories[date] }
coordenates.push(coordanate)
end
burned_stories = burned_stories.sort_by { |key, value| key }
render json: coordenates
else
render json: { error: "The Burndown Chart is only available in projects that use Story Points" }, status: :unprocessable_entity
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_sprint
@sprint = Sprint.find(params[:id])
end

# Only allow a trusted parameter "white list" through.
def sprint_params
params.require(:sprint).permit(:name, :description, :initial_date, :final_date, :release_id)
end
Expand Down
5 changes: 4 additions & 1 deletion app/controllers/stories_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ def create

def update
if @story.update(story_params)
if @story.pipeline == "Done"
@story.final_date = Date.today
end
render json: @story
else
render json: @story.errors, status: :unprocessable_entity
Expand All @@ -55,6 +58,6 @@ def set_story
end

def story_params
params.require(:story).permit(:name, :description, :assign, :pipeline, :initial_date, :story_points, :issue_number)
params.require(:story).permit(:name, :description, :assign, :pipeline, :initial_date, :story_points, :final_date, :issue_number)
end
end
2 changes: 2 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
post "request_github_token", to: "users#request_github_token"
post "remove_github_token", to: "users#remove_github_token"

get "sprints/:id/burndown", to: "sprints#get_burndown"

get "repos", to: "projects#github_projects_list"
get "projects/:id/contributors", to: "projects#get_contributors"
post "projects/:id/issues/assignees", to: "issues#update_assignees"
Expand Down
50 changes: 29 additions & 21 deletions db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,16 @@
Project.find_or_create_by(
name: "Owla",
description: "This project helps improving classes",
is_project_from_github: false,
github_slug: nil,
is_scoring: false,
user_id: "1"
user_id: "1",
is_project_from_github: true,
is_scoring: true
),
Project.find_or_create_by(
name: "Falko",
description: "Agile Projects Manager",
is_project_from_github: false,
github_slug: nil,
is_scoring: false,
user_id: "2"
user_id: "2",
is_project_from_github: true,
is_scoring: true
)
]

Expand Down Expand Up @@ -73,7 +71,7 @@
Release.find_or_create_by(
name: "R - 02",
description: "Second Release",
initial_date: "01-10-2016",
initial_date: "01-01-2016",
final_date: "01-12-2016",
project_id: "2"
)
Expand All @@ -91,8 +89,8 @@
Sprint.find_or_create_by(
name: "Sprint 2 - P1",
description: "Second Sprint",
initial_date: "01-10-2016",
final_date: "01-12-2016",
initial_date: "01-01-2017",
final_date: "07-01-2017",
release_id: "1"
),
Sprint.find_or_create_by(
Expand Down Expand Up @@ -120,8 +118,9 @@
pipeline: "Backlog",
initial_date: "01/01/2017",
final_date: "02/01/2017",
sprint_id: "1",
story_points: "10",
issue_number: "1",
sprint_id: "1"
),
Story.find_or_create_by(
name: "Story 2",
Expand All @@ -130,35 +129,42 @@
pipeline: "Done",
initial_date: "01/01/2017",
final_date: "08/01/2017",
sprint_id: "1",
story_points: "10",
issue_number: "2",
sprint_id: "1"
),
Story.find_or_create_by(
name: "Story 1",
description: "Story 1 us14",
assign: "Matheus B",
pipeline: "In Progress",
initial_date: "03/01/2017",
sprint_id: "2",
pipeline: "Done",
initial_date: "01/01/2017",
final_date: "04/01/2017",
story_points: "10",
issue_number: "3",
sprint_id: "2"
),
Story.find_or_create_by(
name: "Story 2",
description: "Story 2 us14",
assign: "Matheus R",
pipeline: "Backlog",
pipeline: "Done",
initial_date: "01/01/2017",
final_date: "04/01/2017",
sprint_id: "2",
story_points: "10",
issue_number: "4",
sprint_id: "2"
),
Story.find_or_create_by(
name: "Story 1",
description: "Story 1 us14",
assign: "Matheus Roberto",
pipeline: "In Progress",
initial_date: "01/01/2017",
sprint_id: "3",
story_points: "10",
issue_number: "5",
sprint_id: "3"
),
Story.find_or_create_by(
name: "Story 2",
Expand All @@ -167,25 +173,27 @@
pipeline: "Done",
initial_date: "07/01/2017",
final_date: "15/01/2017",
sprint_id: "3",
story_points: "10",
issue_number: "6",
sprint_id: "3"
),
Story.find_or_create_by(
name: "Story 1",
description: "Story 1 us14",
assign: "Vinícius",
pipeline: "In Progress",
initial_date: "01/01/2017",
sprint_id: "4",
story_points: "10",
issue_number: "7",
sprint_id: "4"
),
Story.find_or_create_by(
name: "Story 2",
description: "Story 2 us14",
assign: "Adrianne",
pipeline: "In Progress",
initial_date: "01/01/2017",
sprint_id: "4",
story_points: "10",
issue_number: "8",
)
]
Expand Down
Loading

0 comments on commit 24a7606

Please sign in to comment.