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

Commit

Permalink
Cleave tracker_scalar param to tracker_param
Browse files Browse the repository at this point in the history
  • Loading branch information
mgrauer committed Oct 1, 2015
1 parent b9c981c commit be8693f
Show file tree
Hide file tree
Showing 7 changed files with 228 additions and 9 deletions.
2 changes: 1 addition & 1 deletion modules/tracker/configs/module.ini
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ description = "Track scalar results over time"
category = "Visualization"
dependencies = api,scheduler
uuid = "3048a9fa-89ab-4e61-a55e-a49379fa6dc"
version = "1.2.0"
version = "1.2.2"
56 changes: 56 additions & 0 deletions modules/tracker/database/upgrade/1.2.2.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php
/*=========================================================================
Midas Server
Copyright Kitware SAS, 26 rue Louis Guérin, 69100 Villeurbanne, France.
All rights reserved.
For more information visit http://www.kitware.com/.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0.txt
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
=========================================================================*/

/**
* Upgrade the tracker module to version 1.2.2.
*/
class Tracker_Upgrade_1_2_2 extends MIDASUpgrade
{
/** Upgrade a MySQL database. */
public function mysql()
{
$this->db->query(
'CREATE TABLE IF NOT EXISTS `tracker_param` ('.
' `param_id` bigint(20) NOT NULL AUTO_INCREMENT,'.
' `scalar_id` bigint(20) NOT NULL,'.
' `param_name` varchar(255) NOT NULL,'.
' `param_type` enum(\'text\', \'numeric\') NOT NULL,'.
' `text_value` text,'.
' `numeric_value` double,'.
' PRIMARY KEY (`param_id`),'.
' KEY (`param_name`)'.
') DEFAULT CHARSET=utf8;');
}

/** Upgrade a PostgreSQL database. */
public function pgsql()
{
$this->db->query(
'CREATE TABLE IF NOT EXISTS "tracker_param" ('.
' "param_id" serial PRIMARY KEY,'.
' "scalar_id" bigint NOT NULL,'.
' "param_name" character varying(255) NOT NULL,'.
' "param_type" text CHECK (param_type in (\'text\', \'numeric\')),'.
' "text_value" text,'.
' "numeric_value" double precision);'
);
$this->db->query('CREATE INDEX "tracker_param_param_name_idx" on "tracker_param" ("param_name");');
}
}
49 changes: 49 additions & 0 deletions modules/tracker/models/base/ParamModelBase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php
/*=========================================================================
Midas Server
Copyright Kitware SAS, 26 rue Louis Guérin, 69100 Villeurbanne, France.
All rights reserved.
For more information visit http://www.kitware.com/.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0.txt
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
=========================================================================*/

/** Param base model class for the tracker module. */
abstract class Tracker_ParamModelBase extends Tracker_AppModel
{
/** Constructor. */
public function __construct()
{
parent::__construct();

$this->_name = 'tracker_param';
$this->_key = 'param_id';
$this->_mainData = array(
'param_id' => array('type' => MIDAS_DATA),
'scalar_id' => array('type' => MIDAS_DATA),
'param_name' => array('type' => MIDAS_DATA),
'param_type' => array('type' => MIDAS_DATA),
'text_value' => array('type' => MIDAS_DATA),
'numeric_value' => array('type' => MIDAS_DATA),
'scalar' => array(
'type' => MIDAS_MANY_TO_ONE,
'model' => 'Scalar',
'module' => $this->moduleName,
'parent_column' => 'scalar_id',
'child_column' => 'scalar_id',
),
);

$this->initialize();
}
}
27 changes: 19 additions & 8 deletions modules/tracker/models/base/ScalarModelBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ public function __construct()
'submission_id' => array('type' => MIDAS_DATA),
'official' => array('type' => MIDAS_DATA),
'build_results_url' => array('type' => MIDAS_DATA),
'params' => array('type' => MIDAS_DATA),
'extra_urls' => array('type' => MIDAS_DATA),
'branch' => array('type' => MIDAS_DATA),
'submit_time' => array('type' => MIDAS_DATA),
Expand All @@ -61,6 +60,13 @@ public function __construct()
'parent_column' => 'user_id',
'child_column' => 'user_id',
),
'params' => array(
'type' => MIDAS_ONE_TO_MANY,
'model' => 'Param',
'module' => $this->moduleName,
'parent_column' => 'scalar_id',
'child_column' => 'scalar_id',
),
);

