<commit_before><?php
if (! defined ( 'BASEPATH' ))
	exit ( 'No direct script access allowed' );
class Benchmark_model extends MY_Model {
	var $quarter;
	var $term;
	var $year;
	var $gradeStart;
	var $gradeEnd;
	var $subject;
	var $category;
	var $weight;
	var $benchmark;
	var $recModifier;
	var $recModified;

	function prepare_variables()
	{
		$variables = array (
				"quarter",
				"term",
				"year",
				"gradeStart",
				"gradeEnd",
				"subject",
				"category",
				"weight",
				"benchmark" 
		);
		for($i = 0; $i < count ( $variables ); $i ++) {
			$myVariable = $variables [$i];
			if ($this->input->post ( $myVariable )) {
				$this->$myVariable = $this->input->post ( $myVariable );
			}
		}
		
		$this->recModified = mysql_timestamp ();
		$this->recModifier = $this->session->userdata ( 'userID' );
	}

	function get($kBenchmark, $select = NULL)
	{
		if ($select) {
			if (is_array ( $select )) {
				foreach ( $select as $item ) {
					$this->db->select ( $item );
				}
			} else {
				$this->db->select ( $select );
			}
		}
		$this->db->where ( 'kBenchmark', $kBenchmark );
		$this->db->from ( 'benchmark' );
		$result = $this->db->get ()->row ();
		return $result;
	}

	function get_list($term, $year, $subject, $options = array())
	{
		$this->db->order_by ( "gradeStart,subject,quarter, term,year,category,weight,benchmark", "ASC" );
		if ($term) {
			$this->db->where ( 'term', $term );
		}
		if ($year) {
			$this->db->where ( 'year', $year );
		}
		if ($subject) {
			$this->db->where ( 'subject', $subject );
		}
		if (! empty ( $options ) && array_key_exists ( "grade_range", $options )) {
			$grade_range = $options ['grade_range'];
			if (array_key_exists ( 'gradeStart', $grade_range ) && array_key_exists ( 'gradeEnd', $grade_range )) {
				$gradeStart = $grade_range ['gradeStart'];
				$gradeEnd = $grade_range ['gradeEnd'];
				if ($gradeEnd == "") {
					$gradeEnd = $gradeStart;
				}
				if ($gradeStart != "") {
					$this->db->where ( "`gradeStart` BETWEEN '$gradeStart' AND '$gradeEnd'", NULL, TRUE );
					$this->db->where ( "`gradeEnd` BETWEEN '$gradeStart' AND '$gradeEnd'", NULL, TRUE );
				}
			}
		}
		if (! empty ( $options ) && array_key_exists ( "quarter", $options )) {
			$this->db->where ( "quarter", $options ['quarter'] );
		}
		$this->db->from ( 'benchmark' );
		
		$result = $this->db->get ()->result ();
		return $result;
	}

	function insert()
	{
		$this->prepare_variables ();
		$this->db->insert ( 'benchmark', $this );
		return $this->db->insert_id ();
	}

	function update($kBenchmark)
	{
		$this->prepare_variables ();
		$this->db->where ( 'kBenchmark', $kBenchmark );
		$this->db->update ( 'benchmark', $this );
	}

	function delete($kBenchmark)
	{
		$delete_array ['kBenchmark'] = $kBenchmark;
		$this->db->delete ( 'benchmark', $delete_array );
	}

	function get_for_student($kStudent, $subject, $grade, $term, $year, $quarter = FALSE, $category = FALSE)
	{
		
		// @TODO Real Problem here is finding the benchmarks for grade ranges
		if ($subject != "all") {
			$this->db->where ( "benchmark.subject", $subject );
		}
		$this->db->where ( "(benchmark.gradeStart <= $grade OR benchmark.gradeEnd >= $grade)" );
		$this->db->where ( "benchmark.term", $term );
		$this->db->where ( "benchmark.year", $year );
		if ($category) {
			$this->db->where ( "benchmark.category", $category );
		}
		if($quarter){
			$this->db->where("benchmark.quarter", $quarter);
		}
		$this->db->order_by ( "benchmark.subject, benchmark.category, benchmark.weight ASC" );
		$this->db->join ( "student_benchmark", "benchmark.kBenchmark=student_benchmark.kBenchmark AND student_benchmark.kStudent=$kStudent", "LEFT" );
		$this->db->select ( "benchmark.*,student_benchmark.comment,student_benchmark.grade" );
		$this->db->from ( "benchmark" );
		$result = $this->db->get ()->result ();
		$this->_log ("log",TRUE);
		return $result;
	}

