2005-01-11 01:42:16 +05:30
|
|
|
#
|
|
|
|
# Gramps - a GTK+/GNOME based genealogy program
|
|
|
|
#
|
2006-03-10 02:19:29 +05:30
|
|
|
# Copyright (C) 2003-2006 Donald N. Allingham
|
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
|
|
|
# Statistics plugin (w) 2004-2005 by Eero Tamminen with lots of help
|
|
|
|
# from Alex Roitman.
|
|
|
|
#
|
|
|
|
# To see things still missing, search for "TODO"...
|
2005-01-11 01:42:16 +05:30
|
|
|
#
|
|
|
|
# $Id$
|
|
|
|
|
|
|
|
"""
|
|
|
|
Statistics Chart report
|
|
|
|
"""
|
|
|
|
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# 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
|
|
|
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GNOME/gtk
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
import gtk
|
|
|
|
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GRAMPS modules
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
2005-01-29 22:41:02 +05:30
|
|
|
|
|
|
|
# Person and relation types
|
|
|
|
from RelLib import Person, Family
|
|
|
|
# gender and report type names
|
2005-01-11 01:42:16 +05:30
|
|
|
import BaseDoc
|
2006-03-11 06:42:06 +05:30
|
|
|
from PluginUtils import Report, ReportOptions, ReportUtils, register_report
|
2005-01-23 03:16:55 +05:30
|
|
|
import GenericFilter
|
2005-08-06 08:27:37 +05:30
|
|
|
import DateHandler
|
2006-03-30 10:45:54 +05:30
|
|
|
from Utils import ProgressMeter, format_event
|
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
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
class Extract:
|
|
|
|
|
|
|
|
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_dcause': ("Cause of death", _("Cause of death"),
|
2005-01-31 11:01:30 +05:30
|
|
|
self.get_death, self.get_cause),
|
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:
|
|
|
|
return [name.capitalize() for name in firstnames.split()]
|
|
|
|
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:
|
|
|
|
return [name.capitalize() for name in surnames.split()]
|
|
|
|
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_cause(self, event):
|
2005-01-31 11:01:30 +05:30
|
|
|
"return cause for given event"
|
|
|
|
cause = event.get_cause()
|
|
|
|
if cause:
|
|
|
|
return [cause]
|
2005-01-23 03:16:55 +05:30
|
|
|
return [_("Cause missing")]
|
|
|
|
|
|
|
|
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:
|
|
|
|
places.append(place)
|
|
|
|
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-03-30 10:45:54 +05:30
|
|
|
evtType = format_event( event.get_type() )
|
|
|
|
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):
|
|
|
|
"return number of handles in given (person,handle_list) used for child count, family count"
|
2005-01-29 22:41:02 +05:30
|
|
|
return [str(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)
|
|
|
|
for child_handle in fam.get_child_handle_list():
|
|
|
|
children.append(child_handle)
|
|
|
|
# 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)
|
|
|
|
if family.get_relationship() == Family.MARRIED:
|
|
|
|
for event_handle in family.get_event_list():
|
|
|
|
if event_handle:
|
|
|
|
event = self.db.get_event_from_handle(event_handle)
|
|
|
|
if event.get_name() == "Marriage":
|
|
|
|
marriages.append(event_handle)
|
|
|
|
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():
|
|
|
|
events.append( event_ref.get_reference_handle())
|
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):
|
2005-01-22 03:25:10 +05:30
|
|
|
"""Adds data from the database to 'collect' for the given person,
|
|
|
|
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:
|
|
|
|
if key in chart[1].keys():
|
|
|
|
chart[1][key] += 1
|
|
|
|
else:
|
|
|
|
chart[1][key] = 1
|
|
|
|
|
2005-01-11 01:42:16 +05:30
|
|
|
|
2005-01-22 03:25:10 +05:30
|
|
|
def collect_data(self, db, filter_func, options, 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
|
2005-01-22 03:25:10 +05:30
|
|
|
for key in options:
|
|
|
|
if options[key] and key in self.extractors:
|
2005-01-29 22:41:02 +05:30
|
|
|
# localized data title, value dict, type and data method
|
2005-01-23 03:16:55 +05:30
|
|
|
data.append((ext[key][1], {}, ext[key][2], ext[key][3]))
|
2005-01-22 03:25:10 +05:30
|
|
|
|
2005-01-11 05:58:53 +05:30
|
|
|
# go through the people and collect data
|
|
|
|
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
|
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
|
|
|
|
|
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
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
class StatisticsChart(Report.Report):
|
|
|
|
|
|
|
|
def __init__(self, database, person, options_class):
|
|
|
|
"""
|
|
|
|
Creates 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
|
|
|
"""
|
|
|
|
Report.Report.__init__(self,database,person,options_class)
|
2005-01-11 05:58:53 +05:30
|
|
|
|
2005-01-11 01:42:16 +05:30
|
|
|
filter_num = options_class.get_filter_number()
|
|
|
|
filters = options_class.get_report_filters(person)
|
|
|
|
filters.extend(GenericFilter.CustomFilters.get_filters())
|
|
|
|
filterfun = filters[filter_num]
|
|
|
|
|
2005-01-12 02:01:51 +05:30
|
|
|
options = options_class.handler.options_dict
|
2005-01-30 02:11:22 +05:30
|
|
|
self.bar_items = options['bar_items']
|
2005-01-12 02:01:51 +05:30
|
|
|
year_from = options['year_from']
|
|
|
|
year_to = options['year_to']
|
|
|
|
gender = options['gender']
|
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
|
|
|
}
|
2005-12-06 12:08:09 +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
|
2005-12-06 12:08:09 +05:30
|
|
|
self.progress.set_pass(_('Collecting data...'), 1)
|
2005-01-22 03:25:10 +05:30
|
|
|
tables = _Extract.collect_data(database, filterfun, options,
|
|
|
|
gender, year_from, year_to, options['no_years'])
|
2005-12-06 12:08:09 +05:30
|
|
|
self.progress.step()
|
2005-01-11 05:58:53 +05:30
|
|
|
|
2005-12-06 12:08:09 +05:30
|
|
|
self.progress.set_pass(_('Sorting data...'), len(tables))
|
2005-01-22 03:25:10 +05:30
|
|
|
self.data = []
|
|
|
|
sortby = options['sortby']
|
|
|
|
reverse = options['reverse']
|
|
|
|
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))
|
|
|
|
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
|
2005-01-22 03:25:10 +05:30
|
|
|
index = data.keys()
|
2005-01-11 05:58:53 +05:30
|
|
|
index.sort()
|
|
|
|
if reverse:
|
|
|
|
index.reverse()
|
|
|
|
|
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
|
2005-01-26 01:26:23 +05:30
|
|
|
index.sort(self.lookup_compare)
|
2005-01-11 05:58:53 +05:30
|
|
|
if reverse:
|
|
|
|
index.reverse()
|
|
|
|
|
2005-01-22 03:25:10 +05:30
|
|
|
return index
|
2005-01-11 05:58:53 +05:30
|
|
|
|
|
|
|
|
2005-01-24 22:03:47 +05:30
|
|
|
def define_graphics_styles(self):
|
2005-01-11 01:42:16 +05:30
|
|
|
"""
|
|
|
|
Define the graphics styles used by the report. Paragraph definitions
|
|
|
|
have already been defined in the document. The styles used are:
|
|
|
|
|
|
|
|
SC-title - Contains the SC-Title paragraph style used for
|
|
|
|
the title of the document
|
2005-01-30 02:11:22 +05:30
|
|
|
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.
|
2005-01-11 01:42:16 +05:30
|
|
|
"""
|
2005-01-11 05:58:53 +05:30
|
|
|
g = BaseDoc.GraphicsStyle()
|
2005-01-30 02:11:22 +05:30
|
|
|
g.set_paragraph_style("SC-Title")
|
2005-01-11 01:42:16 +05:30
|
|
|
g.set_color((0,0,0))
|
2005-01-30 02:11:22 +05:30
|
|
|
g.set_fill_color((255,255,255))
|
|
|
|
g.set_line_width(0)
|
|
|
|
g.set_width(self.doc.get_usable_width())
|
|
|
|
self.doc.add_draw_style("SC-title",g)
|
2005-01-11 01:42:16 +05:30
|
|
|
|
|
|
|
g = BaseDoc.GraphicsStyle()
|
|
|
|
g.set_paragraph_style("SC-Text")
|
|
|
|
g.set_color((0,0,0))
|
|
|
|
g.set_fill_color((255,255,255))
|
|
|
|
g.set_line_width(0)
|
|
|
|
self.doc.add_draw_style("SC-text",g)
|
|
|
|
|
2005-01-31 11:01:30 +05:30
|
|
|
width = 0.8
|
2005-01-30 02:11:22 +05:30
|
|
|
self.colors = 7
|
|
|
|
# red
|
2005-01-11 01:42:16 +05:30
|
|
|
g = BaseDoc.GraphicsStyle()
|
2005-01-30 02:11:22 +05:30
|
|
|
g.set_paragraph_style('SC-Text')
|
2005-01-11 01:42:16 +05:30
|
|
|
g.set_color((0,0,0))
|
2005-01-30 02:11:22 +05:30
|
|
|
g.set_fill_color((255,0,0))
|
|
|
|
g.set_line_width(width)
|
|
|
|
self.doc.add_draw_style("SC-color-0",g)
|
2005-02-03 02:20:14 +05:30
|
|
|
# orange
|
2005-01-30 02:11:22 +05:30
|
|
|
g = BaseDoc.GraphicsStyle()
|
|
|
|
g.set_paragraph_style('SC-Text')
|
|
|
|
g.set_color((0,0,0))
|
2005-02-03 02:20:14 +05:30
|
|
|
g.set_fill_color((255,158,33))
|
2005-01-30 02:11:22 +05:30
|
|
|
g.set_line_width(width)
|
|
|
|
self.doc.add_draw_style("SC-color-1",g)
|
2005-02-03 02:20:14 +05:30
|
|
|
# green
|
2005-01-30 02:11:22 +05:30
|
|
|
g = BaseDoc.GraphicsStyle()
|
|
|
|
g.set_paragraph_style('SC-Text')
|
|
|
|
g.set_color((0,0,0))
|
2005-02-03 02:20:14 +05:30
|
|
|
g.set_fill_color((0,178,0))
|
2005-01-30 02:11:22 +05:30
|
|
|
g.set_line_width(width)
|
|
|
|
self.doc.add_draw_style("SC-color-2",g)
|
2005-02-03 02:20:14 +05:30
|
|
|
# violet
|
2005-01-30 02:11:22 +05:30
|
|
|
g = BaseDoc.GraphicsStyle()
|
|
|
|
g.set_paragraph_style('SC-Text')
|
|
|
|
g.set_color((0,0,0))
|
2005-02-03 02:20:14 +05:30
|
|
|
g.set_fill_color((123,0,123))
|
2005-01-30 02:11:22 +05:30
|
|
|
g.set_line_width(width)
|
|
|
|
self.doc.add_draw_style("SC-color-3",g)
|
2005-02-03 02:20:14 +05:30
|
|
|
# yellow
|
2005-01-30 02:11:22 +05:30
|
|
|
g = BaseDoc.GraphicsStyle()
|
|
|
|
g.set_paragraph_style('SC-Text')
|
|
|
|
g.set_color((0,0,0))
|
2005-02-03 02:20:14 +05:30
|
|
|
g.set_fill_color((255,255,0))
|
2005-01-30 02:11:22 +05:30
|
|
|
g.set_line_width(width)
|
|
|
|
self.doc.add_draw_style("SC-color-4",g)
|
2005-02-03 02:20:14 +05:30
|
|
|
# blue
|
2005-01-30 02:11:22 +05:30
|
|
|
g = BaseDoc.GraphicsStyle()
|
|
|
|
g.set_paragraph_style('SC-Text')
|
|
|
|
g.set_color((0,0,0))
|
2005-02-03 02:20:14 +05:30
|
|
|
g.set_fill_color((0,105,214))
|
2005-01-30 02:11:22 +05:30
|
|
|
g.set_line_width(width)
|
|
|
|
self.doc.add_draw_style("SC-color-5",g)
|
|
|
|
# gray
|
|
|
|
g = BaseDoc.GraphicsStyle()
|
|
|
|
g.set_paragraph_style('SC-Text')
|
|
|
|
g.set_color((0,0,0))
|
2005-02-03 02:20:14 +05:30
|
|
|
g.set_fill_color((210,204,210))
|
2005-01-30 02:11:22 +05:30
|
|
|
g.set_line_width(width)
|
|
|
|
self.doc.add_draw_style("SC-color-6",g)
|
|
|
|
|
|
|
|
g = BaseDoc.GraphicsStyle()
|
|
|
|
g.set_color((0,0,0))
|
|
|
|
g.set_fill_color((255,0,0))
|
|
|
|
g.set_line_width(width)
|
|
|
|
self.doc.add_draw_style("SC-bar",g)
|
2005-01-11 01:42:16 +05:30
|
|
|
|
2005-01-24 22:03:47 +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
|
|
|
|
2005-12-06 12:08:09 +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:
|
2005-12-06 12:08:09 +05:30
|
|
|
self.output_piechart(data[0], data[1], data[2], data[3])
|
2005-01-30 02:11:22 +05:30
|
|
|
else:
|
2005-12-06 12:08:09 +05:30
|
|
|
self.output_barchart(data[0], data[1], data[2], data[3])
|
|
|
|
self.doc.end_page()
|
|
|
|
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
|
|
|
|
middle = self.doc.get_usable_width() / 2
|
|
|
|
|
|
|
|
# start output
|
|
|
|
self.doc.center_text('SC-title', title, middle, 0)
|
|
|
|
yoffset = ReportUtils.pt2cm(self.doc.style_list['SC-Title'].get_font().get_size())
|
|
|
|
|
|
|
|
# collect data for output
|
|
|
|
color = 0
|
|
|
|
chart_data = []
|
|
|
|
for key in lookup:
|
|
|
|
style = "SC-color-%d" % color
|
2005-12-06 12:08:09 +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))
|
2005-01-30 02:11:22 +05:30
|
|
|
color = (color+1) % self.colors
|
|
|
|
|
2005-12-06 12:08:09 +05:30
|
|
|
margin = 1.0
|
|
|
|
legendx = 2.0
|
|
|
|
|
2005-01-30 02:11:22 +05:30
|
|
|
# output data...
|
2005-12-06 12:08:09 +05:30
|
|
|
radius = middle - 2*margin
|
|
|
|
yoffset = yoffset + margin + radius
|
2005-01-30 02:11:22 +05:30
|
|
|
ReportUtils.draw_pie_chart(self.doc, middle, yoffset, radius, chart_data, -90)
|
2005-12-06 12:08:09 +05:30
|
|
|
yoffset = yoffset + radius + margin
|
|
|
|
|
|
|
|
text = _("%s (persons):") % typename
|
|
|
|
ReportUtils.draw_legend(self.doc, legendx, yoffset, chart_data, text)
|
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
|
2005-01-11 01:42:16 +05:30
|
|
|
font = self.doc.style_list['SC-Text'].get_font()
|
|
|
|
|
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
|
2005-12-06 12:08:09 +05:30
|
|
|
margin = 1.0
|
|
|
|
middle = width/2.0
|
|
|
|
textx = middle + margin/2.0
|
|
|
|
stopx = middle - margin/2.0
|
|
|
|
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)
|
|
|
|
yoffset = pt2cm(self.doc.style_list['SC-Title'].get_font().get_size())
|
2005-01-26 01:26:23 +05:30
|
|
|
#print title
|
2005-01-11 05:58:53 +05:30
|
|
|
|
2005-12-06 12:08:09 +05:30
|
|
|
# header
|
|
|
|
yoffset += (row_h + pad)
|
|
|
|
text = _("%s (persons):") % typename
|
|
|
|
self.doc.draw_text('SC-text', text, textx, yoffset)
|
|
|
|
|
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)
|
|
|
|
path = ((startx, yoffset),
|
|
|
|
(stopx, yoffset),
|
|
|
|
(stopx, yoffset + row_h),
|
|
|
|
(startx, yoffset + row_h))
|
2005-01-11 05:58:53 +05:30
|
|
|
self.doc.draw_path('SC-bar', path)
|
2005-12-06 12:08:09 +05:30
|
|
|
# text after bar
|
|
|
|
text = "%s (%d)" % (key, data[key])
|
|
|
|
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
|
|
|
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Statistics report options
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
class StatisticsChartOptions(ReportOptions.ReportOptions):
|
|
|
|
"""
|
|
|
|
Defines options and provides their handling interface.
|
|
|
|
"""
|
|
|
|
def __init__(self,name, person_id=None):
|
|
|
|
ReportOptions.ReportOptions.__init__(self, name, person_id)
|
|
|
|
|
|
|
|
def set_new_options(self):
|
2005-01-11 05:58:53 +05:30
|
|
|
# Options specific for this report
|
2005-01-11 01:42:16 +05:30
|
|
|
self.options_dict = {
|
2005-02-01 09:16:29 +05:30
|
|
|
'gender' : Person.UNKNOWN,
|
2005-01-22 03:25:10 +05:30
|
|
|
'sortby' : _options.SORT_VALUE,
|
2005-01-12 02:01:51 +05:30
|
|
|
'reverse' : 0,
|
|
|
|
'year_from' : 1700,
|
|
|
|
'year_to' : time.localtime()[0],
|
2005-01-30 02:11:22 +05:30
|
|
|
'no_years' : 0,
|
2005-01-31 11:01:30 +05:30
|
|
|
'bar_items' : 8
|
2005-01-11 01:42:16 +05:30
|
|
|
}
|
2005-01-22 03:25:10 +05:30
|
|
|
for key in _Extract.extractors:
|
|
|
|
self.options_dict[key] = 0
|
|
|
|
self.options_dict['data_gender'] = 1
|
|
|
|
|
2005-01-11 01:42:16 +05:30
|
|
|
self.options_help = {
|
2005-01-22 03:25:10 +05:30
|
|
|
'gender' : ("=num", "Genders included",
|
|
|
|
["%d\t%s" % (item[0], item[1]) for item in _options.genders],
|
|
|
|
False),
|
|
|
|
'sortby' : ("=num", "Sort chart items by",
|
|
|
|
["%d\t%s" % (item[0], item[1]) for item in _options.sorts],
|
2005-01-12 04:31:54 +05:30
|
|
|
False),
|
|
|
|
'reverse' : ("=0/1", "Whether to sort in reverse order",
|
|
|
|
["Do not sort in reverse", "Sort in reverse"],
|
|
|
|
True),
|
2005-01-12 02:01:51 +05:30
|
|
|
'year_from' : ("=num", "Birth year from which to include people",
|
2005-01-30 02:11:22 +05:30
|
|
|
"Earlier than 'year_to' value"),
|
2005-01-12 02:01:51 +05:30
|
|
|
'year_to' : ("=num", "Birth year until which to include people",
|
2005-01-30 02:11:22 +05:30
|
|
|
"Smaller than %d" % self.options_dict['year_to']),
|
2005-05-24 18:38:06 +05:30
|
|
|
'no_years' : ("=0/1", "Whether to include people without known birth years",
|
2005-01-30 02:11:22 +05:30
|
|
|
["Do not include", "Include"], True),
|
2005-01-31 11:01:30 +05:30
|
|
|
'bar_items' : ("=num", "Use barchart instead of piechart with this many or more items",
|
2005-01-30 02:11:22 +05:30
|
|
|
"Number of items with which piecharts still look good...")
|
2005-01-11 01:42:16 +05:30
|
|
|
}
|
2005-01-22 03:25:10 +05:30
|
|
|
for key in _Extract.extractors:
|
2005-01-23 03:16:55 +05:30
|
|
|
self.options_help[key] = ("=0/1", _Extract.extractors[key][0],
|
2005-12-06 12:08:09 +05:30
|
|
|
["Leave chart with this data out", "Include chart with this data"],
|
2005-01-22 03:25:10 +05:30
|
|
|
True)
|
2005-01-11 01:42:16 +05:30
|
|
|
|
2005-01-31 11:01:30 +05:30
|
|
|
|
2005-01-11 01:42:16 +05:30
|
|
|
def enable_options(self):
|
|
|
|
# Semi-common options that should be enabled for this report
|
|
|
|
self.enable_dict = {
|
|
|
|
'filter' : 0,
|
|
|
|
}
|
2005-01-11 05:58:53 +05:30
|
|
|
|
2005-01-31 11:01:30 +05:30
|
|
|
|
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."""
|
|
|
|
f = BaseDoc.FontStyle()
|
|
|
|
f.set_size(10)
|
|
|
|
f.set_type_face(BaseDoc.FONT_SERIF)
|
|
|
|
p = BaseDoc.ParagraphStyle()
|
|
|
|
p.set_font(f)
|
|
|
|
p.set_alignment(BaseDoc.PARA_ALIGN_RIGHT)
|
|
|
|
p.set_description(_("The style used for the items and values."))
|
|
|
|
default_style.add_style("SC-Text",p)
|
|
|
|
|
|
|
|
f = BaseDoc.FontStyle()
|
|
|
|
f.set_size(14)
|
|
|
|
f.set_type_face(BaseDoc.FONT_SANS_SERIF)
|
|
|
|
p = BaseDoc.ParagraphStyle()
|
|
|
|
p.set_font(f)
|
|
|
|
p.set_alignment(BaseDoc.PARA_ALIGN_CENTER)
|
|
|
|
p.set_description(_("The style used for the title of the page."))
|
|
|
|
default_style.add_style("SC-Title",p)
|
2005-01-11 01:42:16 +05:30
|
|
|
|
2005-01-31 11:01:30 +05:30
|
|
|
|
2005-01-11 01:42:16 +05:30
|
|
|
def get_report_filters(self, person):
|
2005-01-11 05:58:53 +05:30
|
|
|
"""Set up the list of possible content filters."""
|
|
|
|
|
|
|
|
if person:
|
|
|
|
name = person.get_primary_name().get_name()
|
2005-07-09 01:54:54 +05:30
|
|
|
gramps_id = person.get_gramps_id()
|
2005-01-11 05:58:53 +05:30
|
|
|
else:
|
|
|
|
name = 'PERSON'
|
2005-07-09 01:54:54 +05:30
|
|
|
gramps_id = ''
|
2005-01-11 05:58:53 +05:30
|
|
|
|
|
|
|
all = GenericFilter.GenericFilter()
|
|
|
|
all.set_name(_("Entire Database"))
|
|
|
|
all.add_rule(GenericFilter.Everyone([]))
|
|
|
|
|
|
|
|
des = GenericFilter.GenericFilter()
|
|
|
|
des.set_name(_("Descendants of %s") % name)
|
2005-07-09 01:54:54 +05:30
|
|
|
des.add_rule(GenericFilter.IsDescendantOf([gramps_id, 1]))
|
2005-01-11 05:58:53 +05:30
|
|
|
|
|
|
|
ans = GenericFilter.GenericFilter()
|
|
|
|
ans.set_name(_("Ancestors of %s") % name)
|
2005-07-09 01:54:54 +05:30
|
|
|
ans.add_rule(GenericFilter.IsAncestorOf([gramps_id, 1]))
|
2005-01-11 05:58:53 +05:30
|
|
|
|
|
|
|
com = GenericFilter.GenericFilter()
|
|
|
|
com.set_name(_("People with common ancestor with %s") % name)
|
2005-07-09 01:54:54 +05:30
|
|
|
com.add_rule(GenericFilter.HasCommonAncestorWith([gramps_id]))
|
2005-01-11 05:58:53 +05:30
|
|
|
|
|
|
|
return [all, des, ans, com]
|
2005-01-11 01:42:16 +05:30
|
|
|
|
2005-01-23 03:16:55 +05:30
|
|
|
|
2005-01-11 01:42:16 +05:30
|
|
|
def add_user_options(self, dialog):
|
|
|
|
"""
|
|
|
|
Override the base class add_user_options task to add
|
2005-01-11 05:58:53 +05:30
|
|
|
report specific options
|
2005-01-11 01:42:16 +05:30
|
|
|
"""
|
2005-01-11 05:58:53 +05:30
|
|
|
# how to sort the data
|
2005-01-11 07:49:29 +05:30
|
|
|
self.sort_menu = gtk.combo_box_new_text()
|
2005-01-22 03:25:10 +05:30
|
|
|
for item_idx in range(len(_options.sorts)):
|
|
|
|
item = _options.sorts[item_idx]
|
|
|
|
self.sort_menu.append_text(item[2])
|
2005-01-15 11:21:48 +05:30
|
|
|
if item[0] == self.options_dict['sortby']:
|
2005-01-11 07:49:29 +05:30
|
|
|
self.sort_menu.set_active(item_idx)
|
2005-01-11 05:58:53 +05:30
|
|
|
tip = _("Select how the statistical data is sorted.")
|
2005-01-22 03:25:10 +05:30
|
|
|
dialog.add_option(_("Sort chart items by"), self.sort_menu, tip)
|
2005-01-11 01:42:16 +05:30
|
|
|
|
2005-01-11 05:58:53 +05:30
|
|
|
# sorting order
|
|
|
|
tip = _("Check to reverse the sorting order.")
|
2005-01-12 02:01:51 +05:30
|
|
|
self.reverse = gtk.CheckButton(_("Sort in reverse order"))
|
2005-01-11 07:49:29 +05:30
|
|
|
self.reverse.set_active(self.options_dict['reverse'])
|
2005-01-11 01:42:16 +05:30
|
|
|
dialog.add_option(None, self.reverse, tip)
|
|
|
|
self.reverse.show()
|
|
|
|
|
2005-01-11 05:58:53 +05:30
|
|
|
# year range
|
2005-07-09 01:54:54 +05:30
|
|
|
from_adj = gtk.Adjustment(value=self.options_dict['year_from'],
|
|
|
|
lower=1, upper=time.localtime()[0],
|
|
|
|
step_incr=1, page_incr=100)
|
|
|
|
self.from_box = gtk.SpinButton(adjustment=from_adj, digits=0)
|
|
|
|
to_adj = gtk.Adjustment(value=self.options_dict['year_to'],
|
|
|
|
lower=1, upper=time.localtime()[0],
|
|
|
|
step_incr=1, page_incr=100)
|
|
|
|
self.to_box = gtk.SpinButton(adjustment=to_adj, digits=0)
|
2005-01-11 01:42:16 +05:30
|
|
|
|
2005-01-11 05:58:53 +05:30
|
|
|
box = gtk.HBox()
|
|
|
|
box.add(self.from_box)
|
|
|
|
box.add(gtk.Label("-"))
|
|
|
|
box.add(self.to_box)
|
|
|
|
tip = _("Select year range within which people need to be born to be selected for statistics.")
|
2005-01-11 01:42:16 +05:30
|
|
|
dialog.add_option(_('People born between'), box, tip)
|
|
|
|
box.show_all()
|
|
|
|
|
2005-05-24 18:38:06 +05:30
|
|
|
# include people without known birth year?
|
|
|
|
tip = _("Check this if you want people who have no known birth date or year to be accounted also in the statistics.")
|
|
|
|
self.no_years = gtk.CheckButton(_("Include people without known birth years"))
|
2005-01-11 07:49:29 +05:30
|
|
|
self.no_years.set_active(self.options_dict['no_years'])
|
2005-01-11 01:42:16 +05:30
|
|
|
dialog.add_option(None, self.no_years, tip)
|
|
|
|
self.no_years.show()
|
|
|
|
|
2005-01-11 05:58:53 +05:30
|
|
|
# gender selection
|
2005-01-11 07:49:29 +05:30
|
|
|
self.gender_menu = gtk.combo_box_new_text()
|
2005-01-22 03:25:10 +05:30
|
|
|
for item_idx in range(len(_options.genders)):
|
|
|
|
item = _options.genders[item_idx]
|
|
|
|
self.gender_menu.append_text(item[2])
|
2005-01-11 07:49:29 +05:30
|
|
|
if item[0] == self.options_dict['gender']:
|
|
|
|
self.gender_menu.set_active(item_idx)
|
2005-01-11 05:58:53 +05:30
|
|
|
tip = _("Select which genders are included into statistics.")
|
2005-01-12 02:01:51 +05:30
|
|
|
dialog.add_option(_("Genders included"), self.gender_menu, tip)
|
2005-01-11 01:42:16 +05:30
|
|
|
|
2005-01-30 02:11:22 +05:30
|
|
|
# max. pie item selection
|
|
|
|
tip = _("With fewer items pie chart and legend will be used instead of a bar chart.")
|
2005-07-09 01:54:54 +05:30
|
|
|
pie_adj = gtk.Adjustment(value=self.options_dict['bar_items'],
|
|
|
|
lower=0, upper=20, step_incr=1)
|
|
|
|
self.bar_items = gtk.SpinButton(adjustment=pie_adj, digits=0)
|
2005-05-24 18:38:06 +05:30
|
|
|
dialog.add_option(_("Max. items for a pie"), self.bar_items, tip)
|
2005-01-30 02:11:22 +05:30
|
|
|
|
|
|
|
# -------------------------------------------------
|
2005-01-22 03:25:10 +05:30
|
|
|
# List of available charts on a separate option tab
|
2005-01-31 11:01:30 +05:30
|
|
|
idx = 0
|
|
|
|
half = (len(_Extract.extractors)+1)/2
|
2005-01-22 03:25:10 +05:30
|
|
|
hbox = gtk.HBox()
|
|
|
|
vbox = gtk.VBox()
|
|
|
|
self.charts = {}
|
|
|
|
for key in _Extract.extractors:
|
2005-01-23 03:16:55 +05:30
|
|
|
check = gtk.CheckButton(_Extract.extractors[key][1])
|
2005-01-22 03:25:10 +05:30
|
|
|
check.set_active(self.options_dict[key])
|
|
|
|
self.charts[key] = check
|
2005-01-31 11:01:30 +05:30
|
|
|
vbox.add(check)
|
|
|
|
idx += 1
|
|
|
|
if idx == half:
|
|
|
|
hbox.add(vbox)
|
|
|
|
vbox = gtk.VBox()
|
2005-01-22 03:25:10 +05:30
|
|
|
hbox.add(vbox)
|
2005-01-31 11:01:30 +05:30
|
|
|
tip = _("Mark checkboxes to add charts with indicated data")
|
2005-12-06 12:08:09 +05:30
|
|
|
dialog.add_frame_option(_("Charts"), "", hbox, tip)
|
2005-01-22 03:25:10 +05:30
|
|
|
hbox.show_all()
|
|
|
|
|
2005-01-29 22:41:02 +05:30
|
|
|
# Note about children
|
2005-01-30 02:11:22 +05:30
|
|
|
label = gtk.Label(_("Note that both biological and adopted children are taken into account."))
|
2005-12-06 12:08:09 +05:30
|
|
|
dialog.add_frame_option(_("Charts"), "", label)
|
2005-01-29 22:41:02 +05:30
|
|
|
|
2005-01-31 11:01:30 +05:30
|
|
|
|
2005-01-11 01:42:16 +05:30
|
|
|
def parse_user_options(self, dialog):
|
|
|
|
"""
|
|
|
|
Parses the custom options that we have added.
|
|
|
|
"""
|
2005-01-22 03:25:10 +05:30
|
|
|
self.options_dict['sortby'] = _options.sorts[self.sort_menu.get_active()][0]
|
2005-01-12 02:01:51 +05:30
|
|
|
self.options_dict['reverse'] = int(self.reverse.get_active())
|
2005-07-09 01:54:54 +05:30
|
|
|
self.options_dict['year_to'] = int(self.to_box.get_value_as_int())
|
|
|
|
self.options_dict['year_from'] = int(self.from_box.get_value_as_int())
|
2005-01-11 05:58:53 +05:30
|
|
|
self.options_dict['no_years'] = int(self.no_years.get_active())
|
2005-01-22 03:25:10 +05:30
|
|
|
self.options_dict['gender'] = _options.genders[self.gender_menu.get_active()][0]
|
2005-07-09 01:54:54 +05:30
|
|
|
self.options_dict['bar_items'] = int(self.bar_items.get_value_as_int())
|
2005-01-22 03:25:10 +05:30
|
|
|
for key in _Extract.extractors:
|
|
|
|
self.options_dict[key] = int(self.charts[key].get_active())
|
2005-01-11 01:42:16 +05:30
|
|
|
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Register report/options
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
register_report(
|
2005-01-26 01:54:25 +05:30
|
|
|
name = 'statistics_chart',
|
2005-12-06 12:08:09 +05:30
|
|
|
category = Report.CATEGORY_DRAW,
|
2005-01-11 01:42:16 +05:30
|
|
|
report_class = StatisticsChart,
|
|
|
|
options_class = StatisticsChartOptions,
|
|
|
|
modes = Report.MODE_GUI | Report.MODE_BKI | Report.MODE_CLI,
|
|
|
|
translated_name = _("Statistics Chart"),
|
2005-12-06 12:08:09 +05:30
|
|
|
status = (_("Stable")),
|
2005-01-11 01:42:16 +05:30
|
|
|
author_name="Eero Tamminen",
|
|
|
|
author_email="",
|
2005-05-11 19:34:47 +05:30
|
|
|
description= _("Generates statistical bar and pie charts of the people in the database.")
|
2005-01-11 01:42:16 +05:30
|
|
|
)
|