Exemplo n.º 1
0
    def test_date_structure(self):
        '''
        Test creation of geni date structure
        '''
        my_event = event_profile("birth")
        #my_event.setDate(year, month, day, accuracy, year_end, month_end, day_end)
        my_event.setDate(2017, 11, 20, "EXACT")

        output = profile.getDateStructureGeni(my_event)
        assert (output["year"] == 2017)
        assert (output["month"] == 11)
        assert (output["day"] == 20)
        #Testing about
        my_event.setDate(2017, accuracy="ABOUT")
        output2 = profile.getDateStructureGeni(my_event)
        assert (output2["year"] == 2017)
        self.assertFalse("month" in output2.keys())
        self.assertFalse("day" in output2.keys())
        assert (output2["circa"] == True)
        my_event.setDate(2017, accuracy="ABOUT")
        #Testing the data before
        my_event.setDate(2017, accuracy="BEFORE")
        output3 = profile.getDateStructureGeni(my_event)
        assert (output3["range"] == "before")
        #Testing the data before
        my_event.setDate(2017, accuracy="AFTER")
        output4 = profile.getDateStructureGeni(my_event)
        assert (output4["range"] == "after")

        my_other_event = event_profile("birth")
        self.assertFalse(profile.getDateStructureGeni(my_other_event))
    def test_date_checker(self):
        '''
        It will check 2 dates to confirm which one is the smaller
        '''
        new_event = event_profile("birth")

        self.assertFalse(
            is_first_date_lower(2012, None, None, 2010, None, None))
        assert (is_first_date_lower(1910, None, None, 1912, None, None))
        assert (is_first_date_lower(2010, 1, None, 2010, None, None) == None)
        assert (is_first_date_lower(2010, 1, None, 2010, 2, None))
        self.assertFalse(is_first_date_lower(2012, 5, None, 2012, 1, None))
        assert (is_first_date_lower(2010, 1, None, 2010, 1, None) == None)
        assert (is_first_date_lower(2010, 2, 12, 2010, 2, 22))
        self.assertFalse(is_first_date_lower(2012, 5, 12, 2012, 5, 5))
        assert (is_first_date_lower(2010, 1, 2, 2010, 1, 2) == "Equal")

        #Testing that the event is smaller or not
        new_event1 = event_profile("birth")
        new_event1.setDate(2013, month=2, accuracy="AFTER")
        new_event2 = event_profile("death")
        new_event2.setDate(2012, day=3, accuracy="ABOUT")

        self.assertFalse(
            new_event1.is_this_event_earlier_or_simultaneous_to_this(
                new_event2))
        assert (new_event2.is_this_event_earlier_or_simultaneous_to_this(
            new_event1))

        assert (
            new_event1.is_this_event_later_or_simultaneous_to_this(new_event2))
        self.assertFalse(
            new_event2.is_this_event_later_or_simultaneous_to_this(new_event1))
 def test_basic_event(self):
     '''
     Testing basic usage of common_event class
     '''
     event1 = event_profile("birth")
     assert (event1.setDate(2011, accuracy="EXACT"))
     assert (event1.setDate(2013, month=2, accuracy="ABOUT"))
     assert (event1.setDate(2013, month=2, accuracy="BEFORE"))
     assert (event1.setDate(2013, month=2, accuracy="AFTER"))
     assert (event1.setDate(2013,
                            month=2,
                            accuracy="BETWEEN",
                            year_end=2013))
     self.assertFalse(event1.setDate(2013, month=2, accuracy="BETWEEN"))
     self.assertFalse(event1.setDate(2013, month=2, accuracy="LALA"))
     self.assertFalse(
         event1.setDate(2013, month=2, accuracy="ABOUT", month_end=2))
     assert (event1)
     #Introducing wrong data
     self.assertRaises(ValueError, lambda: event_profile("wrong_data"))
     event1.setLocation("Madrid, Spain")
     assert (event1.location["place_name"] == "Madrid")
     #Let's check introducing a lower date in the end day
     assert (event1.setDate(2015,
                            month=2,
                            day=1,
                            accuracy="BETWEEN",
                            year_end=2013,
                            month_end=2,
                            day_end=5))
     assert (event1.year == 2013)
Exemplo n.º 4
0
 def test_date_differences(self):
     '''
     Will test the differences between 2 events
     '''
     event1 = event_profile("birth")
     event1.setDate(2013, 2, 13, "EXACT")
     event2 = event_profile("birth")
     event2.setDate(2013, 6, 26, "EXACT")
     assert (event1.get_difference_in_days(event2) == 133)
     event2.setDate(2013, accuracy="EXACT")
     print(event1.get_difference_in_days(event2) == 43)
    def test_common_init_functions(self):
        '''
        This test will be testing those functions included in init file
        '''
        my_event = event_profile("birth")

        assert (return_date_from_event(my_event) == None)

        my_event.setDate(2019, 5, 3, "EXACT")
        #D.+20190503..+00000000..
        assert (return_date_from_event(my_event) == "D.+20190503..+00000000..")

        my_event.setDate(1970, accuracy="BEFORE")
        #DB+19700000..+00000000..
        assert (return_date_from_event(my_event) == "DB+19700000..+00000000..")

        my_event.setDate(1890, accuracy="AFTER")
        #DA+18900000..+00000000..
        assert (return_date_from_event(my_event) == "DA+18900000..+00000000..")

        my_event.setDate(1820, accuracy="BETWEEN", year_end=1821, month_end=3)
        #DR+18200000..+18210300..
        assert (return_date_from_event(my_event) == "DR+18200000..+18210300..")

        my_event.setDate(1910, accuracy="ABOUT")
        #D.+19100000.C+00000000..
        assert (return_date_from_event(my_event) == "D.+19100000.A+00000000..")
 def setCheckedDate(self,
                    event_name,
                    year,
                    month=None,
                    day=None,
                    accuracy="EXACT",
                    year_end=None,
                    month_end=None,
                    day_end=None):
     '''
     This function will introduce an event with the data related to the dates of the event
     '''
     if (event_name not in EVENT_TYPE) or (accuracy not in VALUES_ACCURACY):
         raise NameError(INITIAL_PART_EVENT_ERROR + event_name + " or " +
                         accuracy + END_PART_EVENT_ERROR)
     new_event = event_profile(event_name)
     new_event.setDate(year, month, day, accuracy, year_end, month_end,
                       day_end)
     if (not self.selfcheckDateConsistency(new_event)):
         return False
     else:
         if event_name in ARRAY_EVENTS:
             self.gen_data[event_name].append(new_event)
         elif event_name in self.gen_data.keys():
             self.gen_data[event_name].setDate(year, month, day, accuracy,
                                               year_end, month_end, day_end)
         else:
             self.gen_data[event_name] = new_event
         return True
    def test_family(self):
        '''
        This test will check the basic operation of family classes
        '''
        father = gen_profile("Father", "Profile")
        mother = gen_profile("Mother", "Profile")
        child1 = gen_profile("Child", "First")
        child2 = gen_profile("Child", "Second")

        event1 = event_profile("birth")
        assert (event1.setDate(2013, month=2, accuracy="ABOUT"))

        family1 = family_profile(child=3)
        assert (len(family1.getChildren()) == 1)

        family2 = family_profile(child=[1, 2])
        assert (len(family2.getChildren()) == 2)

        family3 = family_profile(child=[1, 2],
                                 father=3,
                                 mother=4,
                                 marriage=event1)
        assert (family3.father and family3.mother and family3.children
                and family3.marriage)
        assert (family3.getFather() == 3)
        assert (family3.getMother() == 4)
Exemplo n.º 8
0
 def get_date(self, event_type, data_dict, previous_event=None):
     '''
     Get date from the Geni standard, used in unions and profiles
     '''
     if previous_event:
         my_event = previous_event
     else:
         my_event = event_profile(event_type)
     accuracy = None
     year = None
     month = None
     day = None
     year_end = None
     month_end = None
     day_end = None
     if (data_dict.get("year", None) is not None):
         year = data_dict.get("year")
         month = data_dict.get("month", None)
         day = data_dict.get("day", None)
     #TODO: get and handle BETWEEN dates
     if (data_dict.get("circa", "false") is True): accuracy = "ABOUT"
     elif (data_dict.get("range", "") == "before"): accuracy = "BEFORE"
     elif (data_dict.get("range", "") == "after"): accuracy = "AFTER"
     elif (data_dict.get("range", "") == "between"):
         accuracy = "BETWEEN"
         year_end = data_dict.get("end_year", None)
         month_end = data_dict.get("end_month", None)
         day_end = data_dict.get("end_day", None)
     else:
         accuracy = "EXACT"
     #Now we transfer everything to the profile
     my_event.setDate(year, month, day, accuracy, year_end, month_end,
                      day_end)
     return my_event
