Example #1
0
    def add_parents(p):
        p.generation = distance[graph.node_from_id(p.id)]
        if p.generation >= max_levels:
            return

        fathers = graph.fathers(p.id)
        mothers = graph.mothers(p.id)
        p.parents = [
            None if not fathers else persons.get(fathers[0].main_id, None),
            None if not mothers else persons.get(mothers[0].main_id, None)]

        for pa in p.parents:
            if pa:
                add_parents(pa)
Example #2
0
 def build_sosa_tree(sosa_tree, marriage, sosa, id):
     # A person might not be in 'persons', and yet its parent be there,
     # in case we have filtered out earlier generations.
     if id in persons:
         sosa_tree[sosa] = id
         persons[id].generation = distance[graph.node_from_id(id)]
         if persons[id].marriage:
             marriage[sosa] = persons[id].marriage
     fathers = graph.fathers(id)
     if fathers:
         build_sosa_tree(sosa_tree, marriage, sosa * 2, fathers[0].main_id)
     mothers = graph.mothers(id)
     if mothers:
         build_sosa_tree(
             sosa_tree, marriage, sosa * 2 + 1, mothers[0].main_id)
Example #3
0
    def get_json(self, params, id):
        id = int(id);
        graph.update_if_needed()

        # ??? The stats includes persons "Unknown" that were created during a
        # gedcom import for the purpose of preserving families. Will be fixed
        # when we store children differently (for instance in a group)

        distance = dict()
        decujus = graph.node_from_id(id)

        allpeople = graph.people_in_tree(id=decujus.main_id, distance=distance)
        persons = extended_personas(
            nodes=allpeople, styles=None, event_types=event_types_for_pedigree,
            graph=graph)

        f = graph.fathers(decujus.main_id)
        fathers = graph.people_in_tree(id=f[0], maxdepthDescendants=0) if f else []
        m = graph.mothers(decujus.main_id)
        mothers = graph.people_in_tree(id=m[0], maxdepthDescendants=0) if m else []

        cal = CalendarGregorian()

        generations = dict()  # list of persons for each generation
        for a in allpeople:
            d = distance[a]
            if d not in generations:
                generations[d] = []
            generations[d].append(a)

        ranges = []

        for index in sorted(generations.keys()):
            births = None
            deaths = None
            gen_range = [index + 1, "?", "?", ""]  # gen, min, max, legend
            for p in generations[index]:
                p = persons[p.main_id]
                if p.birth and p.birth.Date:
                    if births is None or p.birth.Date < births:
                        births = p.birth.Date
                        year = p.birth.Date.year(cal)
                        if year is not None:
                            gen_range[1] = year

                if p.death and p.death.Date:
                    if deaths is None or p.death.Date > deaths:
                        deaths = p.death.Date
                        year = p.death.Date.year(cal)
                        if year is not None:
                            gen_range[2] = year

            if index >= 0:
                gen_range[3] = "Gen. %02d (%d / %d) %s - %s" \
                    % (index + 1, len(generations[index]), 2 ** (index + 1),
                       gen_range[1], gen_range[2])
            else:
                gen_range[3] = "Desc. %02d (%d) %s - %s" \
                    % (-index, len(generations[index]),
                       gen_range[1], gen_range[2])

            # Postprocess the ranges:
            #   generation n's earliest date has to be at least 15 years before
            #     its children's earliest date (can't have children before that)
            #   generation n's latest date (death) has to be after the children's
            #     generation earliest date (first birth)

            if len(ranges) > 0:
                if gen_range[1] == "?":
                    gen_range[1] = ranges[-1][1] - 15
                if gen_range[2] == "?" or gen_range[2] < ranges[-1][1]:
                    gen_range[2] = ranges[-1][1]
            if gen_range[2] == '?':
                gen_range[2] = datetime.datetime.now().year

            ranges.append(gen_range)

        ages = []
        for a in range(0, 120, 5):
            ages.append([a, 0, 0, 0])  # date_range, males, females, unknown

        for p in persons.itervalues():
            if p.birth and p.birth.Date and p.death and p.death.Date:
                age = p.death.Date.years_since(p.birth.Date)
                if age is not None:
                    if p.sex == "M":
                        ages[int(age / 5)][1] += 1
                    elif p.sex == "F":
                        ages[int(age / 5)][2] += 1
                    else:
                        ages[int(age / 5)][3] += 1

        return {
            "total_ancestors": len(allpeople),
            "total_father":    len(fathers),
            "total_mother":    len(mothers),
            "total_persons":   len(graph),
            "ranges":          ranges,
            "ages":            ages,
            "decujus":         decujus.main_id,
            "decujus_name":  "%s %s" % (
                persons[decujus.main_id].given_name,
                persons[decujus.main_id].surname)
        }
