Esempio n. 1
0
    def testNodeObject_sort(self):
        cmp = NodeObject(1)
        cmp.dates = DateRange("1917-12-15")
        datevector = [
            DateRange("1917-12-15"), 
            DateRange("1917-12"),
            None,
            DateRange("1917-12-14"), 
            DateRange("1917-12-16")]
        nodevector = []
        for i in range(len(datevector)):
            nodevector.append(NodeObject(i+1))
            nodevector[i].dates = datevector[i]
#             print(f"{nodevector[i]}")

#         print (f"Compare dates:")
#         for i in range(len(datevector)):
#             node = nodevector[i]
#             print(f'A {cmp} < {node} = {cmp.__lt__(node)}')
#             print(f'B {node} < {cmp} = {node.__lt__(cmp)}')

        nodesorted = sorted(nodevector)
        expected_uids = [3, 4, 1, 2, 5]
        for i in range(len(nodesorted)):
            self.assertEqual(nodesorted[i].uniq_id, expected_uids[i], f"Invalid sort order, pos {i}")
Esempio n. 2
0
 def from_node(cls, node, obj=None):
     '''
     Transforms a db node to an object of type Event or EventBl.
     
     <Node id=88532 labels={'Event'} 
         properties={'type': 'Birth', 'change': 1500907890, attr_value': '', 
             'id': 'E0161', 'attr_type': '', 'description': ''
             'datetype': 0, 'date1': 1754183, 'date2': 1754183}>
     '''
     if not obj:
         obj = cls()
     obj.uniq_id = node.id
     obj.id = node['id']
     obj.uuid = node['uuid']
     obj.type = node['type']
     obj.handle = node.get('handle', None)
     obj.change = node.get('change', None)
     if "datetype" in node:
         obj.dates = DateRange(node["datetype"], node["date1"],
                               node["date2"])
     else:
         obj.dates = DateRange()
     obj.description = node['description'] or ''
     obj.attr = node.get('attr', dict())
     return obj
Esempio n. 3
0
 def from_node(cls, node):
     '''
     Transforms a db node to an object of type Family.
     
     You can create a Family or FamilyBl instance. (cls is the class 
     where we are, either Family or FamilyBl)
     
     <Node id=99991 labels={'Family'} 
         properties={'rel_type': 'Married', 'handle': '_da692e4ca604cf37ac7973d7778', 
         'id': 'F0031', 'change': 1507492602}>
     '''
     n = cls()
     n.uniq_id = node.id
     n.id = node.get('id','')
     n.uuid = node['uuid']
     n.handle = node['handle']
     n.change = node['change']
     n.rel_type = node.get('rel_type','')
     n.father_sortname = node.get('father_sortname','')
     n.mother_sortname = node.get('mother_sortname','')
     if "datetype" in node:
         n.dates = DateRange(node["datetype"], node["date1"], node["date2"])
     else:
         n.dates = DateRange()
     return n
