Skip to content

Commit

Permalink
Traingular and bernoulli uncertainty distributions updates (#1009)
Browse files Browse the repository at this point in the history
Forces the "average" values in the bernoulli and triangular uncertainty distributions to lie exclusively within the range of the minimum and maximum provided values. Exceptions to this lead to an invalidated finish button, forcing users to select a value within the allowable range.
  • Loading branch information
Zoophobus authored Aug 15, 2023
1 parent 4c4c358 commit 30ed32c
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions activity_browser/ui/wizards/uncertainty.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from PySide2 import QtCore, QtGui, QtWidgets
from PySide2.QtCore import Signal, Slot
import numpy as np
from stats_arrays import uncertainty_choices as uc
from stats_arrays import uncertainty_choices as uncertainty
from stats_arrays.distributions import *

from ..figures import SimpleDistributionPlot
Expand Down Expand Up @@ -171,7 +171,7 @@ def __init__(self, parent=None):
box1 = QtWidgets.QGroupBox("Select the uncertainty distribution")
box1.setStyleSheet(style_group_box.border_title)
self.distribution = QtWidgets.QComboBox(box1)
self.distribution.addItems([ud.description for ud in uc.choices])
self.distribution.addItems([ud.description for ud in uncertainty.choices])
self.distribution.currentIndexChanged.connect(self.distribution_selection)
self.registerField("uncertainty type", self.distribution, "currentIndex")
self.pedigree = QtWidgets.QPushButton("Use pedigree")
Expand Down Expand Up @@ -339,7 +339,7 @@ def distribution_selection(self):
See https://stats-arrays.readthedocs.io/en/latest/index.html for which
fields to show and hide.
"""
self.dist = uc.id_dict[self.distribution.currentIndex()]
self.dist = uncertainty.id_dict[self.distribution.currentIndex()]

# Huge if/elif tree to ensure the correct fields are shown.
if self.dist.id in {0, 1}:
Expand All @@ -359,19 +359,24 @@ def distribution_selection(self):
self.special_distribution_handling()
self.generate_plot()

@property
def active_fields(self) -> tuple:
"""Returns anywhere from 0 to 3 fields"""
def completed_active_fields(self) -> bool:
"""Returns a boolean value based on the distribution id.
If the distribution contains an average, minimum and maximum this forces the
average to exist exclusively within these bounds"""
completed = False
if self.dist.id in {0, 1}:
return ()
completed = True
elif self.dist.id in {2, 3}:
return self.loc, self.scale
completed = all([field.hasAcceptableInput() and field.text() for field in (self.loc, self.scale)])
elif self.dist.id in {4, 7}:
return self.minimum, self.maximum
completed = all([field.hasAcceptableInput() and field.text() for field in (self.minimum, self.maximum)])
elif self.dist.id in {5, 6}:
return self.loc, self.minimum, self.maximum
completed = all([field.hasAcceptableInput() and field.text() for field in (self.minimum, self.maximum,
self.loc)]) and (float(self.minimum.text()) < float(self.loc.text()) < float(self.maximum.text()))
elif self.dist.id in {8, 9, 10, 11, 12}:
return self.loc, self.scale, self.shape
completed = all([field.hasAcceptableInput() and field.text() for field in (self.scale, self.shape,
self.loc)])
return completed

@Slot(name="locToMean")
def balance_mean_with_loc(self):
Expand Down Expand Up @@ -424,10 +429,7 @@ def generate_plot(self) -> None:
Also tests if all of the visible QLineEdit fields have valid values.
"""
self.complete = all(
(field.hasAcceptableInput() and field.text())
for field in self.active_fields
)
self.complete = self.completed_active_fields()
no_dist = self.dist.id in {UndefinedUncertainty.id, NoUncertainty.id}
if self.complete or no_dist:
array = self.dist.from_dicts(self.wizard().uncertainty_info)
Expand Down

0 comments on commit 30ed32c

Please sign in to comment.