Skip to content
This repository has been archived by the owner on Sep 10, 2021. It is now read-only.

Commit

Permalink
Add units to tracker module scalarAdd API
Browse files Browse the repository at this point in the history
  • Loading branch information
mgrauer committed Aug 15, 2015
1 parent e9e2ab5 commit 26b1e0b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
9 changes: 8 additions & 1 deletion modules/tracker/controllers/components/ApiComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ public function itemAssociate($args)
* @param truthDatasetId (Optional) If this value pertains to a specific ground truth dataset, pass its id here
* @param silent (Optional) If set, do not perform threshold-based email notifications for this scalar
* @param unofficial (Optional) If passed, creates an unofficial scalar visible only to the user performing the submission
* @param unit (Optional) If passed, the unit of the scalar value that identifies which trend this point belongs to.
* @return The scalar DAO that was created
* @throws Exception
*/
Expand Down Expand Up @@ -243,14 +244,20 @@ public function scalarAdd($args)
$buildResultsUrl = isset($args['buildResultsUrl']) ? $args['buildResultsUrl'] : '';
$branch = isset($args['branch']) ? $args['branch'] : '';

if (isset($args['unit'])) {
$unit = $args['unit'];
} else {
$unit = null;
}
/** @var Tracker_TrendModel $trendModel */
$trendModel = MidasLoader::loadModel('Trend', 'tracker');
$trend = $trendModel->createIfNeeded(
$producer->getKey(),
$metricName,
$configItemId,
$testDatasetId,
$truthDatasetId
$truthDatasetId,
$unit
);

$submitTime = strtotime($args['submitTime']);
Expand Down
13 changes: 9 additions & 4 deletions modules/tracker/models/base/TrendModelBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,10 @@ public function __construct()
* @param null|int $configItemId configuration item id
* @param null|int $testDatasetId test dataset item id
* @param null|int $truthDatasetId truth dataset item id
* @param null|string $unit scalar value unit
* @return false|Tracker_TrendDao trend DAO or false if none exists
*/
abstract public function getMatch($producerId, $metricName, $configItemId, $testDatasetId, $truthDatasetId);
abstract public function getMatch($producerId, $metricName, $configItemId, $testDatasetId, $truthDatasetId, $unit);

/**
* Return the trend DAOs that match the given associative array of database columns and values.
Expand Down Expand Up @@ -136,19 +137,23 @@ public function save($trendDao)
* @param null|int $configItemId configuration item id
* @param null|int $testDatasetId test dataset item id
* @param null|int $truthDatasetId truth dataset item id
* @param null|string $unit scalar value unit
* @return Tracker_TrendDao trend DAO
*/
public function createIfNeeded($producerId, $metricName, $configItemId, $testDatasetId, $truthDatasetId)
public function createIfNeeded($producerId, $metricName, $configItemId, $testDatasetId, $truthDatasetId, $unit)
{
$trendDao = $this->getMatch($producerId, $metricName, $configItemId, $testDatasetId, $truthDatasetId);
$trendDao = $this->getMatch($producerId, $metricName, $configItemId, $testDatasetId, $truthDatasetId, $unit);

if ($trendDao === false) {
/** @var Tracker_TrendDao $trendDao */
$trendDao = MidasLoader::newDao('TrendDao', $this->moduleName);
$trendDao->setProducerId($producerId);
$trendDao->setMetricName($metricName);
$trendDao->setDisplayName($metricName);
$trendDao->setUnit('');
if (is_null($unit)) {
$unit = '';
}
$trendDao->setUnit($unit);

if (!is_null($configItemId)) {
$trendDao->setConfigItemId($configItemId);
Expand Down
7 changes: 6 additions & 1 deletion modules/tracker/models/pdo/TrendModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ class Tracker_TrendModel extends Tracker_TrendModelBase
* @param null|int $configItemId configuration item id
* @param null|int $testDatasetId test dataset item id
* @param null|int $truthDatasetId truth dataset item id
* @param null|string $unit scalar value unit
* @return false|Tracker_TrendDao trend DAO or false if none exists
*/
public function getMatch($producerId, $metricName, $configItemId, $testDatasetId, $truthDatasetId)
public function getMatch($producerId, $metricName, $configItemId, $testDatasetId, $truthDatasetId, $unit)
{
$sql = $this->database->select()->setIntegrityCheck(false)->where('producer_id = ?', $producerId)->where(
'metric_name = ?',
Expand All @@ -58,6 +59,10 @@ public function getMatch($producerId, $metricName, $configItemId, $testDatasetId
$sql->where('test_dataset_id = ?', $testDatasetId);
}

if (!is_null($unit) && ($unit !== '')) {
$sql->where('unit = ?', $unit);
}

return $this->initDao('Trend', $this->database->fetchRow($sql), $this->moduleName);
}

Expand Down

0 comments on commit 26b1e0b

Please sign in to comment.