Esempio n. 4
0
def record(oid):
    result = shareds.driver.session().run(cypher_record, id=oid).single()
    print(result)
    if not result: return dict(status="OK", resultCount=0)
    p = result.get('p')
    largerPlaces = result['largerPlaces']
    smallerPlaces = result['smallerPlaces']
    places1 = []
    for h1, largerPlace, id2 in largerPlaces:
        if largerPlace is None: break
        name2 = largerPlace['pname']
        type2 = largerPlace['type']
        place = dict(name=name2, type=type2, id=id2)
        datetype = h1['datetype']
        if datetype:
            date1 = h1['date1']
            date2 = h1['date2']
            d = DateRange(datetype, date1, date2)
            timespan = d.__str__()
            date1 = DateRange.DateInt(h1['date1']).long_date()
            date2 = str(DateRange.DateInt(h1['date2']))
            place['datetype'] = datetype
            place['date1'] = date1
            place['date2'] = date2
            place['timespan'] = timespan
        places1.append(place)
    places2 = []
    for h2, smallerPlace, id2 in smallerPlaces:
        if smallerPlace is None: break
        name2 = smallerPlace['pname']
        type2 = smallerPlace['type']
        place = dict(name=name2, type=type2, id=id2)
        datetype = h2['datetype']
        if datetype:
            date1 = h2['date1']
            date2 = h2['date2']
            d = DateRange(datetype, date1, date2)
            timespan = d.__str__()
            date1 = str(DateRange.DateInt(h2['date1']))
            date2 = str(DateRange.DateInt(h2['date2']))
            place['datetype'] = datetype
            place['date1'] = date1
            place['date2'] = date2
            place['timespan'] = timespan
        places2.append(place)
    record = dict(
        id=oid,
        name=p['pname'],
        type=p['type'],
        surroundedBy=sorted(places1, key=lambda x: x['name']),
        surrounds=sorted(places2, key=lambda x: x['name']),
    )
    return {
        "status": "OK",
        "statusText": "OK",
        "resultCount": 1,
        "record": record,
    }
Esempio n. 5
0
def getplace(id):
    print('id:',id)
    result = shareds.driver.session().run(cypher_getplace,id=id).single()
    print('result:',result)
    if not result: return dict(status="Error",resultCount=0)
    p = result.get('p')
    largerPlaces = result['largerPlaces']
    smallerPlaces = result['smallerPlaces']
    places1 = []
    for h1,largerPlace,id2 in largerPlaces: 
        if largerPlace is None: break
        name2 = largerPlace['pname']
        type2 = largerPlace['type']
        place = dict(name=name2,type=type2,id=id2)
        datetype = h1['datetype']
        if datetype:
            date1 = h1['date1']
            date2 = h1['date2']
            d = DateRange(datetype, date1, date2)
            timespan = d.__str__()
            date1 = DateRange.DateInt(h1['date1']).long_date()
            date2 = str(DateRange.DateInt(h1['date2']))
            place['datetype'] = datetype
            place['date1'] = date1
            place['date2'] = date2
            place['timespan'] = timespan
        places1.append(place)
    places2 = []
    for h2,smallerPlace,id2 in smallerPlaces: 
        if smallerPlace is None: break
        name2 = smallerPlace['pname']
        type2 = smallerPlace['type']
        place = dict(name=name2,type=type2,id=id2)
        datetype = h2['datetype']
        if datetype:
            date1 = h2['date1']
            date2 = h2['date2']
            d = DateRange(datetype, date1, date2)
            timespan = d.__str__()
            date1 = str(DateRange.DateInt(h2['date1']))
            date2 = str(DateRange.DateInt(h2['date2']))
            place['datetype'] = datetype
            place['date1'] = date1
            place['date2'] = date2
            place['timespan'] = timespan
        places2.append(place)
    #names = [dict(name=pn['name'],lang=pn['lang']) for pn in result['names']]
    place = PlaceBl.from_node(p)
    place.names = [PlaceName.from_node(pn) for pn in result['names']]
    print(smallerPlaces)
    if smallerPlaces == [[None,None,None]]: smallerPlaces = []
    place.surrounds = [PlaceName.from_node(p2) for (h2,p2,id2) in smallerPlaces]
    place.surrounds=sorted(places2,key=itemgetter('name'))
    return {"status":"OK",
     "statusText":"OK",
     "resultCount": 1,
     "place": place, 
    }
Esempio n. 6
0
    def testDate_compare(self):
        ''' Compare DR_DATE to other date types '''

        mydate=DateRange(DR['DATE'], "1645")
        # If self < other?
        self.assertEqual(mydate.__lt__(DateRange(DR['DATE'], "1650")), True, "Not 1645 < 1650")
        self.assertEqual(mydate.__eq__(DateRange(DR['DATE'], "1645")), True, "Not 1645 == 1645")
        self.assertEqual(mydate.__gt__(DateRange(DR['DATE'], "1640")), True, "Not 1645 > 1640")
        self.assertEqual(mydate.__gt__(None), True, "Not 1645 > None")
