original_string: private function add_model_metadata(array &$data, \core_analytics\local\time_splitting\base $timesplitting,
              \core_analytics\local\target\base $target) {
          global $CFG;
  
          // If no target the first column is the sampleid, if target the last column is the target.
          // This will need to be updated when we support unsupervised learning models.
          $metadata = array(
              'timesplitting' => $timesplitting->get_id(),
              'nfeatures' => count(current($data)) - 1,
              'moodleversion' => $CFG->version,
              'targetcolumn' => $target->get_id()
          );
          if ($target->is_linear()) {
              $metadata['targettype'] = 'linear';
              $metadata['targetmin'] = $target::get_min_value();
              $metadata['targetmax'] = $target::get_max_value();
          } else {
              $metadata['targettype'] = 'discrete';
              $metadata['targetclasses'] = json_encode($target::get_classes());
          }
  
          // The first 2 samples will be used to store metadata about the dataset.
          $metadatacolumns = [];
          $metadatavalues = [];
          foreach ($metadata as $key => $value) {
              $metadatacolumns[] = $key;
              $metadatavalues[] = $value;
          }
  
          // This will also reset samples' dataset keys.
          array_unshift($data, $metadatacolumns, $metadatavalues);
      }
code: private function add_model_metadata(array &$data, \core_analytics\local\time_splitting\base $timesplitting,
              \core_analytics\local\target\base $target) {
          global $CFG;
  
          // If no target the first column is the sampleid, if target the last column is the target.
          // This will need to be updated when we support unsupervised learning models.
          $metadata = array(
              'timesplitting' => $timesplitting->get_id(),
              'nfeatures' => count(current($data)) - 1,
              'moodleversion' => $CFG->version,
              'targetcolumn' => $target->get_id()
          );
          if ($target->is_linear()) {
              $metadata['targettype'] = 'linear';
              $metadata['targetmin'] = $target::get_min_value();
              $metadata['targetmax'] = $target::get_max_value();
          } else {
              $metadata['targettype'] = 'discrete';
              $metadata['targetclasses'] = json_encode($target::get_classes());
          }
  
          // The first 2 samples will be used to store metadata about the dataset.
          $metadatacolumns = [];
          $metadatavalues = [];
          foreach ($metadata as $key => $value) {
              $metadatacolumns[] = $key;
              $metadatavalues[] = $value;
          }
  
          // This will also reset samples' dataset keys.
          array_unshift($data, $metadatacolumns, $metadatavalues);
      }
code_tokens: private function add_model_metadata ( array & $ data , \ core_analytics \ local \ time_splitting \ base $ timesplitting , \ core_analytics \ local \ target \ base $ target ) { global $ CFG ; // If no target the first column is the sampleid, if target the last column is the target. // This will need to be updated when we support unsupervised learning models. $ metadata = array ( 'timesplitting' => $ timesplitting -> get_id ( ) , 'nfeatures' => count ( current ( $ data ) ) - 1 , 'moodleversion' => $ CFG -> version , 'targetcolumn' => $ target -> get_id ( ) ) ; if ( $ target -> is_linear ( ) ) { $ metadata [ 'targettype' ] = 'linear' ; $ metadata [ 'targetmin' ] = $ target :: get_min_value ( ) ; $ metadata [ 'targetmax' ] = $ target :: get_max_value ( ) ; } else { $ metadata [ 'targettype' ] = 'discrete' ; $ metadata [ 'targetclasses' ] = json_encode ( $ target :: get_classes ( ) ) ; } // The first 2 samples will be used to store metadata about the dataset. $ metadatacolumns = [ ] ; $ metadatavalues = [ ] ; foreach ( $ metadata as $ key => $ value ) { $ metadatacolumns [ ] = $ key ; $ metadatavalues [ ] = $ value ; } // This will also reset samples' dataset keys. array_unshift ( $ data , $ metadatacolumns , $ metadatavalues ) ; }
docstring: Adds target metadata to the dataset.
  
  The final dataset document will look like this:
  ----------------------------------------------------
  metadata1,metadata2,metadata3,.....
  value1, value2, value3,.....
  
  header1,header2,header3,header4,.....
  stud1value1,stud1value2,stud1value3,stud1value4,.....
  stud2value1,stud2value2,stud2value3,stud2value4,.....
  .....
  ----------------------------------------------------
  
  @param array $data
  @param \core_analytics\local\time_splitting\base $timesplitting
  @param \core_analytics\local\target\base         $target
  @return null
docstring_tokens: Adds target metadata to the dataset .