Example #1
0
 def _notify(self, line: str, record: dict = None):
     """
     Notify concerned entities that a record has been parsed
     :param line: original str
     :param record: newly parsed record
     :return: None
     """
     try:
         if self.bom_event:
             self.bom_event(sender=self,
                            line=line,
                            record=record,
                            state=self._state)
     except AttributeError as aerr:
         LOG.error('Invalid BOM Notification', str(aerr))
     except BaseException as err:
         LOG.exception(err)
Example #2
0
def rank_report(source: dict):
    """
    Compiles, sorts and ouputs the report results
    :param source: dict
    :return:
    """
    try:
        results = {}
        for record in source['records']:
            key = format_key(record)
            if key in results:
                results[key]['part'][NUM_OCCURRENCES] += 1

                results[key]['part'][REFERENCE_DESIGNATORS] = list(
                    set(results[key]['part'][REFERENCE_DESIGNATORS] +
                        record[REFERENCE_DESIGNATORS]))

                results[key][
                    'rank'] = results[key]['part'][NUM_OCCURRENCES] + len(
                        results[key]['part'][REFERENCE_DESIGNATORS])

            else:
                results[key] = {
                    'part':
                    record,
                    'rank':
                    record[NUM_OCCURRENCES] +
                    len(record[REFERENCE_DESIGNATORS])
                }

        output = list(
            sorted(results, key=lambda x: results[x]['rank'], reverse=True))

        cursor = 0

        while cursor < source['report_limit']:
            yield results[output[cursor]]['part']
            cursor += 1
    except (KeyError, BaseException) as err:
        LOG.exception(err)