<commit_before> <?php
/**
 * Business logic for the quartz chemistry pages.
 * 
 * Methods appear in the same order as they are listed in the front page for
 * the Quartz Chemistry section.
 */

class Quartz_chem extends MY_Controller
{

    /**
     * The main quartz chemistry page. Contains a series of select boxes and
     * links to the other pages.
     */
    function index()
    {
        $batch_id = $this->input->post('batch_id');
        if ($this->input->post('is_lock') === "true") {
            Doctrine::getTable('Batch')->lock($batch_id);
        }

        // build option tags for the select boxes
        foreach (Doctrine::getTable('Batch')->findOpenBatches() as $b) {
            $data->open_batches .= "<option value=$b->id>$b->start_date $b->owner $b->description";
        }

        foreach (Doctrine::getTable('Batch')->findAllBatches() as $b) {
            $data->all_batches .= "<option value=$b->id>$b->start_date $b->owner $b->description";
        }

        $data->title = 'Quartz Al-Be chemistry';
        $data->subtitle = 'Al-Be extraction from quartz:';
        $data->main = 'quartz_chem/index';
        $this->load->view('template', $data);
    }

    /**
     * Form for adding a batch or editing the batch information after it has been added.
     */
    function new_batch()
    {
        $id = $this->input->post('batch_id');
        $is_edit = (bool)$id;
        $data->allow_num_edit = ( ! $is_edit);

        if ($is_edit) {
            // it's an existing batch, get it
            $batch = Doctrine::getTable('Batch')->find($id);

            if ( ! $batch) {
                show_404('page');
            }

            $data->numsamples = $batch->Analysis->count();
        } else {
            // it's a new batch
            $batch = new Batch();
            // number of samples is not known
            $data->numsamples = null;
        }

        if (! $this->form_validation->run('batches')) {
            // validation failed, redisplay the form
            if ($is_edit) {
                $batch->id = set_value('id', $batch->id);
                $batch->owner = set_value('owner', $batch->owner);
                $batch->description = set_value('description', $batch->description);
                $batch->start_date = set_value('start_date', $batch->start_date);
            } else {
                $batch->id = set_value('id');
                $batch->owner = set_value('owner');
                $batch->description = set_value('description');
                $batch->start_date = date('Y-m-d');
            }
        } else {
            // inputs are valid
            // grab batch info from post and save it to the db
            $new_batch = ( ! ((bool)$batch->id));
            $batch->owner = $this->input->post('owner');
            $batch->description = $this->input->post('description');
            if ($new_batch) {
                $batch->start_date = date('Y-m-d');
            }
            $batch->save();

            if ($new_batch) {
                // new batch: create the analyses linked to this batch
                $numsamples = $this->input->post('numsamples');
                for ($i = 1; $i <= $numsamples; $i++) {
                    $analysis = new Analysis();
                    $analysis->number_within_batch = $i;
                    $batch->Analysis[] = $analysis;
                }
                $batch->save();
            }
        }

        // set the rest of the view data
        $data->numsamples = $this->input->post('numsamples');
        $data->title = 'Add a batch';
        $data->main = 'quartz_chem/new_batch';
        $data->batch = $batch;
        $this->load->view('template', $data);
    }

    /**
     * Shows the sample loading page.
     * @return void
     **/
    function load_samples()
    {
        $refresh = (bool)$this->input->post('is_refresh');
        $batch_id = (int)$this->input->post('batch_id');

        if ($this->input->post('addsplit'))

        // grab the batch with carrier data<commit_msg>Forgot to comment a line in last commit, breaks load_samples in qchem. Fixed.<commit_after> <?php
/**
 * Business logic for the quartz chemistry pages.
 * 
 * Methods appear in the same order as they are listed in the front page for
 * the Quartz Chemistry section.
 */

class Quartz_chem extends MY_Controller
{

    /**
     * The main quartz chemistry page. Contains a series of select boxes and
     * links to the other pages.
     */
    function index()
    {
        $batch_id = $this->input->post('batch_id');
        if ($this->input->post('is_lock') === "true") {
            Doctrine::getTable('Batch')->lock($batch_id);
        }

        // build option tags for the select boxes
        foreach (Doctrine::getTable('Batch')->findOpenBatches() as $b) {
            $data->open_batches .= "<option value=$b->id>$b->start_date $b->owner $b->description";
        }

        foreach (Doctrine::getTable('Batch')->findAllBatches() as $b) {
            $data->all_batches .= "<option value=$b->id>$b->start_date $b->owner $b->description";
        }

        $data->title = 'Quartz Al-Be chemistry';
        $data->subtitle = 'Al-Be extraction from quartz:';
        $data->main = 'quartz_chem/index';
        $this->load->view('template', $data);
    }

    /**
     * Form for adding a batch or editing the batch information after it has been added.
     */
    function new_batch()
    {
        $id = $this->input->post('batch_id');
        $is_edit = (bool)$id;
        $data->allow_num_edit = ( ! $is_edit);

        if ($is_edit) {
            // it's an existing batch, get it
            $batch = Doctrine::getTable('Batch')->find($id);

            if ( ! $batch) {
                show_404('page');
            }

            $data->numsamples = $batch->Analysis->count();
        } else {
            // it's a new batch
            $batch = new Batch();
            // number of samples is not known
            $data->numsamples = null;
        }

        if (! $this->form_validation->run('batches')) {
            // validation failed, redisplay the form
            if ($is_edit) {
                $batch->id = set_value('id', $batch->id);
                $batch->owner = set_value('owner', $batch->owner);
                $batch->description = set_value('description', $batch->description);
                $batch->start_date = set_value('start_date', $batch->start_date);
            } else {
                $batch->id = set_value('id');
                $batch->owner = set_value('owner');
                $batch->description = set_value('description');
                $batch->start_date = date('Y-m-d');
            }
        } else {
            // inputs are valid
            // grab batch info from post and save it to the db
            $new_batch = ( ! ((bool)$batch->id));
            $batch->owner = $this->input->post('owner');
            $batch->description = $this->input->post('description');
            if ($new_batch) {
                $batch->start_date = date('Y-m-d');
            }
            $batch->save();

            if ($new_batch) {
                // new batch: create the analyses linked to this batch
                $numsamples = $this->input->post('numsamples');
                for ($i = 1; $i <= $numsamples; $i++) {
                    $analysis = new Analysis();
                    $analysis->number_within_batch = $i;
                    $batch->Analysis[] = $analysis;
                }
                $batch->save();
            }
        }

        // set the rest of the view data
        $data->numsamples = $this->input->post('numsamples');
        $data->title = 'Add a batch';
        $data->main = 'quartz_chem/new_batch';
        $data->batch = $batch;
        $this->load->view('template', $data);
    }

    /**
     * Shows the sample loading page.
     * @return void
     **/
    function load_samples()
    {
        $refresh = (bool)$this->input->post('is_refresh');
        $batch_id = (int)$this->input->post('batch_id');

        // if ($this->input->post('addsplit')) { }

        // grab the batch with carrier data
{'fraction_non_alphanumeric': 0.15653775322283608, 'fraction_numerical': 0.0009821976672805403, 'mean_word_length': 1.7783083219645293, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 151, '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': '4259358', 'n_tokens_mistral': 2364, 'n_tokens_neox': 2257, 'n_words': 555}