-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathoutput_judge.py
45 lines (38 loc) · 1.38 KB
/
output_judge.py
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
# -*- coding: utf-8 -*-
"""
Created on Tue Mar 28 15:57:12 2017
@author: Chikuwa
"""
import pandas as pd
import numpy as np
import difflib, sys
from os import listdir
from os.path import isfile, join
def non_sp_char(target_str):
target_str = target_str.replace('\n','')
target_str = target_str.replace(' ','')
return target_str
def main(path, real, output_name):
with open(real, 'r') as myfile:
output_real = myfile.read()
path_files = [f for f in listdir(path) if isfile(join(path, f))]
result = []
print('Processing...')
for file in path_files:
if file[-3:] != 'txt':
continue
with open(path+'\\'+file, 'r') as myfile:
output_test = myfile.read()
if difflib.SequenceMatcher(None,output_test,output_real).ratio() == 1:
result.append([file, 'AC'])
else:
output_real_nonsp = non_sp_char(output_real)
output_test_nonsp = non_sp_char(output_test)
if difflib.SequenceMatcher(None,output_test_nonsp.lower(),output_real_nonsp.lower()).ratio() == 1:
result.append([file, 'PE'])
else:
result.append([file, 'WA'])
print('Done...')
return pd.DataFrame(result, columns = ['file', 'type']).to_csv('%s.csv' %output_name, index = 0, header = 0)
if __name__ == "__main__":
main(sys.argv[1], sys.argv[2], sys.argv[3])