Exemple #1
0
    def __year_match(self, t1, t2, tolerance_years=0):
        """
        Extracts and compares two years.
        Possible inputs: 31/12/2005, 2008
        :param t1: record from file containing ["date"] field
        :param t2: record from file containing ["date"] field
        :param tolerance_years: tolerate margin in years
        :return: are dates equal?
        """
        y1 = ExtractionUtils.parse_date(t1.get("date")).get("year")
        y2 = ExtractionUtils.parse_date(t2.get("date")).get("year")

        return ExtractionUtils.date_equals(y1, y2, tolerance_years)
Exemple #2
0
    def __value_match(self, t1, t2, threshold=0):
        """
        Compares two financial values (incl. currencies).
        If one is equal or, if there is a threshold set, in
        allowed margin, returns True.

        :param t1: record from file containing ["fin_value"] and ["currency"] fields
        :param t2: record from file containing ["fin_value"] and ["currency"] fields
        :param threshold: allowed tolerance, e.g., 0.2 = 20%
        :return: are financial values equal?
        """
        v1 = float(t1.get("fin_value"))
        v2 = float(t2.get("fin_value"))
        c1 = t1.get("currency")
        c2 = t2.get("currency")

        return ExtractionUtils.money_equals(v1, c1, v2, c2, EVAL_MONEY_TOLERANCE_PERCENT)