def get_json(self, params, id): graph.update_if_needed() all_sources = {} p2e = {} p2c = {} p2g = {} p = extended_personas( nodes=set([graph.node_from_id(id)]), p2e=p2e, p2c=p2c, p2g=p2g, all_sources=all_sources, styles=None, as_css=True, graph=graph, schemes=None) query = models.P2P.objects.filter( type=models.P2P.sameAs) node = graph.node_from_id(id) assertions = list(models.P2P.objects.filter( type=models.P2P.sameAs, person1__in=node.ids.union(node.different))) decujus = p[node.main_id] return { "person": decujus, "sources": all_sources, "p2c": p2c.values(), "p2e": p2e.values(), "p2p": assertions, "p2g": p2g.values() }
def view(request, id): """Display all details known about persona ID""" id = int(id) graph.update_if_needed() #if len(graph) == 0: # return render_to_response( # 'geneaprove/firsttime.html', # context_instance=RequestContext(request)) styles = None p = extended_personas( nodes=set([graph.node_from_id(id)]), styles=styles, as_css=True, graph=graph, schemes=None) query = models.P2P.objects.filter( type=models.P2P.sameAs) node = graph.node_from_id(id) assertions = list(models.P2P.objects.filter( type=models.P2P.sameAs, person1__in=node.ids.union(node.different))) decujus = p[node.main_id] decujus.all_chars = decujus.all_chars.values() decujus.all_events = decujus.all_events.values() decujus.all_groups = decujus.all_groups.values() data = { "person": decujus, "p2p": assertions, } return HttpResponse(to_json(data), content_type='application/json')
def view(request, id): """View a specific source""" id = int(id) graph.update_if_needed() if len(graph) == 0: return render_to_response('geneaprove/firsttime.html', context_instance=RequestContext(request)) schemes = set() # The surety schemes that are needed sources = extended_sources([id], schemes=schemes) surety_schemes = dict() for s in schemes: surety_schemes[s] = models.Surety_Scheme.objects.get(id=s).parts.all() data = { 'source': sources[id], 'parts': list_of_citations(None, sources[id]), 'repository_types': models.Repository_Type.objects.all(), 'source_types': Citations.source_types(), 'schemes': surety_schemes } return HttpResponse(to_json(data), content_type='application/json')
def view_list(request): """View the list of all personas""" graph.update_if_needed() if len(graph) == 0: return render_to_response( 'geneaprove/firsttime.html', context_instance=RequestContext(request)) styles = Styles(style_rules, graph=graph, decujus=1) # ??? Why "1" all = extended_personas( nodes=None, styles=styles, event_types=event_types_for_pedigree, graph=graph, as_css=True) all = [p for p in all.itervalues()] all.sort(key=lambda x: x.surname) all = [{'surname': p.surname, 'given_name': p.given_name, 'birth': p.birth, 'death': p.death, 'marriage': p.marriage} for p in all] data = { 'persons': all, } return HttpResponse(to_json(data), content_type='application/json')
def get_json(self, params): graph.update_if_needed() styles = Styles(style_rules, graph=graph, decujus=1) # ??? Why "1" all = extended_personas( nodes=None, styles=styles, event_types=event_types_for_pedigree, all_sources=None, graph=graph, as_css=True) all = [p for p in all.itervalues()] all.sort(key=lambda x: x.surn) # Necessary to avoid lots of queries to get extra information all = [{'surn': p.surn, 'givn': p.givn, 'birth': p.birth, 'death': p.death, 'id': p.id, 'styles': p.styles, 'marriage': p.marriage} for p in all] return { 'persons': all, }
def personaEvents(request, id): """All events for the person""" id = int(id) graph.update_if_needed() schemes = set() # The surety schemes that are needed styles = None p = extended_personas(nodes=set([graph.node_from_id(id)]), styles=styles, as_css=True, graph=graph, schemes=schemes) data = [ "%s: %s (%s)%s" % (e.event.name, e.event.date, e.event.place, u"\u2713" if e.event.sources else u"\u2717") for i, e in p[id].all_events.items() if e.role == 'principal' and not e.assertion.disproved ] data.extend("%s: %s%s%s" % (c.char.name, " ".join( "%s:%s" % (p.name, p.value) for p in c.parts), "(%s)" % c.char.date if c.char.date else "", u"\u2713" if c.char.sources else u"\u2717") for k, c in p[id].all_chars.items() if not c.assertion.disproved and c.char.name not in ("_UID", )) return HttpResponse(to_json(data, year_only=False), content_type="application/json")
def personaEvents(request, id): """All events for the person""" id = int(id) graph.update_if_needed() schemes = set() # The surety schemes that are needed styles = None p = extended_personas( nodes=set([graph.node_from_id(id)]), styles=styles, as_css=True, graph=graph, schemes=schemes) data = ["%s: %s (%s)%s" % (e.event.name, e.event.date, e.event.place, u"\u2713" if e.event.sources else u"\u2717") for i, e in p[id].all_events.items() if e.role == 'principal' and not e.assertion.disproved] data.extend("%s: %s%s%s" % ( c.char.name, " ".join("%s:%s" % (p.name, p.value) for p in c.parts), "(%s)" % c.char.date if c.char.date else "", u"\u2713" if c.char.sources else u"\u2717") for k, c in p[id].all_chars.items() if not c.assertion.disproved and c.char.name not in ("_UID", )) return HttpResponse( to_json(data, year_only=False), content_type="application/json")
def view_list(request): """View the list of all personas""" graph.update_if_needed() if len(graph) == 0: return render_to_response('geneaprove/firsttime.html', context_instance=RequestContext(request)) styles = Styles(style_rules, graph=graph, decujus=1) # ??? Why "1" all = extended_personas(nodes=None, styles=styles, event_types=event_types_for_pedigree, graph=graph, as_css=True) all = [p for p in all.itervalues()] all.sort(key=lambda x: x.surname) all = [{ 'surname': p.surname, 'given_name': p.given_name, 'birth': p.birth, 'death': p.death, 'marriage': p.marriage } for p in all] data = { 'persons': all, } return HttpResponse(to_json(data), content_type='application/json')
def pedigree_data(request, decujus): """Return the data for the Pedigree or Fanchart views. This is only needed when the user changes the settings, since initially this data is already part of the view. """ # ??? Should lock until the view has been generated graph.update_if_needed() data = __get_json_sosa_tree( graph, id=int(decujus), style_rules=style_rules, max_levels=int(request.GET.get("gens", 5)), maxdepthDescendants=int(request.GET.get("descendant_gens", 1)), last_descendant_known=int(request.GET.get("desc_known", -1)), last_gen_known=int(request.GET.get("gens_known", -1))) return HttpResponse(data, content_type="application/json")
def view(request, id): """Display all details known about persona ID""" id = int(id) graph.update_if_needed() if len(graph) == 0: return render_to_response( 'geneaprove/firsttime.html', context_instance=RequestContext(request)) schemes = set() # The surety schemes that are needed styles = None p = extended_personas( nodes=set([graph.node_from_id(id)]), styles=styles, as_css=True, graph=graph, schemes=schemes) surety_schemes = dict() for s in schemes: surety_schemes[s] = models.Surety_Scheme.objects.get(id=s).parts.all() query = models.P2P.objects.filter( type=models.P2P.sameAs) node = graph.node_from_id(id) assertions = list(models.P2P.objects.filter( type=models.P2P.sameAs, person1__in=node.ids.union(node.different))) decujus = p[node.main_id] return render_to_response( 'geneaprove/persona.html', {"decujus": id, "person": decujus, "decujus_name": "%s %s" % (decujus.given_name, decujus.surname), "chars": decujus.all_chars, "events": decujus.all_events, "groups": decujus.all_groups, "schemes": surety_schemes, "p2p": [(0, a) for a in assertions], }, context_instance=RequestContext(request))
def fanchart_view(request, decujus=1): """Display the pedigree of a person as a fanchart""" decujus = int(decujus) gens = int(request.GET.get("gens", 4)) # ??? Should lock the graph until the view has been generated graph.update_if_needed() if len(graph) == 0: return render_to_response( 'geneaprove/firsttime.html', context_instance=RequestContext(request)) data = get_sosa_tree( graph, id=decujus, max_levels=gens, style_rules=style_rules) dec = data['persons'][decujus] return render_to_response( 'geneaprove/fanchart.html', {"legend": getLegend(), "decujus": decujus, "decujus_name": "%s %s" % (dec.given_name, dec.surname), "pedigree_data":to_json(data)}, context_instance=RequestContext(request))
def view_list(request): """View the list of all personas""" graph.update_if_needed() if len(graph) == 0: return render_to_response( 'geneaprove/firsttime.html', context_instance=RequestContext(request)) styles = Styles(style_rules, graph=graph, decujus=1) # ??? Why "1" all = extended_personas( nodes=None, styles=styles, event_types=event_types_for_pedigree, graph=graph, as_css=True) all = [p for p in all.itervalues()] all.sort(key=lambda x: x.surname) return render_to_response( 'geneaprove/persona_list.html', {"persons":all, "name":[p.name.encode("utf-8") for p in all], "legend":getLegend()}, context_instance=RequestContext(request))
def view(request, id): """Display all details known about persona ID""" id = int(id) graph.update_if_needed() #if len(graph) == 0: # return render_to_response( # 'geneaprove/firsttime.html', # context_instance=RequestContext(request)) styles = None p = extended_personas(nodes=set([graph.node_from_id(id)]), styles=styles, as_css=True, graph=graph, schemes=None) query = models.P2P.objects.filter(type=models.P2P.sameAs) node = graph.node_from_id(id) assertions = list( models.P2P.objects.filter(type=models.P2P.sameAs, person1__in=node.ids.union(node.different))) decujus = p[node.main_id] decujus.all_chars = decujus.all_chars.values() decujus.all_events = decujus.all_events.values() decujus.all_groups = decujus.all_groups.values() data = { "person": decujus, "p2p": assertions, } return HttpResponse(to_json(data), content_type='application/json')
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) }
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')
def get_json(self, params, id): # ??? Should lock until the view has been generated graph.update_if_needed() max_levels = int(params.get("gens", 5)) last_descendant_known = int(params.get("desc_known", -1)) # The number of generations for which we compute the children. maxdepthDescendants = int(params.get("descendant_gens", 1)) # the number of the last generation for which the client already has # data, and thus do not need to be sent again. -1 to retrieve all. last_gen_known = int(params.get("gens_known", -1)) # Whether to show full dates or only the year self.year_only = params.get('year_only', '') == 'true' decujus = graph.node_from_id(id) styles = Styles(style_rules, graph, decujus=decujus.main_id) distance = dict() people = graph.people_in_tree( id=decujus.main_id, maxdepthAncestors=max_levels - 1, maxdepthDescendants=maxdepthDescendants, distance=distance) ancestors = [a for a in people if distance[a] >= 0 and distance[a] >= last_gen_known] descendants = [a for a in people if a != decujus and distance[a] < 0 and distance[a] <= -last_descendant_known] sosa_tree = dict() marriage = dict() children = {} persons = {} all_person_nodes = set(ancestors).union(descendants) if all_person_nodes: persons = extended_personas( all_person_nodes, styles, event_types=event_types_for_pedigree, graph=graph) 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) def add_children(p, gen): p.children = [] sorted = [(persons[node.main_id] if node.main_id in persons else None, node) for node in graph.children(p.id)] sorted.sort( key=lambda c: c[0].birth.Date if c[0] and c[0].birth else None) for c in sorted: if c[0]: c[0].generation = -gen # distance[c[1]] p.children.append(c[0]) if gen < maxdepthDescendants: add_children(c[0], gen + 1) main = persons[decujus.main_id] add_parents(main) add_children(main, gen=1) return {'generations': max_levels, 'descendants': maxdepthDescendants, 'decujus': main, 'styles': styles.all_styles()}
def view(request): try: graph.update_if_needed() find_candidate(graph=graph) except Exception(e): print "Terminated ", e
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')