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