def get_ancestors(self, source_person, generations):
     '''
     This functions obtains the ancestors up to the requested generations.
     '''
     #Firstly we initiate the list which will contain all
     ancestors = []
     current_gen = {source_person.get_id(): source_person.relations}
     ancestors.append(current_gen)
     #We introduce also a function to check duplications of profile... if they are duplicated, we take them out!
     affected_profiles = []
     affected_profiles.append(source_person.get_id())
     for i in range(1, generations + 1):
         #We create an intermediate source version we will store all parents.
         next_gen = {}
         #We iterate in all ancestors in this generation
         for prof_id in current_gen.keys():
             #Now we go one, by one the parents reflecting the next generation
             for parent in current_gen[prof_id].parents:
                 #be careful with duplications!!! we will not repeat it!
                 if not parent in affected_profiles:
                     #Now we get the profile of the parents
                     next_gen[parent] = immediate_family(parent)
                     #We add it to avoid duplications later on!
                     affected_profiles.append(parent)
         #If there are no longer ancestors, we should stop!
         if len(next_gen) == 0:
             return ancestors
         #Now...we append this generation to ancestors
         ancestors.append(next_gen)
         #And now the next generation is the current!!!
         current_gen = next_gen
     #We just finish delivering the ancestors back!!
     return ancestors, affected_profiles
Example #2
0
 def get_families_from_profile(self, profile_id):
     '''
     Intermediate function providing families for a profile, it will provide
     a class instance of inmmediate_family, used in Geni
     '''
     link_fam = self.inmediate.get(profile_id, immediate_family(profile_id))
     if link_fam not in self.inmediate.keys(): self.inmediate[profile_id] = link_fam
     return link_fam
 def get_families_from_profile(self, profile_id):
     '''
     Intermediate function providing families for a profile
     '''
     link_fam = self.inmediate.get(profile_id, immediate_family(profile_id))
     if not link_fam in self.inmediate.keys():
         self.inmediate[profile_id] = link_fam
     return link_fam
Example #4
0
 def testimmediatefamily(self):
     '''
     This test confirms that the immediate family gets the right values
     '''
     philip_family = immediate_family(FIXTURES.PHILIPIVid)
     assert (len(philip_family.parents) == 2)
     assert(len(philip_family.sibligns) == 8)
     assert(len(philip_family.partner) == 5)
     assert(len(philip_family.children) == 18)
     assert(philip_family.union_extracted)
Example #5
0
 def get_families_from_profile(self, profile_id):
     '''
     Intermediate function providing families for a profile, it will provide
     a class instance of inmmediate_family, used in Geni
     '''
     link_fam = self.inmediate.get(profile_id, immediate_family(profile_id))
     #When is not possible to access, we return None to inform of lack of access
     if link_fam.error: return None
     if link_fam not in self.inmediate.keys(): self.inmediate[profile_id] = link_fam
     return link_fam
Example #6
0
 def get_relations(self):
     '''
     Get relations by using the immediate family api
     '''
     self.relations = immediate_family(self.geni_specific_data['id'])
     self.parents = self.relations.parents
     self.sibligns = self.relations.sibligns
     self.partner = self.relations.partner
     self.children = self.relations.children
     self.parent_union = self.relations.parent_union
     self.marriage_union = self.relations.marriage_union
Example #7
0
 def test_immediatefamily_not_operational(self):
     '''
     I do not know why, but this profile is failing when providing
     the immediate family
     '''
     failing_family = immediate_family(FIXTURES.PROFILE_NOT_WORKING)
     
     assert (len(failing_family.parents) == 0)
     assert(len(failing_family.sibligns) == 0)
     assert(len(failing_family.partner) == 0)
     assert(len(failing_family.children) == 0)
     self.assertFalse(failing_family.union_extracted)
Example #8
0
 def force_update_profile(self, profile_id):
     '''
     It will force the update of the profile id used by functions which include
     new profiles inside database
     '''
     #Profile data is updated
     self.profiles[profile_id] = profile(profile_id)
     id_prof = self.profiles[profile_id].get_id()
     #The link to the families is updated.
     self.inmediate[id_prof] = immediate_family(id_prof)
     #Update of families of the profile
     unions = list(self.inmediate[id_prof].parent_union) + list(self.inmediate[id_prof].marriage_union)
     for union_now in unions:
         self.families[union_now.get_id()] = union(union_now.get_id())
Example #9
0
 def get_relations(self):
     '''
     Get relations by using the immediate family api
     '''
     self.relations = immediate_family(self.geni_specific_data['id'])
     self.parents = self.relations.parents
     self.sibligns = self.relations.sibligns
     self.partner = self.relations.partner
     self.children = self.relations.children
     self.parent_union = self.relations.parent_union
     self.marriage_union = self.relations.marriage_union
     #TODO:This is temporal, only a single marriage is considered
     if (len(self.relations.marriage_events) > 0):
         self.setNewEvent(self.relations.marriage_events[0])
 def get_cousins(self, source_person, generations):
     '''
     This function will create a matrix of cousins, just counting the number
     of affected cousins for a given profile.
     '''
     #We initiate an array of 0s for calculating
     cousins_array = [[0 for j in range(generations + 1)]
                      for i in range(generations + 1)]
     cousins_count = [[0 for j in range(generations + 1)]
                      for i in range(generations + 1)]
     #We need a list for checking duplications:
     affected_profiles = []
     ancestors, affected_ancestors = self.get_ancestors(
         source_person, generations)
     affected_profiles = affected_profiles + affected_ancestors
     for i in range(0, generations + 1):
         cousins_array[i][i] = ancestors[i]
         cousins_count[i][i] = len(ancestors[i])
     #We have finished the list of grand parents, now we need to go down!
     for i in range(1, generations + 1):
         #We go down in the matrix, from one we get the previous
         #we are located in the top previous value! so, the first value
         #are the gran-parents of the guy!
         for j in range(i, 0, -1):
             down_gen = {}
             #We need to get the childrens from the top guys!
             #We iterated in family items
             for family_item in cousins_array[i][j].values():
                 #Now we have the family of a single person...
                 for child in family_item.children:
                     #And now all the children of that person!
                     if not child in affected_profiles:
                         down_gen[child] = immediate_family(child)
                         #We add it to avoid duplications later on!
                         affected_profiles.append(child)
             cousins_array[i][j - 1] = down_gen
             cousins_count[i][j - 1] = len(down_gen)
     return cousins_array, cousins_count, affected_profiles