-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcode-minifier.py
59 lines (45 loc) · 1.79 KB
/
code-minifier.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import requests
from openpyxl import load_workbook
import jsmin
import xlwt
import xlrd
from xlutils.copy import copy
import editdistance
from analysis import minify_c_code, string_similarity
from python_minifier import minify
import re
problem_number = 9
file_path = f"/Users/cymmerjohnmaranga/Downloads/Manipulated/C_Problem_{problem_number}_Test.xlsx"
workbook = load_workbook(filename=file_path)
sheet = workbook.active
start_col = 3
end_col = 4
minified_data = []
for i in range(2, sheet.max_row + 1):
row_data = [cell.value for cell in sheet[i][start_col : end_col + 1]]
row_data_minified = []
for col in row_data:
row_data_minified.append(minify_c_code(col))
minified_data.append(row_data_minified)
# load the excel file
rb = xlrd.open_workbook(file_path)
# copy the contents of excel file
wb = copy(rb)
# open the first sheet
w_sheet = wb.get_sheet(0)
w_sheet_by_index = rb.sheet_by_index(0)
for i, data_row in enumerate(minified_data, start=1):
print(data_row)
corrected_code_minified = minify_c_code(data_row[0])
actual_code_minified = minify_c_code(data_row[1])
google_vision_minified = w_sheet_by_index.cell(i, start_col+2).value
# Open AI Minified
w_sheet.write(i, start_col+3, corrected_code_minified)
# Actual Code Minified
w_sheet.write(i, start_col+4, actual_code_minified)
# Google Vision API vs Corrected Code
w_sheet.write(i, start_col+5, string_similarity(google_vision_minified, corrected_code_minified))
# Corrected Code vs Actual Code
w_sheet.write(i, start_col+6, string_similarity(corrected_code_minified, actual_code_minified))
# save the file
wb.save(f"/Users/cymmerjohnmaranga/Downloads/Manipulated/Minified/C_Problem_{problem_number}_Test_with_minified.xls")