Esempio n. 7
0
    def testDateRange_add_years(self):
        """
        Add years to date
        """
        d = DateRange(DR['DATE'], "2047-01-09").add_years(3)
        ds = str(d)
        self.assertEqual(ds, "9.1.2050")

        d = DateRange(DR['BETWEEN'], date(2017, 4, 8), date(2017, 10, 16))
        da = d.add_years(-100)
        dl = da.to_list()
        self.assertEqual(dl, [4, "1917-04-08", "1917-10-16"])
        self.assertEqual(str(da), "between 8.4.1917 … 16.10.1917")
Esempio n. 8
0
    def testDateInt_month(self):
        ''' Check mid-year date order 
            Test the months in range 5..7 including missing month
        '''
        comp = 1963198
        for s in ["1917-06-30", "1917-06-31", "1917"]:
#             print(" tst month {}".format(s))
            val = DateRange.DateInt(s).value()
            self.assertEqual(val, comp, s)
            comp += 1
        # There is a gap bewtween "1917" and "1917-07-01" ~ no problem?
        s = "1917-07-01"
        comp += 31  
#         print(" test month {}".format(s))
        val = DateRange.DateInt(s).value()
        self.assertEqual(val, comp, s)
Esempio n. 9
0
def __process_larger_places(largerPlaces):
    uppers = []
    if largerPlaces != None:
        for urel, largerPlace, lid in largerPlaces:
            d1 = d2 = dt = None
            if urel and urel[0]:
                print(f"urel  {urel[0].values()} ")
                d1 = urel[0]['date1'] if urel else None
                d2 = urel[0]['date2'] if urel and urel[0]['date2'] else None
                dt = urel[0]['datetype'] if urel[0]['datetype'] else None
            print(largerPlace)
            upper = dict(
                id=largerPlace['id'],
                pname=largerPlace['pname'],
                type=largerPlace['type'],
                coord=largerPlace.get('coord'),
                #                date1 = urel[0]['date1'] if urel and urel[0]['date1'] else None,
                #                date2 = urel[0]['date2'] if urel and urel[0]['date2'] else None,
                #                datetype = urel[0]['datetype'] if urel[0]['datetype'] else None,
                date1=d1,
                date2=d2,
                datetype=dt,
                timespan=DateRange(dt, d1, d2).__str__() if dt else None)
            #            print(upper)
            if upper not in uppers:
                uppers.append(upper)
    return uppers
Esempio n. 10
0
    def testDateInt_day(self):
        ''' Check mid-month date order 
            Test the adjacent days in range 1917-12-14...16 including missing day
        '''
        comp = 1963405
        for s in ["1917-12-14", "1917-12-15", "1917-12", "1917-12-16"]:
#             print(" test day {}".format(s))
            val = DateRange.DateInt(s).value()
            self.assertEqual(val, comp, s)
            comp += 1
Esempio n. 11
0
def __process_places(places):
    rplaces = []
    for h1, place, pid in places:
        if place is None: break
        pname = place['pname']
        ptype = place['type']
        rplace = dict(pname=pname, type=ptype, id=pid)
        datetype = h1['datetype']
        if datetype:
            date1 = h1['date1']
            date2 = h1['date2']
            d = DateRange(datetype, date1, date2)
            timespan = d.__str__()
            date1 = DateRange.DateInt(h1['date1']).long_date()
            date2 = str(DateRange.DateInt(h1['date2']))
            rplace['datetype'] = datetype
            rplace['date1'] = date1
            rplace['date2'] = date2
            rplace['timespan'] = timespan
        rplaces.append(rplace)
    return rplaces
