Ejemplo n.º 1
0
 private function data_qualities_upload()
 {
     // get correct description
     if (isset($_FILES['description']) == false || check_uploaded_file($_FILES['description']) == false) {
         $this->returnError(382, $this->version);
         return;
     }
     // get description from string upload
     $description = $_FILES['description'];
     if (validateXml($description['tmp_name'], xsd('openml.data.qualities', $this->controller, $this->version), $xmlErrors) == false) {
         $this->returnError(383, $this->version, $this->openmlGeneralErrorCode, $xmlErrors);
         return;
     }
     if (!$this->ion_auth->in_group($this->groups_upload_rights, $this->user_id)) {
         $this->returnError(104, $this->version);
         return;
     }
     $xml = simplexml_load_file($description['tmp_name']);
     $did = '' . $xml->children('oml', true)->{'did'};
     $dataset = $this->Dataset->getById($did);
     if ($dataset == false) {
         $this->returnError(384, $this->version);
         return;
     }
     // prepare array for updating data object
     $data = array('processed' => now());
     if ($xml->children('oml', true)->{'error'}) {
         $data['error'] = "true";
     }
     $this->Dataset->update($did, $data);
     $all_qualities = $this->Quality->getColumnWhere('name', '`type` = "DataQuality"');
     $qualities = $this->Data_quality->getAssociativeArray('quality', 'value', '`data` = "' . $dataset->did . '"');
     // check and collect the qualities
     $newQualities = array();
     foreach ($xml->children('oml', true)->{'quality'} as $q) {
         $quality = xml2object($q, true);
         /*if( array_key_exists( $quality->name, $newQualities ) ) { // quality calculated twice
             $this->returnError( 385, $this->openmlGeneralErrorCode, $quality->name );
             return;
           } elseif( $qualities != false && array_key_exists( $quality->name, $qualities ) ) { // prior to this run, we already got this quality
             if( abs( $qualities[$quality->name] - $quality->value ) > $this->config->item('double_epsilon') ) {
               $this->returnError( 386, $this->openmlGeneralErrorCode, $quality->name );
               return;
             }
           } else*/
         if (is_array($all_qualities) == false || in_array($quality->name, $all_qualities) == false) {
             $this->returnError(387, $this->version, $this->openmlGeneralErrorCode, $quality->name);
             return;
         } else {
             $newQualities[] = $quality;
         }
         if (property_exists($quality, 'interval_start')) {
         } else {
         }
     }
     if (count($newQualities) == 0) {
         $this->returnError(388, $this->version);
         return;
     }
     $success = true;
     $this->db->trans_start();
     foreach ($newQualities as $index => $quality) {
         if (property_exists($quality, 'interval_start')) {
             $data = array('data' => $dataset->did, 'quality' => $quality->name, 'interval_start' => $quality->interval_start, 'interval_end' => $quality->interval_end, 'value' => $quality->value);
             $this->Data_quality_interval->insert_ignore($data);
         } else {
             $data = array('data' => $dataset->did, 'quality' => $quality->name, 'value' => $quality->value);
             $this->Data_quality->insert_ignore($data);
         }
     }
     $this->db->trans_complete();
     // add to elastic search index.
     $this->elasticsearch->index('data', $dataset->did);
     if ($success) {
         $this->xmlContents('data-qualities-upload', $this->version, array('did' => $dataset->did));
     } else {
         $this->returnError(389, $this->version);
         return;
     }
 }
