-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
82 lines (64 loc) · 3.21 KB
/
main.py
File metadata and controls
82 lines (64 loc) · 3.21 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
import argparse
import json
import os
from datetime import datetime, timedelta
from build.code_quality_visualizer import plot_repo_code_quality_fast
from build.utils import clone_repository
from build.local_repository_extractor import get_and_insert_local_data
from build.remote_repository_extractor import get_and_insert_remote_data
from build.database_handler import initialise_database, get_ocel_data
from build.contribution_process_miner import divide_event_log_at, split_OCEL_at_guideline_changes, flatten_ocel2, visualise_xes_as
def main(repo_url="https://github.com/matplotlib/matplotlib", **kwargs):
# =============================================
# Set-Up
# =============================================
# Convert repo URL to path by cloning repo to temporary dictionary
api_url = repo_url.replace("github.com", "api.github.com/repos")
collection = repo_url.split("/")[-1]
# Setting different timeperiod
from_date = (datetime.today() - timedelta(days=5*365)).replace(day=1, month=1)
to_date = datetime.today() - timedelta(days=1)
# Select supported file types your code quality analyser
file_types = [".py"]
if not os.path.exists(f"../tmp/{collection}"):
tmp_path = os.path.abspath("../tmp")
repo_path = clone_repository(repo_url, temp_dir=tmp_path)
else:
repo_path = os.path.abspath(f"../tmp/{collection}")
if not os.path.exists(repo_path):
raise Exception(f"Repository at {repo_path} does not exist")
initialise_database(repo_path)
# =========================================================
# RQ1: Creation of OCEL
# =========================================================
# Go through all commits in the given time period
get_and_insert_local_data(repo_path, from_date, to_date, file_types, False)
get_and_insert_remote_data(api_url, repo_path)
path = get_ocel_data(collection)
with open(path) as f:
ocel = json.load(f)
# =========================================================
# RQ2: Code Quality Analysis and Visualisation
# =========================================================
plot_repo_code_quality_fast(collection)
# =========================================================
# RQ3: Contribution Guidelines Analysis and Visualisation
# =========================================================
flat_event_log = flatten_ocel2(ocel, object_type="pull_request", collection=collection)
visualise_xes_as("petri_net", flat_event_log, collection=collection)
if flat_event_log:
before_log, after_log = divide_event_log_at(datetime(2025, 7, 7, 15, 0).replace(tzinfo=None), flat_event_log)
visualise_xes_as("petri_net", before_log, collection=collection)
visualise_xes_as("petri_net", after_log, collection=collection)
else:
print("ERROR: Flattened event log is empty")
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument(
"--repo_url",
type=str,
default='https://github.com/matplotlib/matplotlib',
help="URL of the GitHub repository to analyze (default: https://github.com/matplotlib/matplotlib)"
)
args = parser.parse_args()
main(repo_url=args.repo_url)