mirror of
https://we.phorge.it/source/phorge.git
synced 2025-03-29 04:28:12 +01:00
Summary: Depends on D19119. Ref T13083. This is probably still very buggy, but I'm planning to build support tools to make debugging facts easier shortly. This generates a large number of datapoints, at least, and can render some charts which aren't all completely broken in an obvious way. Test Plan: Ran `bin/fact analyze --all`, got some charts with lines that went up and down in the web UI. Subscribers: yelirekim Maniphest Tasks: T13083 Differential Revision: https://secure.phabricator.com/D19120
97 lines
2.2 KiB
PHP
97 lines
2.2 KiB
PHP
<?php
|
|
|
|
final class PhabricatorFactChartController extends PhabricatorFactController {
|
|
|
|
public function handleRequest(AphrontRequest $request) {
|
|
$viewer = $request->getViewer();
|
|
|
|
$series = $request->getStr('y1');
|
|
|
|
$facts = PhabricatorFact::getAllFacts();
|
|
$fact = idx($facts, $series);
|
|
|
|
if (!$fact) {
|
|
return new Aphront404Response();
|
|
}
|
|
|
|
$key_id = id(new PhabricatorFactKeyDimension())
|
|
->newDimensionID($fact->getKey());
|
|
if (!$key_id) {
|
|
return new Aphront404Response();
|
|
}
|
|
|
|
$table = $fact->newDatapoint();
|
|
$conn_r = $table->establishConnection('r');
|
|
$table_name = $table->getTableName();
|
|
|
|
$data = queryfx_all(
|
|
$conn_r,
|
|
'SELECT value, epoch FROM %T WHERE keyID = %d ORDER BY epoch ASC',
|
|
$table_name,
|
|
$key_id);
|
|
|
|
$points = array();
|
|
$sum = 0;
|
|
foreach ($data as $key => $row) {
|
|
$sum += (int)$row['value'];
|
|
$points[(int)$row['epoch']] = $sum;
|
|
}
|
|
|
|
if (!$points) {
|
|
throw new Exception('No data to show!');
|
|
}
|
|
|
|
// Limit amount of data passed to browser.
|
|
$count = count($points);
|
|
$limit = 2000;
|
|
if ($count > $limit) {
|
|
$i = 0;
|
|
$every = ceil($count / $limit);
|
|
foreach ($points as $epoch => $sum) {
|
|
$i++;
|
|
if ($i % $every && $i != $count) {
|
|
unset($points[$epoch]);
|
|
}
|
|
}
|
|
}
|
|
|
|
$x = array_keys($points);
|
|
$y = array_values($points);
|
|
|
|
$id = celerity_generate_unique_node_id();
|
|
$chart = phutil_tag(
|
|
'div',
|
|
array(
|
|
'id' => $id,
|
|
'style' => 'background: #ffffff; '.
|
|
'height: 480px; ',
|
|
),
|
|
'');
|
|
|
|
require_celerity_resource('d3');
|
|
|
|
Javelin::initBehavior('line-chart', array(
|
|
'hardpoint' => $id,
|
|
'x' => array($x),
|
|
'y' => array($y),
|
|
'xformat' => 'epoch',
|
|
'colors' => array('#0000ff'),
|
|
));
|
|
|
|
$box = id(new PHUIObjectBoxView())
|
|
->setHeaderText(pht('Count of %s', $fact->getName()))
|
|
->appendChild($chart);
|
|
|
|
$crumbs = $this->buildApplicationCrumbs();
|
|
$crumbs->addTextCrumb(pht('Chart'));
|
|
|
|
$title = pht('Chart');
|
|
|
|
return $this->newPage()
|
|
->setTitle($title)
|
|
->setCrumbs($crumbs)
|
|
->appendChild($box);
|
|
|
|
}
|
|
|
|
}
|