-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreviewer_iface.py
180 lines (151 loc) · 6.66 KB
/
reviewer_iface.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
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
import pandas as pd
import gradio as gr
def get_BFCs(results_df):
df = results_df[['id', 'commit_hash', 'is_bug_fixing_commit']]
df = df.rename(columns={'commit_hash': 'hash', 'is_bug_fixing_commit': 'BFC'})
df['hash'] = df['hash'].str.slice(0, 10)
return df
results_A = pd.read_csv('130_results_michel.csv')
results_B = pd.read_csv('130_results_abhishek.csv')
results_C = pd.read_csv('130_results_david.csv')
BFCs_A = get_BFCs(results_A)
BFCs_B = get_BFCs(results_B)
BFCs_C = get_BFCs(results_C)
BFCs = pd.merge(BFCs_A, BFCs_B, on='hash', how='inner', suffixes=('A', 'B'))
BFCs = pd.merge(BFCs, BFCs_C, on='hash', how='inner', suffixes=('', 'C'))
BFCs = BFCs[['hash', 'BFCA', 'BFCB', 'BFC']]
BFCs = BFCs.rename(columns={'BFC': 'BFCC'})
# Manage reviewer file
review_cols = ['hash', 'reviewer', 'bfc', 'comment', 'understanding']
review_filename = '130_review.csv'
class ReviewsDF():
"""Class for storing reviews of annotations (as a dataframe)"""
def __init__(self, filename):
try:
self.df = pd.read_csv(filename)
except FileNotFoundError:
self.df = pd.DataFrame(columns=review_cols)
def update(self, data):
if any(self.df['hash'] == data['hash']):
self.df.loc[self.df['hash'] == data['hash'], data.keys()] = data.values()
else:
self.df.loc[len(self.df)] = data
def get(self, hash):
result_df = self.df[self.df['hash'] == hash]
if len(result_df) == 0:
results = None
else:
results = result_df.iloc[0].to_dict()
return results
def get_values(self, hash):
review = self.get(hash)
if review is None:
text = ""
bfc = None
understanding = None
else:
text = review['comment']
bfc = review['bfc']
understanding = review['understanding']
return text, bfc, understanding
def save(self, filename):
self.df.to_csv(filename, index=False)
BFCs_R = ReviewsDF(review_filename)
def get_annotation(df, hash):
"""Produce markdown for the annotation of a given short hash
in the annotation dataframe
"""
rows = df.loc[df['commit_hash'].str.startswith(hash)]
row = rows.iloc[0].to_dict()
hash_long = row['commit_hash']
link = f"https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?h=v6.7&id={hash_long}"
is_bfc = row['is_bug_fixing_commit']
is_obvious = row['is_obvious_bug']
is_safety = row['is_safety_related']
comment = row['comment']
visited = row['link_visited']
result = (f"[{hash}]({link})\n* bfc: {is_bfc}\n* obvious: {is_obvious}\n"
f"* safety: {is_safety}\n* visited: {visited}\n"
f"* comment: {comment}")
return result
with gr.Blocks() as ui:
with gr.Row():
filter_ddw = gr.Dropdown(label="Select commits",
choices=[("All", "all"),
("All annotators equal", "all-equal"),
("Any annotator different", "any-dif"),
("Annotators A, B different", "ab-dif"),
("Annotators B, C different", "bc-dif"),
("Annotators A, C different", "ac-dif")],
value="all")
search_txt = gr.Textbox(label="Search commit")
count_md = gr.Markdown(f"Commits: {len(BFCs.index)}")
bfcs_df = gr.Dataframe(value=BFCs, height=300)
with gr.Row():
A_md = gr.Markdown()
B_md = gr.Markdown()
C_md = gr.Markdown()
with gr.Row():
R_txt = gr.Textbox(label="Comment by reviewer",
lines=5, interactive=False)
with gr.Column():
hash_txt = gr.Textbox(label="Selected hash", interactive=False)
Rbfc_dd = gr.Dropdown(label="Bug fixing commit",
choices=[("True", True), ("False", False)],
interactive=False)
Runderstd_dd = gr.Dropdown(label="All understand the commit the same way",
choices=[("True", True), ("False", False)],
interactive=False)
R_btn = gr.Button("Save review", interactive=False)
@filter_ddw.change(inputs=[filter_ddw], outputs=[bfcs_df, count_md])
def filter_records(choice):
if choice == "all":
df = BFCs
elif choice == "all-equal":
df = BFCs.query("(BFCA == BFCB) and (BFCB == BFCC)")
elif choice == "any-dif":
df = BFCs.query("(BFCA != BFCB) or (BFCB != BFCC)")
elif choice == "ab-dif":
df = BFCs.query("BFCA != BFCB")
elif choice == "bc-dif":
df = BFCs.query("BFCB != BFCC")
elif choice == "ac-dif":
df = BFCs.query("BFCA != BFCC")
count = len(df.index)
return df, f"Commits: {count}"
@search_txt.change(inputs=[search_txt], outputs=[bfcs_df, count_md])
def find_record(hash):
df = BFCs[BFCs['hash'].str.startswith(hash)]
count = len(df.index)
return df, f"Commits: {count}"
def select_commit(event: gr.SelectData, bfcs):
# print(event.index, event.target, event.value, bfcs)
row = bfcs.iloc[event.index[0]]
hash = row['hash']
annot_A = get_annotation(results_A, hash)
annot_B = get_annotation(results_B, hash)
annot_C = get_annotation(results_C, hash)
text, bfc, understanding = BFCs_R.get_values(hash)
return (hash,
"**Michel**\n\n" + annot_A, "**Abishek**\n\n" + annot_B, "**David**\n\n" + annot_C,
gr.update(interactive=True, value=text),
gr.update(interactive=True, value=bfc),
gr.update(interactive=True, value=understanding))
bfcs_df.select(select_commit, inputs=[bfcs_df],
outputs=[hash_txt, A_md, B_md, C_md, R_txt, Rbfc_dd, Runderstd_dd])
@R_btn.click(inputs=[hash_txt, R_txt, Rbfc_dd, Runderstd_dd], outputs=[R_btn])
def update_review(hash, review, bfc, understanding):
BFCs_R.update({'hash': hash,
'reviewer': 'jesus',
'bfc': bfc,
'comment': review,
'understanding': understanding})
BFCs_R.save(review_filename)
return gr.update(interactive=False)
def review_changed():
return gr.update(interactive=True)
R_txt.change(review_changed, inputs=[], outputs=[R_btn])
Rbfc_dd.change(review_changed, inputs=[], outputs=[R_btn])
# port = 10020
# ui.launch(server_port=port)
ui.launch()