$this->initialize();
Expand Down Expand Up @@ -155,12 +161,6 @@ public function addToTrend(
}
}

if (empty($params)) {
$params = null;
} elseif (is_array($params)) {
$params = json_encode($params);
}

if (empty($extraUrls)) {
$extraUrls = null;
} elseif (is_array($extraUrls)) {
Expand All @@ -180,10 +180,21 @@ public function addToTrend(
$scalarDao->setOfficial((int) $official);
$scalarDao->setBuildResultsUrl($buildResultsUrl);
$scalarDao->setBranch(trim($branch));
$scalarDao->setParams($params);
$scalarDao->setExtraUrls($extraUrls);
$this->save($scalarDao);

if (!empty($params) && is_array($params)) {
$paramModel = MidasLoader::loadModel('Param', $this->moduleName);
foreach ($params as $paramName => $paramValue) {
/** @var Tracker_ParamDao $paramDao */
$paramDao = MidasLoader::newDao('ParamDao', $this->moduleName);
$paramDao->setScalarId($scalarDao->getScalarId());
$paramDao->setParamName($paramName);
$paramDao->setParamValue($paramValue);
$paramModel->save($paramDao);
}
}

return $scalarDao;
}

Expand Down
76 changes: 76 additions & 0 deletions modules/tracker/models/dao/ParamDao.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php
/*=========================================================================
Midas Server
Copyright Kitware SAS, 26 rue Louis Guérin, 69100 Villeurbanne, France.
All rights reserved.
For more information visit http://www.kitware.com/.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0.txt
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
=========================================================================*/

/**
* Param DAO for the tracker module.
*
* @method int getParamId()
* @method void setParamId(int $paramId)
* @method int getScalarId()
* @method void setScalarId(int $scalarId)
* @method int getParamName()
* @method void setParamName(int $paramName)
* @method int getParamType()
* @method void setParamType(int $paramType)
* @method int getTextValue()
* @method void setTextValue(int $textValue)
* @method int getNumericValue()
* @method void setNumericValue(int $numericValue)
*/
class Tracker_ParamDao extends Tracker_AppDao
{
/** @var string */
public $_model = 'Param';

/** @var string */
public $_module = 'tracker';

/**
* Set the value of the param, which will be either stored as a numeric
* value if the paramValue can be coerced to numeric or else a text value.
*
* @param string $paramValue value to be set for this param
*/
public function setParamValue($paramValue)
{
if (!empty($paramValue) && is_numeric($paramValue)) {
$this->setParamType('numeric');
$this->setNumericValue(floatval($paramValue));
} else {
$this->setParamType('text');
$this->setTextValue($paramValue);
}
}

/**
* Get the value of the param, regardless of its type, returning either a
* numeric or a string.
*
* @return mixed value of the param
*/
public function getParamValue()
{
if ($this->getParamType() === 'numeric') {
return $this->getNumericValue();
} else {
return $this->getTextValue();
}
}
}
26 changes: 26 additions & 0 deletions modules/tracker/models/pdo/ParamModel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php
/*=========================================================================
Midas Server
Copyright Kitware SAS, 26 rue Louis Guérin, 69100 Villeurbanne, France.
All rights reserved.
For more information visit http://www.kitware.com/.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0.txt
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
=========================================================================*/

require_once BASE_PATH.'/modules/tracker/models/base/ParamModelBase.php';

/** Param model for the tracker module. */
class Tracker_ParamModel extends Tracker_ParamModelBase
{
}
1 change: 1 addition & 0 deletions modules/tracker/models/pdo/ScalarModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ public function getOtherValuesFromSubmission($scalarDao)
public function delete($scalarDao)
{
$this->database->getDB()->delete('tracker_scalar2item', 'scalar_id = '.$scalarDao->getKey());
$this->database->getDB()->delete('tracker_param', 'scalar_id = '.$scalarDao->getKey());

parent::delete($scalarDao);
}
Expand Down

0 comments on commit be8693f

Please sign in to comment.