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

Commit be8693f

Browse files
author
mgrauer
committed
Cleave tracker_scalar param to tracker_param
1 parent b9c981c commit be8693f

File tree

7 files changed

+228
-9
lines changed

7 files changed

+228
-9
lines changed

modules/tracker/configs/module.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ description = "Track scalar results over time"
66
category = "Visualization"
77
dependencies = api,scheduler
88
uuid = "3048a9fa-89ab-4e61-a55e-a49379fa6dc"
9-
version = "1.2.0"
9+
version = "1.2.2"
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
/*=========================================================================
3+
Midas Server
4+
Copyright Kitware SAS, 26 rue Louis Guérin, 69100 Villeurbanne, France.
5+
All rights reserved.
6+
For more information visit http://www.kitware.com/.
7+
8+
Licensed under the Apache License, Version 2.0 (the "License");
9+
you may not use this file except in compliance with the License.
10+
You may obtain a copy of the License at
11+
12+
http://www.apache.org/licenses/LICENSE-2.0.txt
13+
14+
Unless required by applicable law or agreed to in writing, software
15+
distributed under the License is distributed on an "AS IS" BASIS,
16+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
See the License for the specific language governing permissions and
18+
limitations under the License.
19+
=========================================================================*/
20+
21+
/**
22+
* Upgrade the tracker module to version 1.2.2.
23+
*/
24+
class Tracker_Upgrade_1_2_2 extends MIDASUpgrade
25+
{
26+
/** Upgrade a MySQL database. */
27+
public function mysql()
28+
{
29+
$this->db->query(
30+
'CREATE TABLE IF NOT EXISTS `tracker_param` ('.
31+
' `param_id` bigint(20) NOT NULL AUTO_INCREMENT,'.
32+
' `scalar_id` bigint(20) NOT NULL,'.
33+
' `param_name` varchar(255) NOT NULL,'.
34+
' `param_type` enum(\'text\', \'numeric\') NOT NULL,'.
35+
' `text_value` text,'.
36+
' `numeric_value` double,'.
37+
' PRIMARY KEY (`param_id`),'.
38+
' KEY (`param_name`)'.
39+
') DEFAULT CHARSET=utf8;');
40+
}
41+
42+
/** Upgrade a PostgreSQL database. */
43+
public function pgsql()
44+
{
45+
$this->db->query(
46+
'CREATE TABLE IF NOT EXISTS "tracker_param" ('.
47+
' "param_id" serial PRIMARY KEY,'.
48+
' "scalar_id" bigint NOT NULL,'.
49+
' "param_name" character varying(255) NOT NULL,'.
50+
' "param_type" text CHECK (param_type in (\'text\', \'numeric\')),'.
51+
' "text_value" text,'.
52+
' "numeric_value" double precision);'
53+
);
54+
$this->db->query('CREATE INDEX "tracker_param_param_name_idx" on "tracker_param" ("param_name");');
55+
}
56+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
/*=========================================================================
3+
Midas Server
4+
Copyright Kitware SAS, 26 rue Louis Guérin, 69100 Villeurbanne, France.
5+
All rights reserved.
6+
For more information visit http://www.kitware.com/.
7+
8+
Licensed under the Apache License, Version 2.0 (the "License");
9+
you may not use this file except in compliance with the License.
10+
You may obtain a copy of the License at
11+
12+
http://www.apache.org/licenses/LICENSE-2.0.txt
13+
14+
Unless required by applicable law or agreed to in writing, software
15+
distributed under the License is distributed on an "AS IS" BASIS,
16+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
See the License for the specific language governing permissions and
18+
limitations under the License.
19+
=========================================================================*/
20+
21+
/** Param base model class for the tracker module. */
22+
abstract class Tracker_ParamModelBase extends Tracker_AppModel
23+
{
24+
/** Constructor. */
25+
public function __construct()
26+
{
27+
parent::__construct();
28+
29+
$this->_name = 'tracker_param';
30+
$this->_key = 'param_id';
31+
$this->_mainData = array(
32+
'param_id' => array('type' => MIDAS_DATA),
33+
'scalar_id' => array('type' => MIDAS_DATA),
34+
'param_name' => array('type' => MIDAS_DATA),
35+
'param_type' => array('type' => MIDAS_DATA),
36+
'text_value' => array('type' => MIDAS_DATA),
37+
'numeric_value' => array('type' => MIDAS_DATA),
38+
'scalar' => array(
39+
'type' => MIDAS_MANY_TO_ONE,
40+
'model' => 'Scalar',
41+
'module' => $this->moduleName,
42+
'parent_column' => 'scalar_id',
43+
'child_column' => 'scalar_id',
44+
),
45+
);
46+
47+
$this->initialize();
48+
}
49+
}

modules/tracker/models/base/ScalarModelBase.php

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ public function __construct()
3535
'submission_id' => array('type' => MIDAS_DATA),
3636
'official' => array('type' => MIDAS_DATA),
3737
'build_results_url' => array('type' => MIDAS_DATA),
38-
'params' => array('type' => MIDAS_DATA),
3938
'extra_urls' => array('type' => MIDAS_DATA),
4039
'branch' => array('type' => MIDAS_DATA),
4140
'submit_time' => array('type' => MIDAS_DATA),
@@ -61,6 +60,13 @@ public function __construct()
6160
'parent_column' => 'user_id',
6261
'child_column' => 'user_id',
6362
),
63+
'params' => array(
64+
'type' => MIDAS_ONE_TO_MANY,
65+
'model' => 'Param',
66+
'module' => $this->moduleName,
67+
'parent_column' => 'scalar_id',
68+
'child_column' => 'scalar_id',
69+
),
6470
);
6571

