-
Notifications
You must be signed in to change notification settings - Fork 73
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor PastIteration mounting process #379
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,15 @@ | ||
module Iterations | ||
class PastIteration | ||
attr_reader :start_date, :end_date, :points, :iteration_number | ||
include Virtus.model | ||
|
||
def initialize(start_date:, end_date:, project:, iteration_number: nil) | ||
@start_date = start_date | ||
@end_date = end_date | ||
@project = project | ||
@points = points | ||
@iteration_number = iteration_number | ||
end | ||
attribute :start_date, Date | ||
attribute :end_date, Date | ||
attribute :iteration_number, Integer | ||
attribute :stories, Array[Story] | ||
attribute :points, Integer | ||
|
||
def points | ||
@points ||= stories.sum(:estimate) | ||
end | ||
|
||
def stories | ||
@stories ||= @project.stories.where( | ||
'accepted_at >= ? AND accepted_at <= ?', @start_date, @end_date | ||
) | ||
@points ||= stories.to_a.map(&:estimate).compact.sum | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
module Iterations | ||
class ProjectIterations | ||
DAYS_IN_A_WEEK = 7 | ||
|
||
def initialize(project:) | ||
@project = project | ||
end | ||
|
@@ -10,35 +12,58 @@ def current_iteration_start | |
|
||
def past_iterations | ||
(0...length).map do |iteration_number| | ||
start_date = start_date(iteration_number) | ||
end_date = end_date(start_date) | ||
PastIteration.new(start_date: start_date, | ||
end_date: end_date, | ||
project: @project, | ||
iteration_number: iteration_number + 1) | ||
start_at = start_date(iteration_number) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @rodrigovirgilio apply beginning_of_day and end_of_day in those methods There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Applied a39d2c9 |
||
end_at = end_date(start_at) | ||
|
||
PastIteration.new( | ||
start_date: start_at, | ||
end_date: end_at, | ||
stories: stories_from(start_at, end_at), | ||
iteration_number: iteration_number + 1 | ||
) | ||
end | ||
end | ||
|
||
private | ||
|
||
attr_reader :project | ||
|
||
def stories_from(start_at, end_at) | ||
stories.select do |story| | ||
story.accepted_at.to_date >= start_at && story.accepted_at.to_date <= end_at | ||
end | ||
end | ||
|
||
def stories | ||
@stories ||= begin | ||
project | ||
.stories | ||
.with_dependencies | ||
.where(state: 'accepted') | ||
.where.not(accepted_at: nil) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that chaining There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, makes sense, but I would keep it to prevent any possible inconsistence. It reflects exactly the kind of stories I'm expecting in the filter method above. |
||
.order(:accepted_at) | ||
end | ||
end | ||
|
||
def length | ||
(days_since_project_start / iteration_length_in_days).floor | ||
end | ||
|
||
def iteration_length_in_days | ||
@project.iteration_length * 7 | ||
project.iteration_length * DAYS_IN_A_WEEK | ||
end | ||
|
||
def project_start_date | ||
@project.start_date | ||
project.start_date | ||
end | ||
|
||
def start_date(iteration_number) | ||
project_start_date + (iteration_number * iteration_length_in_days) | ||
iteration_days = (iteration_number * iteration_length_in_days) | ||
(project_start_date + iteration_days) | ||
end | ||
|
||
def end_date(start_date) | ||
start_date + iteration_length_in_days - 1 | ||
(start_date + (iteration_length_in_days - 1)) | ||
end | ||
|
||
def days_since_project_start | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not
stories.sum(:estimate)
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not every story has value in estimate, so I'm doing a map, compacting to remove nil values, and summing after.
I can change if you have a better approach...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just for clarification:
to_a
here is only to always ensure we are doing it in an array, never into database. I'm avoiding queries here...