Esempio n. 12
0
 def testDateRange_DateInt(self):
     """
     Converts string format to int and vice versa
     """
     s = "2047-01-09"
     d = DateRange.DateInt(s)
     ds = d.short_date()
     self.assertEqual(s, ds)
     
     s = "1900-12-31"
     d = DateRange.DateInt(s)
     ds = d.short_date()
     self.assertEqual(s, ds)
     
     s = "1800-09"
     d = DateRange.DateInt(s)
     ds = d.long_date()
     self.assertEqual(s + '-00', ds)
     
     s = "1700"
     d = DateRange.DateInt(s)
     ds = d.long_date()
     self.assertEqual(s + '-00-00', ds)
Esempio n. 13
0
def read_cite_sour_repo(uniq_id=None):
    """ Lukee tietokannasta Repository-, Source- ja Citation- objektit näytettäväksi.
    
        Called from bp.tools.routes.pick_selection  -  NOT IN USE?
    """

    sources = []
    result_cite = Event_combo.get_event_cite(uniq_id)
    for record_cite in result_cite:
        pid = record_cite['id']
        e = Event_combo()
        e.uniq_id = pid
        if record_cite['type']:
            e.type = record_cite['type']


#         if record_cite['date']:
#             e.date = record_cite['date']
        if record_cite['dates']:
            e.dates = DateRange(record_cite['dates'])

        for source_cite in record_cite['sources']:
            c = Citation()
            c.uniq_id = source_cite[0]
            c.dateval = source_cite[1]
            c.page = source_cite[2]
            c.confidence = source_cite[3]

            c.get_sourceref_hlink()
            if c.source_handle != '':
                s = Source()
                s.uniq_id = c.source_handle
                result_source = s.get_source_data()
                for record_source in result_source:
                    if record_source['stitle']:
                        s.stitle = record_source['stitle']
                    if record_source['sauthor']:
                        s.sauthor = record_source['sauthor']
                    if record_source['spubinfo']:
                        s.spubinfo = record_source['spubinfo']

                    s.get_repositories_w_notes()

                c.source = s  # s.append(s)
            e.citations.append(c)

        sources.append(e)

    return (sources)
Esempio n. 14
0
def read_same_eventday(event_type):
    """ Lukee tietokannasta henkilötiedot, joilla on sama syntymäaika, näytettäväksi
    """

    ids = []
    if event_type == "Birth":
        result = Person_combo.get_people_with_same_birthday()
    elif event_type == "Death":
        result = Person_combo.get_people_with_same_deathday()
    else:
        raise NotImplementedError("Only Birth and Death accepted")

    for record in result:
        # <Record
        #    id1=259451 name1=['Julius Ferdinand', '', 'Lundahl']
        #    birth1=[0, 1861880, 1861880] death1=[0, 1898523, 1898523]
        #    id2=494238 name2=['Julius Ferdinand', '', 'Lundahl']
        #    birth2=[0, 1861880, 1861880] death2=[0, 1898523, 1898523]
        # >

        uniq_id = record['id1']
        name = record['name1']
        b = record['birth1']
        birth = DateRange(b)
        d = record['death1']
        death = DateRange(d)
        l = [uniq_id, name, birth, death]

        uniq_id = record['id2']
        name = record['name2']
        b = record['birth2']
        birth = DateRange(b)
        d = record['death2']
        death = DateRange(d)
        l.extend([uniq_id, name, DateRange(birth), DateRange(death)])

        print(f'found {l[0]} {l[1]} {l[2]}, {l[3]}')
        print(f'   -- {l[4]} {l[5]} {l[6]}, {l[7]}')
        ids.append(l)

    return ids
Esempio n. 15
0
 def testDateRange_tooMenyArguments(self):
     print(DateRange(0, "1820-01-01", ""))
