diff options
author | Wesley Dillingham <WWdillingham@sugarlabs.org> | 2009-08-04 20:49:50 (GMT) |
---|---|---|
committer | Wesley Dillingham <WWdillingham@sugarlabs.org> | 2009-08-04 20:49:50 (GMT) |
commit | cdabb9c72395ffa988bc8bf8e71b8933c1c26bb3 (patch) | |
tree | 4e6f4aa49ef1df9076a666d233608977e5ad6e99 | |
parent | 6f17a6877dac1748691dd1dc8d4e28ea73664d4d (diff) |
Initializing variables
-rw-r--r-- | #order_of_operations_parser.php# | 264 | ||||
-rw-r--r-- | 4.N.10_Parser.php | 16 | ||||
-rw-r--r-- | 4.N.10_Parser.php~ | 53 | ||||
-rw-r--r-- | order_of_operations_parser.php~ | 264 |
4 files changed, 596 insertions, 1 deletions
diff --git a/#order_of_operations_parser.php# b/#order_of_operations_parser.php# new file mode 100644 index 0000000..d9226d2 --- /dev/null +++ b/#order_of_operations_parser.php# @@ -0,0 +1,264 @@ +/* Order of Operations Parser + #Filename: order_of_operations_parser.php +#Last updated: See http://git.sugarlabs.org/projects/teacher-reporting + + *** FIELD REFERENCE *** + + MAC= $1 tok[0] + NAME= $2 tok[1] + OPERATION= $3 tok[2] + SUCCESS= $4 tok[3] + +test2 +*/ + + + +<?php + +echo "Student, Only +, Contains +, Only -, Contains -, Only *, Contains *, Only /, Contains /, Understands OoO?" + + +/*Open the data file for reading - mysql calls shortly */ +$fp = fopen("./Student.dat", "r"); +if(!$fp) die ("Cannot open the file"); + + +//Break Each line of the file into its own array element - will have to parse each array element to obtain fields +$lines = file($fp); + + +$numWords = str_word_count($fp); +//Will always be a multiple of four so $NumRecords will be $numWords/4 +$numRecords = $numWords / 4; +//Our Associative array Will also be in sequence 1,5,9,13.. + 4 etc +//Need to tokenize each line and choose appropriate elements ($1) +//This is just to fill the array with Variables. Next we will go through the same process for the remaining fields +// Perform the order of operations logic on them add them to additional associate arrays with various meanings +// For Example addition_correct[] and o_addition_correct[] + +for (i=0;i<=$numRecords;i++) +{ + + + $tok = strtok($lines, " "); + + /* + Because in the end statement we will have to loop through one of the arrays, which will be localized according + #to specific aritmetic operations (- + / *). We need to account for the fact that some students may not answer a + #question with one of these operations, and if we looped through that particular operation, we would not represent + #that student in any of the logic containted within that loop in the END{} statment. Therefore an associative array + #which absolutely, accounts for any student, contained in the .dat, the CLASS[] array. + $Class[tok[0]]; + */ + + while ($tok !== false) + { + $Class[tok[0]]; + } + +} + +//in this loop we will cycle through each line of the .dat file and analyze the third field (or token) +// so for instance $3 in token form is tok[2] +for (i=0;i<=$numRecords;i++) +{ + $tok = strtok($lines, " "); + + while ($tok !== false) + { + $equation = $tok[2]; + +/**********REGULAR EXPRESSION KEY*********/ +//Addition = /\+/ +//Subtraction = /[0-9]\-[0-9]/ +//Division = /\// +//Multiplication= /\*/ + +// ` ********************************ADDITION************************* + + + //contains addition + $regexp = "/\+/"; + if (preg_match($regexp, $equation)) //if ($tok[2] contains TODO check for correctness + { + $contains_addition[tok[0]]++; //but is not correct + + if ($tok[3] = "1") //is it also correct? put it in a different associative array with the same key + { + $contains_addition_correct[tok[0]]++; + } + } + //using if-structure because an else if would not encompass compound(contains more than one operation) operations + + +//Now we need to determine if a particular question contained ONLY a particular operation + //Matches operations with ONLY ADDITION + if (preg_match($regexp, $equation) && !preg_match("-", $equation), && !preg_match("\/", $equation), && !preg_match("*", $equation)) + { + $only_addition[tok[2]]++ + + if ($tok[3] = "1") //is it also correct? put it in a different associative array with the same key + { + $only_addition_correct[tok[0]]++; + } + } + + //******************************************SUBTRACTION******************************** + + +//TODO: account for negative numbers + + //contains subtraction + $regexp = "/[0-9]\-[0-9]/"; //NOTE:operation remains the same, as we are checking it four times for each operation + if (preg_match($regexp, $equation)) + { + $contains_subtraction[tok[0]]++; + + if ($tok[3] = "1") + { + $contains_subtraction_correct[tok[0]]++; + } + } + + //Matches equations with ONLY SUBTRACTION + if (preg_match($regexp, $equation) && !preg_match("+", $equation) && !preg_match("\/", $equation) && !preg_match("*", $equation)) + { + $only_subtraction[tok[2]]++ + + if ($tok[3] = "1") //is it also correct? put it in a different associative array with the same key + { + $only_subtraction_correct[tok[0]]++; + } + } + //******************************DIVISION******************************** + + //contains division + $regexp = "/\//" + if (preg_match($regexp, $equation)) + { + $contains_division[tok[0]]++ + + if ($tok[3] = "1") + { + $contains_division_correct[tok[0]]++ + } + } + + + //Matches equations with ONLY DIVISION + if (preg_match($regexp, $equation) && !preg_match("+", $equation) && !preg_match("-", $equation) && !preg_match("*", $equation)) + { + $only_division[tok[2]]++ + + if ($tok[3] = "1") //is it also correct? put it in a different associative array with the same key + { + $only_division_correct[tok[0]]++; + } + } + //**************************************Multiplication************************* + + + $regexp = "/\*/" //Matches equations with only multiplication + if (preg_match($regexp, $equation)) + { + $contains_multiplication[tok[0]]++; + + if ($tok[3] = "1") + { + $contains_multiplication_correct[tok[0]]++; + } + } + + //Matches equations with ONLY Multiplication + if (preg_match($regexp, $equation) && !preg_match("+", $equation) && !preg_match("\/", $equation) && !preg_match("-", $equation)) + { + $only_multiplication[tok[2]]++; + + if ($tok[3] = "1") //is it also correct? put it in a different associative array with the same key + { + $only_multiplication_correct[tok[0]]++; + } + } + + } + + //**********************************************COMPOUND EQUATIONS********************************* + + // can simply not use regexp but replace with a literal reg expression + if(preg_match("/\+/", $equation) && (preg_match("/[0-9]\-[0-9]/", $equation) || preg_match("/\//", $equation) || preg_match("/\*/", $equation))) + { + + $compound[tok[0]]++; //NOTE compound_incorrect is implicit + if ($tok[3] = "1") //if correct + { + $compound_correct[tok[0]]++; + } + } + elseif( (preg_match("/[0-9]\-[0-9]/", $equation)) && (preg_match("/\+/", $equation) || preg_match("/\//", $equation) || preg_match("/\*/", $equation))) + { + $compound[tok[0]]++; + if ($tok[3] = "1") //if correct + { + $compound_correct[tok[0]]++; + } + + } + elseif(preg_match($"/\//", $equation) && (preg_match("/\+/", $equation) || preg_match("/[0-9]\-[0-9]/", $equation) || preg_match("/\*/", $equation))) + { + $compound[tok[0]]++; + if ($tok[3] = "1") //if correct + { + $compound_correct[tok[0]]++; + } + } + elseif( (preg_match($"/\*/", $equation)) && (preg_match("/\+/", $equation) || preg_match("/[0-9]\-[0-9]/", $equation) || preg_match("/\//", $equation))) + { + $compound[tok[0]]++; + if ($tok[3] = "1") //if correct + { + $compound_correct[tok[0]]++; + } + + } + else + { + $non_compound[tok[0]++; + if ($tok[3] = "1") //if correct + { + $non_compound_correct[tok[0]]++; + } + } + +} + + +/* +# A student doesnt understand order of operations if their is a greater than 20% difference in between compound +# operations and single operation instructions, but only if lower on the compound instruction side. +# or if they get less than 70% on compounds, because getting a 51% on compounds and 70% on non compounds doesnt satisfy +# understaning of OoO +*/ + +foreach ($Class as $student) +{ + if ( ( ($non_compound_correct[$student] / $non_compound[$student]) - ($compound_correct[$student] / $compound[$student]) > .2 ) || ( ($non_compound_correct[$student] / $non_compound[$student]) ) < .7) + { + $understands= "no" + } + else + { + $understands= "yes" + } + +} + +//printing formatted data +sprintf("%-11s%-8s%-11s%-8s%-11s%-8s%-11s%-8s%-11s%-11s\n", $student, int($only_addition_correct[$student]*100/$only_addition[$student]), int($contains_addition_correct[$student]*100/$contains_addition[$student]), int($only_subtraction_correct[$student]*100/$only_subtraction[$student]), int($contains_subtraction_correct[$student]*100/$contains_subtraction[$student]), int($only_multiplication_correct[$student]*100/$only_multiplication[$student]), int($contains_multiplication_correct[$student]*100/$contains_multiplication[$student]), int($only_division_correct[$student]*100/$only_division[$student]), int($contains_division_correct[$student]*100/$contains_division[$student]), $understands) + + + +/*close the file? */ +fclose($fp); + +?> diff --git a/4.N.10_Parser.php b/4.N.10_Parser.php index fd8d2ba..febab18 100644 --- a/4.N.10_Parser.php +++ b/4.N.10_Parser.php @@ -48,6 +48,20 @@ for (i=0;i<=$numRecords;i++) } - +//in this loop we will cycle through each line of the .dat file and determine at each instance of +for (i=0;i<=$numRecords;i++) +{ + $tok = strtok($lines, " "); + + while ($tok !== false) + { + $student_id = $tok[0]; + $question_id = $tok[1]; + $correct_sum = $tok[2]; + $submitted_sum = $tok[3]; + $correct = $tok[4]; + + } +} ?>
\ No newline at end of file diff --git a/4.N.10_Parser.php~ b/4.N.10_Parser.php~ new file mode 100644 index 0000000..fd8d2ba --- /dev/null +++ b/4.N.10_Parser.php~ @@ -0,0 +1,53 @@ +//5.N.10 Parser +//http://git.sugarlabs.org/projects/teacher-reporting +// +//Description: +/* + +Select and use appropriate operations (addition, subtraction, multiplication, and division) to solve problems, including those involving money. + +*/ + +<?php + +$fp = fopen("./4.N.10.dat", "r"); +if(!$fp) die ("Cannot open the file"); + +//Break Each line of the file into its own array element - will have to parse each array element to obtain fields +$lines = file($fp); + + +$numWords = str_word_count($fp); +//Will always be a multiple of four so $NumRecords will be $numWords/4 +$numRecords = $numWords / 5; +//Our Associative array Will also be in sequence 1,5,9,13.. + 4 etc +//Need to tokenize each line and choose appropriate elements ($1) +//This is just to fill the array with Variables. Next we will go through the same process for the remaining fields +// Perform the logic on them add them to additional associate arrays with various meanings +// For Example + +for (i=0;i<=$numRecords;i++) +{ + + + $tok = strtok($lines, " "); + + /* + Because in the end statement we will have to loop through one of the arrays, which will be localized according + #to specific aritmetic operations (- + / *). We need to account for the fact that some students may not answer a + #question with one of these operations, and if we looped through that particular operation, we would not represent + #that student in any of the logic containted within that loop in the END{} statment. Therefore an associative array + #which absolutely, accounts for any student, contained in the .dat, the CLASS[] array. + $Class[tok[0]]; + */ + + while ($tok !== false) + { + $Class[tok[0]]; + } + +} + + + +?>
\ No newline at end of file diff --git a/order_of_operations_parser.php~ b/order_of_operations_parser.php~ new file mode 100644 index 0000000..1da881a --- /dev/null +++ b/order_of_operations_parser.php~ @@ -0,0 +1,264 @@ +/* Order of Operations Parser + #Filename: order_of_operations_parser.php +#Last updated: See http://git.sugarlabs.org/projects/teacher-reporting + + *** FIELD REFERENCE *** + + MAC= $1 tok[0] + NAME= $2 tok[1] + OPERATION= $3 tok[2] + SUCCESS= $4 tok[3] + +test2 +*/ + + + +<?php + +echo "Student, Only +, Contains +, Only -, Contains -, Only *, Contains *, Only /, Contains /, Understands OoO?" + + +/*Open the data file for reading - mysql calls shortly */ +$fp = fopen("./Student.dat", "r"); +if(!$fp) die ("Cannot open the file"); + + +//Break Each line of the file into its own array element - will have to parse each array element to obtain fields +$lines = file($fp); + + +$numWords = str_word_count($str); +//Will always be a multiple of four so $NumRecords will be $numWords/4 +$numRecords = $numWords / 4; +//Our Associative array Will also be in sequence 1,5,9,13.. + 4 etc +//Need to tokenize each line and choose appropriate elements ($1) +//This is just to fill the array with Variables. Next we will go through the same process for the remaining fields +// Perform the order of operations logic on them add them to additional associate arrays with various meanings +// For Example addition_correct[] and o_addition_correct[] + +for (i=0;i<=$numRecords;i++) +{ + + + $tok = strtok($lines, " "); + + /* + Because in the end statement we will have to loop through one of the arrays, which will be localized according + #to specific aritmetic operations (- + / *). We need to account for the fact that some students may not answer a + #question with one of these operations, and if we looped through that particular operation, we would not represent + #that student in any of the logic containted within that loop in the END{} statment. Therefore an associative array + #which absolutely, accounts for any student, contained in the .dat, the CLASS[] array. + $Class[tok[0]]; + */ + + while ($tok !== false) + { + $Class[tok[0]]; + } + +} + +//in this loop we will cycle through each line of the .dat file and analyze the third field (or token) +// so for instance $3 in token form is tok[2] +for (i=0;i<=$numRecords;i++) +{ + $tok = strtok($lines, " "); + + while ($tok !== false) + { + $equation = $tok[2]; + +/**********REGULAR EXPRESSION KEY*********/ +//Addition = /\+/ +//Subtraction = /[0-9]\-[0-9]/ +//Division = /\// +//Multiplication= /\*/ + +// ` ********************************ADDITION************************* + + + //contains addition + $regexp = "/\+/"; + if (preg_match($regexp, $equation)) //if ($tok[2] contains TODO check for correctness + { + $contains_addition[tok[0]]++; //but is not correct + + if ($tok[3] = "1") //is it also correct? put it in a different associative array with the same key + { + $contains_addition_correct[tok[0]]++; + } + } + //using if-structure because an else if would not encompass compound(contains more than one operation) operations + + +//Now we need to determine if a particular question contained ONLY a particular operation + //Matches operations with ONLY ADDITION + if (preg_match($regexp, $equation) && !preg_match("-", $equation), && !preg_match("\/", $equation), && !preg_match("*", $equation)) + { + $only_addition[tok[2]]++ + + if ($tok[3] = "1") //is it also correct? put it in a different associative array with the same key + { + $only_addition_correct[tok[0]]++; + } + } + + //******************************************SUBTRACTION******************************** + + +//TODO: account for negative numbers + + //contains subtraction + $regexp = "/[0-9]\-[0-9]/"; //NOTE:operation remains the same, as we are checking it four times for each operation + if (preg_match($regexp, $equation)) + { + $contains_subtraction[tok[0]]++; + + if ($tok[3] = "1") + { + $contains_subtraction_correct[tok[0]]++; + } + } + + //Matches equations with ONLY SUBTRACTION + if (preg_match($regexp, $equation) && !preg_match("+", $equation) && !preg_match("\/", $equation) && !preg_match("*", $equation)) + { + $only_subtraction[tok[2]]++ + + if ($tok[3] = "1") //is it also correct? put it in a different associative array with the same key + { + $only_subtraction_correct[tok[0]]++; + } + } + //******************************DIVISION******************************** + + //contains division + $regexp = "/\//" + if (preg_match($regexp, $equation)) + { + $contains_division[tok[0]]++ + + if ($tok[3] = "1") + { + $contains_division_correct[tok[0]]++ + } + } + + + //Matches equations with ONLY DIVISION + if (preg_match($regexp, $equation) && !preg_match("+", $equation) && !preg_match("-", $equation) && !preg_match("*", $equation)) + { + $only_division[tok[2]]++ + + if ($tok[3] = "1") //is it also correct? put it in a different associative array with the same key + { + $only_division_correct[tok[0]]++; + } + } + //**************************************Multiplication************************* + + + $regexp = "/\*/" //Matches equations with only multiplication + if (preg_match($regexp, $equation)) + { + $contains_multiplication[tok[0]]++; + + if ($tok[3] = "1") + { + $contains_multiplication_correct[tok[0]]++; + } + } + + //Matches equations with ONLY Multiplication + if (preg_match($regexp, $equation) && !preg_match("+", $equation) && !preg_match("\/", $equation) && !preg_match("-", $equation)) + { + $only_multiplication[tok[2]]++; + + if ($tok[3] = "1") //is it also correct? put it in a different associative array with the same key + { + $only_multiplication_correct[tok[0]]++; + } + } + + } + + //**********************************************COMPOUND EQUATIONS********************************* + + // can simply not use regexp but replace with a literal reg expression + if(preg_match("/\+/", $equation) && (preg_match("/[0-9]\-[0-9]/", $equation) || preg_match("/\//", $equation) || preg_match("/\*/", $equation))) + { + + $compound[tok[0]]++; //NOTE compound_incorrect is implicit + if ($tok[3] = "1") //if correct + { + $compound_correct[tok[0]]++; + } + } + elseif( (preg_match("/[0-9]\-[0-9]/", $equation)) && (preg_match("/\+/", $equation) || preg_match("/\//", $equation) || preg_match("/\*/", $equation))) + { + $compound[tok[0]]++; + if ($tok[3] = "1") //if correct + { + $compound_correct[tok[0]]++; + } + + } + elseif(preg_match($"/\//", $equation) && (preg_match("/\+/", $equation) || preg_match("/[0-9]\-[0-9]/", $equation) || preg_match("/\*/", $equation))) + { + $compound[tok[0]]++; + if ($tok[3] = "1") //if correct + { + $compound_correct[tok[0]]++; + } + } + elseif( (preg_match($"/\*/", $equation)) && (preg_match("/\+/", $equation) || preg_match("/[0-9]\-[0-9]/", $equation) || preg_match("/\//", $equation))) + { + $compound[tok[0]]++; + if ($tok[3] = "1") //if correct + { + $compound_correct[tok[0]]++; + } + + } + else + { + $non_compound[tok[0]++; + if ($tok[3] = "1") //if correct + { + $non_compound_correct[tok[0]]++; + } + } + +} + + +/* +# A student doesnt understand order of operations if their is a greater than 20% difference in between compound +# operations and single operation instructions, but only if lower on the compound instruction side. +# or if they get less than 70% on compounds, because getting a 51% on compounds and 70% on non compounds doesnt satisfy +# understaning of OoO +*/ + +foreach ($Class as $student) +{ + if ( ( ($non_compound_correct[$student] / $non_compound[$student]) - ($compound_correct[$student] / $compound[$student]) > .2 ) || ( ($non_compound_correct[$student] / $non_compound[$student]) ) < .7) + { + $understands= "no" + } + else + { + $understands= "yes" + } + +} + +//printing formatted data +sprintf("%-11s%-8s%-11s%-8s%-11s%-8s%-11s%-8s%-11s%-11s\n", $student, int($only_addition_correct[$student]*100/$only_addition[$student]), int($contains_addition_correct[$student]*100/$contains_addition[$student]), int($only_subtraction_correct[$student]*100/$only_subtraction[$student]), int($contains_subtraction_correct[$student]*100/$contains_subtraction[$student]), int($only_multiplication_correct[$student]*100/$only_multiplication[$student]), int($contains_multiplication_correct[$student]*100/$contains_multiplication[$student]), int($only_division_correct[$student]*100/$only_division[$student]), int($contains_division_correct[$student]*100/$contains_division[$student]), $understands) + + + +/*close the file? */ +fclose($fp); + +?> |