-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChatGPTCode.py
More file actions
133 lines (111 loc) · 3.79 KB
/
ChatGPTCode.py
File metadata and controls
133 lines (111 loc) · 3.79 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
"""
ChatGPTCode.py
This is the main file that will be run to start the program
"""
# Importing the external dependencies
import json
import os
# Importing the internal dependencies
from Extract import extract_data
from WriteToCSV import write_python_to_csv, write_java_to_csv, write_javascript_to_csv
# Define List to store the code objects
code_objects = []
# Getting data from the DevGPT Dataset
for file in os.listdir("DevGPT_Dataset"):
try:
with open(os.path.join("DevGPT_Dataset", file), "r") as f:
code_objects += extract_data(json.load(f))
except:
continue
# Find the type of code objects
python_code_objects = [code for code in code_objects if code.is_language("python")]
java_code_objects = [code for code in code_objects if code.is_language("java")]
javascript_code_objects = [code for code in code_objects if code.is_language("javascript")]
# Print the number of code objects
python_total_code = len(python_code_objects)
java_total_code = len(java_code_objects)
javascript_total_code = len(javascript_code_objects)
print(f"Python Code Objects: {python_total_code}")
print(f"Java Code Objects: {java_total_code}")
print(f"Javascript Code Objects: {javascript_total_code}")
# Lint Python Code Objects
print('-' * 50)
print("ChatGPT Python Code Linting")
print(f"Attempting to lint {python_total_code} Python Code Objects")
print('-' * 50)
count = 1
linting_failure = 0
for code in python_code_objects:
print(f"({count}/{python_total_code}) {code.title}")
count += 1
try:
code.lint()
if code.errors is None:
print(f"Failure Linting: {code.title} - {code.errors}")
linting_failure += 1
if 'astroid-error' in code.errors.keys():
print(f"Failure Linting: {code.title} - astroid-error")
linting_failure += 1
except Exception as e:
print(f"Failure Linting: {code.title} - Action Aborted - {e}")
linting_failure += 1
continue
print('-' * 50)
print("ChatGPT Python Code Linted")
print(f"Failure Rate: {linting_failure}/{python_total_code}")
print('-' * 50)
# Write the Python Code Objects to a CSV file
print('-' * 50)
print("ChatGPT Python Code Writing to CSV")
print('-' * 50)
write_python_to_csv(python_code_objects, "ChatGPT")
# Lint Java Code Objects
print('-' * 50)
print("ChatGPT Java Code Linting")
print(f"Attempting to lint {java_total_code} Java Code Objects")
print('-' * 50)
count = 1
linting_failure = 0
for code in java_code_objects:
print(f"({count}/{java_total_code}) {code.title}")
count += 1
try:
code.lint()
except Exception as e:
print(f"Failure Linting: {code.title} - Action Aborted - {e}")
linting_failure += 1
continue
print('-' * 50)
print("ChatGPT Java Code Linted")
print(f"Failure Rate: {linting_failure}/{java_total_code}")
print('-' * 50)
# Write the Java Code Objects to a CSV file
print('-' * 50)
print("ChatGPT Java Code Writing to CSV")
print('-' * 50)
write_java_to_csv(java_code_objects, "ChatGPT")
# Lint Javascript Code Objects
print('-' * 50)
print("ChatGPT Javascript Code Linting")
print(f"Attempting to lint {javascript_total_code} Javascript Code Objects")
print('-' * 50)
count = 1
linting_failure = 0
for code in javascript_code_objects:
print(f"({count}/{javascript_total_code}) {code.title}")
count += 1
try:
code.lint()
except Exception as e:
print(f"Failure Linting: {code.title} - Action Aborted - {e}")
linting_failure += 1
continue
print('-' * 50)
print("ChatGPT Javascript Code Linted")
print(f"Failure Rate: {linting_failure}/{javascript_total_code}")
print('-' * 50)
# Write the Javascript Code Objects to a CSV file
print('-' * 50)
print("ChatGPT Javascript Code Writing to CSV")
print('-' * 50)
write_javascript_to_csv(javascript_code_objects, "ChatGPT")