Esempio n. 16
0
    def testDateRange_calc_est(self):
        """
            'CALC_BEFORE':9,
            'CALC_BETWEEN':12,
            'CALC_ABOUT':13,
            'EST_BEFORE':17,
            'EST_AFTER':18,
            'EST_PERIOD':19,
            'EST_BETWEEN':20,
            'EST_ABOUT':21
        """
        d = DateRange(DR['CALC_BEFORE'], date(2017, 10, 16))
        self.assertEqual(d.to_list(), [9, "2017-10-16"])
        self.assertEqual(str(d), "calculated till 16.10.2017")
        
        d = DateRange(DR['EST_PERIOD'], date(2017, 4, 8), date(2017, 10, 16))
        self.assertEqual(d.to_list(), [19, "2017-04-08", "2017-10-16"])
        self.assertEqual(str(d), "estimated 8.4.2017 – 16.10.2017")
        
        d = DateRange(DR['CALC_BETWEEN'], date(2017, 4, 8), date(2017, 10, 16))
        self.assertEqual(d.to_list(), [12, "2017-04-08", "2017-10-16"])
        self.assertEqual(str(d), "calculated between 8.4.2017 … 16.10.2017")

        d = DateRange(DR['EST_ABOUT'], date(2017, 10, 16))
        self.assertEqual(d.to_list(), [21, "2017-10-16"])
        self.assertEqual(str(d), "estimated about 16.10.2017")
Esempio n. 17
0
def get_person_data_by_id(pid):
    """ Get 5 data sets:                        ---- vanhempi versio ----

        ###Obsolete? still used in
        - /compare/uniq_id=311006,315556 
        - /lista/person_data/<string:uniq_id>
        - /lista/person_data/<string:uniq_id>

        The given pid may be an uuid (str) or uniq_id (int).

        person: Person object with name data
            The indexes of referred objects are in variables
                event_ref[]        str tapahtuman uniq_id, rooli eventref_role[]
                media_ref[]        str tallenteen uniq_id
                parentin_hlink[]   str vanhempien uniq_id
                note_ref[]         str huomautuksen uniq_id
                citation_ref[]     str viittauksen uniq_id
        events[]         Event_combo  with location name and id (?)
        photos
        citations
        families
    """
    p = Person_combo()
    if isinstance(pid, int):
        p.uniq_id = pid
    else:
        p.uuid = pid
    # Get Person and her Name properties, also Note properties
    p.get_person_w_names()
    # Get reference (uniq_id) and role for Events
    # Get references to Media, Citation objects
    # Get Persons birth family reference and role
    p.get_hlinks_by_id()

    # Person_display(Person)
    events = []
    citations = []
    photos = []
    source_cnt = 0
    my_birth_date = ''

    # Events

    for i in range(len(p.event_ref)):
        # Store Event data
        e = Event_combo()  # Event_for_template()
        e.uniq_id = p.event_ref[i]
        e.role = p.eventref_role[i]
        # Read event with uniq_id's of related Place (Note, and Citation?)
        e.get_event_combo()  # Read data to e
        if e.type == "Birth":
            my_birth_date = e.dates.estimate()

        for ref in e.place_ref:
            place = Place_combo.get_w_notes(ref)
            #             place.read_w_notes()
            # Location / place name, type and reference
            e.place = place
