Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/#order_of_operations_parser.php#
blob: d9226d2597fde1d4ce36518d72b3535b13cbcf0d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
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);

?>