Exemple #1
0
def alive(person):
    """Whether the person is alive"""

    # If we have no birth date, we could assume it is at least 15 years
    # before the first child's birth date (recursively). But that becomes
    # more expensive to compute

    return not person.death \
        and (not person.birth
             or DateRange.today().years_since(person.birth.Date) <= max_age)
Exemple #2
0
def alive(person):
    """Whether the person is alive"""

    # If we have no birth date, we could assume it is at least 15 years
    # before the first child's birth date (recursively). But that becomes
    # more expensive to compute

    return not person.death \
        and (not person.birth
             or DateRange.today().years_since(person.birth.Date) <= max_age)
Exemple #3
0
      def default (self, obj):
         """See inherited documentation"""

         if isinstance (obj, models.Persona):
            b = self._event (obj.birth)
            d = self._event (obj.death)

            if not year_only and obj.birth:
               if obj.death:
                  if obj.death.Date:
                     age = " (age " \
                        + str (obj.death.Date.years_since (obj.birth.Date)) \
                        + ")"
                     d[0] += age
               else:
                  age = " (age " \
                        + str (DateRange.today().years_since (obj.birth.Date)) \
                        + ")"
                  d = [age, None, None]

            return {"id":obj.id, "givn":obj.given_name,
                    'surn':obj.surname, 'sex':obj.sex,
                    'generation': obj.generation,
                    'y':obj.styles, 'b':b, 'd':d}

         elif isinstance (obj, DateRange):
            return obj.display(year_only=year_only)

         elif isinstance (obj, models.Event):
            return self._event (obj)

         elif isinstance(obj, set):
             return list(obj)

         elif hasattr(obj, 'to_json'):
            return obj.to_json()

         return super (ModelEncoder, self).default(obj)
Exemple #4
0
def alive(person):
    """Whether the person is alive"""

    # If we have no birth date, we could assume it is at least 15 years
    # before the first child's birth date (recursively). But that becomes
    # more expensive to compute

    logger.error('Did not compute birth or death for person')
    return False

    if person.death is not None:
        return False
    elif person.birth is None:
        # Might be alive. We could look at other events to guess at the
        # timeframe
        return True
    else:
        d = DateRange.today().years_since(person.birth.Date)
        if d is None:
            # Could not compute elapsed time (likely because birth has no know
            # year
            return True
        else:
            return d <= max_age
Exemple #5
0
    def __init__(self, rules, graph, decujus):
        """Rules specifies the rules to use for the highlighting.
        """
        super(Styles, self).__init__()

        # Preprocess the rules for faster computation

        self.graph = graph
        self.rules = []
        self.today = DateRange.today()
        self.counts = [None] * len(rules)  # the "count" rules: (test, value)
        self._need_place_parts = False

        self.styles_count = 0

        for index, r in enumerate(rules):
            rule_name, rule_type, rule_tests, rule_style = r

            if rule_type in (RULE_EVENT, RULE_ATTR):
                tests = []
                for t in rule_tests:
                    if t[0] == "count" and rule_type == RULE_EVENT:
                        # Handled separately at the end
                        self.counts[index] = (rules_func[t[1]], t[2])
                        continue
                    elif t[0] == "ancestor" and rule_type == RULE_ATTR:
                        ancestors = graph.people_in_tree(
                            id=t[2], maxdepthAncestors=-1, maxdepthDescendants=0)
                        tests.append((t[0], [a.main_id for a in ancestors]))
                        continue
                    elif t[0] == "descendant" and rule_type == RULE_ATTR:
                        descendants = graph.people_in_tree(
                            id=t[2], maxdepthAncestors=0, maxdepthDescendants=-1)
                        tests.append((t[0], [a.main_id for a in descendants]))
                        continue
                    elif t[0] == "IMPLEX" and rule_type == RULE_ATTR:
                        # ??? We used to preprocess the tree to know how many times
                        # an id occurred in the tree, but the graph no longer
                        # provides that info

                        def build_implex(counts, id):
                            counts[id] = counts.get(id, 0) + 1
                            fathers = graph.fathers(id)
                            if fathers:
                                build_implex(counts, fathers[0].main_id)
                            mothers = graph.mothers(id)
                            if mothers:
                                build_implex(counts, mothers[0].main_id)
                        counts = dict()
                        build_implex(
                            counts, graph.node_from_id(decujus).main_id)
                        tests.append((t[0], rules_func[t[1]], t[2], counts))
                        continue
                    elif t[0].startswith("place.") and t[0] != "place.name":
                        self._need_place_parts = True

                    if t[1] == RULE_CONTAINS_INSENSITIVE \
                       or t[1] == RULE_CONTAINS_NOT_INSENSITIVE \
                       or t[1] == RULE_IS_INSENSITIVE:
                        tests.append((t[0], rules_func[t[1]], t[2].lower()))
                    elif t[1] == RULE_BEFORE:
                        tests.append((t[0], rules_func[t[1]], DateRange(t[2])))
                    else:
                        tests.append((t[0], rules_func[t[1]], t[2]))

                self.rules.append((rule_type, tests, rule_style))
            else:
                print "Unknown rule tag in the style rules: %s" % r

        self.no_match = [0] * len(self.rules)
