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

Commit 26b1e0b

Browse files
author
mgrauer
committed
Add units to tracker module scalarAdd API
1 parent e9e2ab5 commit 26b1e0b

File tree

3 files changed

+23
-6
lines changed

3 files changed

+23
-6
lines changed

modules/tracker/controllers/components/ApiComponent.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ public function itemAssociate($args)
127127
* @param truthDatasetId (Optional) If this value pertains to a specific ground truth dataset, pass its id here
128128
* @param silent (Optional) If set, do not perform threshold-based email notifications for this scalar
129129
* @param unofficial (Optional) If passed, creates an unofficial scalar visible only to the user performing the submission
130+
* @param unit (Optional) If passed, the unit of the scalar value that identifies which trend this point belongs to.
130131
* @return The scalar DAO that was created
131132
* @throws Exception
132133
*/
@@ -243,14 +244,20 @@ public function scalarAdd($args)
243244
$buildResultsUrl = isset($args['buildResultsUrl']) ? $args['buildResultsUrl'] : '';
244245
$branch = isset($args['branch']) ? $args['branch'] : '';
245246

247+
if (isset($args['unit'])) {
248+
$unit = $args['unit'];
249+
} else {
250+
$unit = null;
251+
}
246252
/** @var Tracker_TrendModel $trendModel */
247253
$trendModel = MidasLoader::loadModel('Trend', 'tracker');
248254
$trend = $trendModel->createIfNeeded(
249255
$producer->getKey(),
250256
$metricName,
251257
$configItemId,
252258
$testDatasetId,
253-
$truthDatasetId
259+
$truthDatasetId,
260+
$unit
254261
);
255262

256263
$submitTime = strtotime($args['submitTime']);

modules/tracker/models/base/TrendModelBase.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,10 @@ public function __construct()
8282
* @param null|int $configItemId configuration item id
8383
* @param null|int $testDatasetId test dataset item id
8484
* @param null|int $truthDatasetId truth dataset item id
85+
* @param null|string $unit scalar value unit
8586
* @return false|Tracker_TrendDao trend DAO or false if none exists
8687
*/
87-
abstract public function getMatch($producerId, $metricName, $configItemId, $testDatasetId, $truthDatasetId);
88+
abstract public function getMatch($producerId, $metricName, $configItemId, $testDatasetId, $truthDatasetId, $unit);
8889

8990
/**
9091
* Return the trend DAOs that match the given associative array of database columns and values.
@@ -136,19 +137,23 @@ public function save($trendDao)
136137
* @param null|int $configItemId configuration item id
137138
* @param null|int $testDatasetId test dataset item id
138139
* @param null|int $truthDatasetId truth dataset item id
140+
* @param null|string $unit scalar value unit
139141
* @return Tracker_TrendDao trend DAO
140142
*/
141-
public function createIfNeeded($producerId, $metricName, $configItemId, $testDatasetId, $truthDatasetId)
143+
public function createIfNeeded($producerId, $metricName, $configItemId, $testDatasetId, $truthDatasetId, $unit)
142144
{
143-
$trendDao = $this->getMatch($producerId, $metricName, $configItemId, $testDatasetId, $truthDatasetId);
145+
$trendDao = $this->getMatch($producerId, $metricName, $configItemId, $testDatasetId, $truthDatasetId, $unit);
144146

145147
if ($trendDao === false) {
146148
/** @var Tracker_TrendDao $trendDao */
147149
$trendDao = MidasLoader::newDao('TrendDao', $this->moduleName);
148150
$trendDao->setProducerId($producerId);
149151
$trendDao->setMetricName($metricName);
150152
$trendDao->setDisplayName($metricName);
151-
$trendDao->setUnit('');
153+
if (is_null($unit)) {
154+
$unit = '';
155+
}
156+
$trendDao->setUnit($unit);
152157

153158
if (!is_null($configItemId)) {
154159
$trendDao->setConfigItemId($configItemId);

modules/tracker/models/pdo/TrendModel.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,10 @@ class Tracker_TrendModel extends Tracker_TrendModelBase
3131
* @param null|int $configItemId configuration item id
3232
* @param null|int $testDatasetId test dataset item id
3333
* @param null|int $truthDatasetId truth dataset item id
34+
* @param null|string $unit scalar value unit
3435
* @return false|Tracker_TrendDao trend DAO or false if none exists
3536
*/
36-
public function getMatch($producerId, $metricName, $configItemId, $testDatasetId, $truthDatasetId)
37+
public function getMatch($producerId, $metricName, $configItemId, $testDatasetId, $truthDatasetId, $unit)
3738
{
3839
$sql = $this->database->select()->setIntegrityCheck(false)->where('producer_id = ?', $producerId)->where(
3940
'metric_name = ?',
@@ -58,6 +59,10 @@ public function getMatch($producerId, $metricName, $configItemId, $testDatasetId
5859
$sql->where('test_dataset_id = ?', $testDatasetId);
5960
}
6061

62+
if (!is_null($unit) && ($unit !== '')) {
63+
$sql->where('unit = ?', $unit);
64+
}
65+
6166
return $this->initDao('Trend', $this->database->fetchRow($sql), $this->moduleName);
6267
}
6368

0 commit comments

Comments
 (0)