#             #TODO: remove 3 lines
#             e.location = place.pname
#             e.locid = place.uniq_id
#             e.ltype = place.type

        if e.note_ref:  # A list of uniq_ids; prev. e.noteref_hlink != '':
            # Read the Note objects from db and store them as a member of Event
            e.notes = Note.get_notes(e.note_ref)

        events.append(e)

        # Citations

        for ref in e.citation_ref:  # citationref_hlink != '':
            c = Citation()
            c.uniq_id = ref
            # If there is already the same citation on the list of citations,
            # use that index
            citation_ind = -1
            for i in range(len(citations)):
                if citations[i].uniq_id == c.uniq_id:
                    citation_ind = i + 1
                    break
            if citation_ind > 0:
                # Citation found; Event_combo.source = sitaatin numero
                e.source = citation_ind
            else:
                # Store the new source to the list
                # source = lähteen numero samassa listassa
                source_cnt += 1
                e.source = source_cnt

                result = c.get_source_repo(c.uniq_id)
                for record in result:
                    # Citation data & list of Source, Repository and Note data
                    #
                    # <Record id=92127 date='2017-01-25' page='1785 Novembr 3. kaste'
                    #    confidence='3' notetext='http://www.sukuhistoria.fi/...'
                    #    sources=[
                    #        [91360,
                    #         'Lapinjärvi syntyneet 1773-1787 vol  es346',
                    #         'Book',
                    #         100272,
                    #         'Lapinjärven seurakunnan arkisto',
                    #         'Archive']
                    #    ]
                    #   url='http://...">
                    c.dateval = record['date']
                    c.page = record['page']
                    c.confidence = record['confidence']
                    if not record['notetext']:
                        if c.page[:4] == "http":
                            c.notetext = c.page
                            c.page = ''
                    else:
                        c.notetext = record['notetext']

                    for source in record['sources']:
                        s = Source()
                        s.uniq_id = source[0]
                        s.stitle = source[1]
                        s.sauthor = source[2]
                        s.spubinfo = source[3]
                        s.reporef_medium = source[
                            4]  #Todo: Should use repository.medium

                        r = Repository()
                        r.uniq_id = source[5]
                        r.rname = source[6]
                        r.type = source[7]
                        s.repositories.append(r)

                        n = Note()
                        n.url = record['url']
                        s.notes.append(n)

                        c.source = s

                    print("Eve:{} {} > Cit:{} '{}' > Sour:{} '{}' '{}' '{}' > Repo:{} '{}' > Url: '{}'".\
                          format(e.uniq_id, e.id,
                                 c.uniq_id, c.page,
                                 s.uniq_id, s.stitle, s.sauthor, s.spubinfo,
                                 r.uniq_id, r.rname,
                                 n.url,
                          ))
                    citations.append(c)

    for uniq_id in p.media_ref:
        o = Media.get_one(uniq_id)
        photos.append(o)

    # Families

    # Returning a list of Family objects
    # - which include a list of members (Person with 'role' attribute)
    #   - Person includes a list of Name objects
    families = {}
    fid = 0
    result = Person_combo.get_family_members(p.uniq_id)
    for record in result:
        # <Record family_id='F0018' f_uniq_id=217546 role='PARENT' parent_role='mother'
        #  m_id='I0038' uniq_id=217511 sex=2 birth_date=[0, 1892433, 1892433]
        #  names=[
        #    <Node id=217512 labels={'Name'} properties={'firstname': 'Brita Kristina',
        #        'type': 'Birth Name', 'suffix': 'Eriksdotter', 'surname': 'Berttunen',
        #        'order': 0}>,
        #    <Node id=217513 labels={'Name'} properties={'firstname': 'Brita Kristina',
        #        'type': 'Married Name', 'suffix': '', 'surname': 'Silius',
        #        'order': 1}>]>
        if fid != record["f_uniq_id"]:
            fid = record["f_uniq_id"]
            if not fid in families:
                families[fid] = Family_combo(fid)
                families[fid].id = record['family_id']

        member = Person_as_member()  # A kind of Person
        member.role = record["role"]
        member.id = record["m_id"]
        member.uniq_id = record["uniq_id"]
        if member.uniq_id == p.uniq_id:
            # What kind of family this is? I am a Child or Parent in family
            if member.role == "CHILD":
                families[fid].role = "CHILD"
            else:
                families[fid].role = "PARENT"
            if my_birth_date:
                member.birth_date = my_birth_date

        if record["sex"]:
            member.sex = record["sex"]
        if record["birth_date"]:
            datetype, date1, date2 = record["birth_date"]
            if datetype != None:
                member.birth_date = DateRange(datetype, date1,
                                              date2).estimate()
        if record["names"]:
            for node in record["names"]:
                n = Name.from_node(node)
                member.names.append(n)

        if member.role == "CHILD":
            families[fid].children.append(member)
        elif member.role == "PARENT":
            parent_role = record["parent_role"]
            if parent_role == 'mother':
                families[fid].mother = member
            elif parent_role == 'father':
                families[fid].father = member
        # TODO: Remove these, obsolete
        elif member.role == "FATHER":
            families[fid].father = member
        elif member.role == "MOTHER":
            families[fid].mother = member

    family_list = list(families.values())

    # Find all referenced for the nodes found so far

    nodes = {p.uniq_id: p}
    for e in events:
        nodes[e.uniq_id] = e
    for e in photos:
        nodes[e.uniq_id] = e
    for e in citations:
        nodes[e.uniq_id] = e
    for e in family_list:
        nodes[e.uniq_id] = e

    return (p, events, photos, citations, family_list)
