def create_classification(self): sess = Database().session() sess.add( DBClassification( created_at=self.created_at, result=self.result, )) sess.commit() sess.close()
def count_predictions(label): """ count all predictions or all predictions associated to a specific label made. :param label: :return: total amount of classifications """ sess = Database().session() if label: rows = sess.query( func.count('*').filter(DBResult.label == "{label}".format( label=label))).scalar() else: rows = sess.query(func.count(DBResult.result_id)).scalar() sess.close() return rows
def calc_accuracies(): """ Calculates the accuracy with which the class was predicted. :param label: the class with which the associated precisions of the classifications are calculated :return: accuracy of associated predictions """ accuracies = {} sess = Database().session() for label in sess.query(DBResult.label): label = list(label)[0] acc_sum = sess.query(func.sum(DBResult.accuracy)).filter( DBResult.label == "{label}".format(label=label)).scalar() accuracies.update({ label: round(acc_sum / DBClassification.count_predictions(label), 2) }) sess.close() return accuracies
def total_predictions(): """ counts the number of predictions of the corresponding classes :return: The amount of predictions belong to each corresponding class """ predictions = {} sess = Database().session() amounts = [] for label in sess.query(DBResult.label): amounts.append(label) sess.close() predictions.update({ list(label)[0]: amount for label, amount in Counter(amounts).items() }) total_amount = reduce(lambda x, y: x + y, Counter(amounts).values()) return predictions, total_amount
print(f'404: File for Remiss {document.remiss_id} not found.') if f is not None: fp = BytesIO(f) FileManager.write_to_filepath(filepath, f) if FileManager.filepath_exists(filepath): fp = FileManager.get_filepath(filepath) else: continue try: list = DocumentParser.extract_list(fp) except (PDFTextExtractionNotAllowed, PDFSyntaxError): print(f'Document for Remiss {document.remiss_id} was not extracted.') continue if not list: print(f'Document for Remiss {document.remiss_id} was not extracted.') continue document.consultee_list = list Database.commit() print(f'Saved {len(list)} organisations for remiss {document.remiss_id}') fp.close() Database.close()