Repository navigation
Expand file tree
/
Copy pathanalyzedata.py
More file actions
58 lines (44 loc) · 2.07 KB
/
Copy pathanalyzedata.py
File metadata and controls
58 lines (44 loc) · 2.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
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
import os
from properties import dbpath
from libs.dbmanager import DBManager
from libs.codeanalysis import extract_commit_features
from libs.utils import detect_language
from libs.codequality import get_block_violations
# Connect to database
dbmanager = DBManager(dbpath)
# Create a directory for temporary files
temp_dir = "./temp_files"
os.makedirs(temp_dir, exist_ok=True)
print("\nAnalyzing data")
print("Extracting commit features")
# Get all chatgpt links that relate to commits
for l, link in enumerate(dbmanager.db['links'].find({'MentionedSource': 'commit'}, {'_id': False})):
# Get the commit object
commit = dbmanager.db['commits'].find_one({'URL': link['MentionedURL']})
# Call function to detect the programming language
language, updatedsharing = detect_language(commit)
# If language was identified, save it to db
if language:
dbmanager.update('commits', {'_id': commit['_id']}, {'$set': {'Language': language}})
# If information about generated code blocks was modified (entries from repo: tisztamo/Junior), update the db
if updatedsharing:
commit['ChatgptSharing'][0] = updatedsharing
# Define the query to update ChatgptSharing to db
query = {'$set': {f'ChatgptSharing.{0}': updatedsharing}}
dbmanager.update('commits', {'_id': commit['_id']}, query)
# Call function to extract the analysis features of the commit
features = extract_commit_features(commit, temp_dir)
# Add commit's features to the database
dbmanager.update('commits', {'_id': commit['_id']}, {'$set': {'AnalysisFeatures': features}})
# Add attribute to the local variable of the commit
commit['AnalysisFeatures'] = features
# Call function to calculate the quality violations for every generated code block in the shared conversation link
commitsharing = get_block_violations(commit)
# If quality analysis finished sucessfully, update the db
if commitsharing != -1:
query = {'$set': {f'ChatgptSharing.{0}': commitsharing}}
dbmanager.update('commits', {'_id': commit['_id']}, query)
# Remove the directory with temporary files
os.rmdir(temp_dir)
# Close the DB connection
dbmanager.close()