Exemplo n.º 9
0
 def get_specific_event(self, event_name):
     '''
     It will return an specific event or None if not present
     '''
     if EQUIVALENCE[event_name] in self.individual:
         new_event = event_profile(event_name)
         geddate = self.individual.get(EQUIVALENCE[event_name]).get(
             "DATE", {}).get("VALUE")
         if geddate:
             year, month, day, accuracy, year_end, month_end, day_end = get_date_info_from_ged(
                 geddate)
             new_event.setDate(year, month, day, accuracy, year_end,
                               month_end, day_end)
         if self.individual.get(EQUIVALENCE[event_name]).get(
                 "PLAC", {}).get("VALUE"):
             new_event.setParameterInLocation(
                 "place_name",
                 self.individual.get(EQUIVALENCE[event_name]).get(
                     "PLAC", {}).get("VALUE"))
         for key in LOCATION_EQUIVALENCE:
             if self.individual.get(EQUIVALENCE[event_name]).get(
                     "ADDR", {}).get(LOCATION_EQUIVALENCE[key],
                                     {}).get("VALUE"):
                 new_event.setParameterInLocation(
                     key,
                     self.individual.get(EQUIVALENCE[event_name]).get(
                         "ADDR", {}).get(LOCATION_EQUIVALENCE[key],
                                         {}).get("VALUE"))
         if event_name in common_profile.ARRAY_EVENTS: return [new_event]
         else: return new_event
     else:
         if event_name in common_profile.ARRAY_EVENTS: return []
         else: return None
Exemplo n.º 10
0
 def setCheckedDate(self,
                    event_name,
                    year,
                    month=None,
                    day=None,
                    accuracy="EXACT",
                    year_end=None,
                    month_end=None,
                    day_end=None):
     '''
     This function will introduce an event with the data related to the dates of the event
     '''
     if (not event_name in EVENT_TYPE) or (not accuracy in VALUES_ACCURACY):
         return False
     new_event = event_profile(event_name)
     new_event.setDate(year, month, day, accuracy, year_end, month_end,
                       day_end)
     if (not self.selfcheckDateConsistency(new_event)):
         return False
     else:
         if event_name in self.gen_data.keys():
             self.gen_data[event_name].setDate(year, month, day, accuracy,
                                               year_end, month_end, day_end)
         else:
             self.gen_data[event_name] = new_event
         return True
 def return_event_from_database_info(self, event_in_database):
     '''
     This function is used to get info about all events
     '''
     if not str(event_in_database[1]) in DATE_EVENT_ID.values(): return None
     event_output = event_profile(
         list(DATE_EVENT_ID.keys())[list(DATE_EVENT_ID.values()).index(
             str(event_in_database[1]))])
     if not ((event_in_database[7] in ["."])
             or event_in_database[7].startswith("T")):
         #This means that the event has a date, as might be empty
         year_end = None
         month_end = None
         day_end = None
         accuracy_value = "EXACT"
         if event_in_database[7][1] == "B":
             accuracy_value = "BEFORE"
         elif event_in_database[7][1] == "A":
             accuracy_value = "AFTER"
         elif event_in_database[7][1] == "R":
             #Only in the case of dates between is when we analyze and define the dates after
             accuracy_value = "BETWEEN"
             year_end = int(event_in_database[7][14:18])
             month_end = int(event_in_database[7][18:20])
             day_end = int(event_in_database[7][20:22])
             if year_end == 0: year_end = None
             if month_end == 0: month_end = None
             if day_end == 0: day_end = None
         elif event_in_database[7][12] == "A":
             accuracy_value = "ABOUT"
         year = int(event_in_database[7][3:7])
         month = int(event_in_database[7][7:9])
         day = int(event_in_database[7][9:11])
         if month == 0: month = None
         if day == 0: day = None
         event_output.setDate(year, month, day, accuracy_value, year_end,
                              month_end, day_end)
     if not event_in_database[5] == 0:
         #The only valid place is actually when is an entry in the PlaceTbale
         place_input = "SELECT * FROM PlaceTable WHERE PlaceID=?"
         place = self.database.execute(place_input,
                                       (str(event_in_database[5]), ))
         place_info = place.fetchone()
         #We extract the geolocated string from the profile
         geo_string = place_info[2]
         #If was extracted before, we should avoid another geolocation call
         if get_geolocated_before(geo_string):
             event_output.setLocationAlreadyProcessed(
                 get_geolocated_before(geo_string))
         else:
             event_output.setLocation(place_info[2])
             #We store the geolocation in the database for future use
             set_geolocated(geo_string, event_output.get_location())
         if int(place_info[5]) != 0 and int(place_info[6]) != 0:
             event_output.set_geo_location(
                 int(place_info[5]) / 10000000,
                 int(place_info[6]) / 10000000)
     return event_output
Exemplo n.º 12
0
 def setPlaces(self, event_name, location, language="en"):
     '''
     This function will introduce the location related to each event
     '''
     if event_name in ARRAY_EVENTS:
         new_event = event_profile(event_name)
         new_event.setLocation(location, language)
         self.gen_data[event_name].append(new_event)
         return True
     if event_name in EVENT_TYPE:
         new_event = self.gen_data.get(event_name,
                                       event_profile(event_name))
         new_event.setLocation(location, language)
         self.gen_data[event_name] = new_event
         return True
     else:
         raise NameError(INITIAL_PART_EVENT_ERROR + event_name +
                         END_PART_EVENT_ERROR)
Exemplo n.º 13
0
 def setPlaces(self, event_name, location, language="en" ):
     '''
     This function will introduce the location related to each event
     '''
     if event_name in EVENT_TYPE:
         new_event = self.gen_data.get(event_name, event_profile(event_name))
         new_event.setLocation(location, language)
         self.gen_data[event_name] = new_event
         return True
     else:
         return False
 def test_score_birth_death(self):
     '''
     Test the scoring for birth and death
     '''
     birth1 = event_profile("birth")
     birth1.setDate(1900)
     residence1 = event_profile("residence")
     residence1.setDate(1901)
     
     death1 = event_profile("death")
     death1.setDate(2090)
     score1, factor1 = score_factor_birth_and_death(birth1,residence1, [death1])
     assert(score1 == 0)
     assert(factor1 == 0)
     score2, factor2 = score_factor_birth_and_death(birth1,residence1, [])
     assert(score2 == 0)
     assert(factor2 == 1)
     score3, factor3 = score_factor_birth_and_death(None,None,[])
     assert(score3 == 0)
     assert(factor3 == 1)
Exemplo n.º 15
0
 def test_date_for_gedcom(self):
     '''
     Testing the output for gedcom
     '''
     new_event = event_profile("birth")
     new_event.setDate(2013, month=2)
     assert (new_event.get_gedcom_date() == "FEB 2013")
     new_event.setDate(2013)
     assert (new_event.get_gedcom_date() == "2013")
     new_event.setDate(2013, 6, 1)
     assert (new_event.get_gedcom_date() == "01 JUN 2013")
     new_event.setDate(2013, 12, 18)
     assert (new_event.get_gedcom_date() == "18 DEC 2013")
Exemplo n.º 16
0
 def test_adding_a_partner(self):
     '''
     Testing adding a parent to a profile
     '''
     partner_profile = gen_profile(ACTUAL_NAME, FATHER_SURNAME)
     my_event = event_profile("marriage")
     my_event.setDate(2017, 11, 20)
     partner_profile.setCheckedDate("marriage", 2017, 10, 20)
     partner_profile.setPlaces("marriage",GENERIC_PLACE_STRING , language="es")
     profile.profile.create_as_a_partner(partner_profile, geni_input = BROTHER_PROFILE_SANDBOX)
     #TODO: add checking of marriage data once is included
     assert(partner_profile.properly_executed)
     assert(partner_profile.delete_profile())
Exemplo n.º 17
0
 def set_research_item(self, log_id, repository = "", source = "", result = ""):
     '''
     This will introduce a new research item inside the given research log
     log_id is the id of the research log that will contain the research item
     repository is the location of the research, like a webpage
     source is the source of hte information
     result is the final outcome
     '''
     #Get the date of today in the form of RootsMagic
     new_event = event_profile("residence")
     today = date.today()
     new_event.setDate(today.year, today.month, today.day, "EXACT")
     date_of_research = return_date_from_event(new_event)
     new_item = "INSERT INTO ResearchItemTable(LogID,Date,Repository,Source,Result) VALUES(?,?,?,?,?)"
     self.database.execute( new_item, (str(log_id), date_of_research, repository, source, result, ) )
     self.database.commit()
