Skip to content

Commit 8caf8f3

Browse files
IMPLEMENTED - plot like the TDD cagetories pie, but for repo instead of author - modify _create_pie_plot_tdd_levels AND FIXED bug with the counting bounds
1 parent e4ed944 commit 8caf8f3

1 file changed

Lines changed: 61 additions & 6 deletions

File tree

src/analysis/analysis.py

Lines changed: 61 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ def _create_avg_commit_size_plot():
129129
_save_plot(plt, "Average Commit Size")
130130

131131

132-
def _create_pie_plot_tdd_levels():
132+
def _create_pie_plot_tdd_author_categories():
133133
# Read data from the author_data csv
134134
author_data = file_utils.read_csv("author_data")
135135

@@ -154,7 +154,7 @@ def _create_pie_plot_tdd_levels():
154154
counters[3] += 1
155155
elif TDD_percent < 90:
156156
counters[4] += 1
157-
elif TDD_percent < 100:
157+
elif TDD_percent <= 100:
158158
counters[5] += 1
159159

160160
# Convert the counters into percentages using a lambda function and map
@@ -177,12 +177,12 @@ def _create_pie_plot_tdd_levels():
177177

178178
# Set the title and specify axis setting
179179
plt.axis('equal')
180-
plt.title("Pie chart showing the percentage of authors using levels of TDD")
180+
plt.title("Pie chart showing levels of TDD usage by authors")
181181
plt.rcParams["figure.figsize"] = [7.5, 4.25]
182182
plt.rcParams["figure.autolayout"] = True
183183

184184
# Save the plot
185-
_save_plot(plt, "TDD Categories")
185+
_save_plot(plt, "TDD Author Categories")
186186

187187

188188
def _create_pie_plot_overall_tdd_raw():
@@ -269,13 +269,69 @@ def _create_pie_overall_tdd_percentage():
269269
# Save the plot
270270
_save_plot(plt, "Overall TDD Percentage")
271271

272+
def _create_pie_plot_tdd_repo_categories():
273+
# Read data from the author_data csv
274+
repo_data = file_utils.read_csv("repo_data")
275+
276+
# Initialize Counters
277+
#10 25 50 70 90 100
278+
counters = [0,0,0,0,0,0]
279+
280+
281+
for repo in repo_data:
282+
# Calculate the percentage of TDD of the author
283+
# we don't count test_during as we want TDD percentage, not before, during and after percentage
284+
TDD_percent = (float(repo['Test Before']) / max(1, float(repo['Test Before']) + float(repo['Test After']))) * 100
285+
286+
# Update the counters array based on this result
287+
if TDD_percent < 10:
288+
counters[0] += 1
289+
elif TDD_percent < 25:
290+
counters[1] += 1
291+
elif TDD_percent < 50:
292+
counters[2] += 1
293+
elif TDD_percent < 70:
294+
counters[3] += 1
295+
elif TDD_percent < 90:
296+
counters[4] += 1
297+
elif TDD_percent <= 100:
298+
counters[5] += 1
299+
300+
# Convert the counters into percentages using a lambda function and map
301+
percentages = list(map(lambda x: x/max(1, len(repo_data))*100, counters))
302+
303+
# Update labels to include percentage values for each slice
304+
labels = ['Non TDD', 'Rarely TDD', 'Occasionally TDD', 'Somewhat TDD', 'Mostly TDD', 'Consistently TDD']
305+
for i in range(len(labels)):
306+
labels[i] = labels[i] + ' - ' + str(round(percentages[i], 1)) + '%'
307+
308+
# Clear any existing plot
309+
plt.clf()
310+
311+
# Plot the pie
312+
colors = ['#225ea8', '#1d91c0', '#41b6c4', '#7fcdbb', '#c7e9b4', '#71cb71']
313+
patches, texts = plt.pie(percentages, colors=colors)
314+
315+
# Plot the legend
316+
plt.legend(patches, labels, loc="upper left")
317+
318+
# Set the title and specify axis setting
319+
plt.axis('equal')
320+
plt.title("Pie chart showing levels of TDD usage seen in repositories")
321+
plt.rcParams["figure.figsize"] = [7.5, 4.25]
322+
plt.rcParams["figure.autolayout"] = True
323+
324+
# Save the plot
325+
_save_plot(plt, "TDD Repo Categories")
326+
272327
def create_plots():
273328
_create_box_plot()
274329
_create_size_impact_plot()
275330
_create_avg_commit_size_plot()
276-
_create_pie_plot_tdd_levels()
331+
_create_pie_plot_tdd_author_categories()
277332
_create_pie_plot_overall_tdd_raw()
278333
_create_pie_overall_tdd_percentage()
334+
_create_pie_plot_tdd_repo_categories()
279335

280336
# REMEMBER TO REMOVE THESE
281337
create_plots()
@@ -285,7 +341,6 @@ def create_plots():
285341
write the adjustments/estimates code in python
286342
287343
todo -
288-
plot like the TDD cagetories pie, but for repo instead of author - modify _create_pie_plot_tdd_levels
289344
290345
bar chart for tdd percentace per langange - ignoring during
291346

0 commit comments

Comments
 (0)