<commit_before><?php

include_once('class.file.php');

class Experiment {

  public function __construct($experiment_id, $write_access=False, $owner=False) {
    global $data_path;
    $this->id = $experiment_id;
    if ($owner == False) {
      $this->experiments_file = new File($data_path .'experiments', False);
      $this->owner = $this->extractElement($this->id, $this->experiments_file->data);
    }
    else {
      $this->owner = $owner;
    }
    $this->file = new File($data_path .'user_data/'. $this->owner .'/'. $this->id, $write_access);
    $this->changed_data = array();
  }

  public function saveExperimentData() {
    foreach ($this->changed_data as $parameter) {
      if (preg_match('/' . $parameter . ' = \{.*?\}/s', $this->file->data) == 0) {
        if ($parameter == 'calendar') { $this->file->data .= $parameter . ' = {' . $this->flattenCalendar() . "}"; }
        else { $this->file->data .= $parameter . ' = {' . $this->$parameter . "}"; }
        $this->file->data .= "\n\n";
      }
      else {
        $old_piece = $parameter . ' = {' . $this->extractElement($parameter, $this->file->data) . '}';
        if ($parameter == 'calendar') { $new_piece = $parameter . ' = {' . $this->flattenCalendar() . '}'; }
        else { $new_piece = $parameter . ' = {' . $this->$parameter . '}'; }
        $this->file->data = str_replace($old_piece, $new_piece, $this->file->data);
      }
    }
    return $this->file->overwrite();
  }

  public function getName() {
    if (isset($this->name) == False) {
      $this->name = $this->extractElement('name', $this->file->data);
    }
    return $this->name;
  }

  public function setName($name) {
    if ($name != $this->getName()) {
      $this->name = trim($name);
      $this->changed_data[] = 'name';
    }
  }

  public function getStatus() {
    if (isset($this->status) == False) {
      $this->status = $this->extractElement('status', $this->file->data);
    }
    return $this->status;
  }

  public function setStatus($status) {
    $this->status = $status;
    $this->changed_data[] = 'status';
  }

  public function getDescription() {
    if (isset($this->description) == False) {
      $this->description = $this->extractElement('description', $this->file->data);
    }
    return $this->description;
  }

  public function setDescription($description) {
    if ($description != $this->getDescription()) {
      $this->description = trim($description);
      $this->changed_data[] = 'description';
    }
  }

  public function getLocation() {
    if (isset($this->location) == False) {
      $this->location = $this->extractElement('location', $this->file->data);
    }
    return $this->location;
  }

  public function setLocation($location) {
    if ($location != $this->getLocation()) {
      $this->location = trim($location);
      $this->changed_data[] = 'location';
    }
  }

  public function getRequirements() {
    if (isset($this->requirements) == False) {
      $this->requirements = explode('; ', $this->extractElement('requirements', $this->file->data));
    }
    return $this->requirements;
  }

  public function setRequirements($requirements) {
    $this->requirements = $requirements;
    $this->changed_data[] = 'requirements';
  }

  public function getExclusions() {
    if (isset($this->exclusions) == False) {
      $this->exclusions = explode('; ', $this->extractElement('exclusions', $this->file->data));
    }
    return $this->exclusions;
  }

  public function setExclusions($exclusions) {
    $this->exclusions = $exclusions;
    $this->changed_data[] = 'exclusions';
  }

  public function getPerSlot() {
    if (isset($this->per_slot) == False) {
      $this->per_slot = $this->extractElement('per_slot', $this->file->data);<commit_msg>Return null if no requirements<commit_after><?php

include_once('class.file.php');

class Experiment {

  public function __construct($experiment_id, $write_access=False, $owner=False) {
    global $data_path;
    $this->id = $experiment_id;
    if ($owner == False) {
      $this->experiments_file = new File($data_path .'experiments', False);
      $this->owner = $this->extractElement($this->id, $this->experiments_file->data);
    }
    else {
      $this->owner = $owner;
    }
    $this->file = new File($data_path .'user_data/'. $this->owner .'/'. $this->id, $write_access);
    $this->changed_data = array();
  }

  public function saveExperimentData() {
    foreach ($this->changed_data as $parameter) {
      if (preg_match('/' . $parameter . ' = \{.*?\}/s', $this->file->data) == 0) {
        if ($parameter == 'calendar') { $this->file->data .= $parameter . ' = {' . $this->flattenCalendar() . "}"; }
        else { $this->file->data .= $parameter . ' = {' . $this->$parameter . "}"; }
        $this->file->data .= "\n\n";
      }
      else {
        $old_piece = $parameter . ' = {' . $this->extractElement($parameter, $this->file->data) . '}';
        if ($parameter == 'calendar') { $new_piece = $parameter . ' = {' . $this->flattenCalendar() . '}'; }
        else { $new_piece = $parameter . ' = {' . $this->$parameter . '}'; }
        $this->file->data = str_replace($old_piece, $new_piece, $this->file->data);
      }
    }
    return $this->file->overwrite();
  }

  public function getName() {
    if (isset($this->name) == False) {
      $this->name = $this->extractElement('name', $this->file->data);
    }
    return $this->name;
  }

  public function setName($name) {
    if ($name != $this->getName()) {
      $this->name = trim($name);
      $this->changed_data[] = 'name';
    }
  }

  public function getStatus() {
    if (isset($this->status) == False) {
      $this->status = $this->extractElement('status', $this->file->data);
    }
    return $this->status;
  }

  public function setStatus($status) {
    $this->status = $status;
    $this->changed_data[] = 'status';
  }

  public function getDescription() {
    if (isset($this->description) == False) {
      $this->description = $this->extractElement('description', $this->file->data);
    }
    return $this->description;
  }

  public function setDescription($description) {
    if ($description != $this->getDescription()) {
      $this->description = trim($description);
      $this->changed_data[] = 'description';
    }
  }

  public function getLocation() {
    if (isset($this->location) == False) {
      $this->location = $this->extractElement('location', $this->file->data);
    }
    return $this->location;
  }

  public function setLocation($location) {
    if ($location != $this->getLocation()) {
      $this->location = trim($location);
      $this->changed_data[] = 'location';
    }
  }

  public function getRequirements() {
    if (isset($this->requirements) == False) {
      $this->requirements = explode('; ', $this->extractElement('requirements', $this->file->data));
      if ($this->requirements[0] == '') { $this->requirements = Null; }
    }
    return $this->requirements;
  }

  public function setRequirements($requirements) {
    $this->requirements = $requirements;
    $this->changed_data[] = 'requirements';
  }

  public function getExclusions() {
    if (isset($this->exclusions) == False) {
      $this->exclusions = explode('; ', $this->extractElement('exclusions', $this->file->data));
    }
    return $this->exclusions;
  }

  public function setExclusions($exclusions) {
    $this->exclusions = $exclusions;
    $this->changed_data[] = 'exclusions';
  }

  public function getPerSlot() {
    if (isset($this->per_slot) == False) {
      $this->per_slot = $this->extractElement('per_slot', $this->file->data);
{'fraction_non_alphanumeric': 0.20071118135124458, 'fraction_numerical': 0.0003951007506914263, 'mean_word_length': 3.127173913043478, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 185, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2232304', 'n_tokens_mistral': 2444, 'n_tokens_neox': 2389, 'n_words': 427}