Exemplo n.º 18
0
 def get_specific_event(self, event_name):
     '''
     This function will provide the date and related event data of the date
     by looking to the database for this specific data
     '''
     events = self.database.execute("SELECT * FROM EventTable WHERE OwnerId=" + str(self.owner_id) + " AND  EventType=" +
                                    DATE_EVENT_ID[event_name])
     
     date_data = events.fetchone()
     if date_data: 
         event_output = event_profile(event_name)
         year_end = None
         month_end = None
         day_end = None
         #TODO: everything down here will require update with the new data model
         accuracy_value = "EXACT"
         if date_data[7][1] == "B":
             accuracy_value = "BEFORE"
         elif date_data[7][1] == "A":
             accuracy_value = "AFTER"
         elif date_data[7][1] == "R":
             #Only in the case of dates between is when we analyze and define the dates after
             accuracy_value = "BETWEEN"
             year_end = int(date_data[7][14:18])
             month_end = int(date_data[7][18:20])
             day_end = int(date_data[7][20:22])
             if year_end == 0 : year_end = None
             if month_end == 0 : month_end = None
             if day_end == 0 : day_end = None
         elif date_data[7][12] == "C":
             accuracy_value = "ABOUT" 
         year = int(date_data[7][3:7])
         month = int(date_data[7][7:9])
         day = int(date_data[7][9:11])
         if month == 0: month = None
         if day == 0: day = None
         event_output.setDate(year, month, day, accuracy_value, year_end, month_end, day_end)
         return event_output
     else: 
         return None
Exemplo n.º 19
0
    def testName(self):
        '''
        Testing basic introduction of new profiles and families.
        '''
        db = gen_database()
        assert (db.get_db_kind() == "COMMON")
        person1 = gen_profile("Name", "Surname")
        person2 = gen_profile("Name2", "Surname2")
        person3 = gen_profile("Chid", "Surname2")
        assert (db.add_profile(person1) == "I1")
        assert (db.add_profile(person2) == "I2")
        assert (db.add_profile(person3) == "I3")
        assert (db.add_family(father="I1", mother="I2",
                              children=["I3"]) == "F1")
        assert (db.get_profile_by_ID("I1").getName() == "Name")
        assert (len(db.get_several_profile_by_ID(["I1", "I2"])) == 2)
        assert (db.get_family_by_ID("F1").getFather() == "I1")
        assert (db.get_family_by_ID("F1").get_id() == "F1")
        assert (db.get_family_by_ID("xxx1") == None)
        assert (db.get_profile_by_ID("xxx1") == None)

        id_fam, fam = db.get_family_from_child("I3")
        assert (id_fam == "F1")
        assert (fam.getMother() == "I2")
        marriage_event = event_profile("marriage")
        fam.setMarriage(marriage_event)
        assert (fam.getMarriage() == marriage_event)

        id_fam2, fam2 = db.get_family_from_child("I1")
        assert (id_fam2 == None)
        #Get father of profile
        assert (db.get_father_from_child("I3")[0] == "I1")
        #Get mother of profile
        assert (db.get_mother_from_child("I3")[0] == "I2")
        #Get Children function
        assert ("I3" in db.get_all_children("I1"))
        assert ("I2" in db.get_partners_from_profile("I1"))
 def test_compare_date(self):
     '''
     Test comparison of dates with scoring
     '''
     date1 = date(2018, 1, 1)
     date2 = date(2018, 2, 6)
     event1 = event_profile("birth")
     event1.setDate(2018, 1, 1)
     event2 = event_profile("birth")
     event3 = event_profile("birth")
     event3.setDate(2018, 2, 6)
     #No difference score
     score, factor = get_score_compare_dates(event1, event1)
     assert (score == 2.0)
     assert (factor == 1.0)
     #1 day of different
     event2.setDate(2018, 1, 2)
     score, factor = get_score_compare_dates(event1, event2)
     assert (score > 1.8)
     assert (factor > 0.9)
     #One week of different
     event2.setDate(2018, 1, 8)
     score, factor = get_score_compare_dates(event1, event2)
     assert (score > 1.4)
     assert (factor > 0.7)
     #One month of difference
     event2.setDate(2018, 2, 6)
     score, factor = get_score_compare_dates(event1, event2)
     assert (score > 0.8)
     assert (factor > 0.4)
     #one year of different
     event2.setDate(2019, 1, 1)
     score, factor = get_score_compare_dates(event1, event2)
     assert (score > 0.08)
     assert (factor > 0.04)
     #About parameters
     event2.setDate(2017, accuracy="ABOUT")
     score, factor = get_score_compare_dates(event3, event2)
     assert (score == 1.0)
     assert (factor == 1.0)
     #A little bith more than one year
     event2.setDate(2016, accuracy="ABOUT")
     score, factor = get_score_compare_dates(event3, event2)
     assert (score > 0.95)
     assert (factor == 1.0)
     #Several years
     event2.setDate(2013, accuracy="ABOUT")
     score, factor = get_score_compare_dates(event3, event2)
     assert (score > 0.2)
     assert (factor > 0.4)
     #Far beyond....
     event2.setDate(2010, accuracy="ABOUT")
     score, factor = get_score_compare_dates(event3, event2)
     assert (score < 0.1)
     assert (factor > 0.1)
     #Let's check the dates
     event2.setDate(2010, accuracy="ABOUT")
     event3.setDate(2010, accuracy="ABOUT")
     score, factor = get_score_compare_dates(event2, event3)
     assert (score == 1.0)
     assert (factor == 1.0)
     #4 years with about different
     event2.setDate(2014, accuracy="ABOUT")
     event3.setDate(2010, accuracy="ABOUT")
     score, factor = get_score_compare_dates(event2, event3)
     assert (score > 0.499)
     assert (factor > 0.799)
     #7 years with about different
     event2.setDate(2017, accuracy="ABOUT")
     event3.setDate(2010, accuracy="ABOUT")
     score, factor = get_score_compare_dates(event2, event3)
     assert (score > 0.37999)
     assert (factor > 0.41999)
     #20 years with about different
     event2.setDate(2030, accuracy="ABOUT")
     event3.setDate(2010, accuracy="ABOUT")
     score, factor = get_score_compare_dates(event2, event3)
     assert (score > 0.04999)
     assert (factor > 0.074999)
     #Befores become irrelevant
     event2.setDate(2040, accuracy="BEFORE")
     event3.setDate(2030, accuracy="BEFORE")
     score, factor = get_score_compare_dates(event2, event3)
     assert (score == 0.0)
     assert (factor == 1.0)
     #Befores become irrelevant
     event2.setDate(2040, accuracy="BEFORE")
     event3.setDate(2030, accuracy="ABOUT")
     score, factor = get_score_compare_dates(event2, event3)
     assert (score == 0.0)
     assert (factor == 1.0)
     #Inconsistentcy gives null
     event2.setDate(2040, accuracy="BEFORE")
     event3.setDate(2050, accuracy="EXACT")
     score, factor = get_score_compare_dates(event2, event3)
     assert (score == 0.0)
     assert (factor == 0.0)
     #After becomes irrelevant
     event2.setDate(2040, accuracy="AFTER")
     event3.setDate(2030, accuracy="AFTER")
     score, factor = get_score_compare_dates(event2, event3)
     assert (score == 0.0)
     assert (factor == 1.0)
     #After becomes irrelevant
     event2.setDate(2020, accuracy="AFTER")
     event3.setDate(2030, accuracy="ABOUT")
     score, factor = get_score_compare_dates(event2, event3)
     assert (score == 0.0)
     assert (factor == 1.0)
     #After becomes irrelevant
     event2.setDate(2040, accuracy="AFTER")
     event3.setDate(2020, accuracy="EXACT")
     score, factor = get_score_compare_dates(event2, event3)
     assert (score == 0.0)
     assert (factor == 0.0)
     #After becomes irrelevant
     event2.setDate(2030, accuracy="ABOUT")
     event3.setDate(2040, accuracy="BEFORE")
     score, factor = get_score_compare_dates(event2, event3)
     assert (score == 0.0)
     assert (factor == 1.0)
     #After becomes irrelevant
     event2.setDate(2030, accuracy="ABOUT")
     event3.setDate(2020, accuracy="BEFORE")
     score, factor = get_score_compare_dates(event2, event3)
     assert (score == 0.0)
     assert (factor == 0.0)
     #After becomes irrelevant
     event2.setDate(2030, accuracy="ABOUT")
     event3.setDate(2020, accuracy="AFTER")
     score, factor = get_score_compare_dates(event2, event3)
     assert (score == 0.0)
     assert (factor == 1.0)
     #After becomes irrelevant
     event2.setDate(2030, accuracy="ABOUT")
     event3.setDate(2040, accuracy="AFTER")
     score, factor = get_score_compare_dates(event2, event3)
     assert (score == 0.0)
     assert (factor == 0.0)
