コード例 #1
0
    def setData(self, data_name, data_val):
        """
        Set misc data to the DB - should do this for all properties instead of individual pyqtSlots...
        :return:
        """
        if self._current_trip is None:
            self._logger.warning('Attempt to set data with null current trip.')
            return

        data_name = data_name.lower()
        if data_name == 'partial_trip':
            self._current_trip.partial_trip = 'T' if data_val else 'F'
        elif data_name == 'fishing_days_count':
            self._current_trip.fishing_days_count = int(
                data_val) if data_val else None
        elif data_name == 'logbook_type':
            logbook_value = Lookups.get(
                (Lookups.lookup_type == 'VESSEL_LOGBOOK_NAME')
                & (Lookups.description == data_val)).lookup_value
            self._current_trip.logbook_type = logbook_value
            # data_val = logbook_value
        elif data_name == 'logbook_number':
            self._current_trip.logbook_number = data_val
        elif data_name == 'fish_processed':
            self._current_trip.fish_processed = data_val
        elif data_name == 'notes':
            self._current_trip.notes = data_val
        else:
            self._logger.warning(
                'Attempt to set unknown data name: {}'.format(data_name))
            return
        self._set_cur_prop(data_name, data_val)
        self._current_trip.save()

        logging.debug('Set {} to {}'.format(data_name, data_val))
コード例 #2
0
 def getData(self, data_name):
     """
     Shortcut to get data from the DB that doesn't deserve its own property
     (Note, tried to use a dict to simplify this, but DB cursors were not updating)
     :return: Value found in DB
     """
     if self._current_trip is None:
         self._logger.warning('Attempt to get data with null current trip.')
         return None
     data_name = data_name.lower()
     if data_name == 'partial_trip':
         return True if self._current_trip.partial_trip == 'T' else False
     elif data_name == 'fishing_days_count':
         return self._current_trip.fishing_days_count
     elif data_name == 'logbook_type':
         try:
             logbook_value = self._current_trip.logbook_type
             logbook_desc = Lookups.get(
                 (Lookups.lookup_type == 'VESSEL_LOGBOOK_NAME')
                 & (Lookups.lookup_value == logbook_value)).description
             return logbook_desc
         except Lookups.DoesNotExist:
             return None
     elif data_name == 'logbook_number':
         return self._current_trip.logbook_number
     elif data_name == 'fish_processed':
         return self._current_trip.fish_processed
     elif data_name == 'notes':
         return self._current_trip.notes
     else:
         self._logger.warning(
             'Attempt to get unknown data name: {}'.format(data_name))
         return None
コード例 #3
0
 def _get_fishery_ID(self, fishery_name):
     """
     Lookup up fishery ID by fishery_name
     """
     try:
         return Lookups.get((Lookups.lookup_type == 'FISHERY') & (
             Lookups.description == fishery_name)).lookup_value
     except Lookups.DoesNotExist as e:
         self._logger.error(str(e))
     return None
コード例 #4
0
    def lookup_fisheries(fisheries_str):
        """
        Given fisheries, convert to list and return list of ID's from LOOKUPS
        @param fisheries_str: e.g. '15,16'
        @return: e.g. [608, 688]
        """
        found_ids = []
        try:
            fishery_ids = fisheries_str.strip().replace(' ', '').split(',')
            for fish in fishery_ids:
                fish_id = Lookups.get((Lookups.lookup_type == 'FISHERY') & (
                    Lookups.lookup_value == fish.strip())).lookup
                found_ids.append(fish_id)
            return found_ids

        except Lookups.DoesNotExist:
            # noinspection PyUnboundLocalVariable
            logging.error('*** Unable to look up fishery {} in group {} '
                          '(does not exist, check db.)'.format(
                              fish, fisheries_str))
コード例 #5
0
    def lookup_geartypes(geartypes_str):
        """
        Given gear types, convert to list and return list of ID's from LOOKUPS
        @param geartypes_str: e.g. '15,16'
        @return: e.g. [608, 688]
        """
        found_ids = []
        try:
            gear_ids = geartypes_str.strip().replace(' ', '').split(',')
            for geartype in gear_ids:
                gear_id = Lookups.get(
                    ((Lookups.lookup_type == 'FG_GEAR_TYPE')
                     | (Lookups.lookup_type == 'TRAWL_GEAR_TYPE'))
                    & (Lookups.lookup_value == geartype.strip())).lookup
                found_ids.append(gear_id)
            return found_ids

        except Lookups.DoesNotExist:
            # noinspection PyUnboundLocalVariable
            logging.error('*** Unable to look up gear type {} in group {} '
                          '(does not exist, check db.)'.format(
                              geartype, geartypes_str))
コード例 #6
0
    def lookup_protocols(protocols_str):
        """
        Given protocols, convert to list and return list of ID's
        @param protocols_str: e.g. 'FL,WS'
        @return: e.g. [8, 19]
        """
        found_ids = []
        try:
            prot_abbrevs = protocols_str.strip().replace(' ', '').split(',')
            for pa in prot_abbrevs:
                prot_id = Lookups.get((Lookups.lookup_type == 'PROTOCOL') & (
                    Lookups.lookup_value == pa.strip())).lookup
                found_ids.append(prot_id)
            return found_ids

        except Lookups.DoesNotExist:
            # noinspection PyUnboundLocalVariable
            logging.error('*** Unable to look up protocol {} in group {} '
                          '(does not exist, check spreadsheet.)'.format(
                              pa, protocols_str))
        except Exception as e:
            logging.error(f'{e}')
コード例 #7
0
 def _get_fishery_by_ID(fishery_id):
     try:
         return Lookups.get((Lookups.lookup_type == 'FISHERY') & (
             Lookups.lookup_value == fishery_id)).description
     except Lookups.DoesNotExist as e:
         logging.error(e)