reports/src/Task.php

87 lines
2.9 KiB
PHP

<?php
declare(strict_types=1);
namespace Nechaev\Reports;
use DateTime;
/**
* Class Task
* @package Nechaev\Reports
*/
class Task
{
private string $type; // Тип таски: bug, backend...
private string $key; // Номер задачи
private string $description; // Заголовок задачи
private string $assignee; // Исполнитель
private int $estimate; // Время оценки в секундах
private int $totalTime; // суммарное время потраченное на работу в секундах
private string $dateTakeInWork; // дата-время взятия в работу
private string $resolutionDate; // Дата-время завершения задачи
private int $leadTime; // System Lead Time в рабочих днях
private float $recast; // Переработка
private float $efficiency; // КПД
private int $countReview; // Количество заходов на ревью
private int $countTest; // Количество заходов на тест
public function __construct(
string $type,
string $key,
string $description,
string $assignee,
?int $estimate,
int $totalTime,
string $dateTakeInWork,
string $resolutionDate,
?int $countReview,
?int $countTest,
) {
$this->type = $type;
$this->key = $key;
$this->description = $description;
$this->assignee = $assignee;
$this->estimate = $estimate ?? 0;
$this->totalTime = $totalTime;
$this->dateTakeInWork = $dateTakeInWork;
$this->resolutionDate = $resolutionDate;
$this->countReview = $countReview ?? 0;
$this->countTest = $countTest ?? 0;
$this->leadTime = DateHelper::countWorkingDays($dateTakeInWork, $resolutionDate);
if ($this->leadTime == 0) {
$this->leadTime = 1;
}
$this->recast = ($this->estimate == 0) ? 0: round($totalTime/$estimate,4)-1;
// totalTime в секундах, leadTime в днях
$this->efficiency = round(($totalTime/3600)/$this->leadTime*8, 2);
}
public function toCSV(): string {
return implode(";", [
$this->type,
$this->key,
$this->description,
$this->assignee,
new DateTime($this->dateTakeInWork)->format('Y-m-d'),
new DateTime($this->resolutionDate)->format('Y-m-d'),
$this->leadTime,
round($this->estimate/3600,2), // переводим в часы
round($this->totalTime/3600, 2), // переводим в часы
$this->recast,
$this->efficiency,
$this->countReview,
$this->countTest,
]);
}
public function __toString(): string {
return $this->toCSV()."\n";
}
}