Exemplo n.º 21
0
 def __init__(self, union_id):
     '''
     Constructor it takes the union id from Geni
     '''
     #We initiate the base classes
     geni_calls.__init__(self)
     family_profile.__init__(self)
     data = ""
     if (union_id in geni.GENI_CALLED_UNIONS):
         #In order to save calls we try to save the different calls
         data = geni.GENI_CALLED_UNIONS[union_id]
     else:
         url = geni.GENI_API + union_id + geni.GENI_SINGLE_TOKEN + geni.get_token(
         )
         r = geni.geni_request_get(url)
         data = r.json()
         geni.GENI_CALLED_UNIONS[union_id] = data
     self.union_data = {}
     #Initiating values of the parametrs
     self.union_data["partners"] = []
     for key_value in data.keys():
         if key_value == "id": self.union_data["id"] = data[key_value]
         if key_value == "url": self.union_data["url"] = data[key_value]
         if key_value == "guid": self.union_data["guid"] = data[key_value]
         if key_value == "marriage_date":
             #We might have an existing marriage in the file
             self.union_data["marriage"] = self.get_date(
                 "marriage",
                 data["marriage_date"],
                 previous_event=self.union_data.get("marriage", None))
         if key_value == "marriage_location":
             place_data = {}
             for location_key in data["marriage_location"].keys():
                 if location_key == "city":
                     place_data[location_key] = data["marriage_location"][
                         location_key]
                 if location_key == "county":
                     place_data[location_key] = data["marriage_location"][
                         location_key]
                 if location_key == "state":
                     place_data[location_key] = data["marriage_location"][
                         location_key]
                 if location_key == "country":
                     place_data[location_key] = data["marriage_location"][
                         location_key]
                 if location_key == "country_code":
                     place_data[location_key] = data["marriage_location"][
                         location_key]
                 if location_key == "latitude":
                     place_data[location_key] = data["marriage_location"][
                         location_key]
                 if location_key == "longitude":
                     place_data[location_key] = data["marriage_location"][
                         location_key]
                 if location_key == "formatted_location":
                     place_data[location_key] = data["marriage_location"][
                         location_key]
             if not ("marriage" in self.union_data.keys()):
                 self.union_data["marriage"] = event_profile("marriage")
             self.union_data["marriage"].setLocationAlreadyProcessed(
                 place_data)
         if key_value == "status":
             self.union_data["status"] = data[key_value]
         if key_value == "partners":
             #The union stores the partner as a full address, but we are looking for the profile ID which is stored
             for partner in data[key_value]:
                 self.union_data["partners"].append(partner.split("/")[-1])
             self.setFather(
                 geni.get_profile_id_from_address(data[key_value][0]))
             if len(data.get(key_value, None)) > 1:
                 self.setMother(
                     geni.get_profile_id_from_address(data[key_value][1]))
         if key_value == "children":
             self.union_data["children"] = data[key_value]
             children = []
             for child in data[key_value]:
                 children.append(geni.get_profile_id_from_address(child))
             self.setChild(children)
 def test_date_check(self):
     '''
     Test of the function for date check
     '''
     event4end = event_profile("death")
     event4end.setDate(2014,accuracy = "ABOUT")
     event2bend = event_profile("burial")
     event2bend.setDate(2014,month = 2 , day = 1, accuracy = "BEFORE")
     #Test bug of burial and death
     assert(checkDateConsistency([event4end, event2bend]))
     
     
     #Going events onebyone
     event1 = event_profile("residence")
     event1.setDate(2017, 1, 1)
     event4 = event_profile("birth")
     event4.setDate(2014, 1, 1)
     assert(checkDateConsistency( [event1]   ))
     assert(checkDateConsistency([event4]))
     event1b = event_profile("burial")
     event1b.setDate(2017, 1, 1)
     assert(checkDateConsistency([event4, event1b]))
     event1d = event_profile("death")
     event1d.setDate(2017, 1, 1)
     event2 = event_profile("marriage")
     event2.setDate(2016, 1, 1)
     event3 = event_profile("baptism")
     event3.setDate(2015, 1, 1)
     assert(checkDateConsistency([event3, event2,event1d, event4 ]))
     
     
     event1bi = event_profile("birth")
     event1bi.setDate(2017, 1, 1)
     event4b = event_profile("burial")
     event4b.setDate(2014, 1, 1)
     
     assert(not checkDateConsistency([event1bi, event4b]))
     event1ba = event_profile("baptism")
     event1ba.setDate(2017, 1, 1)
     event4d = event_profile("death")
     event4d.setDate(2014, 1, 1)
     assert(not checkDateConsistency([event4d, event1ba]))
     event4bap = event_profile("baptism")
     event4bap.setDate(2014, 1, 1)
     assert(not checkDateConsistency([event4bap, event1bi]))
     #Checking that about dates are ok although the date2b is later than date4
     event2btest = event_profile("birth")
     event2btest.setDate(2014, 2, 1)
     event4test = event_profile("burial")
     event4test.setDate(2014,accuracy = "ABOUT")
     event5test = event_profile("death")
     event5test.setDate(2014,accuracy = "ABOUT")
     assert(checkDateConsistency([event2btest, event4test, event5test ]))
     
     event4end = event_profile("death")
     event4end.setDate(2014,accuracy = "ABOUT")
     event2bend = event_profile("burial")
     event2bend.setDate(2014,month = 2 , day = 1, accuracy = "BEFORE")
     #Test bug of burial and death
     assert(checkDateConsistency([event4end, event2bend]))
     
     #Checking some other methods
     assert(is_this_date_earlier_or_simultaneous_to_this(1912, 12, 1, None, 12, 1) == True)
     assert(is_this_date_earlier_or_simultaneous_to_this(None, 12, 1, 1914, 12, 1) == False)
     assert(is_this_date_earlier_or_simultaneous_to_this(None, 12, 1, None, 12, 1) == None)
 def test_compare_date(self):
     '''
     Test comparison of dates with scoring
     '''
     event1 = event_profile("birth")
     event1.setDate(2018,1,1)
     event2 = event_profile("birth")
     event3 = event_profile("birth")
     event3.setDate(2018,2,6)
     event4 = event_profile("birth")
     event4.setDate(2018)
     #Case of no data available
     score, factor = get_score_compare_dates(event3, event4)
     assert(score*factor > 1.8)
     #No difference score
     score, factor = get_score_compare_dates(event1, event1)
     assert(score == 2.0)
     assert(factor == 1.0)
     #1 day of different
     event2.setDate(2018,1,2)
     score, factor = get_score_compare_dates(event1, event2)
     assert(score >1.8)
     assert(factor > 0.9)
     #One week of different
     event2.setDate(2018,1,8)
     score, factor = get_score_compare_dates(event1, event2)
     assert(score >1.4)
     assert(factor > 0.7)
     #One month of difference
     event2.setDate(2018,2,6)
     score, factor = get_score_compare_dates(event1, event2)
     assert(score >0.8)
     assert(factor > 0.4)
     #one year of different
     event2.setDate(2019,1,1)
     score, factor = get_score_compare_dates(event1, event2)
     assert(score >0.08)
     assert(factor > 0.04)
     #About parameters
     event2.setDate(2017, accuracy="ABOUT")
     score, factor = get_score_compare_dates(event3, event2)
     assert(score == 1.0)
     assert(factor == 1.0)
     #A little bith more than one year
     event2.setDate(2016, accuracy="ABOUT")
     score, factor = get_score_compare_dates(event3, event2)
     assert(score >0.95)
     assert(factor == 1.0)
     #Several years
     event2.setDate(2013, accuracy="ABOUT")
     score, factor = get_score_compare_dates(event3, event2)
     assert(score >0.2)
     assert(factor > 0.4)
     #Far beyond....
     event2.setDate(2010, accuracy="ABOUT")
     score, factor = get_score_compare_dates(event3, event2)
     assert(score < 0.1)
     assert(factor > 0.1)
     #Let's check the dates
     event2.setDate(2010, accuracy="EXACT")
     event3.setDate(1910, accuracy="EXACT")
     score, factor = get_score_compare_dates(event2, event3)
     assert(score < 0.003)
     assert(factor < 0.002)
     #Let's check the dates
     event2.setDate(2010, accuracy="ABOUT")
     event3.setDate(2010, accuracy="ABOUT")
     score, factor = get_score_compare_dates(event2, event3)
     assert(score == 1.0)
     assert(factor == 1.0)
     #4 years with about different
     event2.setDate(2014, accuracy="ABOUT")
     event3.setDate(2010, accuracy="ABOUT")
     score, factor = get_score_compare_dates(event2, event3)
     assert(score > 0.499)
     assert(factor > 0.799)
     #7 years with about different
     event2.setDate(2017, accuracy="ABOUT")
     event3.setDate(2010, accuracy="ABOUT")
     score, factor = get_score_compare_dates(event2, event3)
     assert(score > 0.37999)
     assert(factor > 0.41999)
     #20 years with about different
     event2.setDate(2030, accuracy="ABOUT")
     event3.setDate(2010, accuracy="ABOUT")
     score, factor = get_score_compare_dates(event2, event3)
     assert(score > 0.04999)
     assert(factor > 0.074999)
     #Befores become irrelevant
     event2.setDate(2040, accuracy="BEFORE")
     event3.setDate(2030, accuracy="BEFORE")
     score, factor = get_score_compare_dates(event2, event3)
     assert(score == 0.0)
     assert(factor == 1.0)
     #Befores become irrelevant
     event2.setDate(2040, accuracy="BEFORE")
     event3.setDate(2030, accuracy="ABOUT")
     score, factor = get_score_compare_dates(event2, event3)
     assert(score == 0.0)
     assert(factor == 1.0)
     #Inconsistentcy gives null
     event2.setDate(2040, accuracy="BEFORE")
     event3.setDate(2050, accuracy="EXACT")
     score, factor = get_score_compare_dates(event2, event3)
     assert(score == 0.0)
     assert(factor == 0.0)
     #After becomes irrelevant
     event2.setDate(2040, accuracy="AFTER")
     event3.setDate(2030, accuracy="AFTER")
     score, factor = get_score_compare_dates(event2, event3)
     assert(score == 0.0)
     assert(factor == 1.0)
     #After becomes irrelevant
     event2.setDate(2020, accuracy="AFTER")
     event3.setDate(2030, accuracy="ABOUT")
     score, factor = get_score_compare_dates(event2, event3)
     assert(score == 0.0)
     assert(factor == 1.0)
     #After becomes irrelevant
     event2.setDate(2040, accuracy="AFTER")
     event3.setDate(2020, accuracy="EXACT")
     score, factor = get_score_compare_dates(event2, event3)
     assert(score == 0.0)
     assert(factor == 0.0)
     #After becomes irrelevant
     event2.setDate(2030, accuracy="ABOUT")
     event3.setDate(2040, accuracy="BEFORE")
     score, factor = get_score_compare_dates(event2, event3)
     assert(score == 0.0)
     assert(factor == 1.0)
     #After becomes irrelevant
     event2.setDate(2030, accuracy="ABOUT")
     event3.setDate(2020, accuracy="BEFORE")
     score, factor = get_score_compare_dates(event2, event3)
     assert(score == 0.0)
     assert(factor == 1.0)
     #After becomes irrelevant
     event2.setDate(2030, accuracy="ABOUT")
     event3.setDate(2020, accuracy="AFTER")
     score, factor = get_score_compare_dates(event2, event3)
     assert(score == 0.0)
     assert(factor == 1.0)
     #After becomes irrelevant
     event2.setDate(2030, accuracy="ABOUT")
     event3.setDate(2040, accuracy="AFTER")
     score, factor = get_score_compare_dates(event2, event3)
     assert(score == 0.0)
     assert(factor == 0.0)
     #Comparing between dates
     event2.setDate(2030, 5, 23, accuracy="EXACT")
     event3.setDate(2030,2,21, accuracy="BETWEEN", year_end = 2031)
     score, factor = get_score_compare_dates(event2, event3)
     assert(score == 1.2)
     assert(factor == 1.0)
     event2.setDate(2030, accuracy="EXACT")
     event3.setDate(2029, accuracy="BETWEEN", year_end = 2031)
     score, factor = get_score_compare_dates(event2, event3)
     assert(score == 1.0)
     assert(factor == 1.0)
     event2.setDate(2030, accuracy="EXACT")
     event3.setDate(2029, accuracy="BETWEEN", year_end = 2033)
     score, factor = get_score_compare_dates(event2, event3)
     assert(score == 0.5)
     assert(factor == 1.0)
     event2.setDate(2030, accuracy="EXACT")
     event3.setDate(2029, accuracy="BETWEEN", year_end = 2036)
     score, factor = get_score_compare_dates(event2, event3)
     assert(score< 0.45)
     assert(factor == 1.0)
     event2.setDate(2030, accuracy="EXACT")
     event3.setDate(2029, accuracy="BETWEEN", year_end = 2046)
     score, factor = get_score_compare_dates(event2, event3)
     assert(score < 0.12)
     assert(factor == 1.0)
     event2.setDate(2025, accuracy="EXACT")
     event3.setDate(2029, accuracy="BETWEEN", year_end = 2033)
     score, factor = get_score_compare_dates(event2, event3)
     assert(score == 0.0)
     assert(factor == 0.0)
     event2.setDate(2033, accuracy="BETWEEN")
     event3.setDate(2029, accuracy="EXACT", year_end = 2031)
     score, factor = get_score_compare_dates(event2, event3)
     assert(score == 0.0)
     assert(factor == 0.0)
     event2.setDate(2030, accuracy="BEFORE")
     event3.setDate(2029, accuracy="BETWEEN", year_end = 2031)
     score, factor = get_score_compare_dates(event2, event3)
     assert(score == 0.0)
     assert(factor == 1.0)
     event2.setDate(2028, accuracy="BEFORE")
     event3.setDate(2029, accuracy="BETWEEN", year_end = 2031)
     score, factor = get_score_compare_dates(event2, event3)
     assert(score == 0.0)
     assert(factor == 0.0)
     event2.setDate(2029, accuracy="BETWEEN", year_end = 2031)
     event3.setDate(2032, accuracy="BEFORE")
     score, factor = get_score_compare_dates(event2, event3)
     assert(score == 0.0)
     assert(factor == 1.0)
     
     
     event2.setDate(2030, accuracy="AFTER")
     event3.setDate(2029, accuracy="BETWEEN", year_end = 2031)
     score, factor = get_score_compare_dates(event2, event3)
     assert(score == 0.0)
     assert(factor == 1.0)
     event2.setDate(2033, accuracy="AFTER")
     event3.setDate(2029, accuracy="BETWEEN", year_end = 2031)
     score, factor = get_score_compare_dates(event2, event3)
     assert(score == 0.0)
     assert(factor == 0.0)
     event2.setDate(2029, accuracy="BETWEEN", year_end = 2031)
     event3.setDate(2028, accuracy="AFTER")
     score, factor = get_score_compare_dates(event2, event3)
     assert(score == 0.0)
     assert(factor == 1.0)
     event2.setDate(2028, accuracy="BETWEEN", year_end = 2036)
     event3.setDate(2029, accuracy="BETWEEN", year_end = 2031)
     score, factor = get_score_compare_dates(event2, event3)
     assert(score < 0.32)
     assert(factor == 1.0)
     event2.setDate(2028, accuracy="BETWEEN", year_end = 2031)
     event3.setDate(2034, accuracy="BETWEEN", year_end = 2037)
     score, factor = get_score_compare_dates(event2, event3)
     assert(score == 0.0)
     assert(factor == 0.0)
     event2.setDate(2028, accuracy="BETWEEN", year_end = 2031)
     event3.setDate(2024, accuracy="BETWEEN", year_end = 2027)
     score, factor = get_score_compare_dates(event2, event3)
     assert(score == 0.0)
     assert(factor == 0.0)
     event2.setDate(2030, accuracy="ABOUT")
     event3.setDate(2029, accuracy="BETWEEN", year_end = 2032)
     score, factor = get_score_compare_dates(event2, event3)
     assert(score == 0.5)
     assert(factor > 0.99)
     event2.setDate(2033, accuracy="ABOUT")
     event3.setDate(2029, accuracy="BETWEEN", year_end = 2031)
     score, factor = get_score_compare_dates(event2, event3)
     assert(score == 1.0)
     assert(factor > 0.71)
     event2.setDate(2028, accuracy="BETWEEN", year_end = 2031)
     event3.setDate(2010, accuracy="ABOUT", year_end = 2027)
     score, factor = get_score_compare_dates(event2, event3)
     assert(score == 0.5)
     assert(factor > 0.39)
