-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathpastjudge.py
More file actions
32 lines (28 loc) · 1.07 KB
/
pastjudge.py
File metadata and controls
32 lines (28 loc) · 1.07 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
import os
import sys
import MySQLdb
if __name__ == '__main__':
hw_path = './student/' + sys.argv[1] + '/Past/' + sys.argv[2] + '/answer/'
judge_path = './past/' + sys.argv[2] + '/'
outputfile = open(hw_path + 'output.txt', 'r')
answerfile = open(judge_path + 'answer.txt', 'r')
conn = MySQLdb.connect(host="127.0.0.1",user="root",passwd="pdogsserver",db="pd course")
cursor = conn.cursor()
n = cursor.execute("SELECT total_score FROM past_hw WHERE past_id = '" + sys.argv[3] + "'")
row = cursor.fetchall()
#print row[0][0]
total_score = 0.0
test_num = int(answerfile.readline().strip())
single_score = float(row[0][0]) / float(test_num)
for i in range(test_num):
a = answerfile.readline().strip()
o = outputfile.readline().strip()
if a == o:
total_score += single_score
#print row[0][0] / test_num
outfile = open(hw_path + 'score.txt', 'w')
outfile.write(str(total_score))
outputfile.close()
answerfile.close()
outfile.close()
print str(total_score)