Christopher Johnson (WMDE) has uploaded a new change for review.
https://gerrit.wikimedia.org/r/170880
Change subject: removed global scope for stat functions
......................................................................
removed global scope for stat functions
Change-Id: If1b47a3a3b1fdb46e5b0554e42d69ed5c644e57b
---
M src/controller/BurndownController.php
M src/storage/SprintBuildStats.php
M src/util/BurndownDataDate.php
M src/view/BurndownDataView.php
M src/view/SprintReportBurndownView.php
5 files changed, 294 insertions(+), 180 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/phabricator/extensions/Sprint
refs/changes/80/170880/1
diff --git a/src/controller/BurndownController.php
b/src/controller/BurndownController.php
index 1893c0e..33e1a83 100644
--- a/src/controller/BurndownController.php
+++ b/src/controller/BurndownController.php
@@ -57,16 +57,6 @@
return $nav;
}
- public function getAuxFields($project, $viewer) {
- $field_list = PhabricatorCustomField::getObjectFields(
- $project,
- PhabricatorCustomField::ROLE_EDIT);
- $field_list->setViewer($viewer);
- $field_list->readFieldsFromStorage($project);
- $aux_fields = $field_list->getFields();
- return $aux_fields;
- }
-
protected function buildApplicationCrumbs() {
$crumbs = parent::buildApplicationCrumbs();
diff --git a/src/storage/SprintBuildStats.php b/src/storage/SprintBuildStats.php
index 070e8c0..c8ef178 100644
--- a/src/storage/SprintBuildStats.php
+++ b/src/storage/SprintBuildStats.php
@@ -7,41 +7,52 @@
private $task_statuses = array();
private $task_in_sprint = array();
- public function buildDateArray($start, $end) {
- // Build an array of dates between start and end
- $period = new DatePeriod(
- id(new DateTime("@" . $start))->setTime(0, 0),
- new DateInterval('P1D'), // 1 day interval
- id(new DateTime("@" . $end))->modify('+1 day')->setTime(0, 0));
+ public function buildDateArray($start, $end, $timezone) {
- $dates = array('before' => new BurndownDataDate('Start of Sprint'));
+ $period = new DatePeriod(
+ id(new DateTime("@" . $start, $timezone))->setTime(8, 0),
+ new DateInterval('P1D'), // 1 day interval
+ id(new DateTime("@" . $end, $timezone))->modify('+1 day')->setTime(17,
0));
+
+
+ $dates = array('before' =>$this->getBurndownDate('Before Sprint'));
+
foreach ($period as $day) {
- $dates[$day->format('D M j')] = new BurndownDataDate(
+ $dates[$day->format('D M j')] = $this->getBurndownDate(
$day->format('D M j'));
}
- $dates['after'] = new BurndownDataDate('After end of Sprint');
+ $dates['after'] = $this->getBurndownDate('After Sprint');
return $dates;
}
+ public function buildTimeSeries($start, $end, $timezone) {
+ $timeseries = array_keys($this->buildDateArray ($start, $end, $timezone));
+ return $timeseries;
+ }
+
+ public function getBurndownDate ($date) {
+ $sprint_date = id(new BurndownDataDate($date));
+ return $sprint_date;
+ }
// Now that we have the data for each day, we need to loop over and sum
// up the relevant columns
public function sumSprintStats($dates) {
$previous = null;
foreach ($dates as $current) {
- $current->tasks_total = $current->tasks_added_today;
- $current->points_total = $current->points_added_today;
- $current->tasks_remaining = $current->tasks_added_today;
- $current->points_remaining = $current->points_added_today;
+ $current->setTasksTotal($current->getTasksAddedToday());
+ $current->setPointsTotal($current->getPointsAddedToday());
+ $current->setTasksRemaining($current->getTasksAddedToday());
+ $current->setPointsRemaining($current->getPointsAddedToday());
if ($previous) {
- $current->tasks_total += $previous->tasks_total;
- $current->points_total += $previous->points_total;
- $current->tasks_remaining += $previous->tasks_remaining -
$current->tasks_closed_today;
- $current->points_remaining += $previous->points_remaining -
$current->points_closed_today;
+ $current->sumTasksTotal($current, $previous);
+ $current->sumPointsTotal($current, $previous);
+ $current->sumTasksRemaining($current, $previous);
+ $current->sumPointsRemaining ($current, $previous);
}
$previous = $current;
}
- return;
+ return $dates;
}
// Build arrays to store current point and closed status of tasks as we
@@ -71,10 +82,10 @@
$elapsed_business_days = 0;
foreach ($dates as $key => $date) {
if ($key == 'before') {
- $date->points_ideal_remaining = $date->points_total;
+ $date->setPointsIdealRemaining($date->getPointsTotal());
continue;
} else if ($key == 'after') {
- $date->points_ideal_remaining = 0;
+ $date->setPointsIdealRemaining (null);
continue;
}
@@ -83,8 +94,33 @@
$elapsed_business_days++;
}
- $date->points_ideal_remaining = round($date->points_total *
- (1 - ($elapsed_business_days / $total_business_days)), 1);
+ $date->setPointsIdealRemaining (round($date->getPointsTotal() *
+ (1 - ($elapsed_business_days / $total_business_days)), 1));
}
+ return $dates;
+ }
+
+ public function buildDataSet ($dates) {
+ $data = array(array(
+ pht('Total Points'),
+ pht('Remaining Points'),
+ pht('Ideal Points'),
+ pht('Points Today'),
+ ));
+
+ $future = false;
+ foreach ($dates as $key => $date) {
+ if ($key != 'before' AND $key != 'after') {
+ $future = new DateTime($date->getDate()) > id(new
DateTime())->setTime(0, 0);
+ }
+ $data[] = array(
+ $future ? null : $date->getPointsTotal(),
+ $future ? null : $date->getPointsRemaining(),
+ $date->getPointsIdealRemaining(),
+ $future ? null : $date->getPointsClosedToday(),
+ );
+
+ }
+ return $data;
}
}
diff --git a/src/util/BurndownDataDate.php b/src/util/BurndownDataDate.php
index ca7d7ee..4dcd249 100644
--- a/src/util/BurndownDataDate.php
+++ b/src/util/BurndownDataDate.php
@@ -7,31 +7,141 @@
class BurndownDataDate {
private $date;
-
- // Tasks and points added and closed today
- public $tasks_added_today = 0;
- public $tasks_closed_today = 0;
- public $points_added_today = 0;
- public $points_closed_today = 0;
+ private $tasks_added_today;
+ private $tasks_closed_today;
+ private $points_added_today;
+ private $points_closed_today;
// Totals over time
- public $tasks_total = 0;
- public $tasks_remaining = 0;
- public $points_total = 0;
- public $points_remaining = 0;
- public $points_ideal_remaining = 0;
+ private $tasks_total;
+ private $tasks_remaining;
+ private $points_total;
+ private $points_remaining;
+ private $points_ideal_remaining;
public function __construct($date) {
$this->date = $date;
-
return $this;
}
- /**
- * @return string|null
- */
+ // Tasks and points added and closed today
+ public function getTasksAddedToday () {
+ return $this->tasks_added_today;
+ }
+
+ public function getTasksClosedToday () {
+ return $this->tasks_closed_today;
+ }
+
+ public function setTasksAddedToday () {
+ return $this->tasks_added_today = $this->tasks_added_today +1;
+ }
+
+ public function setTasksRemovedToday ()
+ {
+ return $this->tasks_added_today = $this->tasks_added_today - 1;
+ }
+
+ public function setTasksClosedToday ()
+ {
+ return $this->tasks_closed_today = $this->tasks_closed_today + 1;
+ }
+
+ public function setTasksReopenedToday ()
+ {
+ return $this->tasks_closed_today = $this->tasks_closed_today - 1;
+ }
+
+ public function getPointsAddedToday () {
+ return $this->points_added_today;
+ }
+
+ public function getPointsClosedToday () {
+ return $this->points_closed_today;
+ }
+
+ public function setPointsAddedToday ($task_points) {
+ $this->points_added_today = $this->points_added_today + $task_points;
+ return $this->points_added_today;
+ }
+
+ public function setPointsRemovedToday ($task_points) {
+ return $this->points_added_today = $this->points_added_today -
$task_points;
+ }
+
+ public function setPointsClosedToday ($task_points) {
+ return $this->points_closed_today = $this->points_closed_today +
$task_points;
+ }
+
+ public function setPointsReopenedToday ($task_points) {
+ return $this->points_closed_today = $this->points_closed_today -
$task_points;
+ }
public function getDate() {
return $this->date;
}
-}
\ No newline at end of file
+
+ public function setTasksTotal($tasks_added_today) {
+ $this->tasks_total = $tasks_added_today;
+ return $this->tasks_total ;
+ }
+
+ public function getTasksTotal() {
+ return $this->tasks_total;
+ }
+
+ public function setTasksRemaining($tasks_added_today) {
+ $this->tasks_remaining = $tasks_added_today;
+ return $this->tasks_remaining;
+ }
+
+ public function getTasksRemaining() {
+ return $this->tasks_remaining;
+ }
+
+ public function setPointsTotal($points_added_today) {
+ $this->points_total = $points_added_today;
+ return $this->points_total;
+ }
+
+ public function getPointsTotal() {
+ return $this->points_total;
+ }
+
+ public function setPointsRemaining($points_added_today) {
+ $this->points_remaining = $points_added_today;
+ return $this->points_remaining;
+ }
+
+ public function getPointsRemaining() {
+ return $this->points_remaining;
+ }
+
+ public function getPointsIdealRemaining() {
+ return $this->points_ideal_remaining;
+ }
+
+ public function setPointsIdealRemaining($points_total) {
+ return $this->points_ideal_remaining = $points_total;
+ }
+
+ public function sumTasksTotal($current, $previous) {
+ $current->tasks_total += $previous->tasks_total;
+ return $current->tasks_total ;
+ }
+
+ public function sumPointsTotal($current, $previous) {
+ $current->points_total += $previous->points_total;
+ return $current->points_total;
+ }
+
+ public function sumTasksRemaining($current, $previous) {
+ $current->tasks_remaining = $current->tasks_remaining +
($previous->tasks_remaining - $current->tasks_closed_today);
+ return $current->tasks_remaining;
+ }
+
+ public function sumPointsRemaining($current, $previous) {
+ $current->points_remaining = $current->points_remaining +
($previous->points_remaining -$current->points_closed_today);
+ return $current->points_remaining;
+ }
+}
diff --git a/src/view/BurndownDataView.php b/src/view/BurndownDataView.php
index cb81d68..da9d944 100644
--- a/src/view/BurndownDataView.php
+++ b/src/view/BurndownDataView.php
@@ -6,9 +6,8 @@
final class BurndownDataView extends SprintView {
- private $dates;
- private $data;
- // Project associated with this burndown.
+ private $timeseries;
+ private $sprint_data;
private $project;
private $viewer;
private $tasks;
@@ -16,6 +15,7 @@
private $task_points = array();
private $task_statuses = array();
private $task_in_sprint = array();
+
public function setProject ($project) {
$this->project = $project;
@@ -25,6 +25,11 @@
public function setViewer ($viewer) {
$this->viewer = $viewer;
return $this;
+ }
+
+ public function setTimeZone ($viewer) {
+ $timezone = new DateTimeZone($viewer->getTimezoneIdentifier());
+ return $timezone;
}
public function render() {
@@ -42,51 +47,32 @@
$aux_fields = $query->getAuxFields();
$start = $query->getStartDate($aux_fields);
$end = $query->getEndDate($aux_fields);
+ $stats = id(new SprintBuildStats());
+ $dates = $stats->buildDateArray($start, $end,
$this->setTimeZone($this->viewer));
+ $this->timeseries = $stats->buildTimeSeries($start, $end,
$this->setTimeZone($this->viewer));
$tasks = $query->getTasks();
-
$query->checkNull($start, $end, $tasks);
-
$xactions = $query->getXactions($tasks);
-
- $stats = id(new SprintBuildStats());
- $this->dates = $stats->buildDateArray($start, $end);
-
$events = $query->getEvents($xactions, $tasks);
$this->xactions = mpull($xactions, null, 'getPHID');
$this->tasks = mpull($tasks, null, 'getPHID');
- $this->buildDailyData($events, $start, $end);
+ $dates = $this->buildDailyData($events, $start, $end, $dates);
-
- $stats->sumSprintStats($this->dates);
- $stats->computeIdealPoints($this->dates);
-
-
- $data = array(array(
- pht('Total Points'),
- pht('Remaining Points'),
- pht('Ideal Points'),
- pht('Points Today'),
- ));
-
- $future = false;
- foreach ($this->dates as $key => $date) {
- if ($key != 'before' AND $key != 'after') {
- $future = new DateTime($date->getDate()) > id(new
DateTime())->setTime(0, 0);
- }
- $data[] = array(
- $future ? null : $date->points_total,
- $future ? null : $date->points_remaining,
- $date->points_ideal_remaining,
- $future ? null : $date->points_closed_today,
- );
-
- }
+ $this->sprint_data = $this->setSprintData($dates);
+ $data = $stats->buildDataSet($this->sprint_data);
$data = $this->transposeArray($data);
return $data;
}
+
+ private function setSprintData($dates) {
+ $stats = id(new SprintBuildStats());
+ $dates = $stats->sumSprintStats($dates);
+ $sprint_data = $stats->computeIdealPoints($dates);
+ return $sprint_data;
+}
private function transposeArray($array) {
$transposed_array = array();
@@ -104,10 +90,9 @@
return $transposed_array;
}
- // Now loop through the events and build the data for each day
- private function buildDailyData($events, $start, $end) {
- foreach ($events as $event) {
+ private function buildDailyData($events, $start, $end, $dates) {
+ foreach ($events as $event) {
$xaction = $this->xactions[$event['transactionPHID']];
$xaction_date = $xaction->getDateCreated();
$task_phid = $xaction->getObjectPHID();
@@ -129,127 +114,123 @@
break;
case "task-add":
// A task was added to the sprint
- $operator = "+";
- $stat = "tasks_added_today";
- $pstat = "points_added_today";
- $this->changeTasksToday($date, $operator, $stat);
- $this->changePointsToday($date, $task_phid, $operator, $pstat);
- $this->changeTaskInSprint($task_phid, $operator);
+ $this->AddTasksToday($date, $dates);
+ $this->AddPointsToday($date, $task_phid, $dates);
+ $this->AddTaskInSprint($task_phid);
break;
case "task-remove":
// A task was removed from the sprint
- $operator = "-";
- $stat = "tasks_closed_today";
- $pstat = "points_closed_today";
- $this->changeTasksToday($date, $operator, $stat);
- $this->changePointsToday($date, $task_phid, $operator, $pstat);
- $this->changeTaskInSprint($task_phid, $operator);
+ $this->RemoveTasksToday($date, $dates);
+ $this->RemovePointsToday($date, $task_phid, $dates);
+ $this->RemoveTaskInSprint($task_phid);
break;
case "close":
// A task was closed, mark it as done
- $operator = "+";
- $stat = "tasks_closed_today";
- $pstat = "points_closed_today";
- $this->changeTasksToday($date, $operator, $stat);
- $this->changePointsToday($date, $task_phid, $operator, $pstat);
- $this->changeTaskStatuses($task_phid, $operator);
+ $this->CloseTasksToday($date, $dates);
+ $this->ClosePointsToday($date, $task_phid, $dates);
+ $this->CloseTaskStatus($task_phid);
break;
case "reopen":
// A task was reopened, subtract from done
- $operator = "-";
- $stat = "tasks_added_today";
- $pstat = "points_closed_today";
- $this->changeTasksToday($date, $operator, $stat);
- $this->changePointsToday($date, $task_phid, $operator, $pstat);
- $this->changeTaskStatuses($task_phid, $operator);
+ $this->ReopenedTasksToday($date, $dates);
+ $this->ReopenedPointsToday($date, $task_phid, $dates);
+ $this->OpenTaskStatus($task_phid);
break;
case "points":
// Points were changed
- $this->changePoints($date, $task_phid, $xaction);
+ $this->changePoints($date, $task_phid, $xaction, $dates);
break;
}
}
+ return $dates;
}
- private function changeTasksToday($date, $operator, $stat) {
- switch ($operator) {
- case "+":
- return
- $this->dates[$date]->$stat += 1;
- case "-":
- return
- $this->dates[$date]->$stat -= 1;
- default:
- return true;
- }
+ private function AddTasksToday($date, $dates) {
+ $dates[$date]->setTasksAddedToday();
+ return $dates;
}
- private function changePointsToday($date, $task_phid, $operator, $pstat) {
- if (isset($this->task_points[$task_phid]) == $task_phid) {
- switch ($operator) {
- case "+":
- return
- $this->dates[$date]->$pstat += $this->task_points[$task_phid];
- case "-":
- return
- $this->dates[$date]->$pstat -= $this->task_points[$task_phid];
- default:
- return true;
- }
- }
+ private function RemoveTasksToday($date, $dates) {
+ $dates[$date]->setTasksRemovedToday();
+ return $dates;
}
- private function changeTaskInSprint($task_phid, $operator) {
- switch ($operator) {
- case "+":
- return
- $this->task_in_sprint[$task_phid] = 1;
- case "-":
- return
- $this->task_in_sprint[$task_phid] = 0;
- default:
- return true;
- }
+ private function CloseTasksToday($date, $dates) {
+ $dates[$date]->setTasksClosedToday();
+ return $dates;
}
- private function changeTaskStatuses($task_phid, $operator) {
- switch ($operator) {
- case "+":
- return
- $this->task_statuses[$task_phid] = 'closed';
- case "-":
- return
- $this->task_statuses[$task_phid] = 'open';
- default:
- return true;
- }
+ private function ReopenedTasksToday($date, $dates) {
+ $dates[$date]->setTasksReopenedToday();
+ return $dates;
}
- private function changePoints($date, $task_phid, $xaction) {
+ private function AddPointsToday($date, $task_phid, $dates) {
+ $dates[$date]->setPointsAddedToday($this->task_points[$task_phid]);
+ return $dates;
+ }
+
+ private function RemovePointsToday($date, $task_phid, $dates) {
+ $dates[$date]->setPointsRemovedToday($this->task_points[$task_phid]);
+ return $dates;
+ }
+
+ private function ClosePointsToday($date, $task_phid, $dates) {
+ $dates[$date]->setPointsClosedToday($this->task_points[$task_phid]);
+ return $dates;
+ }
+
+ private function ReopenedPointsToday($date, $task_phid, $dates) {
+ $dates[$date]->setPointsReopenedToday($this->task_points[$task_phid]);
+ return $dates;
+ }
+
+ private function AddTaskInSprint($task_phid) {
+ $this->task_in_sprint[$task_phid] = 1;
+ return $this->task_in_sprint[$task_phid];
+ }
+
+ private function RemoveTaskInSprint($task_phid) {
+ $this->task_in_sprint[$task_phid] = 0;
+ return $this->task_in_sprint[$task_phid];
+ }
+
+ private function CloseTaskStatus($task_phid) {
+ $this->task_statuses[$task_phid] = 'closed';
+ return $this->task_statuses[$task_phid];
+ }
+
+ private function OpenTaskStatus($task_phid) {
+ $this->task_statuses[$task_phid] = 'open';
+ return $this->task_statuses[$task_phid];
+ }
+
+ private function changePoints($date, $task_phid, $xaction, $dates) {
$this->task_points[$task_phid] = $xaction->getNewValue();
// Only make changes if the task is in the sprint
if (isset($this->task_in_sprint[$task_phid])) {
// Adjust points for that day
- $this->dates[$date]->points_added_today +=
- $xaction->getNewValue() - $xaction->getOldValue();
+ $task_points = $xaction->getNewValue() - $xaction->getOldValue();
+ $dates[$date]->setPointsAddedToday($task_points);
// If the task is closed, adjust completed points as well
if (isset($this->task_statuses[$task_phid]) &&
$this->task_statuses[$task_phid] == 'closed') {
- $this->dates[$date]->points_closed_today +=
- $xaction->getNewValue() - $xaction->getOldValue();
+ $task_points = $xaction->getNewValue() - $xaction->getOldValue();
+ $dates[$date]->setPointsClosedToday($task_points);
}
}
- }
+ return $dates;
+ }
private function buildC3Chart() {
- $this->data = $this->buildChartDataSet();
- $totalpoints = $this->data[0];
- $remainingpoints = $this->data[1];
- $idealpoints = $this->data[2];
- $pointstoday = $this->data[3];
- $timeseries = array_keys($this->dates);
+ $data = $this->buildChartDataSet();
+ $totalpoints = $data[0];
+ $remainingpoints = $data[1];
+ $idealpoints = $data[2];
+ $pointstoday = $data[3];
+ $timeseries = $this->timeseries;
require_celerity_resource('d3','sprint');
require_celerity_resource('c3-css','sprint');
@@ -283,18 +264,16 @@
*/
private function buildBurnDownTable() {
$data = array();
- $stats = id(new SprintBuildStats());
- $stats->sumSprintStats($this->dates);
- $stats->computeIdealPoints($this->dates);
- foreach ($this->dates as $date) {
+
+ foreach ($this->sprint_data as $date) {
$data[] = array(
$date->getDate(),
- $date->tasks_total,
- $date->tasks_remaining,
- $date->points_total,
- $date->points_remaining,
- $date->points_ideal_remaining,
- $date->points_closed_today,
+ $date->getTasksTotal(),
+ $date->getTasksRemaining(),
+ $date->getPointsTotal(),
+ $date->getPointsRemaining(),
+ $date->getPointsIdealRemaining(),
+ $date->getPointsClosedToday(),
);
}
diff --git a/src/view/SprintReportBurndownView.php
b/src/view/SprintReportBurndownView.php
index 51b3415..b5e5738 100644
--- a/src/view/SprintReportBurndownView.php
+++ b/src/view/SprintReportBurndownView.php
@@ -3,7 +3,6 @@
final class SprintReportBurndownView extends SprintView {
private $request;
- private $timeperiod = array();
public function setUser (PhabricatorUser $user) {
$this->user = $user;
--
To view, visit https://gerrit.wikimedia.org/r/170880
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: If1b47a3a3b1fdb46e5b0554e42d69ed5c644e57b
Gerrit-PatchSet: 1
Gerrit-Project: phabricator/extensions/Sprint
Gerrit-Branch: master
Gerrit-Owner: Christopher Johnson (WMDE) <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits