def match_date(date: Date, mask: str) -> bool: """Check if date matches mask.""" if date is not None and date.is_valid(): year_mask, month_mask, day_mask = mask.split("/") date = gregorian(date) year = date.get_year() if year_mask == "*" or year == int(year_mask): month = date.get_month() if month_mask == "*" or month == int(month_mask): day = date.get_day() if day_mask == "*" or day == int(day_mask): return True return False
def collect_data(self, dbase, people, menu, genders, year_from, year_to, no_years, cb_progress, rlocale): """goes through the database and collects the selected personal data persons fitting the filter and birth year criteria. The arguments are: dbase - the Gramps database people - a list of filtered people options - report options_dict which sets which methods are used genders - which gender(s) to include into statistics year_from - use only persons who've born this year of after year_to - use only persons who've born this year or before no_years - use also people without known birth year cb_progress - callback to indicate progress rlocale - a GrampsLocale instance Returns an array of tuple of: - Extraction method title - Dict of values with their counts (- Method) """ self.db = dbase # store for use by methods self._locale = rlocale self._ = rlocale.translation.sgettext self._get_type = rlocale.get_type data = [] ext = self.extractors # which methods to use for name in self.extractors: option = menu.get_option_by_name(name) if option.get_value() == True: # localized data title, value dict, type and data method data.append((ext[name][1], {}, ext[name][2], ext[name][3])) # go through the people and collect data for person_handle in people: cb_progress() person = dbase.get_person_from_handle(person_handle) # check whether person has suitable gender if person.gender != genders and genders != Person.UNKNOWN: continue # check whether birth year is within required range birth = self.get_birth(person) if birth: birthdate = birth.get_date_object() if birthdate.get_year_valid(): birthdate = gregorian(birthdate) year = birthdate.get_year() if not (year >= year_from and year <= year_to): continue else: # if death before range, person's out of range too... death = self.get_death(person) if death: deathdate = death.get_date_object() if deathdate.get_year_valid(): deathdate = gregorian(deathdate) if deathdate.get_year() < year_from: continue if not no_years: # don't accept people not known to be in range continue else: continue else: continue self.get_person_data(person, data) return data
def collect_data(self): """ This method runs through the data, and collects the relevant dates and text. """ people = self.database.iter_person_handles() with self._user.progress(_('Birthday and Anniversary Report'), _('Applying Filter...'), self.database.get_number_of_people()) as step: people = self.filter.apply(self.database, people, step) ngettext = self._locale.translation.ngettext # to see "nearby" comments rel_calc = get_relationship_calculator(reinit=True, clocale=self._locale) with self._user.progress(_('Birthday and Anniversary Report'), _('Reading database...'), len(people)) as step: for person_handle in people: step() person = self.database.get_person_from_handle(person_handle) birth_ref = person.get_birth_ref() birth_date = None if birth_ref: birth_event = self.database.get_event_from_handle(birth_ref.ref) birth_date = birth_event.get_date_object() if (self.birthdays and birth_date is not None and birth_date.is_valid()): birth_date = gregorian(birth_date) year = birth_date.get_year() month = birth_date.get_month() day = birth_date.get_day() prob_alive_date = Date(self.year, month, day) nyears = self.year - year # add some things to handle maiden name: father_lastname = None # husband, actually if self.maiden_name in ['spouse_first', 'spouse_last']: # get husband's last name: if person.get_gender() == Person.FEMALE: family_list = person.get_family_handle_list() if len(family_list) > 0: if self.maiden_name == 'spouse_first': fhandle = family_list[0] else: fhandle = family_list[-1] fam = self.database.get_family_from_handle(fhandle) father_handle = fam.get_father_handle() mother_handle = fam.get_mother_handle() if mother_handle == person_handle: if father_handle: father = self.database.get_person_from_handle(father_handle) if father is not None: primary_name = father.get_primary_name() if primary_name: father_lastname = Surname.get_surname(primary_name.get_primary_surname()) short_name = self.get_name(person, father_lastname) alive = probably_alive(person, self.database, prob_alive_date) if ((self.alive and alive) or not self.alive): comment = "" if self.relationships: relation = rel_calc.get_one_relationship( self.database, self.center_person, person, olocale=self._locale) if relation: # FIXME this won't work for RTL languages comment = " --- %s" % relation if nyears == 0: text = self._('%(person)s, birth%(relation)s') % { 'person' : short_name, 'relation' : comment} else: # translators: leave all/any {...} untranslated text = ngettext('{person}, {age}{relation}', '{person}, {age}{relation}', nyears).format(person=short_name, age=nyears, relation=comment) self.add_day_item(text, month, day, person) if self.anniversaries: family_list = person.get_family_handle_list() for fhandle in family_list: fam = self.database.get_family_from_handle(fhandle) father_handle = fam.get_father_handle() mother_handle = fam.get_mother_handle() if father_handle == person.get_handle(): spouse_handle = mother_handle else: continue # with next person if the father is not "person" # this will keep from duplicating the anniversary if spouse_handle: spouse = self.database.get_person_from_handle(spouse_handle) if spouse: spouse_name = self.get_name(spouse) short_name = self.get_name(person) # TEMP: this will handle ordered events # Gramps 3.0 will have a new mechanism for start/stop events are_married = None for event_ref in fam.get_event_ref_list(): event = self.database.get_event_from_handle(event_ref.ref) if event.type in [EventType.MARRIAGE, EventType.MARR_ALT]: are_married = event elif event.type in [EventType.DIVORCE, EventType.ANNULMENT, EventType.DIV_FILING]: are_married = None if are_married is not None: for event_ref in fam.get_event_ref_list(): event = self.database.get_event_from_handle(event_ref.ref) event_obj = event.get_date_object() if event_obj is not Date.EMPTY and event_obj.is_valid(): event_obj = gregorian(event_obj) year = event_obj.get_year() month = event_obj.get_month() day = event_obj.get_day() nyears = self.year - year if event_obj.is_valid(): if nyears == 0: text = self._("%(spouse)s and\n %(person)s, wedding") % { 'spouse' : spouse_name, 'person' : short_name} else: # translators: leave all/any {...} untranslated text = ngettext("{spouse} and\n {person}, {nyears}", "{spouse} and\n {person}, {nyears}", nyears).format(spouse=spouse_name, person=short_name, nyears=nyears) prob_alive_date = Date(self.year, month, day) alive1 = probably_alive(person, self.database, prob_alive_date) alive2 = probably_alive(spouse, self.database, prob_alive_date) if (self.alive and alive1 and alive2) or not self.alive: self.add_day_item(text, month, day, spouse)
def collect_data(self): """ This method runs through the data, and collects the relevant dates and text. """ db = self.database people = db.iter_person_handles() with self._user.progress(_('Calendar Report'), _('Applying Filter...'), db.get_number_of_people()) as step: people = self.filter.apply(self.database, people, step) ngettext = self._locale.translation.ngettext # to see "nearby" comments with self._user.progress(_('Calendar Report'), _('Reading database...'), len(people)) as step: for person_handle in people: step() person = db.get_person_from_handle(person_handle) mark = ReportUtils.get_person_mark(db, person) birth_ref = person.get_birth_ref() birth_date = None if birth_ref: birth_event = db.get_event_from_handle(birth_ref.ref) birth_date = birth_event.get_date_object() if (self.birthdays and birth_date is not None and birth_date.is_valid()): birth_date = gregorian(birth_date) year = birth_date.get_year() month = birth_date.get_month() day = birth_date.get_day() prob_alive_date = Date(self.year, month, day) nyears = self.year - year # add some things to handle maiden name: father_lastname = None # husband, actually if self.maiden_name in ['spouse_first', 'spouse_last' ]: # get husband's last name: if person.get_gender() == Person.FEMALE: family_list = person.get_family_handle_list() if family_list: if self.maiden_name == 'spouse_first': fhandle = family_list[0] else: fhandle = family_list[-1] fam = db.get_family_from_handle(fhandle) father_handle = fam.get_father_handle() mother_handle = fam.get_mother_handle() if mother_handle == person_handle: if father_handle: father = db.get_person_from_handle( father_handle) if father: father_lastname = father.get_primary_name( ).get_surname() short_name = self.get_name(person, father_lastname) alive = probably_alive(person, db, prob_alive_date) if not self.alive or alive: if nyears == 0: text = self._('%(person)s, birth') % { 'person': short_name } else: # translators: leave all/any {...} untranslated text = ngettext('{person}, {age}', '{person}, {age}', nyears).format(person=short_name, age=nyears) self.add_day_item(text, month, day, marks=[mark]) if self.anniversaries: family_list = person.get_family_handle_list() for fhandle in family_list: fam = db.get_family_from_handle(fhandle) father_handle = fam.get_father_handle() mother_handle = fam.get_mother_handle() if father_handle == person.get_handle(): spouse_handle = mother_handle else: continue # with next person if the father is not "person" # this will keep from duplicating the anniversary if spouse_handle: spouse = db.get_person_from_handle(spouse_handle) if spouse: s_m = ReportUtils.get_person_mark(db, spouse) spouse_name = self.get_name(spouse) short_name = self.get_name(person) # TEMP: this will handle ordered events # Gramps 3.0 will have a new mechanism for start/stop events are_married = None for event_ref in fam.get_event_ref_list(): event = db.get_event_from_handle( event_ref.ref) et = EventType rt = EventRoleType if event.type in [et.MARRIAGE, et.MARR_ALT] and \ (event_ref.get_role() == rt.FAMILY or event_ref.get_role() == rt.PRIMARY ): are_married = event elif event.type in [et.DIVORCE, et.ANNULMENT, et.DIV_FILING] and \ (event_ref.get_role() == rt.FAMILY or event_ref.get_role() == rt.PRIMARY ): are_married = None if are_married is not None: for event_ref in fam.get_event_ref_list(): event = db.get_event_from_handle( event_ref.ref) event_obj = event.get_date_object() if event_obj.is_valid(): event_obj = gregorian(event_obj) year = event_obj.get_year() month = event_obj.get_month() day = event_obj.get_day() prob_alive_date = Date( self.year, month, day) nyears = self.year - year if nyears == 0: text = self._( '%(spouse)s and\n %(person)s, wedding' ) % { 'spouse': spouse_name, 'person': short_name, } else: # translators: leave all/any {...} untranslated text = ngettext( "{spouse} and\n {person}, {nyears}", "{spouse} and\n {person}, {nyears}", nyears).format( spouse=spouse_name, person=short_name, nyears=nyears) alive1 = probably_alive( person, self.database, prob_alive_date) alive2 = probably_alive( spouse, self.database, prob_alive_date) if ((self.alive and alive1 and alive2) or not self.alive): self.add_day_item( text, month, day, marks=[mark, s_m])
def collect_data(self): """ This method runs through the data, and collects the relevant dates and text. """ db = self.database people = db.iter_person_handles() with self._user.progress(_('Calendar Report'), _('Applying Filter...'), db.get_number_of_people()) as step: people = self.filter.apply(self.database, people, step) ngettext = self._locale.translation.ngettext # to see "nearby" comments with self._user.progress(_('Calendar Report'), _('Reading database...'), len(people)) as step: for person_handle in people: step() person = db.get_person_from_handle(person_handle) mark = ReportUtils.get_person_mark(db, person) birth_ref = person.get_birth_ref() birth_date = None if birth_ref: birth_event = db.get_event_from_handle(birth_ref.ref) birth_date = birth_event.get_date_object() if (self.birthdays and birth_date is not None and birth_date.is_valid()): birth_date = gregorian(birth_date) year = birth_date.get_year() month = birth_date.get_month() day = birth_date.get_day() prob_alive_date = Date(self.year, month, day) nyears = self.year - year # add some things to handle maiden name: father_lastname = None # husband, actually if self.maiden_name in ['spouse_first', 'spouse_last']: # get husband's last name: if person.get_gender() == Person.FEMALE: family_list = person.get_family_handle_list() if family_list: if self.maiden_name == 'spouse_first': fhandle = family_list[0] else: fhandle = family_list[-1] fam = db.get_family_from_handle(fhandle) father_handle = fam.get_father_handle() mother_handle = fam.get_mother_handle() if mother_handle == person_handle: if father_handle: father = db.get_person_from_handle(father_handle) if father: father_lastname = father.get_primary_name().get_surname() short_name = self.get_name(person, father_lastname) alive = probably_alive(person, db, prob_alive_date) if not self.alive or alive: if nyears == 0: text = self._('%(person)s, birth') % { 'person' : short_name } else: # translators: leave all/any {...} untranslated text = ngettext('{person}, {age}', '{person}, {age}', nyears).format(person=short_name, age=nyears) self.add_day_item(text, month, day, marks=[mark]) if self.anniversaries: family_list = person.get_family_handle_list() for fhandle in family_list: fam = db.get_family_from_handle(fhandle) father_handle = fam.get_father_handle() mother_handle = fam.get_mother_handle() if father_handle == person.get_handle(): spouse_handle = mother_handle else: continue # with next person if the father is not "person" # this will keep from duplicating the anniversary if spouse_handle: spouse = db.get_person_from_handle(spouse_handle) if spouse: s_m = ReportUtils.get_person_mark(db, spouse) spouse_name = self.get_name(spouse) short_name = self.get_name(person) # TEMP: this will handle ordered events # GRAMPS 3.0 will have a new mechanism for start/stop events are_married = None for event_ref in fam.get_event_ref_list(): event = db.get_event_from_handle(event_ref.ref) et = EventType rt = EventRoleType if event.type in [et.MARRIAGE, et.MARR_ALT] and \ (event_ref.get_role() == rt.FAMILY or event_ref.get_role() == rt.PRIMARY ): are_married = event elif event.type in [et.DIVORCE, et.ANNULMENT, et.DIV_FILING] and \ (event_ref.get_role() == rt.FAMILY or event_ref.get_role() == rt.PRIMARY ): are_married = None if are_married is not None: for event_ref in fam.get_event_ref_list(): event = db.get_event_from_handle(event_ref.ref) event_obj = event.get_date_object() if event_obj.is_valid(): event_obj = gregorian(event_obj) year = event_obj.get_year() month = event_obj.get_month() day = event_obj.get_day() prob_alive_date = Date(self.year, month, day) nyears = self.year - year if nyears == 0: text = self._('%(spouse)s and\n %(person)s, wedding') % { 'spouse' : spouse_name, 'person' : short_name, } else: # translators: leave all/any {...} untranslated text = ngettext("{spouse} and\n {person}, {nyears}", "{spouse} and\n {person}, {nyears}", nyears).format(spouse=spouse_name, person=short_name, nyears=nyears) alive1 = probably_alive(person, self.database, prob_alive_date) alive2 = probably_alive(spouse, self.database, prob_alive_date) if ((self.alive and alive1 and alive2) or not self.alive): self.add_day_item(text, month, day, marks=[mark,s_m])
def collect_data(self): """ This method runs through the data, and collects the relevant dates and text. """ people = self.database.iter_person_handles() people = self.filter.apply(self.database, people, user=self._user) ngettext = self._locale.translation.ngettext # to see "nearby" comments rel_calc = get_relationship_calculator(reinit=True, clocale=self._locale) with self._user.progress(_('Birthday and Anniversary Report'), _('Reading database...'), len(people)) as step: for person_handle in people: step() person = self.database.get_person_from_handle(person_handle) birth_ref = person.get_birth_ref() birth_date = None if birth_ref: birth_event = self.database.get_event_from_handle( birth_ref.ref) birth_date = birth_event.get_date_object() if (self.birthdays and birth_date is not None and birth_date.is_valid()): birth_date = gregorian(birth_date) year = birth_date.get_year() month = birth_date.get_month() day = birth_date.get_day() prob_alive_date = Date(self.year, month, day) nyears = self.year - year # add some things to handle maiden name: father_lastname = None # husband, actually if self.maiden_name in ['spouse_first', 'spouse_last' ]: # get husband's last name: if person.get_gender() == Person.FEMALE: family_list = person.get_family_handle_list() if len(family_list) > 0: if self.maiden_name == 'spouse_first': fhandle = family_list[0] else: fhandle = family_list[-1] fam = self.database.get_family_from_handle( fhandle) father_handle = fam.get_father_handle() mother_handle = fam.get_mother_handle() if mother_handle == person_handle: if father_handle: father = self.database.get_person_from_handle( father_handle) if father is not None: primary_name = father.get_primary_name( ) if primary_name: father_lastname = Surname.get_surname( primary_name. get_primary_surname()) short_name = self.get_name(person, father_lastname) alive = probably_alive(person, self.database, prob_alive_date) if ((self.alive and alive) or not self.alive): comment = "" if self.relationships: relation = rel_calc.get_one_relationship( self.database, self.center_person, person, olocale=self._locale) if relation: # FIXME this won't work for RTL languages comment = " --- %s" % relation if nyears == 0: text = self._('%(person)s, birth%(relation)s') % { 'person': short_name, 'relation': comment } else: # translators: leave all/any {...} untranslated text = ngettext('{person}, {age}{relation}', '{person}, {age}{relation}', nyears).format(person=short_name, age=nyears, relation=comment) self.add_day_item(text, month, day, person) if self.anniversaries: family_list = person.get_family_handle_list() for fhandle in family_list: fam = self.database.get_family_from_handle(fhandle) father_handle = fam.get_father_handle() mother_handle = fam.get_mother_handle() if father_handle == person.get_handle(): spouse_handle = mother_handle else: continue # with next person if the father is not "person" # this will keep from duplicating the anniversary if spouse_handle: spouse = self.database.get_person_from_handle( spouse_handle) if spouse: spouse_name = self.get_name(spouse) short_name = self.get_name(person) # TEMP: this will handle ordered events # Gramps 3.0 will have a new mechanism for start/stop events are_married = None for event_ref in fam.get_event_ref_list(): event = self.database.get_event_from_handle( event_ref.ref) if event.type in [ EventType.MARRIAGE, EventType.MARR_ALT ]: are_married = event elif event.type in [ EventType.DIVORCE, EventType.ANNULMENT, EventType.DIV_FILING ]: are_married = None if are_married is not None: for event_ref in fam.get_event_ref_list(): event = self.database.get_event_from_handle( event_ref.ref) event_obj = event.get_date_object() if event_obj is not Date.EMPTY and event_obj.is_valid( ): event_obj = gregorian(event_obj) year = event_obj.get_year() month = event_obj.get_month() day = event_obj.get_day() nyears = self.year - year if event_obj.is_valid(): if nyears == 0: text = self._( "%(spouse)s and\n %(person)s, wedding" ) % { 'spouse': spouse_name, 'person': short_name } else: # translators: leave all/any {...} untranslated text = ngettext( "{spouse} and\n {person}, {nyears}", "{spouse} and\n {person}, {nyears}", nyears).format( spouse=spouse_name, person=short_name, nyears=nyears) prob_alive_date = Date( self.year, month, day) alive1 = probably_alive( person, self.database, prob_alive_date) alive2 = probably_alive( spouse, self.database, prob_alive_date) if (self.alive and alive1 and alive2 ) or not self.alive: self.add_day_item( text, month, day, spouse)