6672
$this->initialize();
@@ -155,12 +161,6 @@ public function addToTrend(
155161
}
156162
}
157163

158-
if (empty($params)) {
159-
$params = null;
160-
} elseif (is_array($params)) {
161-
$params = json_encode($params);
162-
}
163-
164164
if (empty($extraUrls)) {
165165
$extraUrls = null;
166166
} elseif (is_array($extraUrls)) {
@@ -180,10 +180,21 @@ public function addToTrend(
180180
$scalarDao->setOfficial((int) $official);
181181
$scalarDao->setBuildResultsUrl($buildResultsUrl);
182182
$scalarDao->setBranch(trim($branch));
183-
$scalarDao->setParams($params);
184183
$scalarDao->setExtraUrls($extraUrls);
185184
$this->save($scalarDao);
186185

186+
if (!empty($params) && is_array($params)) {
187+
$paramModel = MidasLoader::loadModel('Param', $this->moduleName);
188+
foreach ($params as $paramName => $paramValue) {
189+
/** @var Tracker_ParamDao $paramDao */
190+
$paramDao = MidasLoader::newDao('ParamDao', $this->moduleName);
191+
$paramDao->setScalarId($scalarDao->getScalarId());
192+
$paramDao->setParamName($paramName);
193+
$paramDao->setParamValue($paramValue);
194+
$paramModel->save($paramDao);
195+
}
196+
}
197+
187198
return $scalarDao;
188199
}
189200

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
<?php
2+
/*=========================================================================
3+
Midas Server
4+
Copyright Kitware SAS, 26 rue Louis Guérin, 69100 Villeurbanne, France.
5+
All rights reserved.
6+
For more information visit http://www.kitware.com/.
7+
8+
Licensed under the Apache License, Version 2.0 (the "License");
9+
you may not use this file except in compliance with the License.
10+
You may obtain a copy of the License at
11+
12+
http://www.apache.org/licenses/LICENSE-2.0.txt
13+
14+
Unless required by applicable law or agreed to in writing, software
15+
distributed under the License is distributed on an "AS IS" BASIS,
16+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
See the License for the specific language governing permissions and
18+
limitations under the License.
19+
=========================================================================*/
20+
21+
/**
22+
* Param DAO for the tracker module.
23+
*
24+
* @method int getParamId()
25+
* @method void setParamId(int $paramId)
26+
* @method int getScalarId()
27+
* @method void setScalarId(int $scalarId)
28+
* @method int getParamName()
29+
* @method void setParamName(int $paramName)
30+
* @method int getParamType()
31+
* @method void setParamType(int $paramType)
32+
* @method int getTextValue()
33+
* @method void setTextValue(int $textValue)
34+
* @method int getNumericValue()
35+
* @method void setNumericValue(int $numericValue)
36+
*/
37+
class Tracker_ParamDao extends Tracker_AppDao
38+
{
39+
/** @var string */
40+
public $_model = 'Param';
41+
42+
/** @var string */
43+
public $_module = 'tracker';
44+
45+
/**
46+
* Set the value of the param, which will be either stored as a numeric
47+
* value if the paramValue can be coerced to numeric or else a text value.
48+
*
49+
* @param string $paramValue value to be set for this param
50+
*/
51+
public function setParamValue($paramValue)
52+
{
53+
if (!empty($paramValue) && is_numeric($paramValue)) {
54+
$this->setParamType('numeric');
55+
$this->setNumericValue(floatval($paramValue));
56+
} else {
57+
$this->setParamType('text');
58+
$this->setTextValue($paramValue);
59+
}
60+
}
61+
62+
/**
63+
* Get the value of the param, regardless of its type, returning either a
64+
* numeric or a string.
65+
*
66+
* @return mixed value of the param
67+
*/
68+
public function getParamValue()
69+
{
70+
if ($this->getParamType() === 'numeric') {
71+
return $this->getNumericValue();
72+
} else {
73+
return $this->getTextValue();
74+
}
75+
}
76+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
/*=========================================================================
3+
Midas Server
4+
Copyright Kitware SAS, 26 rue Louis Guérin, 69100 Villeurbanne, France.
5+
All rights reserved.
6+
For more information visit http://www.kitware.com/.
7+
8+
Licensed under the Apache License, Version 2.0 (the "License");
9+
you may not use this file except in compliance with the License.
10+
You may obtain a copy of the License at
11+
12+
http://www.apache.org/licenses/LICENSE-2.0.txt
13+
14+
Unless required by applicable law or agreed to in writing, software
15+
distributed under the License is distributed on an "AS IS" BASIS,
16+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
See the License for the specific language governing permissions and
18+
limitations under the License.
19+
=========================================================================*/
20+
21+
require_once BASE_PATH.'/modules/tracker/models/base/ParamModelBase.php';
22+
23+
/** Param model for the tracker module. */
24+
class Tracker_ParamModel extends Tracker_ParamModelBase
25+
{
26+
}

modules/tracker/models/pdo/ScalarModel.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ public function getOtherValuesFromSubmission($scalarDao)
130130
public function delete($scalarDao)
131131
{
132132
$this->database->getDB()->delete('tracker_scalar2item', 'scalar_id = '.$scalarDao->getKey());
133+
$this->database->getDB()->delete('tracker_param', 'scalar_id = '.$scalarDao->getKey());
133134

134135
parent::delete($scalarDao);
135136
}

0 commit comments

Comments
 (0)