Skip to content

Commit

Permalink
method tree page was improved
Browse files Browse the repository at this point in the history
  • Loading branch information
shagtv committed Feb 21, 2019
1 parent 7217ff8 commit e32cb00
Show file tree
Hide file tree
Showing 12 changed files with 656 additions and 308 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@

There are next changes:

## 1.1.3

There are next changes:

- method tree page was improved: graphs are selectable now
- class FileSource was covered by tests

## 1.1.2

There are next changes:
Expand Down
32 changes: 32 additions & 0 deletions src/Badoo/LiveProfilerUI/DateGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,36 @@ public static function getDatesArray(string $date, int $interval_in_days, int $c
}
return $dates;
}

/**
* @param string $date_from
* @param string $date_to
* @return array
*/
public static function getDatesByRange(string $date_from, string $date_to) : array
{
if (strtotime($date_from) > strtotime($date_to)) {
return [];
}

try {
$period = new \DatePeriod(
new \DateTime($date_from),
new \DateInterval('P1D'),
new \DateTime($date_to)
);
} catch (\Exception $e) {
return [];
}

$dates = [];
foreach ($period as $Date) {
/** @var \DateTime $Date */
$date = $Date->format('Y-m-d');
$dates[$date] = $date;
}
$dates[$date_to] = $date_to;

return array_values($dates);
}
}
44 changes: 33 additions & 11 deletions src/Badoo/LiveProfilerUI/Pages/ProfileMethodTreePage.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,20 @@ protected function cleanData() : bool
$this->data['label'] = isset($this->data['label']) ? trim($this->data['label']) : '';
$this->data['snapshot_id'] = isset($this->data['snapshot_id']) ? (int)$this->data['snapshot_id'] : 0;
$this->data['stat_interval'] = isset($this->data['stat_interval']) ? (int)$this->data['stat_interval'] : 0;
$this->data['date1'] = isset($this->data['date1']) ? trim($this->data['date1']) : '';
$this->data['date2'] = isset($this->data['date2']) ? trim($this->data['date2']) : '';
$this->data['method_id'] = isset($this->data['method_id']) ? (int)$this->data['method_id'] : 0;

if (!$this->data['snapshot_id'] && (!$this->data['app'] || !$this->data['label'])) {
throw new \InvalidArgumentException('Empty snapshot_id, app and label');
}

if (!\in_array($this->data['stat_interval'], self::$graph_intervals, true)) {
$this->data['stat_interval'] = self::STAT_INTERVAL_WEEK;
$this->data['stat_interval'] = self::STAT_INTERVAL_MONTH;
}

if ($this->data['date1'] && $this->data['date2']) {
$this->data['stat_interval'] = 0;
}

return true;
Expand All @@ -98,19 +104,30 @@ public function getTemplateData() : array
throw new \InvalidArgumentException('Can\'t get snapshot');
}

if (!\in_array($this->data['stat_interval'], self::$graph_intervals, true)) {
$this->data['stat_interval'] = self::STAT_INTERVAL_WEEK;
}

if (!$this->data['method_id']) {
$this->data['method_id'] = $this->getMainMethodId();
}

$dates = \Badoo\LiveProfilerUI\DateGenerator::getDatesArray(
$Snapshot->getDate(),
$this->data['stat_interval'],
$this->data['stat_interval']
);
$methods = $this->Method->getListByIds([$this->data['method_id']]);
$method_name = '?';
if ($methods) {
$method_name = $methods[$this->data['method_id']];
}

if ($this->data['date1'] && $this->data['date2']) {
$dates = \Badoo\LiveProfilerUI\DateGenerator::getDatesByRange(
$this->data['date1'],
$this->data['date2']
);
} else {
$dates = \Badoo\LiveProfilerUI\DateGenerator::getDatesArray(
$Snapshot->getDate(),
$this->data['stat_interval'],
$this->data['stat_interval']
);
$this->data['date1'] = current($dates);
$this->data['date2'] = end($dates);
}

$date_to_snapshot_map = $this->Snapshot->getSnapshotIdsByDates(
$dates,
Expand All @@ -120,23 +137,28 @@ public function getTemplateData() : array

$view_data = [
'snapshot' => $Snapshot,
'method_id' => $this->data['method_id'],
'method_name' => $method_name,
'method_dates' => $dates,
'stat_intervals' => $this->getIntervalsFormData($link_base),
'date1' => $this->data['date1'],
'date2' => $this->data['date2'],
];

$common_block_data = [
'link_base' => $link_base,
'fields' => $this->FieldList->getAllFieldsWithVariations(),
'field_descriptions' => $this->FieldList->getFieldDescriptions(),
'stat_interval' => $this->data['stat_interval'],
'date1' => $this->data['date1'],
'date2' => $this->data['date2'],
];

$method_data = $this->getMethodDataWithHistory($date_to_snapshot_map, $this->data['method_id']);
if ($method_data) {
/** @var \Badoo\LiveProfilerUI\Entity\MethodData $MainMethod */
$MainMethod = current($method_data);
$view_data['available_graphs'] = $this->getGraphsData($MainMethod);
$view_data['method_name'] = $MainMethod->getMethodName();
$view_data['method_data'] = $this->View->fetchFile(
'profiler_result_view_part',
$common_block_data + ['data' => $method_data, 'hide_lines_column' => true],
Expand Down
26 changes: 16 additions & 10 deletions src/Badoo/LiveProfilerUI/Pages/SnapshotsDiffPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,20 +81,26 @@ public function getTemplateData() : array

$Snapshot1 = false;
if ($this->data['date1']) {
$Snapshot1 = $this->Snapshot->getOneByAppAndLabelAndDate(
$this->data['app'],
$this->data['label'],
$this->data['date1']
);
try {
$Snapshot1 = $this->Snapshot->getOneByAppAndLabelAndDate(
$this->data['app'],
$this->data['label'],
$this->data['date1']
);
} catch (\InvalidArgumentException $Ex) {
}
}

$Snapshot2 = false;
if ($this->data['date2']) {
$Snapshot2 = $this->Snapshot->getOneByAppAndLabelAndDate(
$this->data['app'],
$this->data['label'],
$this->data['date2']
);
try {
$Snapshot2 = $this->Snapshot->getOneByAppAndLabelAndDate(
$this->data['app'],
$this->data['label'],
$this->data['date2']
);
} catch (\InvalidArgumentException $Ex) {
}
}

$diff = false;
Expand Down
Loading

0 comments on commit e32cb00

Please sign in to comment.