Extra refactors on increment calculations on projects and milestones models
parent
44ff29f511
commit
41dc3fbcc0
|
@ -72,20 +72,14 @@ class Milestone(WatchedMixin):
|
||||||
def _get_user_stories_points(self, user_stories):
|
def _get_user_stories_points(self, user_stories):
|
||||||
role_points = [us.role_points.all() for us in user_stories]
|
role_points = [us.role_points.all() for us in user_stories]
|
||||||
flat_role_points = itertools.chain(*role_points)
|
flat_role_points = itertools.chain(*role_points)
|
||||||
|
flat_role_dicts = map(lambda x: {x.role_id: x.points.value if x.points.value else 0}, flat_role_points)
|
||||||
result = {}
|
return dict_sum(*flat_role_dicts)
|
||||||
for role_point in flat_role_points:
|
|
||||||
if role_point.points.value is not None:
|
|
||||||
if role_point.role_id in result:
|
|
||||||
result[role_point.role_id] += float(role_point.points.value)
|
|
||||||
else:
|
|
||||||
result[role_point.role_id] = float(role_point.points.value)
|
|
||||||
|
|
||||||
return result
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def total_points(self):
|
def total_points(self):
|
||||||
return self._get_user_stories_points([us for us in self.user_stories.all()])
|
return self._get_user_stories_points(
|
||||||
|
[us for us in self.user_stories.all()]
|
||||||
|
)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def closed_points(self):
|
def closed_points(self):
|
||||||
|
@ -93,18 +87,21 @@ class Milestone(WatchedMixin):
|
||||||
[us for us in self.user_stories.all() if us.is_closed]
|
[us for us in self.user_stories.all() if us.is_closed]
|
||||||
)
|
)
|
||||||
|
|
||||||
@property
|
def _get_points_increment(self, client_requirement, team_requirement):
|
||||||
def client_increment_points(self):
|
|
||||||
user_stories = UserStory.objects.none()
|
user_stories = UserStory.objects.none()
|
||||||
if self.estimated_start and self.estimated_finish:
|
if self.estimated_start and self.estimated_finish:
|
||||||
user_stories = UserStory.objects.filter(
|
user_stories = UserStory.objects.filter(
|
||||||
created_date__gte=self.estimated_start,
|
created_date__gte=self.estimated_start,
|
||||||
created_date__lt=self.estimated_finish,
|
created_date__lt=self.estimated_finish,
|
||||||
project_id=self.project_id,
|
project_id=self.project_id,
|
||||||
client_requirement=True,
|
client_requirement=client_requirement,
|
||||||
team_requirement=False
|
team_requirement=team_requirement
|
||||||
)
|
)
|
||||||
client_increment = self._get_user_stories_points(user_stories)
|
return self._get_user_stories_points(user_stories)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def client_increment_points(self):
|
||||||
|
client_increment = self._get_points_increment(True, False)
|
||||||
shared_increment = {
|
shared_increment = {
|
||||||
key: value/2 for key, value in self.shared_increment_points.items()
|
key: value/2 for key, value in self.shared_increment_points.items()
|
||||||
}
|
}
|
||||||
|
@ -112,16 +109,7 @@ class Milestone(WatchedMixin):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def team_increment_points(self):
|
def team_increment_points(self):
|
||||||
user_stories = UserStory.objects.none()
|
team_increment = self._get_points_increment(False, True)
|
||||||
if self.estimated_start and self.estimated_finish:
|
|
||||||
user_stories = UserStory.objects.filter(
|
|
||||||
created_date__gte=self.estimated_start,
|
|
||||||
created_date__lt=self.estimated_finish,
|
|
||||||
project_id=self.project_id,
|
|
||||||
client_requirement=False,
|
|
||||||
team_requirement=True
|
|
||||||
)
|
|
||||||
team_increment = self._get_user_stories_points(user_stories)
|
|
||||||
shared_increment = {
|
shared_increment = {
|
||||||
key: value/2 for key, value in self.shared_increment_points.items()
|
key: value/2 for key, value in self.shared_increment_points.items()
|
||||||
}
|
}
|
||||||
|
@ -129,16 +117,7 @@ class Milestone(WatchedMixin):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def shared_increment_points(self):
|
def shared_increment_points(self):
|
||||||
user_stories = UserStory.objects.none()
|
return self._get_points_increment(True, True)
|
||||||
if self.estimated_start and self.estimated_finish:
|
|
||||||
user_stories = UserStory.objects.filter(
|
|
||||||
created_date__gte=self.estimated_start,
|
|
||||||
created_date__lt=self.estimated_finish,
|
|
||||||
project_id=self.project_id,
|
|
||||||
client_requirement=True,
|
|
||||||
team_requirement=True
|
|
||||||
)
|
|
||||||
return self._get_user_stories_points(user_stories)
|
|
||||||
|
|
||||||
def _get_watchers_by_role(self):
|
def _get_watchers_by_role(self):
|
||||||
return {
|
return {
|
||||||
|
|
|
@ -166,59 +166,36 @@ class Project(models.Model):
|
||||||
def _get_user_stories_points(self, user_stories):
|
def _get_user_stories_points(self, user_stories):
|
||||||
role_points = [us.role_points.all() for us in user_stories]
|
role_points = [us.role_points.all() for us in user_stories]
|
||||||
flat_role_points = itertools.chain(*role_points)
|
flat_role_points = itertools.chain(*role_points)
|
||||||
|
flat_role_dicts = map(lambda x: {x.role_id: x.points.value if x.points.value else 0}, flat_role_points)
|
||||||
|
return dict_sum(*flat_role_dicts)
|
||||||
|
|
||||||
result = {}
|
def _get_points_increment(self, client_requirement, team_requirement):
|
||||||
for role_point in flat_role_points:
|
|
||||||
if role_point.points.value is not None:
|
|
||||||
if role_point.role_id in result:
|
|
||||||
result[role_point.role_id] += float(role_point.points.value)
|
|
||||||
else:
|
|
||||||
result[role_point.role_id] = float(role_point.points.value)
|
|
||||||
|
|
||||||
return result
|
|
||||||
|
|
||||||
@property
|
|
||||||
def future_team_increment(self):
|
|
||||||
user_stories = UserStory.objects.none()
|
user_stories = UserStory.objects.none()
|
||||||
last_milestones = self.milestones.order_by('-estimated_finish')
|
last_milestones = self.milestones.order_by('-estimated_finish')
|
||||||
last_milestone = last_milestones[0] if last_milestones else None
|
last_milestone = last_milestones[0] if last_milestones else None
|
||||||
user_stories = UserStory.objects.filter(
|
user_stories = UserStory.objects.filter(
|
||||||
created_date__gte=last_milestone.estimated_finish if last_milestones else None,
|
created_date__gte=last_milestone.estimated_finish if last_milestones else None,
|
||||||
project_id=self.id,
|
project_id=self.id,
|
||||||
client_requirement=False,
|
client_requirement=client_requirement,
|
||||||
team_requirement=True
|
team_requirement=team_requirement
|
||||||
)
|
)
|
||||||
team_increment = self._get_user_stories_points(user_stories)
|
return self._get_user_stories_points(user_stories)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def future_team_increment(self):
|
||||||
|
team_increment = self._get_points_increment(False, True)
|
||||||
shared_increment = {key: value/2 for key, value in self.future_shared_increment.items()}
|
shared_increment = {key: value/2 for key, value in self.future_shared_increment.items()}
|
||||||
return dict_sum(team_increment, shared_increment)
|
return dict_sum(team_increment, shared_increment)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def future_client_increment(self):
|
def future_client_increment(self):
|
||||||
user_stories = UserStory.objects.none()
|
client_increment = self._get_points_increment(True, False)
|
||||||
last_milestones = self.milestones.order_by('-estimated_finish')
|
|
||||||
last_milestone = last_milestones[0] if last_milestones else None
|
|
||||||
user_stories = UserStory.objects.filter(
|
|
||||||
created_date__gte=last_milestone.estimated_finish if last_milestones else None,
|
|
||||||
project_id=self.id,
|
|
||||||
client_requirement=True,
|
|
||||||
team_requirement=False
|
|
||||||
)
|
|
||||||
client_increment = self._get_user_stories_points(user_stories)
|
|
||||||
shared_increment = {key: value/2 for key, value in self.future_shared_increment.items()}
|
shared_increment = {key: value/2 for key, value in self.future_shared_increment.items()}
|
||||||
return dict_sum(client_increment, shared_increment)
|
return dict_sum(client_increment, shared_increment)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def future_shared_increment(self):
|
def future_shared_increment(self):
|
||||||
user_stories = UserStory.objects.none()
|
return self._get_points_increment(True, True)
|
||||||
last_milestones = self.milestones.order_by('-estimated_finish')
|
|
||||||
last_milestone = last_milestones[0] if last_milestones else None
|
|
||||||
user_stories = UserStory.objects.filter(
|
|
||||||
created_date__gte=last_milestone.estimated_finish if last_milestones else None,
|
|
||||||
project_id=self.id,
|
|
||||||
client_requirement=True,
|
|
||||||
team_requirement=True
|
|
||||||
)
|
|
||||||
return self._get_user_stories_points(user_stories)
|
|
||||||
|
|
||||||
|
|
||||||
# User Stories common Models
|
# User Stories common Models
|
||||||
|
|
Loading…
Reference in New Issue