	function update_for_student($kStudent, $kBenchmark, $kTeach, $grade, $comment = NULL)
	{
		$output = FALSE;
		$data = array (
				"kTeach" => $kTeach,
				"grade" => $grade 
		);
		if (isset ( $comment )) {
			$data ["comment"] = $comment;
		}<commit_msg>more bug testing<commit_after><?php
if (! defined ( 'BASEPATH' ))
	exit ( 'No direct script access allowed' );
class Benchmark_model extends MY_Model {
	var $quarter;
	var $term;
	var $year;
	var $gradeStart;
	var $gradeEnd;
	var $subject;
	var $category;
	var $weight;
	var $benchmark;
	var $recModifier;
	var $recModified;

	function prepare_variables()
	{
		$variables = array (
				"quarter",
				"term",
				"year",
				"gradeStart",
				"gradeEnd",
				"subject",
				"category",
				"weight",
				"benchmark" 
		);
		for($i = 0; $i < count ( $variables ); $i ++) {
			$myVariable = $variables [$i];
			if ($this->input->post ( $myVariable )) {
				$this->$myVariable = $this->input->post ( $myVariable );
			}
		}
		
		$this->recModified = mysql_timestamp ();
		$this->recModifier = $this->session->userdata ( 'userID' );
	}

	function get($kBenchmark, $select = NULL)
	{
		if ($select) {
			if (is_array ( $select )) {
				foreach ( $select as $item ) {
					$this->db->select ( $item );
				}
			} else {
				$this->db->select ( $select );
			}
		}
		$this->db->where ( 'kBenchmark', $kBenchmark );
		$this->db->from ( 'benchmark' );
		$result = $this->db->get ()->row ();
		return $result;
	}

	function get_list($term, $year, $subject, $options = array())
	{
		$this->db->order_by ( "gradeStart,subject,quarter, term,year,category,weight,benchmark", "ASC" );
		if ($term) {
			$this->db->where ( 'term', $term );
		}
		if ($year) {
			$this->db->where ( 'year', $year );
		}
		if ($subject) {
			$this->db->where ( 'subject', $subject );
		}
		if (! empty ( $options ) && array_key_exists ( "grade_range", $options )) {
			$grade_range = $options ['grade_range'];
			if (array_key_exists ( 'gradeStart', $grade_range ) && array_key_exists ( 'gradeEnd', $grade_range )) {
				$gradeStart = $grade_range ['gradeStart'];
				$gradeEnd = $grade_range ['gradeEnd'];
				if ($gradeEnd == "") {
					$gradeEnd = $gradeStart;
				}
				if ($gradeStart != "") {
					$this->db->where ( "`gradeStart` BETWEEN '$gradeStart' AND '$gradeEnd'", NULL, TRUE );
					$this->db->where ( "`gradeEnd` BETWEEN '$gradeStart' AND '$gradeEnd'", NULL, TRUE );
				}
			}
		}
		if (! empty ( $options ) && array_key_exists ( "quarter", $options )) {
			$this->db->where ( "quarter", $options ['quarter'] );
		}
		$this->db->from ( 'benchmark' );
		
		$result = $this->db->get ()->result ();
		return $result;
	}

	function insert()
	{
		$this->prepare_variables ();
		$this->db->insert ( 'benchmark', $this );
		return $this->db->insert_id ();
	}

	function update($kBenchmark)
	{
		$this->prepare_variables ();
		$this->db->where ( 'kBenchmark', $kBenchmark );
		$this->db->update ( 'benchmark', $this );
	}

	function delete($kBenchmark)
	{
		$delete_array ['kBenchmark'] = $kBenchmark;
		$this->db->delete ( 'benchmark', $delete_array );
	}

	function get_for_student($kStudent, $subject, $grade, $term, $year, $quarter = FALSE, $category = FALSE)
	{
		
		// @TODO Real Problem here is finding the benchmarks for grade ranges
		if ($subject != "all") {
			$this->db->where ( "benchmark.subject", $subject );
		}
		$this->db->where ( "(benchmark.gradeStart = $grade OR benchmark.gradeEnd = $grade)" );
		$this->db->where ( "benchmark.term", $term );
		$this->db->where ( "benchmark.year", $year );
		if ($category) {
			$this->db->where ( "benchmark.category", $category );
		}
		if($quarter){
			$this->db->where("benchmark.quarter", $quarter);
		}
		$this->db->order_by ( "benchmark.subject, benchmark.category, benchmark.weight ASC" );
		$this->db->join ( "student_benchmark", "benchmark.kBenchmark=student_benchmark.kBenchmark AND student_benchmark.kStudent=$kStudent", "LEFT" );
		$this->db->select ( "benchmark.*,student_benchmark.comment,student_benchmark.grade" );
		$this->db->from ( "benchmark" );
		$result = $this->db->get ()->result ();
		$this->_log ("log",TRUE);
		return $result;
	}

	function update_for_student($kStudent, $kBenchmark, $kTeach, $grade, $comment = NULL)
	{
		$output = FALSE;
		$data = array (
				"kTeach" => $kTeach,
				"grade" => $grade 
		);
		if (isset ( $comment )) {
			$data ["comment"] = $comment;
		}
{'fraction_non_alphanumeric': 0.20384941290400677, 'fraction_numerical': 0.000242101440503571, 'mean_word_length': 3.6182224706539965, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 158, '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': '7573881', 'n_tokens_mistral': 3353, 'n_tokens_neox': 2915, 'n_words': 598}