Skip to content

Commit

Permalink
FEAT: Enable index selector to be used without a parent expected loss…
Browse files Browse the repository at this point in the history
… model.
  • Loading branch information
genedan committed Jan 13, 2024
1 parent 9bbd589 commit 9bf5326
Showing 1 changed file with 22 additions and 31 deletions.
53 changes: 22 additions & 31 deletions faslr/methods/expected_loss.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,6 @@
make_corner_button
)

from faslr.style.triangle import (
PERCENT_STYLE,
RATIO_STYLE
)

from faslr.common import (
AddRemoveButtonWidget
)
Expand Down Expand Up @@ -51,21 +46,17 @@

from PyQt6.QtCore import (
QModelIndex,
QSize,
Qt
)

from PyQt6.QtGui import QStandardItemModel

from PyQt6.QtWidgets import (
QAbstractButton,
QAbstractItemView,
QComboBox,
QHBoxLayout,
QLabel,
QListView,
QStyle,
QStyleOptionHeader,
QTabWidget,
QWidget,
QVBoxLayout
Expand All @@ -86,6 +77,7 @@
ppa_premium_trend['Name'][0]: ppa_premium_trend
}


class ExpectedLossModel(FAbstractTableModel):
def __init__(
self,
Expand All @@ -101,7 +93,6 @@ def __init__(
self.reported_ultimate = fetch_ultimate(triangles[0])
self.paid_ultimate = fetch_ultimate(triangles[1])


self._data = pd.DataFrame({
'Accident Year': self.origin,
'Reported Losses': self.reported,
Expand Down Expand Up @@ -427,7 +418,6 @@ def display_index(

selected_indexes = index_list_view.index_view.selectedIndexes()


if not selected_indexes:
# If user clicks on whitespace below list, do nothing.
if index_list_view.model.rowCount() != 0:
Expand Down Expand Up @@ -555,29 +545,31 @@ def add_index(self) -> None:

idx_df = calculate_index_factors(index=idx_df)

self.parent.parent.parent.selection_model.setData(
index=QModelIndex(),
value=idx_df['Factor'],
role=Qt.ItemDataRole.EditRole
)
# If view belongs to an expected loss model, add a column to the selection model.

column_position = self.parent.parent.parent.selection_model.columnCount()
if self.parent.parent.parent:

self.parent.parent.parent.selection_model.insertColumn(column_position+1)
self.parent.parent.parent.selection_model.layoutChanged.emit()
self.parent.parent.parent.selection_view.hheader.model().insertColumn(column_position + 1)
self.parent.parent.parent.selection_model.setData(
index=QModelIndex(),
value=idx_df['Factor'],
role=Qt.ItemDataRole.EditRole
)

if self.prem_loss == "premium":
header_prefix = "Premium Index:\n"
else:
header_prefix = "Loss Index:\n"
self.parent.parent.parent.selection_view.hheader.setCellLabel(
row=0,
column=9,
label=header_prefix + idx_name
)
column_position = self.parent.parent.parent.selection_model.columnCount()

self.parent.parent.parent.selection_model.insertColumn(column_position+1)
self.parent.parent.parent.selection_model.layoutChanged.emit()
self.parent.parent.parent.selection_view.hheader.model().insertColumn(column_position + 1)

if self.prem_loss == "premium":
header_prefix = "Premium Index:\n"
else:
header_prefix = "Loss Index:\n"
self.parent.parent.parent.selection_view.hheader.setCellLabel(
row=0,
column=9,
label=header_prefix + idx_name
)

def remove_premium_index(self) -> None:

Expand Down Expand Up @@ -681,7 +673,6 @@ def __init__(self):
self.corner_btn = make_corner_button(parent=self)



class ExpectedLossMatrixWidget(QWidget):
def __init__(
self,
Expand Down Expand Up @@ -714,7 +705,7 @@ def __init__(
self.layout.addWidget(self.matrix_view)
self.setLayout(self.layout)

self.selection_box.currentTextChanged.connect(self.update_matrix)
self.selection_box.currentTextChanged.connect(self.update_matrix) # noqa

def update_matrix(self) -> None:

Expand Down

0 comments on commit 9bf5326

Please sign in to comment.