2005-01-11 01:42:16 +05:30
|
|
|
#
|
|
|
|
# Gramps - a GTK+/GNOME based genealogy program
|
|
|
|
#
|
2008-01-06 02:12:05 +05:30
|
|
|
# Copyright (C) 2003-2006 Donald N. Allingham
|
2008-05-12 00:37:30 +05:30
|
|
|
# Copyright (C) 2004-2005 Eero Tamminen
|
2008-01-06 02:12:05 +05:30
|
|
|
# Copyright (C) 2007-2008 Brian G. Matherly
|
2008-02-18 10:19:54 +05:30
|
|
|
# Copyright (C) 2008 Peter Landgren
|
2005-01-11 01:42:16 +05:30
|
|
|
#
|
|
|
|
# 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
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
#
|
2005-01-29 22:41:02 +05:30
|
|
|
# To see things still missing, search for "TODO"...
|
2005-01-11 01:42:16 +05:30
|
|
|
#
|
|
|
|
# $Id$
|
|
|
|
|
2008-03-02 04:17:48 +05:30
|
|
|
"""Reports/Graphical Reports/Statistics Report"""
|
2005-01-11 01:42:16 +05:30
|
|
|
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# python modules
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
import time
|
2006-03-17 01:54:27 +05:30
|
|
|
from TransUtils import sgettext as _
|
2005-01-11 01:42:16 +05:30
|
|
|
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GRAMPS modules
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
2005-01-29 22:41:02 +05:30
|
|
|
|
|
|
|
# Person and relation types
|
2009-10-25 22:22:45 +05:30
|
|
|
from gen.lib import Person, FamilyRelType, EventType, EventRoleType
|
2005-01-29 22:41:02 +05:30
|
|
|
# gender and report type names
|
2009-05-31 20:29:56 +05:30
|
|
|
from gen.plug.docgen import (FontStyle, ParagraphStyle, GraphicsStyle,
|
|
|
|
FONT_SANS_SERIF, FONT_SERIF,
|
|
|
|
PARA_ALIGN_CENTER, PARA_ALIGN_LEFT)
|
2008-09-27 19:26:17 +05:30
|
|
|
from gen.plug.menu import BooleanOption, NumberOption, EnumeratedListOption, \
|
|
|
|
FilterOption, PersonOption
|
2009-10-24 19:23:20 +05:30
|
|
|
from ReportBase import Report, ReportUtils, MenuReportOptions
|
2005-08-06 08:27:37 +05:30
|
|
|
import DateHandler
|
2009-06-19 20:53:58 +05:30
|
|
|
from gui.utils import ProgressMeter
|
2005-01-11 01:42:16 +05:30
|
|
|
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
2005-01-26 01:26:23 +05:30
|
|
|
# Global options and their names
|
2005-01-11 01:42:16 +05:30
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
|
2005-01-22 03:25:10 +05:30
|
|
|
class _options:
|
|
|
|
# sort type identifiers
|
|
|
|
SORT_VALUE = 0
|
|
|
|
SORT_KEY = 1
|
|
|
|
|
|
|
|
sorts = [
|
|
|
|
(SORT_VALUE, "Item count", _("Item count")),
|
|
|
|
(SORT_KEY, "Item name", _("Item name"))
|
|
|
|
]
|
|
|
|
genders = [
|
2005-02-01 09:16:29 +05:30
|
|
|
(Person.UNKNOWN, "Both", _("Both")),
|
|
|
|
(Person.MALE, "Men", _("Men")),
|
|
|
|
(Person.FEMALE, "Women", _("Women"))
|
2005-01-22 03:25:10 +05:30
|
|
|
]
|
|
|
|
|
|
|
|
|
2005-01-11 01:42:16 +05:30
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Data extraction methods from the database
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
2009-05-21 22:49:50 +05:30
|
|
|
class Extract(object):
|
2005-01-11 01:42:16 +05:30
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
"""Methods for extracting statistical data from the database"""
|
2005-01-31 11:01:30 +05:30
|
|
|
# key, non-localized name, localized name, type method, data method
|
2005-01-22 03:25:10 +05:30
|
|
|
self.extractors = {
|
2006-03-17 01:54:27 +05:30
|
|
|
'data_title': ("Title", _("person|Title"),
|
2005-01-31 11:01:30 +05:30
|
|
|
self.get_person, self.get_title),
|
2005-12-06 12:08:09 +05:30
|
|
|
'data_sname': ("Surname", _("Surname"),
|
2005-04-02 02:02:06 +05:30
|
|
|
self.get_person, self.get_surname),
|
2005-12-06 12:08:09 +05:30
|
|
|
'data_fname': ("Forename", _("Forename"),
|
2005-01-31 11:01:30 +05:30
|
|
|
self.get_person, self.get_forename),
|
2005-12-06 12:08:09 +05:30
|
|
|
'data_gender': ("Gender", _("Gender"),
|
2005-01-31 11:01:30 +05:30
|
|
|
self.get_person, self.get_gender),
|
2005-12-06 12:08:09 +05:30
|
|
|
'data_byear': ("Birth year", _("Birth year"),
|
2005-01-31 11:01:30 +05:30
|
|
|
self.get_birth, self.get_year),
|
2005-12-06 12:08:09 +05:30
|
|
|
'data_dyear': ("Death year", _("Death year"),
|
2005-01-31 11:01:30 +05:30
|
|
|
self.get_death, self.get_year),
|
2005-12-06 12:08:09 +05:30
|
|
|
'data_bmonth': ("Birth month", _("Birth month"),
|
2005-01-31 11:01:30 +05:30
|
|
|
self.get_birth, self.get_month),
|
2005-12-06 12:08:09 +05:30
|
|
|
'data_dmonth': ("Death month", _("Death month"),
|
2005-01-31 11:01:30 +05:30
|
|
|
self.get_death, self.get_month),
|
2005-12-06 12:08:09 +05:30
|
|
|
'data_bplace': ("Birth place", _("Birth place"),
|
2005-01-31 11:01:30 +05:30
|
|
|
self.get_birth, self.get_place),
|
2005-12-06 12:08:09 +05:30
|
|
|
'data_dplace': ("Death place", _("Death place"),
|
2005-01-31 11:01:30 +05:30
|
|
|
self.get_death, self.get_place),
|
2005-12-06 12:08:09 +05:30
|
|
|
'data_mplace': ("Marriage place", _("Marriage place"),
|
2005-01-31 11:01:30 +05:30
|
|
|
self.get_marriage_handles, self.get_places),
|
2005-04-02 02:02:06 +05:30
|
|
|
'data_mcount': ("Number of relationships", _("Number of relationships"),
|
|
|
|
self.get_family_handles, self.get_handle_count),
|
2005-12-06 12:08:09 +05:30
|
|
|
'data_fchild': ("Age when first child born", _("Age when first child born"),
|
2005-01-31 11:01:30 +05:30
|
|
|
self.get_child_handles, self.get_first_child_age),
|
2005-12-06 12:08:09 +05:30
|
|
|
'data_lchild': ("Age when last child born", _("Age when last child born"),
|
2005-01-31 11:01:30 +05:30
|
|
|
self.get_child_handles, self.get_last_child_age),
|
2005-01-29 22:41:02 +05:30
|
|
|
'data_ccount': ("Number of children", _("Number of children"),
|
2005-04-02 02:02:06 +05:30
|
|
|
self.get_child_handles, self.get_handle_count),
|
2005-12-06 12:08:09 +05:30
|
|
|
'data_mage': ("Age at marriage", _("Age at marriage"),
|
2005-01-31 11:01:30 +05:30
|
|
|
self.get_marriage_handles, self.get_event_ages),
|
2005-12-06 12:08:09 +05:30
|
|
|
'data_dage': ("Age at death", _("Age at death"),
|
2005-01-31 11:01:30 +05:30
|
|
|
self.get_person, self.get_death_age),
|
2005-12-06 12:08:09 +05:30
|
|
|
'data_age': ("Age", _("Age"),
|
2005-04-02 02:02:06 +05:30
|
|
|
self.get_person, self.get_person_age),
|
2005-12-06 12:08:09 +05:30
|
|
|
'data_etypes': ("Event type", _("Event type"),
|
2005-04-02 02:02:06 +05:30
|
|
|
self.get_event_handles, self.get_event_type)
|
2005-01-22 03:25:10 +05:30
|
|
|
}
|
2005-01-11 05:58:53 +05:30
|
|
|
|
2005-01-23 03:16:55 +05:30
|
|
|
# ----------------- data extraction methods --------------------
|
|
|
|
# take an object and return a list of strings
|
2005-01-11 05:58:53 +05:30
|
|
|
|
2005-01-23 03:16:55 +05:30
|
|
|
def get_title(self, person):
|
2005-01-31 11:01:30 +05:30
|
|
|
"return title for given person"
|
2005-01-29 22:41:02 +05:30
|
|
|
# TODO: return all titles, not just primary ones...
|
2005-01-11 05:58:53 +05:30
|
|
|
title = person.get_primary_name().get_title()
|
|
|
|
if title:
|
|
|
|
return [title]
|
|
|
|
else:
|
2005-01-23 03:16:55 +05:30
|
|
|
return [_("(Preferred) title missing")]
|
2005-01-11 05:58:53 +05:30
|
|
|
|
2005-01-23 03:16:55 +05:30
|
|
|
def get_forename(self, person):
|
2005-01-31 11:01:30 +05:30
|
|
|
"return forenames for given person"
|
2005-01-29 22:41:02 +05:30
|
|
|
# TODO: return all forenames, not just primary ones...
|
2005-01-11 05:58:53 +05:30
|
|
|
firstnames = person.get_primary_name().get_first_name().strip()
|
|
|
|
if firstnames:
|
2008-02-12 10:19:43 +05:30
|
|
|
return firstnames.split()
|
2005-01-11 05:58:53 +05:30
|
|
|
else:
|
2005-01-23 03:16:55 +05:30
|
|
|
return [_("(Preferred) forename missing")]
|
2005-01-11 01:42:16 +05:30
|
|
|
|
2005-04-02 02:02:06 +05:30
|
|
|
def get_surname(self, person):
|
|
|
|
"return surnames for given person"
|
|
|
|
# TODO: return all surnames, not just primary ones...
|
|
|
|
surnames = person.get_primary_name().get_surname().strip()
|
|
|
|
if surnames:
|
2008-02-12 10:19:43 +05:30
|
|
|
return surnames.split()
|
2005-04-02 02:02:06 +05:30
|
|
|
else:
|
|
|
|
return [_("(Preferred) surname missing")]
|
|
|
|
|
2005-01-23 03:16:55 +05:30
|
|
|
def get_gender(self, person):
|
2005-01-31 11:01:30 +05:30
|
|
|
"return gender for given person"
|
2005-01-11 05:58:53 +05:30
|
|
|
# TODO: why there's no Person.getGenderName?
|
|
|
|
# It could be used by getDisplayInfo & this...
|
2005-02-01 09:16:29 +05:30
|
|
|
if person.gender == Person.MALE:
|
2005-01-26 01:26:23 +05:30
|
|
|
return [_("Men")]
|
2005-02-01 09:16:29 +05:30
|
|
|
if person.gender == Person.FEMALE:
|
2005-01-26 01:26:23 +05:30
|
|
|
return [_("Women")]
|
|
|
|
return [_("Gender unknown")]
|
2005-01-22 03:25:10 +05:30
|
|
|
|
2005-01-23 03:16:55 +05:30
|
|
|
def get_year(self, event):
|
2005-01-31 11:01:30 +05:30
|
|
|
"return year for given event"
|
|
|
|
date = event.get_date_object()
|
|
|
|
if date:
|
2005-01-23 03:16:55 +05:30
|
|
|
year = date.get_year()
|
|
|
|
if year:
|
|
|
|
return [str(year)]
|
2005-01-26 01:26:23 +05:30
|
|
|
return [_("Date(s) missing")]
|
2005-01-23 03:16:55 +05:30
|
|
|
|
|
|
|
def get_month(self, event):
|
2005-01-31 11:01:30 +05:30
|
|
|
"return month for given event"
|
|
|
|
date = event.get_date_object()
|
|
|
|
if date:
|
2005-01-23 03:16:55 +05:30
|
|
|
month = date.get_month()
|
|
|
|
if month:
|
2005-08-06 08:27:37 +05:30
|
|
|
return [DateHandler.displayer._months[month]]
|
2005-01-26 01:26:23 +05:30
|
|
|
return [_("Date(s) missing")]
|
2005-01-23 03:16:55 +05:30
|
|
|
|
|
|
|
def get_place(self, event):
|
2005-01-31 11:01:30 +05:30
|
|
|
"return place for given event"
|
|
|
|
place_handle = event.get_place_handle()
|
|
|
|
if place_handle:
|
2005-01-23 03:16:55 +05:30
|
|
|
place = self.db.get_place_from_handle(place_handle).get_title()
|
2005-01-31 11:01:30 +05:30
|
|
|
if place:
|
|
|
|
return [place]
|
2005-01-23 03:16:55 +05:30
|
|
|
return [_("Place missing")]
|
2005-01-29 22:41:02 +05:30
|
|
|
|
|
|
|
def get_places(self, data):
|
|
|
|
"return places for given (person,event_handles)"
|
|
|
|
places = []
|
|
|
|
person, event_handles = data
|
|
|
|
for event_handle in event_handles:
|
|
|
|
event = self.db.get_event_from_handle(event_handle)
|
|
|
|
place_handle = event.get_place_handle()
|
|
|
|
if place_handle:
|
|
|
|
place = self.db.get_place_from_handle(place_handle).get_title()
|
|
|
|
if place:
|
2008-01-06 01:40:26 +05:30
|
|
|
places.append(place)
|
2005-01-29 22:41:02 +05:30
|
|
|
else:
|
|
|
|
places.append(_("Place missing"))
|
|
|
|
return places
|
2005-01-23 03:16:55 +05:30
|
|
|
|
|
|
|
def get_person_age(self, person):
|
2005-01-31 11:01:30 +05:30
|
|
|
"return age for given person, if alive"
|
2006-03-30 10:45:54 +05:30
|
|
|
death_ref = person.get_death_ref()
|
|
|
|
if not death_ref:
|
2005-01-29 22:41:02 +05:30
|
|
|
return [self.estimate_age(person)]
|
2005-01-26 01:26:23 +05:30
|
|
|
return [_("Already dead")]
|
2005-01-23 03:16:55 +05:30
|
|
|
|
|
|
|
def get_death_age(self, person):
|
2005-01-31 11:01:30 +05:30
|
|
|
"return age at death for given person, if dead"
|
2006-03-30 10:45:54 +05:30
|
|
|
death_ref = person.get_death_ref()
|
|
|
|
if death_ref:
|
|
|
|
return [self.estimate_age(person, death_ref.ref)]
|
2005-01-26 01:26:23 +05:30
|
|
|
return [_("Still alive")]
|
2005-01-23 03:16:55 +05:30
|
|
|
|
2005-01-29 22:41:02 +05:30
|
|
|
def get_event_ages(self, data):
|
|
|
|
"return ages at given (person,event_handles)"
|
|
|
|
ages = []
|
|
|
|
person, event_handles = data
|
|
|
|
for event_handle in event_handles:
|
|
|
|
ages.append(self.estimate_age(person, event_handle))
|
|
|
|
if ages:
|
|
|
|
return ages
|
2005-01-31 11:01:30 +05:30
|
|
|
return [_("Events missing")]
|
2005-01-29 22:41:02 +05:30
|
|
|
|
2005-04-02 02:02:06 +05:30
|
|
|
def get_event_type(self, data):
|
|
|
|
"return event types at given (person,event_handles)"
|
|
|
|
types = []
|
|
|
|
person, event_handles = data
|
|
|
|
for event_handle in event_handles:
|
|
|
|
event = self.db.get_event_from_handle(event_handle)
|
2006-04-28 10:03:28 +05:30
|
|
|
evtType = str(event.get_type())
|
2006-03-30 10:45:54 +05:30
|
|
|
types.append(evtType)
|
2005-04-02 02:02:06 +05:30
|
|
|
if types:
|
|
|
|
return types
|
|
|
|
return [_("Events missing")]
|
|
|
|
|
2005-01-29 22:41:02 +05:30
|
|
|
def get_first_child_age(self, data):
|
|
|
|
"return age when first child in given (person,child_handles) was born"
|
|
|
|
ages, errors = self.get_sorted_child_ages(data)
|
|
|
|
if ages:
|
|
|
|
errors.append(ages[0])
|
|
|
|
return errors
|
|
|
|
return [_("Children missing")]
|
|
|
|
|
|
|
|
def get_last_child_age(self, data):
|
|
|
|
"return age when last child in given (person,child_handles) was born"
|
|
|
|
ages, errors = self.get_sorted_child_ages(data)
|
|
|
|
if ages:
|
|
|
|
errors.append(ages[-1])
|
|
|
|
return errors
|
|
|
|
return [_("Children missing")]
|
|
|
|
|
2005-04-02 02:02:06 +05:30
|
|
|
def get_handle_count(self, data):
|
2008-02-24 19:25:55 +05:30
|
|
|
"return number of handles in given (person, handle_list) used for child count, family count"
|
2008-03-10 18:37:08 +05:30
|
|
|
return ["%3d" % len(data[1])]
|
2005-01-23 03:16:55 +05:30
|
|
|
|
|
|
|
# ------------------- utility methods -------------------------
|
2005-01-29 22:41:02 +05:30
|
|
|
|
|
|
|
def get_sorted_child_ages(self, data):
|
|
|
|
"return (sorted_ages,errors) for given (person,child_handles)"
|
|
|
|
ages = []
|
|
|
|
errors = []
|
|
|
|
person, child_handles = data
|
|
|
|
for child_handle in child_handles:
|
|
|
|
child = self.db.get_person_from_handle(child_handle)
|
2006-03-30 10:45:54 +05:30
|
|
|
birth_ref = child.get_birth_ref()
|
|
|
|
if birth_ref:
|
|
|
|
ages.append(self.estimate_age(person, birth_ref.ref))
|
2005-01-31 11:01:30 +05:30
|
|
|
else:
|
2005-01-29 22:41:02 +05:30
|
|
|
errors.append(_("Birth missing"))
|
|
|
|
continue
|
|
|
|
ages.sort()
|
|
|
|
return (ages, errors)
|
2005-01-23 03:16:55 +05:30
|
|
|
|
2005-01-29 22:41:02 +05:30
|
|
|
def estimate_age(self, person, end=None, begin=None):
|
|
|
|
"""return estimated age (range) for given person or error message.
|
|
|
|
age string is padded with spaces so that it can be sorted"""
|
|
|
|
age = ReportUtils.estimate_age(self.db, person, end, begin)
|
2005-01-23 03:16:55 +05:30
|
|
|
if age[0] < 0 or age[1] < 0:
|
|
|
|
# inadequate information
|
2005-01-29 22:41:02 +05:30
|
|
|
return _("Date(s) missing")
|
2005-01-23 03:16:55 +05:30
|
|
|
if age[0] == age[1]:
|
|
|
|
# exact year
|
2005-01-29 22:41:02 +05:30
|
|
|
return "%3d" % age[0]
|
2005-01-23 03:16:55 +05:30
|
|
|
else:
|
|
|
|
# minimum and maximum
|
2005-01-29 22:41:02 +05:30
|
|
|
return "%3d-%d" % (age[0], age[1])
|
2005-01-23 03:16:55 +05:30
|
|
|
|
|
|
|
# ------------------- type methods -------------------------
|
|
|
|
# take db and person and return suitable gramps object(s)
|
|
|
|
|
|
|
|
def get_person(self, person):
|
2005-01-31 11:01:30 +05:30
|
|
|
"return person"
|
|
|
|
return person
|
2005-01-23 03:16:55 +05:30
|
|
|
|
|
|
|
def get_birth(self, person):
|
2005-01-29 22:41:02 +05:30
|
|
|
"return birth event for given person or None"
|
2006-03-30 10:45:54 +05:30
|
|
|
birth_ref = person.get_birth_ref()
|
|
|
|
if birth_ref:
|
|
|
|
return self.db.get_event_from_handle(birth_ref.ref)
|
2005-01-29 22:41:02 +05:30
|
|
|
return None
|
2005-01-23 03:16:55 +05:30
|
|
|
|
|
|
|
def get_death(self, person):
|
2005-01-29 22:41:02 +05:30
|
|
|
"return death event for given person or None"
|
2006-03-30 10:45:54 +05:30
|
|
|
death_ref = person.get_death_ref()
|
|
|
|
if death_ref:
|
|
|
|
return self.db.get_event_from_handle(death_ref.ref)
|
2005-01-29 22:41:02 +05:30
|
|
|
return None
|
|
|
|
|
|
|
|
def get_child_handles(self, person):
|
|
|
|
"return list of child handles for given person or None"
|
|
|
|
children = []
|
|
|
|
for fam_handle in person.get_family_handle_list():
|
|
|
|
fam = self.db.get_family_from_handle(fam_handle)
|
2006-04-28 10:03:28 +05:30
|
|
|
for child_ref in fam.get_child_ref_list():
|
|
|
|
children.append(child_ref.ref)
|
2005-01-29 22:41:02 +05:30
|
|
|
# TODO: it would be good to return only biological children,
|
|
|
|
# but GRAMPS doesn't offer any efficient way to check that
|
|
|
|
# (I don't want to check each children's parent family mother
|
|
|
|
# and father relations as that would make this *much* slower)
|
|
|
|
if children:
|
|
|
|
return (person, children)
|
|
|
|
return None
|
|
|
|
|
|
|
|
def get_marriage_handles(self, person):
|
|
|
|
"return list of marriage event handles for given person or None"
|
|
|
|
marriages = []
|
|
|
|
for family_handle in person.get_family_handle_list():
|
|
|
|
family = self.db.get_family_from_handle(family_handle)
|
2006-04-28 10:03:28 +05:30
|
|
|
if int(family.get_relationship()) == FamilyRelType.MARRIED:
|
|
|
|
for event_ref in family.get_event_ref_list():
|
|
|
|
event = self.db.get_event_from_handle(event_ref.ref)
|
2009-10-25 22:22:45 +05:30
|
|
|
if event.get_type() == EventType.MARRIAGE and \
|
|
|
|
(event_ref.get_role() == EventRoleType.FAMILY or
|
|
|
|
event_ref.get_role() == EventRoleType.PRIMARY ):
|
2006-04-28 10:03:28 +05:30
|
|
|
marriages.append(event_ref.ref)
|
2005-01-29 22:41:02 +05:30
|
|
|
if marriages:
|
|
|
|
return (person, marriages)
|
|
|
|
return None
|
2005-01-23 03:16:55 +05:30
|
|
|
|
2005-04-02 02:02:06 +05:30
|
|
|
def get_family_handles(self, person):
|
|
|
|
"return list of family handles for given person or None"
|
|
|
|
families = person.get_family_handle_list()
|
|
|
|
|
|
|
|
if families:
|
|
|
|
return (person, families)
|
|
|
|
return None
|
|
|
|
|
|
|
|
def get_event_handles(self, person):
|
|
|
|
"return list of event handles for given person or None"
|
2006-03-30 10:45:54 +05:30
|
|
|
events = []
|
|
|
|
for event_ref in person.get_event_ref_list():
|
2006-04-28 10:03:28 +05:30
|
|
|
events.append(event_ref.ref)
|
2005-04-02 02:02:06 +05:30
|
|
|
|
|
|
|
if events:
|
|
|
|
return (person, events)
|
|
|
|
return None
|
|
|
|
|
2005-01-23 03:16:55 +05:30
|
|
|
# ----------------- data collection methods --------------------
|
|
|
|
|
|
|
|
def get_person_data(self, person, collect):
|
2008-02-24 19:25:55 +05:30
|
|
|
"""Add data from the database to 'collect' for the given person,
|
2005-01-22 03:25:10 +05:30
|
|
|
using methods rom the 'collect' data dict tuple
|
|
|
|
"""
|
|
|
|
for chart in collect:
|
|
|
|
# get the information
|
2005-01-23 03:16:55 +05:30
|
|
|
type_func = chart[2]
|
2005-01-31 11:01:30 +05:30
|
|
|
data_func = chart[3]
|
|
|
|
obj = type_func(person) # e.g. get_date()
|
|
|
|
if obj:
|
|
|
|
value = data_func(obj) # e.g. get_year()
|
|
|
|
else:
|
|
|
|
value = [_("Personal information missing")]
|
2005-01-22 03:25:10 +05:30
|
|
|
# list of information found
|
|
|
|
for key in value:
|
2009-05-23 00:13:40 +05:30
|
|
|
if key in chart[1]:
|
2005-01-22 03:25:10 +05:30
|
|
|
chart[1][key] += 1
|
|
|
|
else:
|
|
|
|
chart[1][key] = 1
|
|
|
|
|
2005-01-11 01:42:16 +05:30
|
|
|
|
2008-01-23 11:11:46 +05:30
|
|
|
def collect_data(self, db, filter_func, menu, genders,
|
2005-01-11 01:42:16 +05:30
|
|
|
year_from, year_to, no_years):
|
|
|
|
"""goes through the database and collects the selected personal
|
2005-01-11 05:58:53 +05:30
|
|
|
data persons fitting the filter and birth year criteria. The
|
|
|
|
arguments are:
|
2005-01-22 03:25:10 +05:30
|
|
|
db - the GRAMPS database
|
|
|
|
filter_func - filtering function selected by the StatisticsDialog
|
|
|
|
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
|
2005-05-24 18:38:06 +05:30
|
|
|
no_years - use also people without known birth year
|
2005-01-31 11:01:30 +05:30
|
|
|
|
|
|
|
Returns an array of tuple of:
|
|
|
|
- Extraction method title
|
|
|
|
- Dict of values with their counts
|
|
|
|
(- Method)
|
2005-01-11 05:58:53 +05:30
|
|
|
"""
|
2005-01-31 11:01:30 +05:30
|
|
|
self.db = db # store for use by methods
|
2005-01-23 03:16:55 +05:30
|
|
|
|
2005-01-22 03:25:10 +05:30
|
|
|
data = []
|
|
|
|
ext = self.extractors
|
2005-01-26 01:26:23 +05:30
|
|
|
# which methods to use
|
2009-05-23 00:13:40 +05:30
|
|
|
for name in self.extractors:
|
2008-02-12 10:19:43 +05:30
|
|
|
option = menu.get_option_by_name(name)
|
|
|
|
if option.get_value() == True:
|
2005-01-29 22:41:02 +05:30
|
|
|
# localized data title, value dict, type and data method
|
2008-01-23 11:11:46 +05:30
|
|
|
data.append((ext[name][1], {}, ext[name][2], ext[name][3]))
|
2005-01-22 03:25:10 +05:30
|
|
|
|
2005-01-11 05:58:53 +05:30
|
|
|
# go through the people and collect data
|
2009-07-04 01:53:41 +05:30
|
|
|
for person_handle in filter_func.apply(db, db.iter_person_handles()):
|
2005-01-11 05:58:53 +05:30
|
|
|
|
|
|
|
person = db.get_person_from_handle(person_handle)
|
|
|
|
# check whether person has suitable gender
|
2005-02-01 09:16:29 +05:30
|
|
|
if person.gender != genders and genders != Person.UNKNOWN:
|
2005-01-11 05:58:53 +05:30
|
|
|
continue
|
|
|
|
|
|
|
|
# check whether birth year is within required range
|
2005-02-19 00:52:06 +05:30
|
|
|
birth = self.get_birth(person)
|
2005-01-31 11:01:30 +05:30
|
|
|
if birth:
|
2005-02-19 00:52:06 +05:30
|
|
|
birthdate = birth.get_date_object()
|
|
|
|
if birthdate.get_year_valid():
|
|
|
|
year = birthdate.get_year()
|
2005-01-11 05:58:53 +05:30
|
|
|
if not (year >= year_from and year <= year_to):
|
|
|
|
continue
|
|
|
|
else:
|
|
|
|
# if death before range, person's out of range too...
|
2005-02-19 00:52:06 +05:30
|
|
|
death = self.get_death(person)
|
2005-01-31 11:01:30 +05:30
|
|
|
if death:
|
2005-02-19 00:52:06 +05:30
|
|
|
deathdate = death.get_date_object()
|
|
|
|
if deathdate.get_year_valid() and deathdate.get_year() < year_from:
|
2005-01-11 05:58:53 +05:30
|
|
|
continue
|
|
|
|
if not no_years:
|
|
|
|
# do not accept people who are not known to be in range
|
|
|
|
continue
|
2008-02-18 10:19:54 +05:30
|
|
|
else:
|
|
|
|
continue
|
|
|
|
else:
|
|
|
|
continue
|
2005-01-11 05:58:53 +05:30
|
|
|
|
2005-01-23 03:16:55 +05:30
|
|
|
self.get_person_data(person, data)
|
2005-01-22 03:25:10 +05:30
|
|
|
return data
|
2005-01-11 01:42:16 +05:30
|
|
|
|
2005-01-12 02:01:51 +05:30
|
|
|
# GLOBAL: required so that we get access to _Extract.extractors[]
|
|
|
|
# Unfortunately class variables cannot reference instance methods :-/
|
2005-01-11 01:42:16 +05:30
|
|
|
_Extract = Extract()
|
|
|
|
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Statistics report
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
2006-06-01 10:09:40 +05:30
|
|
|
class StatisticsChart(Report):
|
2005-01-11 01:42:16 +05:30
|
|
|
|
2008-02-20 10:22:10 +05:30
|
|
|
def __init__(self, database, options_class):
|
2005-01-11 01:42:16 +05:30
|
|
|
"""
|
2008-02-24 19:25:55 +05:30
|
|
|
Create the Statistics object that produces the report.
|
2005-01-11 05:58:53 +05:30
|
|
|
Uses the Extractor class to extract the data from the database.
|
2005-01-11 01:42:16 +05:30
|
|
|
|
|
|
|
The arguments are:
|
|
|
|
|
|
|
|
database - the GRAMPS database instance
|
|
|
|
person - currently selected person
|
|
|
|
options_class - instance of the Options class for this report
|
|
|
|
|
2005-01-11 05:58:53 +05:30
|
|
|
To see what the options are, check the options help in the options class.
|
2005-01-11 01:42:16 +05:30
|
|
|
"""
|
2008-02-20 10:22:10 +05:30
|
|
|
Report.__init__(self, database, options_class)
|
2008-02-12 10:19:43 +05:30
|
|
|
menu = options_class.menu
|
2005-01-11 05:58:53 +05:30
|
|
|
|
2008-02-12 10:19:43 +05:30
|
|
|
self.filter_option = menu.get_option_by_name('filter')
|
2008-01-06 02:12:05 +05:30
|
|
|
self.filter = self.filter_option.get_filter()
|
2005-01-11 01:42:16 +05:30
|
|
|
|
2008-01-23 11:11:46 +05:30
|
|
|
self.bar_items = menu.get_option_by_name('bar_items').get_value()
|
|
|
|
year_from = menu.get_option_by_name('year_from').get_value()
|
|
|
|
year_to = menu.get_option_by_name('year_to').get_value()
|
|
|
|
gender = menu.get_option_by_name('gender').get_value()
|
2005-01-11 05:58:53 +05:30
|
|
|
|
|
|
|
# title needs both data extraction method name + gender name
|
2005-02-01 09:16:29 +05:30
|
|
|
if gender == Person.MALE:
|
2005-01-30 02:11:22 +05:30
|
|
|
genders = _("Men")
|
2005-02-01 09:16:29 +05:30
|
|
|
elif gender == Person.FEMALE:
|
2005-01-30 02:11:22 +05:30
|
|
|
genders = _("Women")
|
2005-01-11 05:58:53 +05:30
|
|
|
else:
|
2005-01-23 03:16:55 +05:30
|
|
|
genders = None
|
|
|
|
|
|
|
|
# needed for keyword based localization
|
|
|
|
mapping = {
|
|
|
|
'genders': genders,
|
|
|
|
'year_from': year_from,
|
|
|
|
'year_to': year_to
|
2005-01-31 11:01:30 +05:30
|
|
|
}
|
2008-01-06 01:40:26 +05:30
|
|
|
self.progress = ProgressMeter(_('Statistics Charts'))
|
2005-01-11 05:58:53 +05:30
|
|
|
|
2005-01-22 03:25:10 +05:30
|
|
|
# extract requested items from the database and count them
|
2008-01-06 01:40:26 +05:30
|
|
|
self.progress.set_pass(_('Collecting data...'), 1)
|
2008-01-23 11:11:46 +05:30
|
|
|
tables = _Extract.collect_data(database, self.filter, menu,
|
|
|
|
gender, year_from, year_to,
|
|
|
|
menu.get_option_by_name('no_years').get_value())
|
2008-01-06 01:40:26 +05:30
|
|
|
self.progress.step()
|
2005-01-11 05:58:53 +05:30
|
|
|
|
2008-01-06 01:40:26 +05:30
|
|
|
self.progress.set_pass(_('Sorting data...'), len(tables))
|
2005-01-22 03:25:10 +05:30
|
|
|
self.data = []
|
2008-01-23 11:11:46 +05:30
|
|
|
sortby = menu.get_option_by_name('sortby').get_value()
|
|
|
|
reverse = menu.get_option_by_name('reverse').get_value()
|
2005-01-22 03:25:10 +05:30
|
|
|
for table in tables:
|
|
|
|
# generate sorted item lookup index index
|
|
|
|
lookup = self.index_items(table[1], sortby, reverse)
|
|
|
|
# document heading
|
2005-01-30 02:11:22 +05:30
|
|
|
mapping['chart_title'] = table[0]
|
2005-01-23 03:16:55 +05:30
|
|
|
if genders:
|
2005-05-11 19:34:47 +05:30
|
|
|
heading = _("%(genders)s born %(year_from)04d-%(year_to)04d: %(chart_title)s") % mapping
|
2005-01-22 03:25:10 +05:30
|
|
|
else:
|
2005-05-11 19:34:47 +05:30
|
|
|
heading = _("Persons born %(year_from)04d-%(year_to)04d: %(chart_title)s") % mapping
|
2005-12-06 12:08:09 +05:30
|
|
|
self.data.append((heading, table[0], table[1], lookup))
|
2008-01-06 01:40:26 +05:30
|
|
|
self.progress.step()
|
|
|
|
#DEBUG
|
2005-01-31 11:01:30 +05:30
|
|
|
#print heading
|
|
|
|
#print table[1]
|
2005-01-26 01:26:23 +05:30
|
|
|
|
|
|
|
|
|
|
|
def lookup_compare(self, a, b):
|
|
|
|
"compare given keys according to corresponding lookup values"
|
|
|
|
return cmp(self.lookup_items[a], self.lookup_items[b])
|
|
|
|
|
2005-01-22 03:25:10 +05:30
|
|
|
def index_items(self, data, sort, reverse):
|
2005-01-11 05:58:53 +05:30
|
|
|
"""creates & stores a sorted index for the items"""
|
|
|
|
|
|
|
|
# sort by item keys
|
2009-05-27 23:03:45 +05:30
|
|
|
index = sorted(data, reverse=True if reverse else False)
|
2005-01-11 05:58:53 +05:30
|
|
|
|
2005-01-22 03:25:10 +05:30
|
|
|
if sort == _options.SORT_VALUE:
|
2005-01-11 05:58:53 +05:30
|
|
|
# set for the sorting function
|
2005-01-26 01:26:23 +05:30
|
|
|
self.lookup_items = data
|
2005-01-11 05:58:53 +05:30
|
|
|
|
|
|
|
# then sort by value
|
2009-05-27 23:03:45 +05:30
|
|
|
index.sort(self.lookup_compare,
|
|
|
|
reverse=True if reverse else False)
|
2005-01-11 05:58:53 +05:30
|
|
|
|
2005-01-22 03:25:10 +05:30
|
|
|
return index
|
2005-01-11 05:58:53 +05:30
|
|
|
|
2005-01-11 01:42:16 +05:30
|
|
|
def write_report(self):
|
2005-01-11 05:58:53 +05:30
|
|
|
"output the selected statistics..."
|
2005-01-11 01:42:16 +05:30
|
|
|
|
2008-01-06 01:40:26 +05:30
|
|
|
self.progress.set_pass(_('Saving charts...'), len(self.data))
|
2005-01-22 03:25:10 +05:30
|
|
|
for data in self.data:
|
2005-01-26 01:26:23 +05:30
|
|
|
self.doc.start_page()
|
2005-01-30 02:11:22 +05:30
|
|
|
if len(data[2]) < self.bar_items:
|
2009-07-03 21:23:28 +05:30
|
|
|
self.output_piechart(*data[:4])
|
2005-01-30 02:11:22 +05:30
|
|
|
else:
|
2009-07-03 21:23:28 +05:30
|
|
|
self.output_barchart(*data[:4])
|
2005-12-06 12:08:09 +05:30
|
|
|
self.doc.end_page()
|
2008-01-06 01:40:26 +05:30
|
|
|
self.progress.step()
|
|
|
|
self.progress.close()
|
2005-01-22 03:25:10 +05:30
|
|
|
|
|
|
|
|
2005-12-06 12:08:09 +05:30
|
|
|
def output_piechart(self, title, typename, data, lookup):
|
2005-01-30 02:11:22 +05:30
|
|
|
|
|
|
|
# set layout variables
|
2008-02-18 10:19:54 +05:30
|
|
|
middle_w = self.doc.get_usable_width() / 2
|
|
|
|
middle_h = self.doc.get_usable_height() / 2
|
|
|
|
middle = min(middle_w,middle_h)
|
2005-01-30 02:11:22 +05:30
|
|
|
|
|
|
|
# start output
|
2008-02-18 10:19:54 +05:30
|
|
|
self.doc.center_text('SC-title', title, middle_w, 0)
|
2007-04-23 17:16:26 +05:30
|
|
|
style_sheet = self.doc.get_style_sheet()
|
|
|
|
pstyle = style_sheet.get_paragraph_style('SC-Title')
|
|
|
|
yoffset = ReportUtils.pt2cm(pstyle.get_font().get_size())
|
2005-01-30 02:11:22 +05:30
|
|
|
|
|
|
|
# collect data for output
|
|
|
|
color = 0
|
|
|
|
chart_data = []
|
|
|
|
for key in lookup:
|
|
|
|
style = "SC-color-%d" % color
|
2007-04-23 17:16:26 +05:30
|
|
|
text = "%s (%d)" % (key, data[key])
|
2005-01-30 02:11:22 +05:30
|
|
|
# graphics style, value, and it's label
|
2005-12-06 12:08:09 +05:30
|
|
|
chart_data.append((style, data[key], text))
|
2007-04-23 17:16:26 +05:30
|
|
|
color = (color+1) % 7 # There are only 7 color styles defined
|
2005-01-30 02:11:22 +05:30
|
|
|
|
2008-02-18 10:19:54 +05:30
|
|
|
margin = 1.0
|
|
|
|
legendx = 2.0
|
2008-01-06 01:40:26 +05:30
|
|
|
|
2005-01-30 02:11:22 +05:30
|
|
|
# output data...
|
2005-12-06 12:08:09 +05:30
|
|
|
radius = middle - 2*margin
|
2009-09-11 00:19:48 +05:30
|
|
|
yoffset += margin + radius
|
2008-02-18 10:19:54 +05:30
|
|
|
ReportUtils.draw_pie_chart(self.doc, middle_w, yoffset, radius, chart_data, -90)
|
2009-09-11 00:19:48 +05:30
|
|
|
yoffset += radius + 2*margin
|
2008-02-18 10:19:54 +05:30
|
|
|
if middle == middle_h: # Landscape
|
|
|
|
legendx = 1.0
|
|
|
|
yoffset = margin
|
2008-01-06 01:40:26 +05:30
|
|
|
|
|
|
|
text = _("%s (persons):") % typename
|
|
|
|
ReportUtils.draw_legend(self.doc, legendx, yoffset, chart_data, text,'SC-legend')
|
2005-01-30 02:11:22 +05:30
|
|
|
|
|
|
|
|
2005-12-06 12:08:09 +05:30
|
|
|
def output_barchart(self, title, typename, data, lookup):
|
2005-01-23 03:16:55 +05:30
|
|
|
|
|
|
|
pt2cm = ReportUtils.pt2cm
|
2007-04-23 17:16:26 +05:30
|
|
|
style_sheet = self.doc.get_style_sheet()
|
|
|
|
pstyle = style_sheet.get_paragraph_style('SC-Text')
|
|
|
|
font = pstyle.get_font()
|
2005-01-11 01:42:16 +05:30
|
|
|
|
2005-01-11 05:58:53 +05:30
|
|
|
# set layout variables
|
|
|
|
width = self.doc.get_usable_width()
|
2005-01-11 01:42:16 +05:30
|
|
|
row_h = pt2cm(font.get_size())
|
2005-01-11 05:58:53 +05:30
|
|
|
max_y = self.doc.get_usable_height() - row_h
|
2005-01-11 01:42:16 +05:30
|
|
|
pad = row_h * 0.5
|
|
|
|
|
2005-12-06 12:08:09 +05:30
|
|
|
# check maximum value
|
2005-01-11 05:58:53 +05:30
|
|
|
max_value = 0
|
2005-01-22 03:25:10 +05:30
|
|
|
for key in lookup:
|
|
|
|
max_value = max(data[key], max_value)
|
2005-01-11 05:58:53 +05:30
|
|
|
# horizontal area for the gfx bars
|
2008-01-06 01:40:26 +05:30
|
|
|
margin = 1.0
|
|
|
|
middle = width/2.0
|
|
|
|
textx = middle + margin/2.0
|
|
|
|
stopx = middle - margin/2.0
|
2005-12-06 12:08:09 +05:30
|
|
|
maxsize = stopx - margin
|
2005-01-11 01:42:16 +05:30
|
|
|
|
2005-01-11 05:58:53 +05:30
|
|
|
# start output
|
2005-12-06 12:08:09 +05:30
|
|
|
self.doc.center_text('SC-title', title, middle, 0)
|
2007-04-23 17:16:26 +05:30
|
|
|
pstyle = style_sheet.get_paragraph_style('SC-Title')
|
|
|
|
yoffset = pt2cm(pstyle.get_font().get_size())
|
2005-01-26 01:26:23 +05:30
|
|
|
#print title
|
2005-01-11 05:58:53 +05:30
|
|
|
|
2008-01-06 01:40:26 +05:30
|
|
|
# header
|
|
|
|
yoffset += (row_h + pad)
|
|
|
|
text = _("%s (persons):") % typename
|
|
|
|
self.doc.draw_text('SC-text', text, textx, yoffset)
|
2005-12-06 12:08:09 +05:30
|
|
|
|
2005-01-22 03:25:10 +05:30
|
|
|
for key in lookup:
|
2005-01-11 05:58:53 +05:30
|
|
|
yoffset += (row_h + pad)
|
|
|
|
if yoffset > max_y:
|
|
|
|
# for graphical report, page_break() doesn't seem to work
|
|
|
|
self.doc.end_page()
|
|
|
|
self.doc.start_page()
|
|
|
|
yoffset = 0
|
|
|
|
|
2005-12-06 12:08:09 +05:30
|
|
|
# right align bar to the text
|
2005-01-22 03:25:10 +05:30
|
|
|
value = data[key]
|
2005-12-06 12:08:09 +05:30
|
|
|
startx = stopx - (maxsize * value / max_value)
|
2007-02-27 09:40:43 +05:30
|
|
|
self.doc.draw_box('SC-bar',"",startx,yoffset,stopx-startx,row_h)
|
2008-01-06 01:40:26 +05:30
|
|
|
# text after bar
|
|
|
|
text = "%s (%d)" % (key, data[key])
|
2005-12-06 12:08:09 +05:30
|
|
|
self.doc.draw_text('SC-text', text, textx, yoffset)
|
|
|
|
#print key + ":",
|
|
|
|
|
2005-01-11 05:58:53 +05:30
|
|
|
return
|
2005-01-11 01:42:16 +05:30
|
|
|
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
2008-01-06 02:12:05 +05:30
|
|
|
# StatisticsChartOptions
|
2005-01-11 01:42:16 +05:30
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
2008-01-06 02:12:05 +05:30
|
|
|
class StatisticsChartOptions(MenuReportOptions):
|
|
|
|
|
2008-01-24 18:20:33 +05:30
|
|
|
def __init__(self, name, dbase):
|
2008-01-18 11:09:50 +05:30
|
|
|
self.__pid = None
|
|
|
|
self.__filter = None
|
2008-01-24 18:20:33 +05:30
|
|
|
self.__db = dbase
|
|
|
|
MenuReportOptions.__init__(self, name, dbase)
|
2008-01-06 02:12:05 +05:30
|
|
|
|
2008-01-24 18:20:33 +05:30
|
|
|
def add_menu_options(self, menu):
|
2008-01-06 02:12:05 +05:30
|
|
|
"""
|
|
|
|
Add options to the menu for the statistics report.
|
|
|
|
"""
|
|
|
|
category_name = _("Report Options")
|
|
|
|
|
2008-01-23 11:11:46 +05:30
|
|
|
self.__filter = FilterOption(_("Filter"), 0)
|
|
|
|
self.__filter.set_help(
|
|
|
|
_("Determines what people are included in the report"))
|
|
|
|
menu.add_option(category_name, "filter", self.__filter)
|
|
|
|
self.__filter.connect('value-changed', self.__filter_changed)
|
|
|
|
|
2008-01-18 11:09:50 +05:30
|
|
|
self.__pid = PersonOption(_("Filter Person"))
|
|
|
|
self.__pid.set_help(_("The center person for the filter"))
|
|
|
|
menu.add_option(category_name, "pid", self.__pid)
|
|
|
|
self.__pid.connect('value-changed', self.__update_filters)
|
|
|
|
|
|
|
|
self.__update_filters()
|
2008-01-06 02:12:05 +05:30
|
|
|
|
|
|
|
sortby = EnumeratedListOption(_('Sort chart items by'),
|
|
|
|
_options.SORT_VALUE )
|
|
|
|
for item_idx in range(len(_options.sorts)):
|
|
|
|
item = _options.sorts[item_idx]
|
|
|
|
sortby.add_item(item_idx,item[2])
|
|
|
|
sortby.set_help( _("Select how the statistical data is sorted."))
|
|
|
|
menu.add_option(category_name,"sortby",sortby)
|
|
|
|
|
|
|
|
reverse = BooleanOption(_("Sort in reverse order"), False)
|
|
|
|
reverse.set_help(_("Check to reverse the sorting order."))
|
|
|
|
menu.add_option(category_name,"reverse", reverse)
|
|
|
|
|
|
|
|
this_year = time.localtime()[0]
|
2008-02-18 10:19:54 +05:30
|
|
|
year_from = NumberOption(_("People Born After"),
|
2008-01-06 02:12:05 +05:30
|
|
|
1700, 1, this_year)
|
|
|
|
year_from.set_help(_("Birth year from which to include people"))
|
|
|
|
menu.add_option(category_name,"year_from", year_from)
|
|
|
|
|
2008-02-18 10:19:54 +05:30
|
|
|
year_to = NumberOption(_("People Born Before"),
|
2008-01-06 02:12:05 +05:30
|
|
|
this_year, 1, this_year)
|
|
|
|
year_to.set_help(_("Birth year until which to include people"))
|
|
|
|
menu.add_option(category_name,"year_to", year_to)
|
|
|
|
|
|
|
|
no_years = BooleanOption(_("Include people without known birth years"),
|
|
|
|
False)
|
|
|
|
no_years.set_help(_("Whether to include people without "
|
|
|
|
"known birth years"))
|
|
|
|
menu.add_option(category_name,"no_years", no_years)
|
|
|
|
|
|
|
|
gender = EnumeratedListOption(_('Genders included'),
|
|
|
|
Person.UNKNOWN )
|
|
|
|
for item_idx in range(len(_options.genders)):
|
|
|
|
item = _options.genders[item_idx]
|
|
|
|
gender.add_item(item[0],item[2])
|
|
|
|
gender.set_help( _("Select which genders are included into "
|
|
|
|
"statistics."))
|
|
|
|
menu.add_option(category_name,"gender",gender)
|
|
|
|
|
|
|
|
bar_items = NumberOption(_("Max. items for a pie"), 8, 0, 20)
|
|
|
|
bar_items.set_help(_("With fewer items pie chart and legend will be "
|
|
|
|
"used instead of a bar chart."))
|
|
|
|
menu.add_option(category_name,"bar_items", bar_items)
|
|
|
|
|
|
|
|
# -------------------------------------------------
|
|
|
|
# List of available charts on separate option tabs
|
|
|
|
idx = 0
|
|
|
|
half = (len(_Extract.extractors))/2
|
|
|
|
self.charts = {}
|
2005-01-22 03:25:10 +05:30
|
|
|
for key in _Extract.extractors:
|
2008-01-06 02:12:05 +05:30
|
|
|
if idx < half:
|
|
|
|
category_name = _("Charts 1")
|
|
|
|
else:
|
|
|
|
category_name = _("Charts 2")
|
|
|
|
|
|
|
|
opt = BooleanOption(_Extract.extractors[key][1], False)
|
2008-02-12 10:19:43 +05:30
|
|
|
opt.set_help(_("Include charts with indicated data"))
|
2008-01-06 02:12:05 +05:30
|
|
|
menu.add_option(category_name,key, opt)
|
|
|
|
idx += 1
|
|
|
|
|
|
|
|
# Enable a couple of charts by default
|
|
|
|
menu.get_option_by_name("data_gender").set_value(True)
|
|
|
|
menu.get_option_by_name("data_ccount").set_value(True)
|
|
|
|
menu.get_option_by_name("data_bmonth").set_value(True)
|
2008-01-18 11:09:50 +05:30
|
|
|
|
|
|
|
def __update_filters(self):
|
|
|
|
"""
|
|
|
|
Update the filter list based on the selected person
|
|
|
|
"""
|
|
|
|
gid = self.__pid.get_value()
|
2008-01-24 18:20:33 +05:30
|
|
|
person = self.__db.get_person_from_gramps_id(gid)
|
2008-01-18 11:09:50 +05:30
|
|
|
filter_list = ReportUtils.get_person_filters(person, False)
|
|
|
|
self.__filter.set_filters(filter_list)
|
|
|
|
|
|
|
|
def __filter_changed(self):
|
|
|
|
"""
|
|
|
|
Handle filter change. If the filter is not specific to a person,
|
|
|
|
disable the person option
|
|
|
|
"""
|
|
|
|
filter_value = self.__filter.get_value()
|
|
|
|
if filter_value in [1, 2, 3, 4]:
|
|
|
|
# Filters 1, 2, 3 and 4 rely on the center person
|
|
|
|
self.__pid.set_available(True)
|
|
|
|
else:
|
|
|
|
# The rest don't
|
|
|
|
self.__pid.set_available(False)
|
2005-01-11 01:42:16 +05:30
|
|
|
|
|
|
|
def make_default_style(self, default_style):
|
2005-01-11 05:58:53 +05:30
|
|
|
"""Make the default output style for the Statistics report."""
|
2007-04-23 17:16:26 +05:30
|
|
|
# Paragraph Styles
|
2009-05-30 03:55:44 +05:30
|
|
|
f = FontStyle()
|
2005-01-11 05:58:53 +05:30
|
|
|
f.set_size(10)
|
2009-05-30 03:55:44 +05:30
|
|
|
f.set_type_face(FONT_SERIF)
|
|
|
|
p = ParagraphStyle()
|
2005-01-11 05:58:53 +05:30
|
|
|
p.set_font(f)
|
2009-05-30 03:55:44 +05:30
|
|
|
p.set_alignment(PARA_ALIGN_LEFT)
|
2005-01-11 05:58:53 +05:30
|
|
|
p.set_description(_("The style used for the items and values."))
|
2007-04-23 17:16:26 +05:30
|
|
|
default_style.add_paragraph_style("SC-Text",p)
|
2005-01-11 05:58:53 +05:30
|
|
|
|
2009-05-30 03:55:44 +05:30
|
|
|
f = FontStyle()
|
2005-01-11 05:58:53 +05:30
|
|
|
f.set_size(14)
|
2009-05-30 03:55:44 +05:30
|
|
|
f.set_type_face(FONT_SANS_SERIF)
|
|
|
|
p = ParagraphStyle()
|
2005-01-11 05:58:53 +05:30
|
|
|
p.set_font(f)
|
2009-05-30 03:55:44 +05:30
|
|
|
p.set_alignment(PARA_ALIGN_CENTER)
|
2005-01-11 05:58:53 +05:30
|
|
|
p.set_description(_("The style used for the title of the page."))
|
2007-04-23 17:16:26 +05:30
|
|
|
default_style.add_paragraph_style("SC-Title",p)
|
|
|
|
|
|
|
|
"""
|
|
|
|
Graphic Styles:
|
|
|
|
SC-title - Contains the SC-Title paragraph style used for
|
|
|
|
the title of the document
|
|
|
|
SC-text - Contains the SC-Name paragraph style used for
|
|
|
|
the individual's name
|
|
|
|
SC-color-N - The colors for drawing pies.
|
|
|
|
SC-bar - A red bar with 0.5pt black line.
|
|
|
|
"""
|
2009-05-30 03:55:44 +05:30
|
|
|
g = GraphicsStyle()
|
2007-04-23 17:16:26 +05:30
|
|
|
g.set_paragraph_style("SC-Title")
|
|
|
|
g.set_color((0,0,0))
|
|
|
|
g.set_fill_color((255,255,255))
|
|
|
|
g.set_line_width(0)
|
|
|
|
default_style.add_draw_style("SC-title",g)
|
|
|
|
|
2009-05-30 03:55:44 +05:30
|
|
|
g = GraphicsStyle()
|
2007-04-23 17:16:26 +05:30
|
|
|
g.set_paragraph_style("SC-Text")
|
|
|
|
g.set_color((0,0,0))
|
|
|
|
g.set_fill_color((255,255,255))
|
|
|
|
g.set_line_width(0)
|
|
|
|
default_style.add_draw_style("SC-text",g)
|
|
|
|
|
|
|
|
width = 0.8
|
|
|
|
# red
|
2009-05-30 03:55:44 +05:30
|
|
|
g = GraphicsStyle()
|
2007-04-23 17:16:26 +05:30
|
|
|
g.set_paragraph_style('SC-Text')
|
|
|
|
g.set_color((0,0,0))
|
|
|
|
g.set_fill_color((255,0,0))
|
|
|
|
g.set_line_width(width)
|
|
|
|
default_style.add_draw_style("SC-color-0",g)
|
|
|
|
# orange
|
2009-05-30 03:55:44 +05:30
|
|
|
g = GraphicsStyle()
|
2007-04-23 17:16:26 +05:30
|
|
|
g.set_paragraph_style('SC-Text')
|
|
|
|
g.set_color((0,0,0))
|
|
|
|
g.set_fill_color((255,158,33))
|
|
|
|
g.set_line_width(width)
|
|
|
|
default_style.add_draw_style("SC-color-1",g)
|
|
|
|
# green
|
2009-05-30 03:55:44 +05:30
|
|
|
g = GraphicsStyle()
|
2007-04-23 17:16:26 +05:30
|
|
|
g.set_paragraph_style('SC-Text')
|
|
|
|
g.set_color((0,0,0))
|
|
|
|
g.set_fill_color((0,178,0))
|
|
|
|
g.set_line_width(width)
|
|
|
|
default_style.add_draw_style("SC-color-2",g)
|
|
|
|
# violet
|
2009-05-30 03:55:44 +05:30
|
|
|
g = GraphicsStyle()
|
2007-04-23 17:16:26 +05:30
|
|
|
g.set_paragraph_style('SC-Text')
|
|
|
|
g.set_color((0,0,0))
|
|
|
|
g.set_fill_color((123,0,123))
|
|
|
|
g.set_line_width(width)
|
|
|
|
default_style.add_draw_style("SC-color-3",g)
|
|
|
|
# yellow
|
2009-05-30 03:55:44 +05:30
|
|
|
g = GraphicsStyle()
|
2007-04-23 17:16:26 +05:30
|
|
|
g.set_paragraph_style('SC-Text')
|
|
|
|
g.set_color((0,0,0))
|
|
|
|
g.set_fill_color((255,255,0))
|
|
|
|
g.set_line_width(width)
|
|
|
|
default_style.add_draw_style("SC-color-4",g)
|
|
|
|
# blue
|
2009-05-30 03:55:44 +05:30
|
|
|
g = GraphicsStyle()
|
2007-04-23 17:16:26 +05:30
|
|
|
g.set_paragraph_style('SC-Text')
|
|
|
|
g.set_color((0,0,0))
|
|
|
|
g.set_fill_color((0,105,214))
|
|
|
|
g.set_line_width(width)
|
|
|
|
default_style.add_draw_style("SC-color-5",g)
|
|
|
|
# gray
|
2009-05-30 03:55:44 +05:30
|
|
|
g = GraphicsStyle()
|
2007-04-23 17:16:26 +05:30
|
|
|
g.set_paragraph_style('SC-Text')
|
|
|
|
g.set_color((0,0,0))
|
|
|
|
g.set_fill_color((210,204,210))
|
|
|
|
g.set_line_width(width)
|
|
|
|
default_style.add_draw_style("SC-color-6",g)
|
|
|
|
|
2009-05-30 03:55:44 +05:30
|
|
|
g = GraphicsStyle()
|
2007-04-23 17:16:26 +05:30
|
|
|
g.set_color((0,0,0))
|
|
|
|
g.set_fill_color((255,0,0))
|
|
|
|
g.set_line_width(width)
|
|
|
|
default_style.add_draw_style("SC-bar",g)
|
|
|
|
|
|
|
|
# legend
|
2009-05-30 03:55:44 +05:30
|
|
|
g = GraphicsStyle()
|
2007-04-23 17:16:26 +05:30
|
|
|
g.set_paragraph_style('SC-Text')
|
|
|
|
g.set_color((0,0,0))
|
|
|
|
g.set_fill_color((255,255,255))
|
|
|
|
g.set_line_width(0)
|
|
|
|
default_style.add_draw_style("SC-legend",g)
|