Skip to content

Commit 2e7e439

Browse files
added another pie
1 parent 5afb228 commit 2e7e439

1 file changed

Lines changed: 65 additions & 9 deletions

File tree

src/analysis/analysis.py

Lines changed: 65 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
def _save_plot(plot: plt, name: str):
77
file_path = os.path.join(file_utils.CHARTS_PATH, f"{name}.jpg")
8-
plot.savefig(file_path, dpi=300)
8+
plot.savefig(file_path)
99

1010
def _create_size_impact_plot():
1111
# Read data from the repo_data csv
@@ -47,6 +47,7 @@ def _create_size_impact_plot():
4747
plt.ylabel("Percentage of TDD")
4848
plt.title("Repo size and TDD percentage")
4949

50+
# Save the plot
5051
_save_plot(plt, "Size Impact")
5152

5253
def _create_box_plot():
@@ -75,13 +76,16 @@ def _create_box_plot():
7576
# Plot the box plots
7677
boxplt = plt.boxplot([before, after, during], patch_artist=True, tick_labels=["Before", "After", "During"], flierprops= dict(markerfacecolor='coral'))
7778

79+
# Give each bar a color
7880
colors = ['palegreen', 'lightblue', 'lightskyblue']
7981
for patch, color in zip(boxplt['boxes'], colors):
8082
patch.set_facecolor(color)
8183

8284
# Set title and axes labels
8385
plt.ylabel("Percentage")
8486
plt.title("How often a test is created before, after and during implementation")
87+
88+
# Save the plot
8589
_save_plot(plt, "TDD Usage Statistics")
8690

8791

@@ -111,10 +115,12 @@ def _create_avg_commit_size_plot():
111115
# Set title and axes labels
112116
plt.ylabel("Average Commit Size (No. of files)")
113117
plt.title("Average commit size when tests are created \nbefore, after and during implementation")
118+
119+
# Save the plot
114120
_save_plot(plt, "Average Commit Size")
115121

116122

117-
def _create_pie_plot():
123+
def _create_pie_plot_tdd_levels():
118124
# Read data from the author_data csv
119125
author_data = file_utils.read_csv("author_data")
120126

@@ -144,28 +150,78 @@ def _create_pie_plot():
144150
# Convert the counters into percentages using a lambda function and map
145151
percentages = list(map(lambda x: x/max(1, len(author_data))*100, counters))
146152

153+
# Update labels to include percentage values for each slice
147154
labels = ['Non TDD', 'Rarely TDD', 'Occasionally TDD', 'Somewhat TDD', 'Mostly TDD', 'Consistently TDD']
148155
for i in range(len(labels)):
149156
labels[i] = labels[i] + ' - ' + str(round(percentages[i], 0)) + '%'
150157

151158
# Clear any existing plot
152159
plt.clf()
153160

154-
# Set up and plot the pie chart, colors, legend and title
155-
colours = ['#225ea8', '#1d91c0', '#41b6c4', '#7fcdbb', '#c7e9b4', '#71cb71']
156-
plt.rcParams["figure.figsize"] = [7.5, 4.25]
157-
plt.rcParams["figure.autolayout"] = True
158-
patches, texts = plt.pie(percentages, colors=colours)
161+
# Plot the pie
162+
colors = ['#225ea8', '#1d91c0', '#41b6c4', '#7fcdbb', '#c7e9b4', '#71cb71']
163+
patches, texts = plt.pie(percentages, colors=colors)
164+
165+
# Plot the legend
159166
plt.legend(patches, labels, loc="upper left")
167+
168+
# Set the title and specify axis setting
160169
plt.axis('equal')
161170
plt.title("Pie chart showing the percentage of authors using levels of TDD")
171+
plt.rcParams["figure.figsize"] = [7.5, 4.25]
172+
plt.rcParams["figure.autolayout"] = True
173+
174+
# Save the plot
162175
_save_plot(plt, "TDD Categories")
163176

164177

178+
def _create_pie_plot_tdd_overall():
179+
# Read data from the author_data csv
180+
repo_data = file_utils.read_csv("repo_data")
181+
182+
# Initialize Counters
183+
total = 0
184+
data = [0, 0, 0]
185+
186+
for repo in repo_data:
187+
data[0] += int(repo['Test Before'])
188+
data[1] += int(repo['Test After'])
189+
data[2] += int(repo['Test During'])
190+
total += int(repo['Test Before']) + int(repo['Test After']) + int(repo['Test During'])
191+
192+
# Convert the data into percentages using a lambda function and map
193+
percentages = list(map(lambda x: x / max(1, total) * 100, data))
194+
195+
196+
# Update labels to include percentage values for each slice
197+
labels = ['TDD', 'Not TDD', 'Unclear']
198+
for i in range(len(labels)):
199+
labels[i] = labels[i] + ' - ' + str(round(percentages[i], 0)) + '%'
200+
201+
# Clear any existing plot
202+
plt.clf()
203+
204+
# Plot the pie
205+
colors = ['palegreen', 'lightblue', 'lightskyblue']
206+
patches, texts, x = plt.pie(percentages, colors=colors, autopct='%1.1f%%')
207+
208+
# Plot the legend
209+
plt.legend(patches, labels, loc="upper left")
210+
211+
# Set the title and specify axis setting
212+
plt.axis('equal')
213+
plt.title("Overall TDD Percentage (Raw Data)")
214+
plt.rcParams["figure.figsize"] = [7.5, 4.25]
215+
plt.rcParams["figure.autolayout"] = True
216+
217+
# Save the plot
218+
_save_plot(plt, "Overall TDD Usage Raw")
219+
165220
def create_plots():
166221
_create_box_plot()
167222
_create_size_impact_plot()
168223
_create_avg_commit_size_plot()
169-
_create_pie_plot()
224+
_create_pie_plot_tdd_levels()
225+
_create_pie_plot_tdd_overall()
170226

171-
create_plots()
227+
create_plots()

0 commit comments

Comments
 (0)