Ejemplo n.º 2
0
 public function task_upload()
 {
     if (isset($_FILES['description']) == false || $_FILES['source']['error'] > 0) {
         $this->returnError(530, $this->version);
         return;
     }
     $descriptionFile = $_FILES['description']['tmp_name'];
     $xsd = xsd('openml.task.upload', $this->controller, $this->version);
     if (!$xsd) {
         $this->returnError(531, $this->version, $this->openmlGeneralErrorCode);
         return;
     }
     if (validateXml($descriptionFile, $xsd, $xmlErrors) == false) {
         // TODO: do later!
         $this->returnError(532, $this->version, $this->openmlGeneralErrorCode, $xmlErrors);
         return;
     }
     if (!$this->ion_auth->in_group($this->groups_upload_rights, $this->user_id)) {
         $this->returnError(104, $this->version);
         return;
     }
     $xml = simplexml_load_file($descriptionFile);
     $task_type_id = $xml->children('oml', true)->{'task_type_id'};
     $inputs = array();
     foreach ($xml->children('oml', true) as $input) {
         if ($input->getName() == 'input') {
             $name = $input->attributes() . '';
             $inputs[$name] = $input . '';
         }
     }
     $search = $this->Task->search($task_type_id, $inputs);
     if ($search) {
         $task_ids = array();
         foreach ($search as $s) {
             $task_ids[] = $s->task_id;
         }
         $this->returnError(533, $this->version, 'matched id(s): [' . implode(',', $task_ids) . ']');
         return;
     }
     // THE INSERTION
     $task = array('ttid' => '' . $task_type_id, 'creator' => $this->user_id, 'creation_date' => now());
     $id = $this->Task->insert($task);
     // TODO: sanity check on input data!
     if ($id == false) {
         $this->returnError(534, $this->version);
         return;
     }
     foreach ($inputs as $name => $value) {
         $task_input = array('task_id' => $id, 'input' => $name, 'value' => $value);
         $this->Task_inputs->insert($task_input);
     }
     $this->xmlContents('task-upload', $this->version, array('id' => $id));
 }
Ejemplo n.º 3
0
 private function _openml_run_evaluate()
 {
     // check uploaded file
     $description = isset($_FILES['description']) ? $_FILES['description'] : false;
     if (!check_uploaded_file($description)) {
         $this->_returnError(422);
         return;
     }
     // validate xml
     if (validateXml($description['tmp_name'], xsd('openml.run.evaluate'), $xmlErrors) == false) {
         $this->_returnError(423, $this->openmlGeneralErrorCode, $xmlErrors);
         return;
     }
     // fetch xml
     $xml = simplexml_load_file($description['tmp_name']);
     if ($xml === false) {
         $this->_returnError(424);
         return;
     }
     $run_id = (string) $xml->children('oml', true)->{'run_id'};
     $runRecord = $this->Run->getById($run_id);
     if ($runRecord == false) {
         $this->_returnError(425);
         return;
     }
     if ($runRecord->processed != null) {
         $this->_returnError(426);
         return;
     }
     $data = array('processed' => now());
     if (isset($xml->children('oml', true)->{'error'})) {
         $data['error'] = '' . $xml->children('oml', true)->{'error'};
     }
     $this->Run->update($run_id, $data);
     $implementation_ids = $this->Implementation->getAssociativeArray('fullName', 'id', '`name` = `name`');
     $this->db->trans_start();
     foreach ($xml->children('oml', true)->{'evaluation'} as $e) {
         $evaluation = xml2assoc($e, true);
         // naming convention
         $evaluation['function'] = $evaluation['name'];
         unset($evaluation['name']);
         // more naming convention
         if (array_key_exists($evaluation['implementation'], $implementation_ids)) {
             $evaluation['implementation_id'] = $implementation_ids[$evaluation['implementation']];
             unset($evaluation['implementation']);
         } else {
             $this->Log->mapping(__FILE__, __LINE__, 'Implementation ' . $evaluation['implementation'] . ' not found in database. ');
             continue;
         }
         // adding rid
         $evaluation['source'] = $run_id;
         if (array_key_exists('fold', $evaluation) && array_key_exists('repeat', $evaluation) && array_key_exists('sample', $evaluation)) {
             // evaluation_sample
             $this->Evaluation_sample->insert($evaluation);
         } elseif (array_key_exists('fold', $evaluation) && array_key_exists('repeat', $evaluation)) {
             // evaluation_fold
             $this->Evaluation_fold->insert($evaluation);
         } elseif (array_key_exists('interval_start', $evaluation) && array_key_exists('interval_end', $evaluation)) {
             // evaluation_interval
             $this->Evaluation_interval->insert($evaluation);
         } else {
             // global
             $this->Evaluation->insert($evaluation);
         }
     }
     $this->db->trans_complete();
     // update elastic search index.
     $this->elasticsearch->index('run', $run_id);
     $this->_xmlContents('run-evaluate', array('run_id' => $run_id));
 }
