コード例 #1
0
    def __init__(self, observer_catches):
        """
        
        :param observer_catches: Limited use: Used to determine if current catch's Weight Method is 3.
        """
        super().__init__()
        self._logger = logging.getLogger(__name__)

        self._observer_catches = observer_catches

        ####
        # Set up Table CATCH_ADDITIONAL_BASKETS for use with Weight Method 3 catch weight calculations
        ####

        # Until DB Sync is extended to include CATCHES_ADDITIONAL_BASKETS, it's possible this table
        # may not exist. Create it if it's missing
        if not CatchAdditionalBaskets.table_exists():
            CatchAdditionalBaskets.create_table()
            self._logger.info("Observer DB table CatchAdditionalBaskets doesn't exist. Created.")
        else:
            n_records = CatchAdditionalBaskets.select().count()
            self._logger.info(f"Table CatchAdditionalBaskets exists with {n_records} records.")

        self._catch_additional_baskets_view_model = CatchAdditionalBasketsViewModel(
                sort_role='catch_addtl_baskets', sort_reverse=True)

        # For convenience, build a dictionary of CAB_BASKET_TYPEs extracted from LOOKUPS Table.
        self._catch_additional_basket_types = self._get_catch_additional_basket_types_from_lookup_table()

        # Get signal that current catch has changed
        self._observer_catches.catchIdChanged.connect(self._handle_change_in_current_catch)
コード例 #2
0
    def hasWM3BasketData(self):
        """
        :return: True if any weighed or unweighed data for the current catch in Table CATCH_ADDITIONAL_BASKETS.
        """
        if self._current_catch is None:
            self._logger.debug("No catch, no catch additional baskets")
            return False

        try:
            basket_q = CatchAdditionalBaskets.select().where(CatchAdditionalBaskets.catch == self._current_catch.catch)
            self._logger.info(f"Found {basket_q.count()} weighed or unweighed (tallied) catch additional baskets " +
                              f"for Catch ID {self._current_catch.catch}.")
            return basket_q.count() > 0
        except CatchAdditionalBaskets.DoesNotExist:
            self._logger.debug("No catch additional baskets found for Catch ID {self._current_catch.catch}.")
            return False
コード例 #3
0
 def countOfUnweighedCatchAdditionalBaskets(self):
     """
     :return: The number of unweighed catch additional baskets for the current catch.
     """
     if self._current_catch is None:
         self._logger.debug("No catch, no catch additional baskets")
         return 0
     self._logger.debug(f"Current catch ID is {self._current_catch.catch}.")
     try:
         basket_q = CatchAdditionalBaskets.select().where(
                 (CatchAdditionalBaskets.catch == self._current_catch.catch) &
                 (CatchAdditionalBaskets.basket_type == ObserverCatchBaskets.LOOKUP_VALUE_CAB_BASKET_TYPE_UNWEIGHED_FULL))
         self._logger.info(f"Found {basket_q.count()} unweighed (tallied) catch additional baskets " +
                           f"for Catch ID {self._current_catch.catch}.")
         return basket_q.count()
     except CatchAdditionalBaskets.DoesNotExist:
         self._logger.debug("No unweighed catch additional baskets found for Catch ID {self._current_catch.catch.")
         return 0
コード例 #4
0
    def get_WM3_catch_values(self) -> Dict[str, QVariant]:
        """
        Get all the Weight Method 3 information needed to display catch weight and its components.
        
        :return: Values are returned as float or int, not text.
        """
        if self._current_catch is None:
            return {}

        n_weighed_full_baskets = 0
        weighed_full_total_weight = 0.0
        n_weighed_partial_baskets = 0
        weighed_partial_total_weight = 0.0
        n_unweighed_baskets = 0

        baskets_q = CatchAdditionalBaskets.select().where(CatchAdditionalBaskets.catch == self._current_catch.catch)
        for basket in baskets_q:
            if basket.basket_type == ObserverCatchBaskets.LOOKUP_VALUE_CAB_BASKET_TYPE_UNWEIGHED_FULL:
                n_unweighed_baskets += 1
            elif basket.basket_type == ObserverCatchBaskets.LOOKUP_VALUE_CAB_BASKET_TYPE_WEIGHED_PARTIAL:
                n_weighed_partial_baskets += 1
                weighed_partial_total_weight += basket.basket_weight
            elif basket.basket_type == ObserverCatchBaskets.LOOKUP_VALUE_CAB_BASKET_TYPE_WEIGHED_FULL:
                n_weighed_full_baskets += 1
                weighed_full_total_weight += basket.basket_weight
            else:
                self._logger.error(f"Unrecognized catch_type {basket.basket_type}. Ignored.")

        wm3_dict = {
            'N_WEIGHED_FULL_BASKETS': n_weighed_full_baskets,
            'WEIGHED_FULL_TOTAL_WEIGHT': weighed_full_total_weight,
            'N_WEIGHED_PARTIAL_BASKETS': n_weighed_partial_baskets,
            'WEIGHED_PARTIAL_TOTAL_WEIGHT': weighed_partial_total_weight,
            'N_UNWEIGHED_BASKETS': n_unweighed_baskets
        }
        return wm3_dict