Exemplo n.º 24
0
 def __init__(self, union_id):
     '''
     Constructor it takes the union id from Geni
     '''
     #We initiate the base classes
     geni_calls.__init__(self)
     data = ""
     if (union_id in geni.GENI_CALLED_UNIONS):
         #In order to save calls we try to save the different calls
         data = geni.GENI_CALLED_UNIONS[union_id]
     else:
         url = geni.GENI_API + union_id + geni.GENI_SINGLE_TOKEN + geni.get_token(
         )
         r = geni.geni_request_get(url)
         data = r.json()
         geni.GENI_CALLED_UNIONS[union_id] = data
     self.union_data = {}
     for key_value in data.keys():
         if key_value == "id": self.union_data["id"] = data[key_value]
         if key_value == "url": self.union_data["url"] = data[key_value]
         if key_value == "guid": self.union_data["guid"] = data[key_value]
         if key_value == "marriage_date":
             #We might have an existing marriage in the file
             self.union_data["marriage"] = self.get_date(
                 "marriage",
                 data["marriage_date"],
                 previous_event=self.union_data.get("marriage", None))
         if key_value == "marriage_location":
             place_data = {}
             for location_key in data["marriage_location"].keys():
                 if location_key == "city":
                     place_data[location_key] = data["marriage_location"][
                         location_key]
                 if location_key == "county":
                     place_data[location_key] = data["marriage_location"][
                         location_key]
                 if location_key == "state":
                     place_data[location_key] = data["marriage_location"][
                         location_key]
                 if location_key == "country":
                     place_data[location_key] = data["marriage_location"][
                         location_key]
                 if location_key == "country_code":
                     place_data[location_key] = data["marriage_location"][
                         location_key]
                 if location_key == "latitude":
                     place_data[location_key] = data["marriage_location"][
                         location_key]
                 if location_key == "longitude":
                     place_data[location_key] = data["marriage_location"][
                         location_key]
                 if location_key == "formatted_location":
                     place_data[location_key] = data["marriage_location"][
                         location_key]
             if not ("marriage" in self.union_data.keys()):
                 self.union_data["marriage"] = event_profile("marriage")
             self.union_data["marriage"].setLocationAlreadyProcessed(
                 place_data)
         if key_value == "status":
             self.union_data["status"] = data[key_value]
         if key_value == "partners":
             self.union_data["partners"] = data[key_value]
         if key_value == "children":
             self.union_data["children"] = data[key_value]
