Skip to content

Commit c69cb9a

Browse files
committed
Updated docstrings for ResultMatrix model.
1 parent d2563be commit c69cb9a

File tree

4 files changed

+46
-4
lines changed

4 files changed

+46
-4
lines changed

core/models.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,13 +221,31 @@ def find_fund(self, fund_name):
221221

222222

223223
class ResultMatrix():
224+
"""
225+
Result Matrix stores the overlap comparisons and other details
226+
like the fund which is being compared and the portfolio with
227+
which comparison is made.
228+
229+
Args:
230+
current_portfolio (Portfolio): Portfolio instance to which
231+
comparison is made.
232+
other_fund (Fund): Fund instance which is being compared.
233+
"""
224234
def __init__(self, current_portfolio, other_fund) -> None:
235+
"""
236+
Initialises the ResultMatrix model and generate the
237+
overlap matrix which holds information of overlap of given
238+
fund with each fund in the portfolio.
239+
"""
225240
self.other_fund = other_fund
226241
self.current_portfolio = current_portfolio
227242
self.overlap_matrix = {}
228243
self.__store_overlap()
229244

230245
def __store_overlap(self):
246+
"""
247+
Generates the overlap data.
248+
"""
231249
if not(self.other_fund is None):
232250
for current_fund in self.current_portfolio.get_fund_list():
233251
self.overlap_matrix[
@@ -237,7 +255,22 @@ def __store_overlap(self):
237255
)
238256

239257
def fetch(self):
258+
"""
259+
Returns the overlap matrix.
260+
261+
Returns:
262+
(dict): Matrix containing information on
263+
fund names and corresponding overlap with
264+
the given fund.
265+
"""
240266
return(self.overlap_matrix)
241267

242268
def get_other_fund_name(self):
269+
"""
270+
Returns the name of the fund instance to which
271+
comparison is made.
272+
273+
Returns:
274+
(str): Name of the fund instance.
275+
"""
243276
return(self.other_fund.get_fund_name())

core/utils.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ def create_portfolio(fund_names):
5454

5555
def compare(fund_name, current_portfolio):
5656
"""
57-
Compares fund_name with each Fund instances in the current_portfolio.
57+
Compares the Fund instance corresponding fund_name with
58+
each Fund instances in the current_portfolio.
5859
5960
Args:
6061
fund_name (str): Name of the fund for which overlap
@@ -72,10 +73,19 @@ def compare(fund_name, current_portfolio):
7273

7374

7475
def process_result(result_matrix):
75-
for fund_name, overlap in result_matrix.fetch().items():
76+
"""
77+
Process the Result Matrix instance and output according to the
78+
problem requirements.
79+
80+
Args:
81+
result_matrix (ResultMatrix): Result matrix for a given case.
82+
"""
83+
result_dict = result_matrix.fetch()
84+
other_fund_name = result_matrix.get_other_fund_name()
85+
for fund_name, overlap in result_dict.items():
7686
if overlap > 0:
7787
print(
78-
f"{result_matrix.get_other_fund_name()} {fund_name} {overlap:.2f}%"
88+
f"{other_fund_name} {fund_name} {overlap:.2f}%"
7989
)
8090

8191

portfolio_overlap.tar.gz

14.4 KB
Binary file not shown.

test/test_integration.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,3 @@ def test_getinput_2(self, mock_stdout):
3030
expected_out = f.read()
3131
getinput('test/fixtures/input3.txt')
3232
self.assertEqual(mock_stdout.getvalue(), expected_out)
33-

0 commit comments

Comments
 (0)