Esempio n. 18
0
 def test_create(self):
     ''' DateRange creation formats '''
     d = DateRange(DR['DATE'], "2017-11-09")
     self.assertEqual(d.to_list(), [0, "2017-11-09"])
     d = DateRange(DR['BEFORE'], "2017-10-16")
     self.assertEqual(d.to_list(), [1, "2017-10-16"])
     d = DateRange(1, 2065744)
     self.assertEqual(d.to_list(), [1, "2017-10-16"])
     d = DateRange(DR['BETWEEN'], date(1917, 12, 6), date(2017, 10, 16))
     self.assertEqual(d.to_list(), [4, "1917-12-06", "2017-10-16"])
     d = DateRange(4, 1963397, 2065744)
     self.assertEqual(d.to_list(), [4, "1917-12-06", "2017-10-16"])
     d = DateRange("1", "2017-10-16")
     self.assertEqual(d.to_list(), [1, "2017-10-16"])
     d = DateRange(DR['PERIOD'], "1917-12-06", "2017-10-16")
     dic = {'datetype': 3, 
            'date1': DateRange.DateInt("1917-12-06").value(), 
            'date2': DateRange.DateInt("2017-10-16").value() }
     self.assertEqual(d.for_db(), dic)
     d = DateRange(DR['PERIOD'], "1784", "1796-05")
     dic = {'datetype': 3, 
            'date1': DateRange.DateInt("1784").value(), 
            'date2': DateRange.DateInt("1796-05").value() }
     self.assertEqual(d.for_db(), dic)
Esempio n. 19
0
    def testDateRange_date(self):
        ''' Single DateRange DR['DATE']
            DateRange(d1)
            DateRange(int, d1)
            DateRange(int, d1, d2)
        '''
        d = DateRange(date(2017, 4, 8))
        self.assertEqual(d.to_list(), [0, "2017-04-08"])
        self.assertEqual(str(d), "8.4.2017")

        d = DateRange("2017-10-16")
        self.assertEqual(d.to_list(), [0, "2017-10-16"])
        self.assertEqual(str(d), "16.10.2017")

        d = DateRange((0, "1640-09-31", ""))
        self.assertEqual(d.to_list(), [0, "1640-09-31"])
        self.assertEqual(str(d), "31.9.1640")

        d = DateRange(0, "1820-01-01")
        self.assertEqual(d.to_list(), [0, "1820-01-01"])
        self.assertEqual(str(d), "1.1.1820")
Esempio n. 20
0
def _jinja2_filter_dates(dates):
    """ Aikamääreet suodatetaan suomalaiseksi """
    return str(DateRange(dates))