Exemplo n.º 25
0
    def test_merge_profile(self):
        '''
        Test merge of profiles
        '''
        profile = gen_profile("Juana", "Bargas")
        profile2 = gen_profile("Juana", "de Bargas Gómez")
        profile.add_nickname("Juana de Bargas")
        assert (profile.get_nicknames() == ["Juana de Bargas"])
        profile.setCheckedDate("birth", 2016, 4, 23, "EXACT")
        date1 = date(2016, 1, 1)
        date2 = date(2018, 8, 25)
        date3 = date(2018, 8, 27)
        profile2.setCheckedDateWithDates("birth", date1, accuracy="ABOUT")
        profile.setCheckedDate("death", 2018, 1, 1, "ABOUT")
        profile2.setCheckedDate("death", 2018, 8, 24, "EXACT")
        profile2.setCheckedDate("baptism", 2017, 1, 1, "ABOUT")
        profile2.setCheckedDateWithDates("burial",
                                         date2,
                                         accuracy="BETWEEN",
                                         date2=date3)
        event_fail = event_profile("residence")
        event_fail.setDate(1800, 2, 1)
        assert (not profile2.setNewEvent(event_fail))
        event_fail.setDate(2017, 11, 1)
        assert (profile2.setNewEvent(event_fail))
        profile.setComments("comment1")
        profile2.setComments("comment2")
        profile.setWebReference("THIS")
        profile2.setWebReference("OTHER")
        profile.gen_data["birth_place"] = {}
        profile.gen_data["birth_place"]["raw"] = "a"
        profile.set_accessible(True)
        profile.set_main_language("es")
        profile2.setPlaces("birth", GENERIC_PLACE_WITH_PLACE)

        result = profile.merge_profile(profile2,
                                       language="es",
                                       convention="spanish_surname")

        assert (result)
        assert (profile.gen_data["name"] == "Juana")
        assert (profile.gen_data["surname"] == "de Bargas Gómez")
        assert (profile.gen_data["birth"].get_date() == date(2016, 4, 23))
        assert (profile.gen_data["birth"].get_accuracy() == "EXACT")
        assert (profile.gen_data["comments"] == "comment1\ncomment2")
        assert ("THIS" in profile.get_all_urls())
        assert ("OTHER" in profile.get_all_urls())
        assert (len(profile.get_all_webs()) == 2)
        assert (profile2.get_specific_event("death").get_date() == date(
            2018, 8, 24))
        assert (profile2.get_specific_event("death").get_accuracy() == "EXACT")
        assert (
            profile2.get_specific_event("burial").get_accuracy() == "BETWEEN")
        assert (profile2.get_specific_event("burial").get_year_end() == 2018)
        assert (profile2.get_specific_event("baptism").get_date() == date(
            2017, 1, 1))
        assert (
            profile2.get_specific_event("baptism").get_accuracy() == "ABOUT")
        assert (profile2.get_specific_event("birth").get_location()
                ["place_name"] == "Calle Nuestra Señora De Los Remedios")
        assert (profile2.get_this_profile_url() == None)
        #From the moment, the common profile class provides only the date of today as common date, to be improved in the future
        assert (profile.get_update_datetime().day == datetime.now().day)

        profile3 = gen_profile("Juana", "Bargas")
        profile4 = gen_profile("Facundo", "Smith")
        result2 = profile3.merge_profile(profile4,
                                         language="es",
                                         convention="spanish_surname")
        self.assertFalse(result2)
    def test_insert_methods(self):
        '''
        Testing insert methods inside RootsMagic
        '''
        initial_file = os.path.join(self.filelocation, "Rootstest.rmgc")
        working_file = os.path.join(self.filelocation, "Rootstest_insert.rmgc")

        if os.path.exists(working_file): os.remove(working_file)
        copyfile(initial_file, working_file)

        db = database_rm(working_file)

        prof = db.get_profile_by_ID(5)
        prof.setWebReference([TEST_GOOGLE, TEST_FACEBOOK])
        prof.setWebReference(TEST_WIKIPEDIA,
                             name="Wikipedia",
                             notes="introduced")
        webs = prof.get_all_webs()
        google_found = False
        for web in webs:
            if web["url"] == "http://www.google.com":
                if web["name"] == "": google_found = True
        assert (google_found)
        assert (prof.update_web_ref(TEST_GOOGLE, "Google", "A note"))
        google_found = False
        webs = prof.get_all_webs()
        for web in webs:
            if web["name"] == "Google": google_found = True
        assert (google_found)
        assert (TEST_GOOGLE in prof.get_all_urls())
        assert (TEST_WIKIPEDIA in prof.get_all_urls())
        assert (prof.get_specific_web("Google"))
        assert (not prof.get_specific_web("Not existing"))

        prof.del_web_ref(TEST_WIKIPEDIA)
        assert (not (TEST_WIKIPEDIA in prof.get_all_urls()))
        #It does not essent
        assert (prof.update_web_ref("DOES NOT EXISTS", "Googles", "A note") is
                None)

        prof.set_task("TEST", details="HAHA")

        #Introduce a research log
        row_id = prof.set_task("TEST_OF_LOG", task_type=2)
        assert (prof.get_specific_research_log("TEST_OF_LOG"))
        assert (prof.get_specific_research_log("TEST_NOT_EXISTING") == None)

        prof.set_research_item(row_id,
                               repository="www.google.com",
                               source="GOOGLE",
                               result="GOOD")
        prof.update_research_item(row_id,
                                  "www.google.com",
                                  source="GOOGLE2",
                                  result="BAD")
        #Error when 2 research logs of the same name in the same profile.
        profb = db.get_profile_by_ID(6)
        with self.assertLogs("rootsmagic", level="WARNING") as cm:
            profb.get_specific_research_log("TWICE")
            assert ("TWICE" in cm.output[0])

        prof2 = db.get_profile_by_ID(1)

        assert (len(prof2.get_all_research_item()) == 2)

        prof3 = db.get_profile_by_ID(3)

        assert (len(prof3.get_all_research_item()) == 0)

        #Setting up the sources
        assert (prof2.get_source_id_ref("TESTING") == None)
        prof2.set_source_id("TESTING")
        prof2.setWebReference("http//here.com", "NEW_URL")
        assert (prof2.get_source_id_ref("TESTING") == 1)
        assert (prof2.get_citation_with_comments("http://test.com") == None)
        prof2.set_citation(1, details="http://test.com")
        assert (prof2.get_citation_with_comments("http://test.com") == 1)

        #Testing the insert of the profiles
        insert_profile = gen_profile("RootsMagic", "Adding")
        insert_profile.setCheckedGender("M")
        insert_profile.setCheckedDate("birth", 1820, accuracy="ABOUT")

        event_both = event_profile("birth")
        event_both.setLocationAlreadyProcessed(
            {"formatted_location": "Gallegos, Segovia"})
        event_both.setDate(1820, accuracy="ABOUT")
        event_date = event_profile("death")
        event_date.setDate(1902, month=2, day=1, accuracy="EXACT")
        event_location = event_profile("burial")
        event_location.setLocation("Aldealaguna, Segovia, Spain")

        insert_profile.setNewEvent(event_both)
        insert_profile.setNewEvent(event_date)
        insert_profile.setNewEvent(event_location)

        prof_id = db.add_profile(insert_profile)
        #Check the results
        prof_entered = db.get_profile_by_ID(prof_id)
        assert (prof_entered.getName() == "RootsMagic")
        assert (prof_entered.get_specific_event("birth").get_year() == 1820)
        assert (
            prof_entered.get_specific_event("birth").get_accuracy() == "ABOUT")
        assert (prof_entered.get_specific_event("birth").get_location()["raw"]
                == "Gallegos, Segovia")
        assert (prof_entered.get_specific_event("death").get_year() == 1902)
        assert (
            prof_entered.get_specific_event("death").get_accuracy() == "EXACT")
        assert (
            prof_entered.get_specific_event("death").get_location() == None)
        assert (prof_entered.get_specific_event("burial").get_year() == None)
        assert (prof_entered.get_specific_event("burial").get_location()["raw"]
                == 'Aldealaguna, Segovia, Spain')

        #Now, let's also create a family for this profile
        insert_wife = gen_profile("RootsMagic", "Wife")
        insert_wife.setCheckedGender("F")
        wife_id = db.add_profile(insert_wife)
        prof_wife = db.get_profile_by_ID(wife_id)
        event_marriage = event_profile("marriage")
        event_marriage.setDate(1815, accuracy="ABOUT")
        assert (prof_wife.get_specific_event("marriage") == [])
        fam_id = db.add_family(father=prof_id,
                               mother=wife_id,
                               children=[6],
                               marriage=event_marriage)
        assert (prof_wife.get_specific_event("marriage")[0].get_year() == 1815)
        assert (db.get_family_from_child(6)[0] == fam_id)

        #Methods for updating the family of RootsMagic
        assert (not db.update_family(fam_id))
        new_husband = gen_profile("New", "Husband")
        new_wife = gen_profile("New", "Wife")
        new_child = gen_profile("New", "Child")
        new_husband_id = db.add_profile(new_husband)
        new_wife_id = db.add_profile(new_wife)
        new_child_id = db.add_profile(new_child)
        marriage = event_profile("marriage")
        marriage.setDate(1900)
        fam3 = db.get_family_by_ID(3)
        assert (fam3.getMother() == None)
        db.update_family(3,
                         mother_id=new_wife_id,
                         children=[new_child_id],
                         marriage=marriage)
        assert (fam3.getMother() == new_wife_id)

        fam4 = db.get_family_by_ID(4)
        assert (fam4.getFather() == None)
        db.update_family(4, father_id=new_husband_id, marriage=marriage)
        assert (fam4.getFather() == new_husband_id)

        new_child2 = gen_profile("Newer", "Child")
        new_child3 = gen_profile("Older", "Child")
        previous_len = len(fam4.getChildren())
        db.add_child(4, [new_child2, new_child3])
        assert (len(fam4.getChildren()) - previous_len == 2)

        new_partner1 = gen_profile("New", "Partner")
        new_marriage = event_profile("birth")
        new_marriage.set_year("2019")
        previous_partners = len(db.get_partners_from_profile(4))
        db.add_partner(4, new_partner1, new_marriage)
        assert (len(db.get_partners_from_profile(4)) - previous_partners == 1)

        db.close_db()
        if os.path.exists(working_file): os.remove(working_file)
