Skip to content

Commit cd1a713

Browse files
adjustments.py is now complete and has been integrated with analysis.py
1 parent 8bb5a2a commit cd1a713

File tree

2 files changed

+50
-11
lines changed

2 files changed

+50
-11
lines changed

src/analysis/adjustments.py

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,50 @@
11
from src.infrastructure import file_utils
22

3-
def make_adjustments():
4-
pass
3+
def _generate_array(existing_data, new_headers):
4+
# Initialize an empty array for new data to go in
5+
new_data = []
56

6-
# REMOVE THIS CALL
7-
make_adjustments()
7+
for row in existing_data:
8+
# for each existing row, create an array to represent the row from the dictionary
9+
new_row = []
10+
for header in new_headers:
11+
new_row.append(row[header])
12+
13+
# append this row to the new_data array
14+
new_data.append(new_row)
15+
16+
# return the new data array and prepend the headers to this array
17+
return [new_headers] + new_data
18+
19+
20+
def make_adjustments(filename):
21+
existing_data = file_utils.read_csv(filename)
22+
23+
for row in existing_data:
24+
# Calculate the tdd percentage
25+
try:
26+
tdd_percentage = int(row['Test Before']) / (int(row['Test Before']) + int(row['Test After']))
27+
except ZeroDivisionError:
28+
tdd_percentage = 0
29+
30+
# Calculate the adjusted variables
31+
adjusted_test_before = int(row['Test Before']) + (tdd_percentage * int(row['Test During']))
32+
adjusted_test_after = int(row['Test After']) + ((1 - tdd_percentage) * int(row['Test During']))
33+
34+
# Create a new item in the dictionary to store the new data
35+
row['Adjusted Test Before'] = int(adjusted_test_before)
36+
row['Adjusted Test After'] = int(adjusted_test_after)
37+
38+
# Get the headers of the relevant file
39+
headers = []
40+
if filename == 'author_data':
41+
headers = ["Author", "Test Before", "Test After", "Test During"]
42+
elif filename == 'repo_data':
43+
headers = ["Repo Name", "Language", "Commit Count", "Test Before", "Test After", "Test During", "Duration (s)",
44+
"Avg Before Commit Size", "Avg After Commit Size", "Avg During Commit Size", "Avg Commit Size"]
45+
46+
# Generate the new data as a 2D array from the dictionary
47+
new_data = _generate_array(existing_data, headers + ["Adjusted Test Before", "Adjusted Test After"])
48+
49+
# Write this data to a new csv
50+
file_utils.write_csv(new_data, filename+'_adjusted')

src/analysis/analysis.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -360,17 +360,13 @@ def _create_tdd_repo_categories_pie():
360360

361361

362362
def create_plots():
363-
#make_adjustments()
363+
make_adjustments('author_data')
364+
make_adjustments('repo_data')
364365
_create_size_impact_scatter()
365366
_create_tdd_usage_box_plot()
366367
_create_avg_commit_size_bar_graph()
367368
_create_tdd_languages_bar_graph()
368369
_create_raw_tdd_percentage_pie()
369370
_create_overall_tdd_percentage_pie()
370371
_create_tdd_author_categories_pie()
371-
_create_tdd_repo_categories_pie()
372-
373-
'''
374-
todo -
375-
write the adjustments/estimates code in python
376-
'''
372+
_create_tdd_repo_categories_pie()

0 commit comments

Comments
 (0)