Esempio n. 21
0
    def testDateRange_before_after(self):
        """
        DR_TILL = 1          # Date till d1
        DR_FROM = 2          # Date from d1
        DateRange(int, d1)
        DataRange((int, str1, str2))
        """
        d = DateRange(DR['BEFORE'], date(2017, 10, 16))
        self.assertEqual(d.to_list(), [1, "2017-10-16"])
        self.assertEqual(str(d), "till 16.10.2017")

        d = DateRange(DR['AFTER'], date(2017, 4, 8))
        self.assertEqual(d.to_list(), [2, "2017-04-08"])
        self.assertEqual(str(d), "from 8.4.2017")

        d = DateRange((1, "2017-04-08", ""))
        self.assertEqual(d.to_list(), [1, "2017-04-08"])
        d = DateRange((2, "2017-04-08", ""))
        self.assertEqual(d.to_list(), [2, "2017-04-08"])
Esempio n. 22
0
def set_family_calculated_attributes(tx=None, uniq_id=None):
    """ Set Family sortnames and estimated DateRange.
    
        Called from bp.gramps.xml_dom_handler.DOM_handler.set_family_calculated_attributes

        Set Family.father_sortname and Family.mother_sortname using the data in Person
        Set Family.date1 using the data in marriage Event
        Set Family.datetype and Family.date2 using the data in divorce or death Events
        If handler is defined
        - if there is transaction tx, use it, else create a new 
    """
    dates_count = 0
    sortname_count = 0

    if tx:
        my_tx = tx
    else:
        my_tx = User.beginTransaction()

    # Process each family
    result = Family_combo.get_dates_parents(my_tx, uniq_id)
    for record in result:
        father_sortname = record['father_sortname']
        father_death_date = record['father_death_date']
        mother_sortname = record['mother_sortname']
        mother_death_date = record['mother_death_date']
        marriage_date = record['marriage_date']
        divorce_date = record['divorce_date']

        dates = None
        end_date = None
        if divorce_date:
            end_date = divorce_date
        elif father_death_date and mother_death_date:
            if father_death_date < mother_death_date:
                end_date = father_death_date
            else:
                end_date = mother_death_date
        elif father_death_date:
            end_date = father_death_date
        elif mother_death_date:
            end_date = mother_death_date

        if marriage_date:
            if end_date:
                dates = DateRange(DR['PERIOD'], marriage_date, end_date)
            else:
                dates = DateRange(DR['DATE'], marriage_date)
        elif end_date:
            dates = DateRange(DR['BEFORE'], end_date)

        # Copy the dates from Event node and sortnames from Person nodes
        Family_combo.set_dates_sortnames(my_tx, uniq_id, dates,
                                         father_sortname, mother_sortname)
        dates_count += 1
        sortname_count += 1

    if not tx:
        # Close my own created transaction
        User.endTransaction(my_tx)

    return (dates_count, sortname_count)
Esempio n. 23
0
    def testDateRange_period_between(self):
        """
        DR_PERIOD = 3        # Date period d1-d2
        DR_BETWEEN = 4       # A date between d1 and d2
        DateRange(int, d1, d2)
        DataRange((int, str1, str2))
        """
        d = DateRange(DR['PERIOD'], date(2017, 4, 8), date(2017, 10, 16))
        self.assertEqual(d.to_list(), [3, "2017-04-08", "2017-10-16"])
        self.assertEqual(str(d), "8.4.2017 – 16.10.2017")
        
        d = DateRange(DR['BETWEEN'], date(2017, 4, 8), date(2017, 10, 16))
        self.assertEqual(d.to_list(), [4, "2017-04-08", "2017-10-16"])
        self.assertEqual(str(d), "between 8.4.2017 … 16.10.2017")

        d = DateRange(DR['PERIOD'], "1784", "1796")
        self.assertEqual(d.to_list(), [3, "1784", "1796"])
        self.assertEqual(str(d), "1784 – 1796")

        d = DateRange(4, 1740992, 1843503)
        self.assertEqual(d.to_list(), [4, '1700', '1800-09'])
        self.assertEqual(str(d), 'between 1700 … 9.1800')