Exemplo n.º 27
0
'''
Created on 8 oct. 2017

@author: Val

This example will show how to use several  common genealogical tools that can be used.

All these functionalities are independent of the rest of the code
'''
from pyGenealogy.gen_utils import checkDateConsistency, getBestDate, get_formatted_location, get_name_surname_from_complete_name
from datetime import date
from pyGenealogy.common_event import event_profile

all_events = []

birth_event = event_profile("birth")
birth_event.setDate(1900, 1, 1)
all_events.append(birth_event)
residence_event = event_profile("residence")
residence_event.setDate(1910, 1, 1)
all_events.append(residence_event)
baptism_event = event_profile("baptism")
baptism_event.setDate(1901, 1, 12)
all_events.append(baptism_event)
marriage_event = event_profile("marriage")
marriage_event.setDate(1930, 6, 1)
all_events.append(marriage_event)
death_event = event_profile("death")
death_event.setDate(1970, 1, 1)
all_events.append(death_event)
burial_event = event_profile("burial")
 def __get_profiles__(self):
     '''
     This function will take all different profiles included inside the excel file
     '''
     current_sheet = self.loaded_data[self.sheet_title]
     #Iterator of missing inptus
     number_missing = 0
     #The id number to be used
     id_profiles = 0
     #Temporal variable checking the correct reading
     correct_introduction = True
     #Intermediate variables for potential parent surnames in the input file
     potential_father_surname = []
     potential_father_surname_repetitions = []
     potential_mother_surname = []
     potential_mother_surname_repetitions = []
     #Intermediate variables for potential parent names in the input file
     potential_father_name = []
     potential_father_name_repetitions = []
     potential_mother_name = []
     potential_mother_name_repetitions = []
     #We firstly detect the surnames of the parents of the profile,we cannot avoid the double
     #iteration
     for row in range(self.initial_row + 1,
                      self.loaded_data[self.sheet_title].max_row + 1):
         for column_index in range(
                 self.initial_column,
                 self.loaded_data[self.sheet_title].max_column):
             column_criteria = current_sheet.cell(row=self.initial_row,
                                                  column=column_index).value
             cell_value = current_sheet.cell(row=row,
                                             column=column_index).value
             if (column_criteria
                     in ["father_full_name", "mother_full_name"]):
                 #If the cell_value is null we shall avoid continuing
                 if (cell_value is not None):
                     name_data = get_name_surname_from_complete_name(
                         cell_value,
                         convention=self.naming_convention,
                         language=self.language)
                     #We have two surnames or one?
                     surname_cand = name_data[1]
                     if (name_data[2] == 2):
                         surname_cand = name_data[1].split()[0]
                     if (column_criteria == "father_full_name"):
                         if (surname_cand not in potential_father_surname):
                             potential_father_surname.append(surname_cand)
                             potential_father_surname_repetitions.append(1)
                         else:
                             index = potential_father_surname.index(
                                 surname_cand)
                             potential_father_surname_repetitions[
                                 index] = potential_father_surname_repetitions[
                                     index] + 1
                         if (not name_data[0] in potential_father_name):
                             potential_father_name.append(name_data[0])
                             potential_father_name_repetitions.append(1)
                         else:
                             index = potential_father_name.index(
                                 name_data[0])
                             potential_father_name_repetitions[
                                 index] = potential_father_name_repetitions[
                                     index] + 1
                     elif (column_criteria == "mother_full_name"):
                         if (surname_cand not in potential_mother_surname):
                             potential_mother_surname.append(surname_cand)
                             potential_mother_surname_repetitions.append(1)
                         else:
                             index = potential_mother_surname.index(
                                 surname_cand)
                             potential_mother_surname_repetitions[
                                 index] = potential_mother_surname_repetitions[
                                     index] + 1
                         if (not name_data[0] in potential_mother_name):
                             potential_mother_name.append(name_data[0])
                             potential_mother_name_repetitions.append(1)
                         else:
                             index = potential_mother_name.index(
                                 name_data[0])
                             potential_mother_name_repetitions[
                                 index] = potential_mother_name_repetitions[
                                     index] + 1
     index_father_surname = potential_father_surname_repetitions.index(
         max(potential_father_surname_repetitions))
     index_mother_surname = potential_mother_surname_repetitions.index(
         max(potential_mother_surname_repetitions))
     father_surname = potential_father_surname[index_father_surname]
     mother_surname = potential_mother_surname[index_mother_surname]
     index_father_name = potential_father_name_repetitions.index(
         max(potential_father_name_repetitions))
     index_mother_name = potential_mother_name_repetitions.index(
         max(potential_mother_name_repetitions))
     father_name = potential_father_name[index_father_name]
     mother_name = potential_mother_name[index_mother_name]
     self.father_profile = gen_profile(father_name, father_surname)
     self.mother_profile = gen_profile(mother_name, mother_surname)
     children_surname = get_children_surname(father_surname, mother_surname,
                                             self.naming_convention)
     #Now we read the complete file
     for row in range(self.initial_row + 1,
                      self.loaded_data[self.sheet_title].max_row + 1):
         included_profile = gen_profile("TBD", children_surname)
         event_marriage = event_profile("marriage")
         is_marriage = False
         event_residence = event_profile("residence")
         is_residence = False
         included_right = True
         for column_index in range(
                 self.initial_column,
                 self.loaded_data[self.sheet_title].max_column):
             column_criteria = current_sheet.cell(row=self.initial_row,
                                                  column=column_index).value
             cell_value = current_sheet.cell(row=row,
                                             column=column_index).value
             #We are ignoring all those cells that are empty.
             if (cell_value):
                 this_introduction = True
                 #Ok, now we go one by one each of the different values
                 if (column_criteria == "gender"):
                     this_introduction = included_profile.setCheckedGender(
                         cell_value)
                 elif (column_criteria == "marriage_place_text"):
                     event_marriage.setLocation(cell_value, self.language)
                     is_marriage = True
                 elif (column_criteria == "residence_place_text"):
                     event_residence.setLocation(cell_value, self.language)
                     is_residence = True
                 elif (column_criteria == "marriage_date"):
                     mar_date = datetime.strptime(cell_value,
                                                  "%d %b %Y").date()
                     event_marriage.setDate(mar_date.year,
                                            mar_date.month,
                                            mar_date.day,
                                            accuracy="EXACT")
                 elif (column_criteria == "residence_date"):
                     if (is_year(cell_value)):
                         event_residence.setDate(datetime.strptime(
                             str(cell_value.replace(" ", "")),
                             "%Y").date().year,
                                                 accuracy="ABOUT")
                         is_residence = True
                 elif (column_criteria in LOCATION_EQUIVALENCE.keys()):
                     included_profile.setPlaces(
                         LOCATION_EQUIVALENCE[column_criteria], cell_value,
                         self.language)
                 elif (column_criteria == "person_url"):
                     included_profile.setWebReference(
                         "https://familysearch.org/" + cell_value)
                 elif (column_criteria in date_fields.keys()):
                     #Notice that we shall detect if the given date is a year or a specific date
                     #we will make the different using "about" and using datetime in the background
                     if (is_year(cell_value)):
                         this_introduction = self.__include_a_date__(
                             column_criteria, included_profile,
                             datetime.strptime(
                                 str(cell_value.replace(" ", "")),
                                 "%Y").date(), "ABOUT")
                     else:
                         this_introduction = self.__include_a_date__(
                             column_criteria, included_profile,
                             datetime.strptime(cell_value,
                                               "%d %b %Y").date(), "EXACT")
                 elif (column_criteria == "full_name"):
                     included_profile.set_name(
                         get_name_from_fullname(cell_value,
                                                potential_father_surname,
                                                potential_mother_surname,
                                                language=self.language))
                     #In the case the name if not the same, we create it as nickname
                     if (cell_value != included_profile.returnFullName()):
                         included_profile.add_nickname(cell_value)
                 elif (column_criteria == "spouse_full_name"):
                     #Here we create a new profile using the surname of the guy
                     names = get_name_surname_from_complete_name(
                         cell_value,
                         convention=self.naming_convention,
                         language=self.language)
                     partner = gen_profile(names[0], names[1])
                     partner.set_id(id_profiles)
                     #If the surname is changed we shall include the previous surname in the nicknames
                     if (cell_value != partner.returnFullName()):
                         partner.add_nickname(cell_value)
                     #Now we link the profiles
                     included_profile.set_marriage_id_link(id_profiles)
                     self.related_profiles[id_profiles] = partner
                 elif (column_criteria == "other_full_names"):
                     #The separator provided by family search is semicolumn
                     parents = cell_value.split(";")
                     #We obtain firstly the different names
                     father_name, father_surname, _ = get_name_surname_from_complete_name(
                         parents[0],
                         convention=self.naming_convention,
                         language=self.language)
                     if (len(parents) == 2):
                         mother_name, mother_surname, _ = get_name_surname_from_complete_name(
                             parents[1],
                             convention=self.naming_convention,
                             language=self.language)
                     #The algorithm provides an empty surname, we fill it with not known
                     if (father_surname == ""):
                         father_surname = NOT_KNOWN_VALUE
                     if (mother_surname == ""):
                         mother_surname = NOT_KNOWN_VALUE
                     #Create the standard profiles
                     father = gen_profile(father_name, father_surname)
                     mother = gen_profile(mother_name, mother_surname)
                     #If the surname is changed we shall include the previous surname in the nicknames
                     if (parents[0] != father.returnFullName()):
                         father.add_nickname(parents[0])
                     if (len(parents) == 2) and (parents[1] !=
                                                 mother.returnFullName()):
                         mother.add_nickname(parents[1])
                     #add gender
                     father.setCheckedGender("M")
                     mother.setCheckedGender("F")
                     self.parents_profiles[id_profiles] = [father, mother]
                 elif (column_criteria in ignored_fields):
                     pass
                 else:
                     number_missing = number_missing + 1
                     logging.warning(COLUMN_NOT_FOUND + column_criteria)
                 if (not this_introduction): included_right = False
             #This is a way to later on identify the link between the profiles
         if is_marriage: included_profile.setNewEvent(event_marriage)
         if is_residence: included_profile.setNewEvent(event_residence)
         id_profiles += 1
         if (not included_right): correct_introduction = False
         self.profiles.append(included_profile)
     #Now we know the data we fix some with the proper logic
     for profile_obtained in self.profiles:
         #If the baptism and birth are close enough we assign the birth place to the baptism place
         birth_event = profile_obtained.gen_data.get("birth", None)
         bapt_event = profile_obtained.gen_data.get("baptism", None)
         if birth_event and bapt_event:
             difference = bapt_event.get_date() - birth_event.get_date()
             if abs(difference.days) < DIFFERNCE_BIRTH_BAPT:
                 place_birth = None
                 place_baptism = None
                 if profile_obtained.gen_data.get(
                         "birth", None) and profile_obtained.gen_data.get(
                             "birth", None).get_location():
                     place_birth = profile_obtained.gen_data.get(
                         "birth", None).get_location().get("raw", None)
                 if profile_obtained.gen_data.get(
                         "baptism", None) and profile_obtained.gen_data.get(
                             "baptism", None).get_location():
                     place_birth = profile_obtained.gen_data.get(
                         "baptism", None).get_location().get("raw", None)
                 if place_baptism and not place_birth:
                     profile_obtained.setPlaces(
                         "birth",
                         get_location_standard(
                             profile_obtained.gen_data["baptism"].
                             get_location()), self.language)
         if profile_obtained.gen_data.get(
                 "marriage_link", None) in self.related_profiles.keys():
             id_of_marriage = profile_obtained.gen_data["marriage_link"]
             partner = self.related_profiles[id_of_marriage]
             partner.setWebReference(profile_obtained.get_all_urls())
             #It is a partner so we add as opposite sex!
             partner.setCheckedGender(
                 get_partner_gender(profile_obtained.gen_data["gender"]))
             partner.setNewEvent(profile_obtained.gen_data["marriage"][0])
             partner.setPlaces("marriage",
                               profile_obtained.gen_data["marriage"]
                               [0].get_location()["raw"],
                               language=self.language)
             if id_of_marriage in self.parents_profiles.keys():
                 father = self.parents_profiles[id_of_marriage][0]
                 mother = self.parents_profiles[id_of_marriage][1]
                 father.setWebReference(profile_obtained.get_all_urls())
                 mother.setWebReference(profile_obtained.get_all_urls())
                 surnames = get_splitted_name_from_complete_name(
                     partner.gen_data["surname"], language=self.language)[0]
                 if (father.gen_data["surname"] == NOT_KNOWN_VALUE):
                     #It might be the case that the surname is empty
                     #Ok the data was not including the right data, but we know the surname
                     if (self.naming_convention == "spanish_surname"
                             and len(surnames) != 0):
                         father.gen_data["surname"] = surnames[0]
                     else:
                         father.gen_data["surname"] = partner.gen_data[
                             "surname"]
                 if (mother.gen_data["surname"] == NOT_KNOWN_VALUE) and (
                         self.naming_convention
                         == "spanish_surname") and (len(surnames) == 2):
                     mother.gen_data["surname"] = surnames[1]
                 if (self.naming_convention == "spanish_surname"):
                     #We need to ensure 2 surnames in spanish naming conventions
                     if not (mother.gen_data["surname"]
                             in partner.gen_data["surname"]) or (len(
                                 partner.gen_data["surname"].split()) == 1):
                         #In the case we have 2 surnames, we try to eliminate the second surnames.
                         partner_surname_data = get_splitted_name_from_complete_name(
                             partner.gen_data["surname"],
                             language=self.language)
                         mother_surname_data = get_splitted_name_from_complete_name(
                             mother.gen_data["surname"],
                             language=self.language)
                         if len(partner.gen_data["nicknames"]) == 0:
                             partner.add_nickname(partner.returnFullName())
                         partner.gen_data["surname"] = " ".join([
                             partner_surname_data[0][0],
                             mother_surname_data[0][0]
                         ])
     #Finally, let's merge those profiles that are the same!
     indexes_to_remove = []
     iterating_list = list(self.profiles)
     for i in range(len(iterating_list)):
         #We are going one by one all the different profiles
         if i not in indexes_to_remove:
             for j, other_prof in enumerate(iterating_list[i + 1:]):
                 merged = self.profiles[i].merge_profile(
                     other_prof,
                     language=self.language,
                     convention=self.naming_convention)
                 if merged:
                     indexes_to_remove.append(i + j + 1)
     new_values = list(set(indexes_to_remove))
     new_values.sort()
     for deletion in reversed(new_values):
         del self.profiles[deletion]
     return correct_introduction
 def test_wrong_event(self):
     '''
     Test introducing a wrong event
     '''
     event = event_profile("birth")
     assert (get_gedcom_formatted_date(event) == None)