5609: Improvements for Records report (by reinhard)

svn: r19004
This commit is contained in:
Jérôme Rapinat
2012-03-04 08:34:59 +00:00
parent 154a49bad9
commit b708b68160
2 changed files with 39 additions and 35 deletions

View File

@@ -35,14 +35,14 @@ from gen.ggettext import sgettext as _
# GRAMPS modules # GRAMPS modules
# #
#------------------------------------------------------------------------ #------------------------------------------------------------------------
from gen.lib import ChildRefType, Date, EventType, Name, StyledText, \ from gen.lib import (ChildRefType, Date, Span, EventType, Name,
StyledTextTag, StyledTextTagType StyledText, StyledTextTag, StyledTextTagType)
from gen.plug.docgen import FontStyle, ParagraphStyle, FONT_SANS_SERIF, \ from gen.plug.docgen import (FontStyle, ParagraphStyle, FONT_SANS_SERIF,
PARA_ALIGN_CENTER PARA_ALIGN_CENTER)
from gen.display.name import displayer as name_displayer from gen.display.name import displayer as name_displayer
from gen.plug import Gramplet from gen.plug import Gramplet
from gen.plug.menu import (BooleanOption, EnumeratedListOption, from gen.plug.menu import (BooleanOption, EnumeratedListOption,
FilterOption, PersonOption, StringOption) FilterOption, NumberOption, PersonOption, StringOption)
from gen.plug.report import Report from gen.plug.report import Report
from gen.plug.report import utils as ReportUtils from gen.plug.report import utils as ReportUtils
from gen.plug.report import MenuReportOptions from gen.plug.report import MenuReportOptions
@@ -55,13 +55,7 @@ from Utils import probably_alive
#------------------------------------------------------------------------ #------------------------------------------------------------------------
def _good_date(date): def _good_date(date):
if date: return (date is not None and date.is_valid())
if RecordsReportOptions.REGULAR_DATES_ONLY:
return date.is_regular()
else:
return date.is_valid()
else:
return False
def _find_death_date(db, person): def _find_death_date(db, person):
@@ -78,7 +72,7 @@ def _find_death_date(db, person):
return None return None
def _find_records(db, filter, callname): def _find_records(db, filter, top_size, callname):
today = datetime.date.today() today = datetime.date.today()
today_date = Date(today.year, today.month, today.day) today_date = Date(today.year, today.month, today.day)
@@ -126,11 +120,13 @@ def _find_records(db, filter, callname):
if probably_alive(person, db): if probably_alive(person, db):
# Still living, look for age records # Still living, look for age records
_record(person_youngestliving, person_oldestliving, _record(person_youngestliving, person_oldestliving,
today_date - birth_date, name, 'Person', person_handle) today_date - birth_date, name, 'Person', person_handle,
top_size)
elif _good_date(death_date): elif _good_date(death_date):
# Already died, look for age records # Already died, look for age records
_record(person_youngestdied, person_oldestdied, _record(person_youngestdied, person_oldestdied,
death_date - birth_date, name, 'Person', person_handle) death_date - birth_date, name, 'Person', person_handle,
top_size)
for family_handle in person.get_family_handle_list(): for family_handle in person.get_family_handle_list():
family = db.get_family_from_handle(family_handle) family = db.get_family_from_handle(family_handle)
@@ -151,12 +147,12 @@ def _find_records(db, filter, callname):
if _good_date(marriage_date): if _good_date(marriage_date):
_record(person_youngestmarried, person_oldestmarried, _record(person_youngestmarried, person_oldestmarried,
marriage_date - birth_date, marriage_date - birth_date,
name, 'Person', person_handle) name, 'Person', person_handle, top_size)
if _good_date(divorce_date): if _good_date(divorce_date):
_record(person_youngestdivorced, person_oldestdivorced, _record(person_youngestdivorced, person_oldestdivorced,
divorce_date - birth_date, divorce_date - birth_date,
name, 'Person', person_handle) name, 'Person', person_handle, top_size)
for child_ref in family.get_child_ref_list(): for child_ref in family.get_child_ref_list():
if person.get_gender() == person.MALE: if person.get_gender() == person.MALE:
@@ -183,11 +179,11 @@ def _find_records(db, filter, callname):
if person.get_gender() == person.MALE: if person.get_gender() == person.MALE:
_record(person_youngestfather, person_oldestfather, _record(person_youngestfather, person_oldestfather,
child_birth_date - birth_date, child_birth_date - birth_date,
name, 'Person', person_handle) name, 'Person', person_handle, top_size)
elif person.get_gender() == person.FEMALE: elif person.get_gender() == person.FEMALE:
_record(person_youngestmother, person_oldestmother, _record(person_youngestmother, person_oldestmother,
child_birth_date - birth_date, child_birth_date - birth_date,
name, 'Person', person_handle) name, 'Person', person_handle, top_size)
# Family records # Family records
@@ -221,7 +217,7 @@ def _find_records(db, filter, callname):
_record(None, family_mostchildren, _record(None, family_mostchildren,
len(family.get_child_ref_list()), len(family.get_child_ref_list()),
name, 'Family', family.handle) name, 'Family', family.handle, top_size)
marriage_date = None marriage_date = None
divorce = None divorce = None
@@ -262,7 +258,7 @@ def _find_records(db, filter, callname):
if probably_alive(father, db) and probably_alive(mother, db): if probably_alive(father, db) and probably_alive(mother, db):
_record(family_youngestmarried, family_oldestmarried, _record(family_youngestmarried, family_oldestmarried,
today_date - marriage_date, today_date - marriage_date,
name, 'Family', family.handle) name, 'Family', family.handle, top_size)
elif (_good_date(divorce_date) or elif (_good_date(divorce_date) or
_good_date(father_death_date) or _good_date(father_death_date) or
_good_date(mother_death_date)): _good_date(mother_death_date)):
@@ -281,25 +277,32 @@ def _find_records(db, filter, callname):
duration = end - marriage_date duration = end - marriage_date
_record(family_shortest, family_longest, _record(family_shortest, family_longest,
duration, name, 'Family', family.handle) duration, name, 'Family', family.handle, top_size)
return [(text, varname, locals()[varname]) for (text, varname, default) in RECORDS] return [(text, varname, locals()[varname]) for (text, varname, default) in RECORDS]
def _record(lowest, highest, value, text, handle_type, handle): def _record(lowest, highest, value, text, handle_type, handle, top_size):
if isinstance(value, Span):
low_value = value.minmax[0]
high_value = value.minmax[1]
else:
low_value = value
high_value = value
if lowest is not None: if lowest is not None:
lowest.append((value, text, handle_type, handle)) lowest.append((high_value, value, text, handle_type, handle))
lowest.sort(lambda a,b: cmp(a[0], b[0])) # FIXME: Ist das lambda notwendig? lowest.sort(lambda a,b: cmp(a[0], b[0])) # FIXME: Ist das lambda notwendig?
for i in range(RecordsReportOptions.TOP_SIZE, len(lowest)): for i in range(top_size, len(lowest)):
if lowest[i-1][0] < lowest[i][0]: if lowest[i-1][0] < lowest[i][0]:
del lowest[i:] del lowest[i:]
break break
if highest is not None: if highest is not None:
highest.append((value, text, handle_type, handle)) highest.append((low_value, value, text, handle_type, handle))
highest.sort(reverse=True) highest.sort(reverse=True)
for i in range(RecordsReportOptions.TOP_SIZE, len(highest)): for i in range(top_size, len(highest)):
if highest[i-1][0] > highest[i][0]: if highest[i-1][0] > highest[i][0]:
del highest[i:] del highest[i:]
break break
@@ -405,14 +408,14 @@ class RecordsGramplet(Gramplet):
def main(self): def main(self):
self.set_text(_("Processing...") + "\n") self.set_text(_("Processing...") + "\n")
yield True yield True
records = _find_records(self.dbstate.db, None, _Name_CALLNAME_DONTUSE) records = _find_records(self.dbstate.db, None, 3, _Name_CALLNAME_DONTUSE)
self.set_text("") self.set_text("")
for (text, varname, top) in records: for (text, varname, top) in records:
yield True yield True
self.render_text("<b>%s</b>" % text) self.render_text("<b>%s</b>" % text)
last_value = None last_value = None
rank = 0 rank = 0
for (number, (value, name, handletype, handle)) in enumerate(top): for (number, (sort, value, name, handletype, handle)) in enumerate(top):
if value != last_value: if value != last_value:
last_value = value last_value = value
rank = number rank = number
@@ -439,6 +442,7 @@ class RecordsReport(Report):
self.filter_option = menu.get_option_by_name('filter') self.filter_option = menu.get_option_by_name('filter')
self.filter = self.filter_option.get_filter() self.filter = self.filter_option.get_filter()
self.top_size = menu.get_option_by_name('top_size').get_value()
self.callname = menu.get_option_by_name('callname').get_value() self.callname = menu.get_option_by_name('callname').get_value()
self.footer = menu.get_option_by_name('footer').get_value() self.footer = menu.get_option_by_name('footer').get_value()
@@ -453,7 +457,7 @@ class RecordsReport(Report):
Build the actual report. Build the actual report.
""" """
records = _find_records(self.database, self.filter, self.callname) records = _find_records(self.database, self.filter, self.top_size, self.callname)
self.doc.start_paragraph('REC-Title') self.doc.start_paragraph('REC-Title')
self.doc.write_text(_("Records")) self.doc.write_text(_("Records"))
@@ -473,7 +477,7 @@ class RecordsReport(Report):
last_value = None last_value = None
rank = 0 rank = 0
for (number, (value, name, handletype, handle)) in enumerate(top): for (number, (sort, value, name, handletype, handle)) in enumerate(top):
if value != last_value: if value != last_value:
last_value = value last_value = value
rank = number rank = number
@@ -498,9 +502,6 @@ class RecordsReportOptions(MenuReportOptions):
Defines options and provides handling interface. Defines options and provides handling interface.
""" """
REGULAR_DATES_ONLY = True
TOP_SIZE = 3
def __init__(self, name, dbase): def __init__(self, name, dbase):
self.__pid = None self.__pid = None
@@ -526,6 +527,9 @@ class RecordsReportOptions(MenuReportOptions):
self.__update_filters() self.__update_filters()
top_size = NumberOption(_("Number of ranks to display"), 3, 1, 100)
menu.add_option(category_name, "top_size", top_size)
callname = EnumeratedListOption(_("Use call name"), _Name_CALLNAME_DONTUSE) callname = EnumeratedListOption(_("Use call name"), _Name_CALLNAME_DONTUSE)
callname.set_items([ callname.set_items([
(_Name_CALLNAME_DONTUSE, _("Don't use call name")), (_Name_CALLNAME_DONTUSE, _("Don't use call name")),

View File

@@ -31,7 +31,7 @@ register(REPORT,
id = 'records', id = 'records',
name = _("Records Report"), name = _("Records Report"),
description = _("Shows some interesting records about people and families"), description = _("Shows some interesting records about people and families"),
version = '1.0', version = '1.1',
gramps_target_version = '3.4', gramps_target_version = '3.4',
status = STABLE, status = STABLE,
fname = 'Records.py', fname = 'Records.py',