-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAutocheck.java
More file actions
320 lines (268 loc) · 10.3 KB
/
Autocheck.java
File metadata and controls
320 lines (268 loc) · 10.3 KB
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
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
import java.io.*;
import java.sql.*;
import java.util.*;
public class Autocheck
{
public static void main(String arg[])
{
try
{
int quizid=0;
int item=0;
if(arg[0]!=null)
{
quizid=Integer.parseInt(arg[0]);
}
String language = arg[1];
String extension = null;
String ofilename = null;
if(language.equalsIgnoreCase("C"))
{
extension = ".c";
item = 16;
}
else if((language.equalsIgnoreCase("C++")) || (language.equalsIgnoreCase("CPP")))
{
extension = ".cpp";
item = 31;
}
else if(language.equalsIgnoreCase("java"))
{
extension = ".java";
item=32;
}
else
{
System.out.println("Enter a proper language. Thank you!!!!");
System.exit(0);
}
String filename = null;
File file=null;
String location=null; String dir_path=null;
int ccc=0;
String question=null;
String key=null;
int update =0;
double sumgrades=0;
double average=0;
ArrayList<Integer> userid = new ArrayList<Integer>();
ArrayList<Integer> uniqueid = new ArrayList<Integer>();
ArrayList<Integer> attemptid = new ArrayList<Integer>();
ArrayList<Integer> attemptid2 = new ArrayList<Integer>();
ArrayList<Integer> questionid = new ArrayList<Integer>();
ArrayList<String> behaviour = new ArrayList<String>();
ArrayList<String> answer = new ArrayList<String>();
ArrayList<String> keyword = new ArrayList<String>();
try
{
Class.forName("com.mysql.jdbc.Driver");
// Connection con= DriverManager.getConnection("jdbc:mysql://localhost:3306/OTC","javauser","javauser123*");
Connection con= DriverManager.getConnection("jdbc:mysql://localhost:3306/newmoodle2_4","root","root");
Statement sts1 = con.createStatement();
Statement sts2 = con.createStatement();
Statement sts3 = con.createStatement();
Statement sts4 = con.createStatement();
Statement sts5 = con.createStatement();
Statement sts6 =con.createStatement();
Statement sts7 = con.createStatement();
ResultSet rs = sts1.executeQuery("select userid, uniqueid from mdl_quiz_attempts where quiz="+quizid+" and sumgrades is NULL;");
// ResultSet rs = sts1.executeQuery("select userid, uniqueid from mdl_quiz_attempts where quiz="+quizid+";");
/* ResultSet rs=sts1.executeQuery( "select a.userid,b.responsesummary,c.fraction,c.state from mdl_quiz_attempts a inner join mdl_question_attempts b on a.uniqueid=b.questionusageid inner join mdl_question_attempt_steps c on c.questionattemptid = b.id where a.userid=2 and a.quiz=7;");*/
ResultSetMetaData rsmd = rs.getMetaData();
System.out.print(""+(rsmd.getColumnName(1)));
// System.out.print("\t\t"+(rsmd.getColumnName(2)));
// System.out.printx("\t\t"+(rsmd.getColumnName(3)));
//System.out.println("\t\t"+(rsmd.getColumnName(4)));
int j =0;
while(rs.next())
{
userid.add(Integer.parseInt(rs.getString(1)));
System.out.print(userid.get(j));
uniqueid.add(Integer.parseInt(rs.getString(2)));
System.out.print(uniqueid.get(j));
j++;
//System.out.print("\t\t"+rs.getString(2));
//System.out.print("\t\t"+rs.getString(3));
//System.out.println("\t\t"+rs.getString(4));
}
//rs.last();
//int i =rs.getRow();
System.out.println("\n Number of rows "+ userid.size());
for(int x=0; x < userid.size();x++ )
{
ResultSet rs2 =sts2.executeQuery("select qa.id, qa.questionid,qa.behaviour,qa.responsesummary, q.name from mdl_question_attempts qa, mdl_question q where qa.questionid = q.id and behaviour='manualgraded' and questionusageid = "+uniqueid.get(x)+";");
int k=0;
while(rs2.next())
{
attemptid.add(Integer.parseInt(rs2.getString(1)));
questionid.add(Integer.parseInt(rs2.getString(2)));
behaviour.add(rs2.getString(3));
answer.add(rs2.getString(4));
keyword.add(rs2.getString(5));
System.out.println(attemptid.get(k)+" "+questionid.get(k)+" "+ behaviour.get(k)+" "+answer.get(k)+" "+keyword.get(k));
k++;
}
ResultSet rs4 =sts5.executeQuery("select qa.id from mdl_question_attempts qa, mdl_question q where qa.questionid = q.id and questionusageid = "+uniqueid.get(x)+";");
while(rs4.next())
{attemptid2.add(Integer.parseInt(rs4.getString(1)));}
System.out.println("values "+attemptid2);
try
{
// dir_path="/home/javauser/testing_v2/cache/"+userid.get(x)+uniqueid.get(x)+"";
dir_path="/home/ttt/moodle-test/"+userid.get(x)+uniqueid.get(x)+"";
File dir = new File(dir_path);
dir.mkdir();
}catch(Exception ex){System.out.println(" 2nd main "+ex);}
for(int z = 0; z < questionid.size(); z++ )
{
try
{
String rep =answer.get(z);
if(rep==null)
{rep="";}
String w = rep.replaceAll(String.valueOf((char)160)," ").trim();
ofilename = keyword.get(z)+"";
filename = ofilename+extension+"";
//file = new File(dir_path+"/"+filename);
FileWriter fstream = new FileWriter(dir_path+"/"+filename);
BufferedWriter out = new BufferedWriter(fstream);
out.write(w);
//Close the output stream
out.close();
/*FileOutputStream fos = new FileOutputStream(file);
DataOutputStream dos = new DataOutputStream(fos);
char[] ch = w.toCharArray();
for(int i=0;i< ch.length;i++)
{
int b = (int)ch[i];
dos.write(b);
}
*/
key=keyword.get(z);
location =dir_path;
}catch(Exception e1){System.out.println("e1 :"+e1);}
if(key.equals("Addition"))
{
Testcode_interface ttt = new Testcode_implementation();
ccc = ttt.additiontest(location,filename,language,ofilename);
System.out.println("\n\n\n\nfrom face add "+ccc);
}
else if(key.equals("SumCheck"))
{
Testcode_interface ttt = new Testcode_implementation();
ccc = ttt.sumchecktest(location,filename,language,ofilename);
System.out.println("\n\n\n\nfrom face sum "+ccc);
}
else if(key.equals("Perimeter"))
{
Testcode_interface ttt = new Testcode_implementation();
ccc = ttt.perimetertest(location,filename,language,ofilename);
System.out.println("\n\n\n\nfrom face peri "+ccc);
}
else if(key.equals("SimpleInterest"))
{
Testcode_interface ttt = new Testcode_implementation();
ccc = ttt.interesttest(location,filename,language,ofilename);
System.out.println("\n\n\n\nfrom face interest"+ccc);
}
else if(key.equals("Average"))
{
Testcode_interface ttt = new Testcode_implementation();
ccc = ttt.averagetest(location,filename,language,ofilename);
System.out.println("\n\n\n\nfrom face average"+ccc);
}
else if(key.equals("Cube"))
{
Testcode_interface ttt = new Testcode_implementation();
ccc = ttt.cubetest(location,filename,language,ofilename);
System.out.println("\n\n\n\nfrom face cube"+ccc);
}
else if(key.equals("Area"))
{
Testcode_interface ttt = new Testcode_implementation();
ccc = ttt.areatest(location,filename,language,ofilename);
System.out.println("\n\n\n\nfrom face area "+ccc);
}
else if(key.equals("Velocity"))
{
Testcode_interface ttt = new Testcode_implementation();
ccc = ttt.velocitytest(location,filename,language,ofilename);
System.out.println("\n\n\n\nfrom face velocity "+ccc);
}
else if(key.equals("Length"))
{
Testcode_interface ttt = new Testcode_implementation();
ccc = ttt.lengthtest(location,filename,language,ofilename);
System.out.println("\n\n\n\nfrom face length "+ccc);
}
else
{
System.out.println("no input");
}
try
{
if(ccc==3)
{
update = sts3.executeUpdate("update mdl_question_attempt_steps set state='mangrright',fraction = 1 where userid ="+userid.get(x)+" and questionattemptid="+attemptid.get(z)+" and state='needsgrading';");
System.out.println(""+update);
}
else
{
update = sts3.executeUpdate("update mdl_question_attempt_steps set state='mangrwrong', fraction = 0 where userid ="+userid.get(x)+" and questionattemptid="+attemptid.get(z)+" and state='needsgrading';");
System.out.println(""+update);
}
}catch(Exception e3){System.out.println("e3 :"+e3);}
// if(key.equals("SumCheck"))
//{
//}
}
try
{
System.out.println(attemptid2.get(0)+" "+attemptid2.get((attemptid2.size())-1)+" "+attemptid2.size());
ResultSet rs3 = sts4.executeQuery("select sum(fraction), avg(fraction) from mdl_question_attempt_steps where userid ="+ userid.get(x)+" and questionattemptid between "+attemptid2.get(0)+" and "+attemptid2.get((attemptid2.size())-1)+";");
while(rs3.next())
{
sumgrades = Double.parseDouble(rs3.getString(1));
average = Double.parseDouble(rs3.getString(2));
average=sumgrades/attemptid2.size();
}
System.out.println(" pp"+sumgrades+average);
average = average*100;
}catch(Exception e4){System.out.println("e4 :"+e4);}
try
{
update = sts6.executeUpdate("update mdl_quiz_attempts set sumgrades = "+sumgrades+" where quiz ="+quizid+" and userid ="+userid.get(x)+"");
System.out.println("the1"+update);
}catch(Exception e5){System.out.println("e5 :"+e5);}
try
{
PreparedStatement ps = con.prepareStatement("insert into mdl_quiz_grades (id,quiz,userid,grade,timemodified) values (?,?,?,?,?);");
ps.setInt(1,0);
ps.setInt(2,quizid);
ps.setInt(3,userid.get(x));
ps.setDouble(4,average);
ps.setInt(5,0);
update= ps.executeUpdate();
System.out.println("the"+update);
/*
PreparedStatement ps2 = con.prepareStatement("insert into mdl_grade_grades (itemid,userid,finalgrade) values (?,?,?);");
ps2.setInt(1,item);
ps2.setInt(2,userid.get(x));
ps2.setDouble(3,average);
update = ps2.executeUpdate();
*/
update = sts7.executeUpdate("update mdl_grade_grades set finalgrade ="+average+" where userid="+userid.get(x)+" and itemid="+item+";");
System.out.println("the2"+update);
sumgrades=0;average=0;
}catch(Exception e6){System.out.println("e6 :"+e6);}
attemptid2.clear();
attemptid.clear();
questionid.clear();
behaviour.clear();
answer.clear();
keyword.clear();
}
}catch(Exception e){System.out.println(e);}
}catch(Exception emain){System.out.println("Error: no arguments");}
}
}