• Модуль: tasks
  • Путь к файлу: ~/bitrix/modules/tasks/lib/scrum/utility/storypoints.php
  • Класс: BitrixTasksScrumUtilityStoryPoints
  • Вызов: StoryPoints::calculateStoryPointsStats
public function calculateStoryPointsStats(int $groupId, array $sprints): array
{
	$cacheKey = hash_init('sha256');
	foreach ($sprints as $sprint)
	{
		hash_update($cacheKey, $sprint->getId());
	}
	$cacheKey = hash_final($cacheKey);

	$cacheService = new CacheService($groupId, CacheService::TEAM_STATS, $cacheKey);

	if ($cacheService->init())
	{
		return $cacheService->getData();
	}

	$kanbanService = new KanbanService();
	$itemService = new ItemService();

	$listSumStoryPoints = [];
	foreach ($sprints as $sprint)
	{
		$completedTaskIds = $kanbanService->getFinishedTaskIdsInSprint($sprint->getId());

		$listStoryPoints = $itemService->getItemsStoryPointsBySourceId($completedTaskIds);

		$listSumStoryPoints[$sprint->getId()] = $this->calculateSumStoryPoints($listStoryPoints);
	}

	$stats = [
		'average' => 0,
		'maximum' => 0,
		'minimum' => 0,
	];
	if ($listSumStoryPoints)
	{
		$stats = [
			'average' => round(
				array_sum(array_values($listSumStoryPoints)) / count($listSumStoryPoints),
				1
			),
			'maximum' => max($listSumStoryPoints),
			'minimum' => min($listSumStoryPoints),
		];
	}

	$cacheService->start();
	$cacheService->end($stats);

	return $stats;
}