Rename 'trial' to 'experiment'

This commit is contained in:
Eike Foken
2011-09-08 01:37:32 +02:00
parent 33e116ed60
commit 7b329f4501
25 changed files with 341 additions and 277 deletions

View File

@@ -0,0 +1,145 @@
<?php defined('BASEPATH') || exit('No direct script access allowed');
/*
* Copyright (c) 2011 Karsten Heiken <karsten@disposed.de>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
/**
* Experiments are used to store different variations of the same project.
*
* @author Karsten Heiken <karsten@disposed.de>
*/
class Experiment extends CI_Model {
/**
* Create a new experiment.
*
* @param array $data The data of the new experiment
* @return boolean Was the insert successful?
*/
public function create($data) {
if (!isset($data['project_id'])) {
return false;
}
do { // generate unique hash
$data['id'] = random_hash();
} while ($this->db->where('id', $data['id'])->from('experiments')->count_all_results() > 0);
if ($this->db->insert('experiments', $data)) {
return $data['id'];
} else {
return false;
}
}
/**
* Deletes a experiment.
*
* @param string $experimentId The experiments ID to delete
* @return boolean Was the deletion successful?
*/
public function delete($experimentId) {
return $this->db->delete('experiments', array('id' => $experimentId));
}
/**
* Adds a parameter for a specific experiment.
*
* @param array $data
* @param string $experimentId
* @return boolean Returns TRUE if the parameter was added successfully.
*/
public function addParameter($data, $experimentId) {
if (!isset($data['parameter_id'])) {
return false;
}
$experiment = $this->get($experimentId);
$parameter = $this->db->get_where('parameters', array('id' => $data['parameter_id']))->row_array();
if (isset($experiment['id']) && $experiment['program_id'] == $parameter['program_id']) {
$data['experiment_id'] = $experimentId;
$this->db->insert('experiments_parameters', $data);
}
return $this->db->affected_rows() == 1 ? $experimentId : false;
}
/**
* Gets all parameters for the specified experiment.
*
* @param string $experimentId
* @return array
*/
public function getParameters($experimentId) {
$this->db->select('experiments_parameters.*, parameters.name AS `name`, parameters.type AS `type`');
$this->db->join('parameters', 'experiments_parameters.parameter_id = parameters.id', 'left');
$this->db->where('experiment_id', $experimentId);
$query = $this->db->get('experiments_parameters');
return $query->num_rows() > 0 ? $query->result_array() : false;
}
/**
* Gets an experiment by ID.
*
* @param string $experimentId The experiment to get
* @return array The experiment
*/
public function get($experimentId) {
$query = $this->db->get_where('experiments', array('id' => $experimentId));
return $query->row_array();
}
/**
* Gets an experiment by ID.
*
* @param string $experimentId The experiment to get
* @return array The experiment
*/
public function getById($experimentId) {
return $this->db->get_where('experiments', array('id' => $experimentId))->row_array();
}
/**
* Gets a experiment by its project ID.
*
* @param string $projectId
* @return array
*/
public function getByProjectId($projectId) {
$query = $this->db->get_where('experiments', array('project_id' => $projectId));
return $query->result_array();
}
/**
* Search for a specific experiment and return a list of possible results.
*
* @param string $needle The needle to look for in the haystack.
*/
public function search($project, $needle) {
$query = $this->db->where('project_id', $project)
->like('name', $needle)->get('experiments');
$results = $query->result_array();
return $results;
}
}

View File