Exemple #6
0
    def __init__(self, rules, graph, decujus):
        """Rules specifies the rules to use for the highlighting.
        """
        super(Styles, self).__init__()

        # Preprocess the rules for faster computation

        self.graph = graph
        self.rules = []
        self.today = DateRange.today()
        self.counts = [None] * len(rules)  # the "count" rules: (test, value)
        self._need_place_parts = False

        self.styles_count = 0

        for index, r in enumerate(rules):
            rule_name, rule_type, rule_tests, rule_style = r

            if rule_type in (RULE_EVENT, RULE_ATTR):
                tests = []
                for t in rule_tests:
                    if t[0] == "count" and rule_type == RULE_EVENT:
                        # Handled separately at the end
                        self.counts[index] = (rules_func[t[1]], t[2])
                        continue
                    elif t[0] == "ancestor" and rule_type == RULE_ATTR:
                        ancestors = graph.people_in_tree(id=t[2],
                                                         maxdepthAncestors=-1,
                                                         maxdepthDescendants=0)
                        tests.append((t[0], [a.main_id for a in ancestors]))
                        continue
                    elif t[0] == "descendant" and rule_type == RULE_ATTR:
                        descendants = graph.people_in_tree(
                            id=t[2],
                            maxdepthAncestors=0,
                            maxdepthDescendants=-1)
                        tests.append((t[0], [a.main_id for a in descendants]))
                        continue
                    elif t[0] == "IMPLEX" and rule_type == RULE_ATTR:
                        # ??? We used to preprocess the tree to know how many times
                        # an id occurred in the tree, but the graph no longer
                        # provides that info

                        def build_implex(counts, id):
                            counts[id] = counts.get(id, 0) + 1
                            fathers = graph.fathers(id)
                            if fathers:
                                build_implex(counts, fathers[0].main_id)
                            mothers = graph.mothers(id)
                            if mothers:
                                build_implex(counts, mothers[0].main_id)

                        counts = dict()
                        build_implex(counts,
                                     graph.node_from_id(decujus).main_id)
                        tests.append((t[0], rules_func[t[1]], t[2], counts))
                        continue
                    elif t[0].startswith("place.") and t[0] != "place.name":
                        self._need_place_parts = True

                    if t[1] == RULE_CONTAINS_INSENSITIVE \
                       or t[1] == RULE_CONTAINS_NOT_INSENSITIVE \
                       or t[1] == RULE_IS_INSENSITIVE:
                        tests.append((t[0], rules_func[t[1]], t[2].lower()))
                    elif t[1] == RULE_BEFORE:
                        tests.append((t[0], rules_func[t[1]], DateRange(t[2])))
                    else:
                        tests.append((t[0], rules_func[t[1]], t[2]))

                self.rules.append((rule_type, tests, rule_style))
            else:
                print "Unknown rule tag in the style rules: %s" % r

        self.no_match = [0] * len(self.rules)