Example #4
0
def view(request, decujus=1):
    """Display the statistics for a given person"""

    decujus = int(decujus)

    graph.update_if_needed()
    if len(graph) == 0:
        return render_to_response(
            'geneaprove/firsttime.html',
            context_instance=RequestContext(request))

    # ??? The stats includes persons "Unknown" that were created during a
    # gedcom import for the purpose of preserving families. Will be fixed
    # when we store children differently (for instance in a group)

    distance = dict()
    ancestors = graph.people_in_tree(id=decujus, distance=distance)
    persons = extended_personas(
        nodes=ancestors, styles=None, event_types=event_types_for_pedigree,
        graph=graph)

    f = graph.fathers(decujus)
    fathers = graph.people_in_tree(id=f[0], maxdepthDescendants=0) if f else []
    m = graph.mothers(decujus)
    mothers = graph.people_in_tree(id=m[0], maxdepthDescendants=0) if m else []

    cal = CalendarGregorian()

    generations = dict()  # list of persons for each generation
    for a in ancestors:
        d = distance[a]
        if d not in generations:
            generations[d] = []
        generations[d].append(a)

    ranges = []

    for index in sorted(generations.keys()):
        births = None
        deaths = None
        gen_range = [index + 1, "?", "?", ""]  # gen, min, max, legend
        for p in generations[index]:
            p = persons[p.main_id]
            if p.birth and p.birth.Date:
                if births is None or p.birth.Date < births:
                    births = p.birth.Date
                    year = p.birth.Date.year(cal)
                    if year is not None:
                        gen_range[1] = year

            if p.death and p.death.Date:
                if deaths is None or p.death.Date > deaths:
                    deaths = p.death.Date
                    year = p.death.Date.year(cal)
                    if year is not None:
                        gen_range[2] = year

        gen_range[3] = "Gen. %02d (%d / %d) (%s - %s)" \
            % (index + 1, len(generations[index]), 2 ** (index + 1),
               gen_range[1], gen_range[2])

        # Postprocess the ranges:
        #   generation n's earliest date has to be at least 15 years before
        #     its children's earliest date (can't have children before that)
        #   generation n's latest date (death) has to be after the children's
        #     generation earliest date (first birth)

        if len(ranges) > 0:
            if gen_range[1] == "?":
                gen_range[1] = ranges[-1][1] - 15
            if gen_range[2] == "?" or gen_range[2] < ranges[-1][1]:
                gen_range[2] = ranges[-1][1]
        if gen_range[2] == '?':
            gen_range[2] = datetime.datetime.now().year

        ranges.append(gen_range)

    ages = []
    for a in range(0, 120, 5):
        ages.append([a, 0, 0, 0])  # date_range, males, females, unknown

    for p in persons.itervalues():
        if p.birth and p.birth.Date and p.death and p.death.Date:
            age = p.death.Date.years_since(p.birth.Date)
            if age is not None:
                if p.sex == "M":
                    ages[int(age / 5)][1] += 1
                elif p.sex == "F":
                    ages[int(age / 5)][2] += 1
                else:
                    ages[int(age / 5)][3] += 1

    data = {
        "total_ancestors": len(ancestors),
        "total_father":    len(fathers),
        "total_mother":    len(mothers),
        "total_persons":   len(graph),
        "ranges":          ranges,
        "ages":            ages,
        "decujus":         decujus,
        "decujus_name":  "%s %s" % (
            persons[decujus].given_name, persons[decujus].surname)
    }

    return HttpResponse(to_json(data), content_type='application/json')
