Skip to content

Commit 3b93e30

Browse files
Refined graph formatting
1 parent cd1a713 commit 3b93e30

File tree

1 file changed

+33
-24
lines changed

1 file changed

+33
-24
lines changed

src/analysis/analysis.py

Lines changed: 33 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -214,33 +214,32 @@ def _create_raw_tdd_percentage_pie():
214214

215215
# Plot the pie
216216
colors = ['palegreen', 'lightblue', 'lightskyblue']
217-
patches, texts, x = plt.pie(percentages, colors=colors, autopct='%1.1f%%')
217+
patches, texts, x = plt.pie(percentages, colors=colors, autopct='%1.1f%%', radius=1.5)
218218

219219
# Plot the legend
220-
plt.legend(patches, labels, loc="upper left")
220+
plt.legend(patches, labels, loc='upper center', bbox_to_anchor=(0.5, -0.001), ncol=3)
221221

222222
# Set the title and specify axis setting
223223
plt.axis('equal')
224224
plt.title("Overall TDD Percentage (Raw Data)")
225-
plt.rcParams["figure.figsize"] = [7.5, 4.25]
226225
plt.rcParams["figure.autolayout"] = True
227226

228227
# Save the plot
229-
_save_plot(plt, "5 - Raw TDD Percentage")
228+
_save_plot(plt, "5 - Overall TDD Percentage (Raw Data)")
230229

231230

232231
def _create_overall_tdd_percentage_pie():
233232
# Read data from the author_data csv
234-
repo_data = file_utils.read_csv("repo_data")
233+
repo_data = file_utils.read_csv("repo_data_adjusted")
235234

236235
# Initialize Counters
237236
total = 0
238237
data = [0, 0]
239238

240239
for repo in repo_data:
241-
data[0] += int(repo['Test Before'])
242-
data[1] += int(repo['Test After'])
243-
total += int(repo['Test Before']) + int(repo['Test After'])
240+
data[0] += int(repo['Adjusted Test Before'])
241+
data[1] += int(repo['Adjusted Test After'])
242+
total += int(repo['Adjusted Test Before']) + int(repo['Adjusted Test After'])
244243

245244
# Convert the data into percentages using a lambda function and map
246245
percentages = list(map(lambda x: x / max(1, total) * 100, data))
@@ -249,26 +248,25 @@ def _create_overall_tdd_percentage_pie():
249248
# Update labels to include percentage values for each slice
250249
labels = ['TDD', 'Not TDD']
251250
for i in range(len(labels)):
252-
labels[i] = labels[i] + ' - ' + str(round(percentages[i], 1)) + '%'
251+
labels[i] = labels[i] + ' - ' + str(round(percentages[i], 1)) + '%, ' f"{data[i]:,}" + ' repos'
253252

254253
# Clear any existing plot
255254
plt.clf()
256255

257256
# Plot the pie
258257
colors = ['palegreen', 'lightblue']
259-
patches, texts, x = plt.pie(percentages, colors=colors, autopct='%1.1f%%')
258+
patches, texts, x = plt.pie(percentages, colors=colors, autopct='%1.1f%%', radius=2)
260259

261260
# Plot the legend
262-
plt.legend(patches, labels, loc="upper left")
261+
plt.legend(patches, labels, loc='upper center', bbox_to_anchor=(0.5, -0.001), ncol=2)
263262

264263
# Set the title and specify axis setting
265264
plt.axis('equal')
266-
plt.title("Overall TDD Percentage")
267-
plt.rcParams["figure.figsize"] = [7.5, 4.25]
265+
plt.title("Overall TDD Percentage (Adjusted Data)")
268266
plt.rcParams["figure.autolayout"] = True
269267

270268
# Save the plot
271-
_save_plot(plt, "6 - Overall TDD Percentage")
269+
_save_plot(plt, "6 - Overall TDD Percentage (Adjusted Data)")
272270

273271

274272
def _create_tdd_author_categories_pie():
@@ -300,15 +298,14 @@ def _create_tdd_author_categories_pie():
300298

