Skip to content

Commit

Permalink
refactor even more
Browse files Browse the repository at this point in the history
  • Loading branch information
kwypchlo committed Apr 17, 2018
1 parent 09e33db commit f882c57
Showing 1 changed file with 10 additions and 14 deletions.
24 changes: 10 additions & 14 deletions src/cr/cube/measures/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,19 @@ def prune(self):
def data(self):
'''Return table index by margin.'''
if self.cube.has_mr:
return self._mr_index(self.weighted)
return self._mr_index()

margin = (
self.cube.margin(axis=0, weighted=self.weighted, prune=self.prune) /
self.cube.margin(weighted=self.weighted, prune=self.prune)
)
props = self.cube.proportions(axis=1, weighted=self.weighted, prune=self.prune)
proportions = self.cube.proportions(axis=1, weighted=self.weighted, prune=self.prune)

return props / margin
return proportions / margin

def _mr_index(self, weighted):
def _mr_index(self):
# mr by mr
if self.cube.mr_dim_ind == (0, 1):
if len(self.cube.dimensions) == 2 and self.cube.mr_dim_ind == (0, 1):
col_proportions = self.cube.proportions(axis=0,
weighted=self.weighted,
prune=self.prune)
Expand All @@ -55,15 +55,11 @@ def _mr_index(self, weighted):
# mr by cat and cat by mr
if self.cube.mr_dim_ind == 0 or self.cube.mr_dim_ind == 1:
axis = self.cube.mr_dim_ind
proportions = self.cube.proportions(axis=axis,
weighted=weighted,
prune=self.prune)
mr_margin = self.cube.margin(axis=1 - axis,
weighted=self.weighted,
prune=self.prune)
cell_margin = self.cube.margin(weighted=self.weighted,
prune=self.prune)
margin = mr_margin / cell_margin
margin = (
self.cube.margin(axis=1 - axis, weighted=self.weighted, prune=self.prune) /
self.cube.margin(weighted=self.weighted, prune=self.prune)
)
proportions = self.cube.proportions(axis=axis, weighted=self.weighted, prune=self.prune)
if self.cube.mr_dim_ind == 0:
margin = margin[:, np.newaxis] # pivot
return proportions / margin
Expand Down

0 comments on commit f882c57

Please sign in to comment.