Some fixes
svn: r3892
This commit is contained in:
parent
b2628777c3
commit
9d5016a538
@ -1,7 +1,7 @@
|
||||
#
|
||||
# Gramps - a GTK+/GNOME based genealogy program
|
||||
#
|
||||
# Copyright (C) 2003-2004 Donald N. Allingham
|
||||
# Copyright (C) 2003-2005 Donald N. Allingham
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
@ -31,7 +31,6 @@ Statistics Chart report
|
||||
# python modules
|
||||
#
|
||||
#------------------------------------------------------------------------
|
||||
import os
|
||||
import time
|
||||
from gettext import gettext as _
|
||||
|
||||
@ -49,7 +48,7 @@ import gtk
|
||||
#------------------------------------------------------------------------
|
||||
from Utils import pt2cm
|
||||
import const # gender and report type names
|
||||
import RelLib # need Person internals for getting gender / gender name
|
||||
from RelLib import Person # need Person internals for getting gender / gender name
|
||||
import Utils
|
||||
import Report
|
||||
import BaseDoc
|
||||
@ -105,95 +104,109 @@ class Extract:
|
||||
(_("Genders"), self.gender)
|
||||
]
|
||||
|
||||
def estimate_age(self, person, date):
|
||||
def estimate_age(self, db, person, date):
|
||||
"""Utility method to estimate person's age at given date:
|
||||
person -- person whose age is to be estimated
|
||||
date -- date at which the age should be estimated
|
||||
This expects that Person's birth and the date argument are
|
||||
using the same calendar and that between those two dates
|
||||
there haven't been any calendar discontinuations."""
|
||||
birth = person.getBirth().getDateObj()
|
||||
if not (date.getYearValid() and birth.getYearValid()):
|
||||
birth_handle = person.get_birth_handle()
|
||||
if birth_handle:
|
||||
birth = db.get_event_from_handle(birth_handle).get_date_object()
|
||||
if not (date.get_year_valid() and birth.get_year_valid()):
|
||||
return _("Missing date(s)")
|
||||
age = date.getYear() - birth.getYear()
|
||||
if date.getMonthValid() and birth.getMonthValid():
|
||||
if date.getMonth() < birth.getMonth():
|
||||
age -= 1
|
||||
else:
|
||||
if (date.getMonth() == birth.getMonth() and
|
||||
date.getDayValid() and birth.getDayValid() and
|
||||
date.getDay() < birth.getDay()):
|
||||
return _("Missing date(s)")
|
||||
|
||||
age = date.get_year() - birth.get_year()
|
||||
if date.get_month_valid() and birth.get_month_valid():
|
||||
if date.get_month() < birth.get_month():
|
||||
age -= 1
|
||||
elif (date.get_month() == birth.get_month() and
|
||||
date.get_day_valid() and birth.get_day_valid() and
|
||||
date.get_day() < birth.get_day()):
|
||||
age -= 1
|
||||
if age >= 0:
|
||||
return str(age)
|
||||
else:
|
||||
return _("Invalid date(s)")
|
||||
|
||||
def title(self, person):
|
||||
title = person.getPrimaryName().getTitle()
|
||||
def title(self, db, person):
|
||||
title = person.get_primary_name().get_title()
|
||||
if title:
|
||||
return [title]
|
||||
else:
|
||||
return [_("Person's missing (preferred) title")]
|
||||
|
||||
def forename(self, person):
|
||||
def forename(self, db, person):
|
||||
# because this returns list, other methods return list too
|
||||
firstnames = person.getPrimaryName().getFirstName().strip()
|
||||
firstnames = person.get_primary_name().get_first_name().strip()
|
||||
if firstnames:
|
||||
return [name.capitalize() for name in firstnames.split()]
|
||||
else:
|
||||
return [_("Person's missing (preferred) forename")]
|
||||
|
||||
def birth_year(self, person):
|
||||
year = person.getBirth().getDateObj().getYear()
|
||||
if year != Date.UNDEF:
|
||||
def birth_year(self, db, person):
|
||||
birth_handle = person.get_birth_handle()
|
||||
if birth_handle:
|
||||
birth = db.get_event_from_handle(birth_handle).get_date_object()
|
||||
year = birth.get_year()
|
||||
if year:
|
||||
return [str(year)]
|
||||
else:
|
||||
return [_("Person's missing birth year")]
|
||||
|
||||
def death_year(self, person):
|
||||
year = person.getDeath().getDateObj().getYear()
|
||||
if year != Date.UNDEF:
|
||||
def death_year(self, db, person):
|
||||
death_handle = person.get_death_handle()
|
||||
if death_handle:
|
||||
death = db.get_event_from_handle(death_handle).get_date_object()
|
||||
year = death.get_year()
|
||||
if year:
|
||||
return [str(year)]
|
||||
else:
|
||||
return [_("Person's missing death year")]
|
||||
|
||||
def birth_month(self, person):
|
||||
month = person.getBirth().getDateObj().start
|
||||
if month.getMonthValid():
|
||||
return [month.getMonthStr()]
|
||||
else:
|
||||
def birth_month(self, db, person):
|
||||
birth_handle = person.get_birth_handle()
|
||||
if birth_handle:
|
||||
birth = db.get_event_from_handle(birth_handle).get_date_object()
|
||||
month = birth.get_month()
|
||||
if month:
|
||||
return ["Month text here"]#month.getMonthStr()]
|
||||
return [_("Person's missing birth month")]
|
||||
|
||||
def death_month(self, person):
|
||||
month = person.getDeath().getDateObj().start
|
||||
if month.getMonthValid():
|
||||
return [month.getMonthStr()]
|
||||
else:
|
||||
def death_month(self, db, person):
|
||||
death_handle = person.get_death_handle()
|
||||
if death_handle:
|
||||
death = db.get_event_from_handle(death_handle).get_date_object()
|
||||
month = death.get_month()
|
||||
if month:
|
||||
return ["Month text here"]#[month.getMonthStr()]
|
||||
return [_("Person's missing death month")]
|
||||
|
||||
def death_age(self, person):
|
||||
def death_age(self, db, person):
|
||||
birth_handle = person.get_birth_handle()
|
||||
if birth_handle:
|
||||
birth = db.get_event_from_handle(birth_handle).get_date_object()
|
||||
return [self.estimate_age(person, person.getDeath().getDateObj())]
|
||||
|
||||
def marriage_age(self, person):
|
||||
def marriage_age(self, db, person):
|
||||
return "Marriage age stat unimplemented"
|
||||
|
||||
def first_child_age(self, person):
|
||||
def first_child_age(self, db, person):
|
||||
return "First child bearing age stat unimplemented"
|
||||
|
||||
def last_child_age(self, person):
|
||||
def last_child_age(self, db, person):
|
||||
return "Last child bearing age stat unimplemented"
|
||||
|
||||
def child_count(self, person):
|
||||
def child_count(self, db, person):
|
||||
return "Child count stat unimplemented"
|
||||
|
||||
def death_cause(self, person):
|
||||
def death_cause(self, db, person):
|
||||
return "Death cause stat unimplemented"
|
||||
|
||||
def gender(self, person):
|
||||
def gender(self, db, person):
|
||||
# TODO: why there's no Person.getGenderName?
|
||||
# It could be used by getDisplayInfo & this...
|
||||
Person = RelLib.Person
|
||||
if person.gender == Person.male:
|
||||
gender = const.male
|
||||
elif person.gender == Person.female:
|
||||
@ -215,32 +228,36 @@ class Extract:
|
||||
year_to - use only persons who've born this year or before
|
||||
no_years - use also people without any birth year
|
||||
"""
|
||||
Person = RelLib.Person
|
||||
items = {}
|
||||
# go through the people and collect data
|
||||
for person in filter_func.apply(db, db.getPersonMap().values()):
|
||||
for person_handle in filter_func.apply(db, db.get_person_handles(sort_handles=False)):
|
||||
|
||||
person = db.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 = person.getBirth().getDateObj()
|
||||
if birth.getYearValid():
|
||||
year = birth.getYear()
|
||||
birth_handle = person.get_birth_handle()
|
||||
if birth_handle:
|
||||
birth = db.get_event_from_handle(birth_handle).get_date_object()
|
||||
if birth.get_year_valid():
|
||||
year = birth.get_year()
|
||||
if not (year >= year_from and year <= year_to):
|
||||
continue
|
||||
else:
|
||||
# if death before range, person's out of range too...
|
||||
death = person.getDeath().getDateObj()
|
||||
if death.getYearValid() and death.getYear() < year_from:
|
||||
death_handle = person.get_death_handle()
|
||||
if death_handle:
|
||||
death = db.get_event_from_handle(death_handle).get_date_object()
|
||||
if death.get_year_valid() and death.get_year() < year_from:
|
||||
continue
|
||||
if not no_years:
|
||||
# do not accept people who are not known to be in range
|
||||
continue
|
||||
|
||||
# get the information
|
||||
value = extract_func(person)
|
||||
value = extract_func(db,person)
|
||||
# list of information found
|
||||
for key in value:
|
||||
if key in items.keys():
|
||||
@ -279,19 +296,20 @@ class StatisticsChart(Report.Report):
|
||||
filters.extend(GenericFilter.CustomFilters.get_filters())
|
||||
filterfun = filters[filter_num]
|
||||
|
||||
year_from = options_dict['year_from']
|
||||
year_to = options_dict['year_to']
|
||||
gender = options_dict['gender']
|
||||
year_from = options_class.handler.options_dict['year_from']
|
||||
year_to = options_class.handler.options_dict['year_to']
|
||||
gender = options_class.handler.options_dict['gender']
|
||||
|
||||
extract = _Extract.extractors[options_dict['extract']]
|
||||
extract = _Extract.extractors[options_class.handler.options_dict['extract']]
|
||||
# extract requested items from the database and count them
|
||||
self.items = extractor.collect_data(self.db, filterfun, extract[1], gender,
|
||||
year_from, year_to, options_dict['no_years'])
|
||||
self.items = _Extract.collect_data(database, filterfun, extract[1],
|
||||
gender, year_from, year_to,
|
||||
options_class.handler.options_dict['no_years'])
|
||||
# generate sorted item lookup index index
|
||||
self.index_items(options_dict['sort'], options_dict['reverse'])
|
||||
self.index_items(options_class.handler.options_dict['sort'],
|
||||
options_class.handler.options_dict['reverse'])
|
||||
|
||||
# title needs both data extraction method name + gender name
|
||||
Person = RelLib.Person
|
||||
if gender == Person.male:
|
||||
genderstr = _("men")
|
||||
elif gender == Person.female:
|
||||
@ -433,9 +451,9 @@ class StatisticsChartOptions(ReportOptions.ReportOptions):
|
||||
(_SORT_KEY, _("Item name"))
|
||||
]
|
||||
_genders = [
|
||||
(RelLib.Person.unknown, _("Both")),
|
||||
(RelLib.Person.male, _("Men")),
|
||||
(RelLib.Person.female, _("Women"))
|
||||
(Person.unknown, _("Both")),
|
||||
(Person.male, _("Men")),
|
||||
(Person.female, _("Women"))
|
||||
]
|
||||
|
||||
def __init__(self,name, person_id=None):
|
||||
@ -493,7 +511,12 @@ class StatisticsChartOptions(ReportOptions.ReportOptions):
|
||||
def get_report_filters(self, person):
|
||||
"""Set up the list of possible content filters."""
|
||||
|
||||
name = person.getPrimaryName().getName()
|
||||
if person:
|
||||
name = person.get_primary_name().get_name()
|
||||
handle = person.get_handle()
|
||||
else:
|
||||
name = 'PERSON'
|
||||
handle = ''
|
||||
|
||||
all = GenericFilter.GenericFilter()
|
||||
all.set_name(_("Entire Database"))
|
||||
@ -501,15 +524,15 @@ class StatisticsChartOptions(ReportOptions.ReportOptions):
|
||||
|
||||
des = GenericFilter.GenericFilter()
|
||||
des.set_name(_("Descendants of %s") % name)
|
||||
des.add_rule(GenericFilter.IsDescendantOf([person.getId(), 1]))
|
||||
des.add_rule(GenericFilter.IsDescendantOf([handle, 1]))
|
||||
|
||||
ans = GenericFilter.GenericFilter()
|
||||
ans.set_name(_("Ancestors of %s") % name)
|
||||
ans.add_rule(GenericFilter.IsAncestorOf([person.getId(), 1]))
|
||||
ans.add_rule(GenericFilter.IsAncestorOf([handle, 1]))
|
||||
|
||||
com = GenericFilter.GenericFilter()
|
||||
com.set_name(_("People with common ancestor with %s") % name)
|
||||
com.add_rule(GenericFilter.HasCommonAncestorWith([person.getId()]))
|
||||
com.add_rule(GenericFilter.HasCommonAncestorWith([handle]))
|
||||
|
||||
return [all, des, ans, com]
|
||||
|
||||
@ -575,7 +598,6 @@ class StatisticsChartOptions(ReportOptions.ReportOptions):
|
||||
self.no_years.show()
|
||||
|
||||
# gender selection
|
||||
Person = RelLib.Person
|
||||
self.gender_menu = gtk.Menu()
|
||||
for item in self._genders:
|
||||
menuitem = gtk.MenuItem(item[1])
|
||||
@ -594,11 +616,11 @@ class StatisticsChartOptions(ReportOptions.ReportOptions):
|
||||
"""
|
||||
self.options_dict['year_to'] = int(self.to_box.get_text())
|
||||
self.options_dict['year_from'] = int(self.from_box.get_text())
|
||||
self.options_dict['no_years'] = self.no_years.get_active()
|
||||
self.options_dict['no_years'] = int(self.no_years.get_active())
|
||||
self.options_dict['gender'] = self.gender_menu.get_active().get_data('gender')
|
||||
self.options_dict['extract'] = self.extract_menu.get_active().get_data('extract')
|
||||
self.options_dict['sort'] = self.sort_menu.get_active().get_data('sort')
|
||||
self.options_dict['reverse'] = self.reverse.get_active()
|
||||
self.options_dict['reverse'] = int(self.reverse.get_active())
|
||||
|
||||
|
||||
#------------------------------------------------------------------------
|
||||
|
Loading…
x
Reference in New Issue
Block a user