301299
# Plot the pie
302300
colors = ['#225ea8', '#1d91c0', '#41b6c4', '#7fcdbb', '#c7e9b4', '#71cb71']
303-
patches, texts = plt.pie(percentages, colors=colors)
301+
patches, texts = plt.pie(percentages, colors=colors, radius=2)
304302

305303
# Plot the legend
306-
plt.legend(patches, labels, loc="upper left")
304+
plt.legend(patches, labels, loc='upper center', bbox_to_anchor=(0.5, -0.001))
307305

308306
# Set the title and specify axis setting
309307
plt.axis('equal')
310308
plt.title("Pie chart showing levels of TDD usage by authors")
311-
plt.rcParams["figure.figsize"] = [7.5, 4.25]
312309
plt.rcParams["figure.autolayout"] = True
313310

314311
# Save the plot
@@ -322,37 +319,47 @@ def _create_tdd_repo_categories_pie():
322319
# Initialize Counters
323320
#10 25 50 70 90 100
324321
counters = [0,0,0,0,0,0]
322+
total_commit_count = [0,0,0,0,0,0]
325323

326324
for repo in repo_data:
327325
# Calculate the percentage of TDD of the author
328326
# we don't count test_during as we want TDD percentage, not before, during and after percentage
329327
tdd_percentage = (float(repo['Test Before']) / max(1, float(repo['Test Before']) + float(repo['Test After']))) * 100
330328

331-
# Update the counters array based on this result
332-
counters[_get_category_index(tdd_percentage)] += 1
329+
# Update the counter arrays based on this result
330+
index = _get_category_index(tdd_percentage)
331+
counters[index] += 1
332+
total_commit_count[index] += int(repo['Commit Count'])
333+
333334

334335
# Convert the counters into percentages using a lambda function and map
335336
percentages = list(map(lambda x: x/max(1, len(repo_data))*100, counters))
336337

338+
# Average the commit count array
339+
average_commit_count = []
340+
for i in range(len(counters)):
341+
average_commit_count.append(round(total_commit_count[i] / counters[i], 1))
342+
343+
print(average_commit_count)
344+
337345
# Update labels to include percentage values for each slice
338346
labels = ['Non TDD', 'Rarely TDD', 'Occasionally TDD', 'Somewhat TDD', 'Mostly TDD', 'Consistently TDD']
339347
for i in range(len(labels)):
340-
labels[i] = labels[i] + ' - ' + str(round(percentages[i], 1)) + '%'
348+
labels[i] = labels[i] + ' - ' + str(round(percentages[i], 1)) + '%, Average Commit Count - ' + f"{average_commit_count[i]:,}"
341349

342350
# Clear any existing plot
343351
plt.clf()
344352

345353
# Plot the pie
346354
colors = ['#225ea8', '#1d91c0', '#41b6c4', '#7fcdbb', '#c7e9b4', '#71cb71']
347-
patches, texts = plt.pie(percentages, colors=colors)
355+
patches, texts = plt.pie(percentages, colors=colors, radius=2)
348356

349357
# Plot the legend
350-
plt.legend(patches, labels, loc="upper left")
358+
plt.legend(patches, labels, loc='upper center', bbox_to_anchor=(0.5, -0.001))
351359

352360
# Set the title and specify axis setting
353361
plt.axis('equal')
354362
plt.title("Pie chart showing levels of TDD usage seen in repositories")
355-
plt.rcParams["figure.figsize"] = [7.5, 4.25]
356363
plt.rcParams["figure.autolayout"] = True
357364

358365
# Save the plot
@@ -369,4 +376,6 @@ def create_plots():
369376
_create_raw_tdd_percentage_pie()
370377
_create_overall_tdd_percentage_pie()
371378
_create_tdd_author_categories_pie()
372-
_create_tdd_repo_categories_pie()
379+
_create_tdd_repo_categories_pie()
380+
381+
create_plots()

0 commit comments

Comments
 (0)