@@ -1,4 +1,25 @@
<?php defined('BASEPATH') || exit("No direct script access allowed");
<?php defined('BASEPATH') || exit('No direct script access allowed');
/*
* Copyright (c) 2011 Eike Foken <kontakt@eikefoken.de>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
/**
* Group model.

View File

@@ -1,5 +1,4 @@
<?php
<?php defined('BASEPATH') || exit('No direct script access allowed');
/*
* Copyright (c) 2011 Karsten Heiken <karsten@disposed.de>
*
@@ -74,8 +73,8 @@ class Job extends CI_Model {
* @return array
*/
public function getRecent($projectId = '') {
$this->db->select('jobs.*, trials.project_id, trials.name');
$this->db->join('trials', 'jobs.trial_id = trials.id', 'left');
$this->db->select('jobs.*, experiments.project_id, experiments.name');
$this->db->join('experiments', 'jobs.experiment_id = experiments.id', 'left');
//$this->db->where('finished_at', 0);
if (!empty($projectId)) {
@@ -112,3 +111,6 @@ class Job extends CI_Model {
return $this->db->count_all_results() > 0 ? $query->row() : FALSE;
}
}
/* End of file job.php */
/* Location: ./application/controllers/job.php */

View File

@@ -1,4 +1,4 @@
<?php
<?php defined('BASEPATH') || exit('No direct script access allowed');
/*
* Copyright (c) 2011 Eike Foken <kontakt@eikefoken.de>
*
@@ -24,7 +24,7 @@
/**
* Model for parameters.
*
* Each program has many parameters used for configuration of trials.
* Each program has many parameters used for configuration of experiments.
*
* @author Eike Foken <kontakt@eikefoken.de>
*/

View File

@@ -1,4 +1,4 @@
<?php
<?php defined('BASEPATH') || exit('No direct script access allowed');
/*
* Copyright (c) 2011 Karsten Heiken <karsten@disposed.de>
*
@@ -22,7 +22,7 @@
*/
/**
* Programs are used to do the actual calculation of a trial.
* Programs are used to do the actual calculation of a experiment.
*
* @author Karsten Heiken <karsten@disposed.de>
* @author Eike Foken <kontakt@eikefoken.de>
@@ -135,3 +135,6 @@ class Program extends CI_Model {
return $query->result_array();
}
}
/* End of file program.php */
/* Location: ./application/models/program.php */

View File

@@ -1,5 +1,4 @@
<?php
<?php defined('BASEPATH') || exit('No direct script access allowed');
/*
* Copyright (c) 2011 Karsten Heiken <karsten@disposed.de>
*
@@ -28,10 +27,10 @@
* @author Karsten Heiken <karsten@disposed.de>
*/
class Project extends CI_Model {
/**
* Add a short and medium length description to one project.
*
*
* @param mixed $project
*/
private function _addShortName($project) {
@@ -39,10 +38,10 @@ class Project extends CI_Model {
$project['mediumname'] = character_limiter($project['name'], 35);
return $project;
}
/**
* Add a short and medium length description to an array of projects.
*
*
* @param mixed $project
*/
private function _addShortNames($project) {
@@ -205,4 +204,7 @@ class Project extends CI_Model {
return $this->db->delete('projects', array('id' => $projectId));
}
}
}
/* End of file project.php */
/* Location: ./application/models/project.php */

View File

@@ -1,5 +1,4 @@
<?php
<?php defined('BASEPATH') || exit('No direct script access allowed');
/*
* Copyright (c) 2011 Karsten Heiken <karsten@disposed.de>
*
@@ -85,11 +84,22 @@ class Server extends CI_Model {
get_where('servers', 'workload <= 2')->row_array();
}
/**
*
* @param string $secret
*/
public function getBySecret($secret) {
return $this->db->get_where('servers', array('secret' => $secret))->row();
}
public function getById($server_id) {
return $this->db->get_where('servers', array('id' => $server_id))->row();
/**
*
* @param string $serverId
*/
public function getById($serverId) {
return $this->db->get_where('servers', array('id' => $serverId))->row();
}
}
/* End of file server.php */
/* Location: ./application/models/server.php */

View File

@@ -1,147 +0,0 @@
<?php
/*
* Copyright (c) 2011 Karsten Heiken <karsten@disposed.de>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
/**
* Trials are used to store different variations of the same project.
*
* @author Karsten Heiken <karsten@disposed.de>
*/
class Trial extends CI_Model {
/**
* Create a new trial.
*
* @param array $data the data of the new trial
* @return bool was the insert successful
*/
public function create($data) {
if (!isset($data['project_id'])) {
return false;
}
do { // generate unique hash
$data['id'] = random_hash();
} while ($this->db->where('id', $data['id'])->from('trials')->count_all_results() > 0);
if ($this->db->insert('trials', $data)) {
return $data['id'];
} else {
return false;
}
}
/**
* Delete a trial.
* @param string the trial id to delete
* @return bool was the deletion successful
*/
public function delete($trial_id) {
return $this->db->delete('trials', array('id' => $trial_id));
}
/**
* Adds a parameter for a specific trial.
*
* @param array $data
* @param string $trialId
* @return boolean Returns TRUE if the parameter was added successfully.
*/
public function addParameter($data, $trialId) {
if (!isset($data['parameter_id'])) {
return false;
}
$trial = $this->get($trialId);
$parameter = $this->db->get_where('parameters', array('id' => $data['parameter_id']))->row_array();
if (isset($trial['id']) && $trial['program_id'] == $parameter['program_id']) {
$data['trial_id'] = $trialId;
$this->db->insert('trials_parameters', $data);
}
return $this->db->affected_rows() == 1 ? $trialId : false;
}
/**
* Gets all parameters for the specified trial.
*
* @param string $trialId
* @return array
*/
public function getParameters($trialId) {
$this->db->select('trials_parameters.*, parameters.name AS `name`, parameters.type AS `type`');
$this->db->join('parameters', 'trials_parameters.parameter_id = parameters.id', 'left');
$this->db->where('trial_id', $trialId);
$query = $this->db->get('trials_parameters');
return $query->num_rows() > 0 ? $query->result_array() : false;
}
/**
* Get a trial by id.
*
* @param string $trial_id The trial to get.
* @return array The trial
*/
public function get($trial_id) {
$query = $this->db->get_where('trials', array('id' => $trial_id));
return $query->row_array();
}
/**
* Gets a trial by ID.
*
* @param string $trialId The trial to get
* @return array The trial
*/
public function getById($trialId) {
return $this->db->get_where('trials', array('id' => $trialId))->row_array();
}
/**
* Get a trial by its project id.
*
* @param type $trial_id The trials to get.
* @return array The trial
*/
public function getByProjectId($project_id) {
$query = $this->db->get_where('trials', array('project_id' => $project_id));
return $query->result_array();
}
/**
* Search for a specific trial and return a list of possible results.
*
* @param string $needle The needle to look for in the haystack.
*/
public function search($project, $needle) {
$query = $this->db->where('project_id', $project)
->like('name', $needle)->get('trials');
$results = $query->result_array();
return $results;
}
}

View File

@@ -1,4 +1,25 @@
<?php defined('BASEPATH') || exit('No direct script access allowed');
/*
* Copyright (c) 2011 Eike Foken <kontakt@eikefoken.de>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
/**
* User model.