-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
106 lines (73 loc) · 3.08 KB
/
main.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
#! /usr/bin/env python3
__author__ = 'Pranav Marla'
from collections import OrderedDict
from datetime import date, datetime
import json
import lib
input_file_path = lib.parse_command_line_args()
sprints, id_to_sprint_dict, stories, id_to_story_dict = lib.load_input_data(input_file_path)
# Populate list of children
lib.populate_children_from_ids(stories, id_to_story_dict)
#! DEBUG
# print('Stories, after populating kids, before normalizing:\n')
# for story in stories:
# print('\t{}\n'.format(story))
# print()
# Normalize stories
lib.normalize_stories(stories)
#! DEBUG
# print('Stories, after normalizing, before sorting:\n')
# for story in stories:
# print('\t{}\n'.format(story))
# print()
# Sort stories
lib.sort_stories(stories)
#! DEBUG
# print('Stories, after sorting:')
# for story in stories:
# print(repr(story))
# print('\t{}'.format(story))
# print()
# Slot stories
remaining_stories = lib.slot_stories(stories, sprints, id_to_sprint_dict)
print('Sprints, after slotting in stories:')
for sprint in sprints:
print('-------------')
print('Sprint {}:\tCapacity remaining: {}/{}\n'.format(sprint.id, sprint.available_capacity, sprint.total_capacity))
for story in sprint.stories:
print(story)
print()
if sprint.assignee_total_capacities:
print('\t-------------\n')
print('\tAssignee Workload:')
for assignee, assignee_remaining_capacity in sprint.assignee_available_capacities.items():
assignee_total_capacity = sprint.assignee_total_capacities[assignee]
print('\t\t{}:\t{}/{}'.format(assignee, assignee_total_capacity - assignee_remaining_capacity, assignee_total_capacity))
print()
print('-------------\n')
if remaining_stories:
print('The following stories could not be slotted into any sprint:')
for story in remaining_stories:
print(story)
else:
print('All stories were successfully slotted into sprints!')
print()
#! DEBUG
# print('Stories, after slotting:')
# for story in stories:
# print(repr(story))
# print('\t{}'.format(story))
# print()
# Create a more compact, consistent representation of the results, for easy comparison, and save to output JSON file.
# Ensure that, given the same input, the same output is consistently generated!
output_dict = OrderedDict()
for sprint in sprints:
sprint_dict = output_dict[sprint.id] = OrderedDict()
sprint_dict['Stories'] = [story.id for story in sprint.stories]
sprint_assignees_dict = sprint_dict['Assignee Workload'] = OrderedDict()
for assignee, assignee_remaining_capacity in sprint.assignee_available_capacities.items():
assignee_total_capacity = sprint.assignee_total_capacities[assignee]
sprint_assignees_dict[assignee] = sprint.assignee_total_capacities[assignee] - assignee_remaining_capacity
output_dict['Remaining'] = [story.id for story in remaining_stories]
with open('output.json', 'w') as output_file:
output_file.write(json.dumps(output_dict, indent=4))