Example #5
0
def view(request, decujus=1):
    """Display the statistics for a given person"""

    decujus = int(decujus)

    graph.update_if_needed()
    if len(graph) == 0:
        return render_to_response('geneaprove/firsttime.html',
                                  context_instance=RequestContext(request))

    # ??? The stats includes persons "Unknown" that were created during a
    # gedcom import for the purpose of preserving families. Will be fixed
    # when we store children differently (for instance in a group)

    distance = dict()
    ancestors = graph.people_in_tree(id=decujus, distance=distance)
    persons = extended_personas(nodes=ancestors,
                                styles=None,
                                event_types=event_types_for_pedigree,
                                graph=graph)

    f = graph.fathers(decujus)
    fathers = graph.people_in_tree(id=f[0], maxdepthDescendants=0) if f else []
    m = graph.mothers(decujus)
    mothers = graph.people_in_tree(id=m[0], maxdepthDescendants=0) if m else []

    cal = CalendarGregorian()

    generations = dict()  # list of persons for each generation
    for a in ancestors:
        d = distance[a]
        if d not in generations:
            generations[d] = []
        generations[d].append(a)

    ranges = []

    for index in sorted(generations.keys()):
        births = None
        deaths = None
        gen_range = [index + 1, "?", "?", ""]  # gen, min, max, legend
        for p in generations[index]:
            p = persons[p.main_id]
            if p.birth and p.birth.Date:
                if births is None or p.birth.Date < births:
                    births = p.birth.Date
                    year = p.birth.Date.year(cal)
                    if year is not None:
                        gen_range[1] = year

            if p.death and p.death.Date:
                if deaths is None or p.death.Date > deaths:
                    deaths = p.death.Date
                    year = p.death.Date.year(cal)
                    if year is not None:
                        gen_range[2] = year

        gen_range[3] = "Generation %02d (%d out of %d) (%s - %s)" \
            % (index + 1, len(generations[index]), 2 ** (index + 1),
               gen_range[1], gen_range[2])

        # Postprocess the ranges:
        #   generation n's earliest date has to be at least 15 years before
        #     its children's earliest date (can't have children before that)
        #   generation n's latest date (death) has to be after the children's
        #     generation earliest date (first birth)

        if len(ranges) > 0:
            if gen_range[1] == "?":
                gen_range[1] = ranges[-1][1] - 15
            if gen_range[2] == "?" or gen_range[2] < ranges[-1][1]:
                gen_range[2] = ranges[-1][1]
        if gen_range[2] == '?':
            gen_range[2] = datetime.datetime.now().year

        ranges.append(gen_range)

    ages = []
    for a in range(0, 120, 5):
        ages.append([a, 0, 0, 0])  # date_range, males, females, unknown

    for p in persons.itervalues():
        if p.birth and p.birth.Date and p.death and p.death.Date:
            age = p.death.Date.years_since(p.birth.Date)
            if age is not None:
                if p.sex == "M":
                    ages[int(age / 5)][1] += 1
                elif p.sex == "F":
                    ages[int(age / 5)][2] += 1
                else:
                    ages[int(age / 5)][3] += 1

    data = {
        "total_ancestors":
        len(ancestors),
        "total_father":
        len(fathers),
        "total_mother":
        len(mothers),
        "total_persons":
        len(graph),
        "ranges":
        ranges,
        "ages":
        ages,
        "decujus":
        decujus,
        "decujus_name":
        "%s %s" % (persons[decujus].given_name, persons[decujus].surname)
    }

    return HttpResponse(to_json(data), content_type='application/json')