Skip to content

Commit

Permalink
FEAT: Begin deprecation of old index matrix functions.
Browse files Browse the repository at this point in the history
  • Loading branch information
genedan committed Jan 10, 2025
1 parent a182446 commit 2bbcaed
Showing 1 changed file with 58 additions and 43 deletions.
101 changes: 58 additions & 43 deletions faslr/index/index_matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,41 +32,41 @@
from pandas import DataFrame


def relative_index(
base_yr: int,
years: list,
index: list
) -> dict:
idx = years.index(base_yr)
res = {}
for x in range(len(years)):
if years[x] < base_yr:
adj = float(np.array(index[x+1:idx + 1]).prod()) ** - 1
else:
adj = np.array(index[idx + 1:x + 1]).prod()
res[str(years[x])] = adj
return res


def index_matrix(
years: list,
index: list
) -> DataFrame:

d: list = [] # holds the data used to initialize the resulting dataframe
for year in years:
d += [relative_index(
base_yr=year,
years=years,
index=index
)]

df_res: DataFrame = pd.DataFrame(
data=d,
index=years
)

return df_res
# def relative_index(
# base_yr: int,
# years: list,
# index: list
# ) -> dict:
# idx = years.index(base_yr)
# res = {}
# for x in range(len(years)):
# if years[x] < base_yr:
# adj = float(np.array(index[x+1:idx + 1]).prod()) ** - 1
# else:
# adj = np.array(index[idx + 1:x + 1]).prod()
# res[str(years[x])] = adj
# return res
#
#
# def index_matrix(
# years: list,
# index: list
# ) -> DataFrame:
#
# d: list = [] # holds the data used to initialize the resulting dataframe
# for year in years:
# d += [relative_index(
# base_yr=year,
# years=years,
# index=index
# )]
#
# df_res: DataFrame = pd.DataFrame(
# data=d,
# index=years
# )
#
# return df_res

class IndexMatrixModel(FAbstractTableModel):
def __init__(
Expand All @@ -75,7 +75,13 @@ def __init__(
):
super().__init__()

self._data = matrix
if not (matrix is None):

self.matrix = matrix

else:

self._data = pd.DataFrame()

def data(self, index: QModelIndex, role: int = ...) -> typing.Any:

Expand Down Expand Up @@ -104,6 +110,21 @@ def headerData(
if qt_orientation == Qt.Orientation.Vertical:
return str(self._data.index[p_int])

def setData(
self,
index: QModelIndex,
value: typing.Any,
role: int = ...
) -> bool:

if role == Qt.ItemDataRole.EditRole:

self._data = value

self.layoutChanged.emit()

return True

class IndexMatrixView(FTableView):
def __init__(self):
super().__init__()
Expand All @@ -117,13 +138,7 @@ def __init__(
):
super().__init__()

if matrix:

self.matrix = matrix

else:

self.matrix = pd.DataFrame()
self.matrix = matrix

self.layout = QVBoxLayout()

Expand Down

0 comments on commit 2bbcaed

Please sign in to comment.