Skip to content

Commit

Permalink
Merging pull request #175 from fga-gpp-mds/US21_manter_nota
Browse files Browse the repository at this point in the history
  • Loading branch information
alaxalves authored Dec 13, 2017
2 parents edd1d32 + 88ef72c commit b420b47
Show file tree
Hide file tree
Showing 24 changed files with 1,057 additions and 78 deletions.
59 changes: 59 additions & 0 deletions app/controllers/grades_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
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] do
validate_grade(: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
final_metric = get_metrics(@grade)
render json: final_metric
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
40 changes: 9 additions & 31 deletions app/controllers/sprints_controller.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
class SprintsController < ApplicationController
include ValidationsHelper
include VelocityHelper
include BurndownHelper
include MetricHelper

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

before_action only: [:index, :create] do
validate_release(0, :release_id)
end

before_action only: [:show, :update, :destroy, :get_velocity] do
before_action only: [:show, :update, :destroy, :get_velocity, :get_metrics] do
validate_sprint(:id, 0)
end

Expand Down Expand Up @@ -68,45 +70,21 @@ def get_velocity

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

for story in @sprint.stories
total_points += story.story_points
total_points = get_total_points(@sprint)
burned_stories = get_burned_points(@sprint, 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
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)

set_dates_and_points(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, total_points)

coordenates = { x: date_axis, y: points_axis, ideal_line: ideal_line }

Expand Down
18 changes: 9 additions & 9 deletions app/controllers/stories_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
48 changes: 48 additions & 0 deletions app/helpers/burndown_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
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
check_pipeline(story, burned_stories)
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

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
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
124 changes: 124 additions & 0 deletions app/helpers/metric_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
module MetricHelper
include BurndownHelper
include VelocityHelper

def get_metrics(grade)
last_release = grade.project.releases.last
if last_release.blank?
return nil
else
metrics = calculate_metrics(last_release)

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
end

return final_metric.round(1)
end
end

def calculate_metrics(release)
sprint = release.sprints.last
if sprint.blank? || sprint.stories.blank?
return nil
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
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] >= 200
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
24 changes: 24 additions & 0 deletions app/helpers/validations_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -44,6 +48,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)
Expand Down Expand Up @@ -76,6 +86,20 @@ def validate_project(id, project_id)
end
end


def validate_grade(id, grade_id)
current_user
verifies_id(id, grade_id, "grade")
project_grade
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")
Expand Down
Loading

0 comments on commit b420b47

Please sign in to comment.