Ejemplo n.º 4
0
 private function flow_upload()
 {
     if (isset($_FILES['source']) && $_FILES['source']['error'] == 0) {
         $source = true;
     } else {
         $source = false;
         unset($_FILES['source']);
     }
     if (isset($_FILES['binary']) && $_FILES['binary']['error'] == 0) {
         $binary = true;
     } else {
         $binary = false;
         unset($_FILES['binary']);
     }
     if ($source == false && $binary == false) {
         $this->returnError(162, $this->version);
         return;
     }
     foreach ($_FILES as $key => $file) {
         if (check_uploaded_file($file) == false) {
             $this->returnError(160, $this->version);
             return;
         }
     }
     $xsd = xsd('openml.implementation.upload', $this->controller, $this->version);
     if (!$xsd) {
         $this->returnError(172, $this->version, $this->openmlGeneralErrorCode);
         return;
     }
     // get correct description
     if ($this->input->post('description')) {
         // get description from string upload
         $description = $this->input->post('description');
         $xmlErrors = "";
         if (validateXml($description, $xsd, $xmlErrors, false) == false) {
             $this->returnError(163, $this->version, $this->openmlGeneralErrorCode, $xmlErrors);
             return;
         }
         $xml = simplexml_load_string($description);
     } elseif (isset($_FILES['description'])) {
         // get description from file upload
         $description = $_FILES['description'];
         if (validateXml($description['tmp_name'], $xsd, $xmlErrors) == false) {
             $this->returnError(163, $this->version, $this->openmlGeneralErrorCode, $xmlErrors);
             return;
         }
         $xml = simplexml_load_file($description['tmp_name']);
         $similar = $this->Implementation->compareToXML($xml);
         if ($similar) {
             $this->returnError(171, $this->version, $this->openmlGeneralErrorCode, 'implementation_id:' . $similar);
             return;
         }
     } else {
         $this->returnError(161, $this->version);
         return;
     }
     if (!$this->ion_auth->in_group($this->groups_upload_rights, $this->user_id)) {
         $this->returnError(104, $this->version);
         return;
     }
     $name = '' . $xml->children('oml', true)->{'name'};
     $implementation = array('uploadDate' => now(), 'uploader' => $this->user_id);
     foreach ($_FILES as $key => $file) {
         if ($key == 'description') {
             continue;
         }
         if (!in_array($key, array('description', 'source', 'binary'))) {
             $this->returnError(167, $this->version);
             return;
         }
         $file_id = $this->File->register_uploaded_file($_FILES[$key], $this->data_folders['implementation'] . $key . '/', $this->user_id, 'implementation');
         if ($file_id === false) {
             $this->returnError(165, $this->version);
             return;
         }
         $file_record = $this->File->getById($file_id);
         //$implementation[$key.'Url'] = $this->data_controller . 'download/' . $file_id . '/' . $file_record->filename_original;
         $implementation[$key . '_md5'] = $file_record->md5_hash;
         $implementation[$key . '_file_id'] = $file_id;
         //$implementation[$key.'Format'] = $file_record->md5_hash;
         if (property_exists($xml->children('oml', true), $key . '_md5')) {
             if ($xml->children('oml', true)->{$key . '_md5'} != $file_record->md5_hash) {
                 $this->returnError(168, $this->version);
                 return;
             }
         }
     }
     $impl = insertImplementationFromXML($xml->children('oml', true), $this->xml_fields_implementation, $implementation);
     if ($impl == false) {
         $this->returnError(165, $this->version);
         return;
     }
     $implementation = $this->Implementation->getById($impl);
     $this->xmlContents('implementation-upload', $this->version, $implementation);
 }