2002-10-20 19:55:16 +05:30
|
|
|
#
|
|
|
|
# Gramps - a GTK+/GNOME based genealogy program
|
|
|
|
#
|
2006-03-10 02:19:29 +05:30
|
|
|
# Copyright (C) 2000-2006 Donald N. Allingham
|
2008-03-30 08:02:56 +05:30
|
|
|
# Copyright (C) 2008 Brian G. Matherly
|
2002-10-20 19:55: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
|
|
|
|
#
|
|
|
|
|
2004-05-07 07:50:39 +05:30
|
|
|
# $Id$
|
|
|
|
|
2009-08-09 22:39:32 +05:30
|
|
|
"""
|
|
|
|
Reports/Text Reports/Database Summary Report.
|
|
|
|
"""
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# standard python modules
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
import posixpath
|
2006-04-07 03:32:46 +05:30
|
|
|
from gettext import gettext as _
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
2005-01-03 05:18:39 +05:30
|
|
|
# GRAMPS modules
|
2002-10-20 19:55:16 +05:30
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
2007-10-08 22:11:39 +05:30
|
|
|
import gen.lib
|
2009-10-24 19:23:20 +05:30
|
|
|
from ReportBase import Report, ReportUtils, MenuReportOptions
|
2009-05-31 20:29:56 +05:30
|
|
|
from gen.plug.docgen import (IndexMark, FontStyle, ParagraphStyle,
|
|
|
|
FONT_SANS_SERIF, INDEX_TYPE_TOC, PARA_ALIGN_CENTER)
|
2008-02-18 19:36:41 +05:30
|
|
|
from Utils import media_path_full
|
2005-08-06 08:27:37 +05:30
|
|
|
import DateHandler
|
2008-03-30 08:02:56 +05:30
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
2008-03-30 08:02:56 +05:30
|
|
|
# SummaryReport
|
2002-10-20 19:55:16 +05:30
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
2008-03-30 08:02:56 +05:30
|
|
|
class SummaryReport(Report):
|
|
|
|
"""
|
|
|
|
This report produces a summary of the objects in the database.
|
|
|
|
"""
|
|
|
|
def __init__(self, database, options_class):
|
|
|
|
"""
|
|
|
|
Create the SummaryReport object that produces the report.
|
|
|
|
|
|
|
|
The arguments are:
|
2003-03-19 09:57:34 +05:30
|
|
|
|
2008-03-30 08:02:56 +05:30
|
|
|
database - the GRAMPS database instance
|
|
|
|
options_class - instance of the Options class for this report
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2008-03-30 08:02:56 +05:30
|
|
|
"""
|
|
|
|
Report.__init__(self, database, options_class)
|
|
|
|
self.__db = database
|
|
|
|
|
|
|
|
def write_report(self):
|
|
|
|
"""
|
|
|
|
Overridden function to generate the report.
|
|
|
|
"""
|
|
|
|
self.doc.start_paragraph("SR-Title")
|
|
|
|
title = _("Database Summary Report")
|
2009-05-30 03:55:44 +05:30
|
|
|
mark = IndexMark(title, INDEX_TYPE_TOC, 1)
|
2008-03-30 08:18:29 +05:30
|
|
|
self.doc.write_text(title, mark)
|
2008-03-30 08:02:56 +05:30
|
|
|
self.doc.end_paragraph()
|
|
|
|
|
|
|
|
self.summarize_people()
|
|
|
|
self.summarize_families()
|
|
|
|
self.summarize_media()
|
|
|
|
|
|
|
|
def summarize_people(self):
|
|
|
|
"""
|
|
|
|
Write a summary of all the people in the database.
|
|
|
|
"""
|
|
|
|
with_media = 0
|
|
|
|
incomp_names = 0
|
|
|
|
disconnected = 0
|
|
|
|
missing_bday = 0
|
|
|
|
males = 0
|
|
|
|
females = 0
|
|
|
|
unknowns = 0
|
|
|
|
namelist = []
|
|
|
|
|
|
|
|
self.doc.start_paragraph("SR-Heading")
|
|
|
|
self.doc.write_text(_("Individuals"))
|
|
|
|
self.doc.end_paragraph()
|
|
|
|
|
2009-07-14 19:46:03 +05:30
|
|
|
num_people = 0
|
2009-09-15 02:20:25 +05:30
|
|
|
for person in self.__db.iter_people():
|
2009-07-04 01:53:41 +05:30
|
|
|
num_people += 1
|
2008-03-30 08:02:56 +05:30
|
|
|
|
|
|
|
# Count people with media.
|
|
|
|
length = len(person.get_media_list())
|
|
|
|
if length > 0:
|
2009-09-11 00:19:48 +05:30
|
|
|
with_media += 1
|
2008-03-30 08:02:56 +05:30
|
|
|
|
|
|
|
# Count people with incomplete names.
|
|
|
|
name = person.get_primary_name()
|
|
|
|
if name.get_first_name() == "" or name.get_surname() == "":
|
2009-09-11 00:19:48 +05:30
|
|
|
incomp_names += 1
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2008-03-30 08:02:56 +05:30
|
|
|
# Count people without families.
|
|
|
|
if (not person.get_main_parents_family_handle()) and \
|
|
|
|
(not len(person.get_family_handle_list())):
|
2009-09-11 00:19:48 +05:30
|
|
|
disconnected += 1
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2008-03-30 08:02:56 +05:30
|
|
|
# Count missing birthdays.
|
|
|
|
birth_ref = person.get_birth_ref()
|
|
|
|
if birth_ref:
|
|
|
|
birth = self.__db.get_event_from_handle(birth_ref.ref)
|
|
|
|
if not DateHandler.get_date(birth):
|
2009-09-11 00:19:48 +05:30
|
|
|
missing_bday += 1
|
2008-03-30 08:02:56 +05:30
|
|
|
else:
|
2009-09-11 00:19:48 +05:30
|
|
|
missing_bday += 1
|
2008-03-30 08:02:56 +05:30
|
|
|
|
|
|
|
# Count genders.
|
|
|
|
if person.get_gender() == gen.lib.Person.FEMALE:
|
2009-09-11 00:19:48 +05:30
|
|
|
females += 1
|
2008-03-30 08:02:56 +05:30
|
|
|
elif person.get_gender() == gen.lib.Person.MALE:
|
2009-09-11 00:19:48 +05:30
|
|
|
males += 1
|
2008-03-30 08:02:56 +05:30
|
|
|
else:
|
|
|
|
unknowns += 1
|
|
|
|
|
|
|
|
# Count unique surnames
|
|
|
|
if name.get_surname() not in namelist:
|
|
|
|
namelist.append(name.get_surname())
|
|
|
|
|
|
|
|
self.doc.start_paragraph("SR-Normal")
|
2009-07-04 01:53:41 +05:30
|
|
|
self.doc.write_text(_("Number of individuals: %d") % num_people)
|
2008-03-30 08:02:56 +05:30
|
|
|
self.doc.end_paragraph()
|
|
|
|
|
|
|
|
self.doc.start_paragraph("SR-Normal")
|
|
|
|
self.doc.write_text(_("Males: %d") % males)
|
|
|
|
self.doc.end_paragraph()
|
|
|
|
|
|
|
|
self.doc.start_paragraph("SR-Normal")
|
|
|
|
self.doc.write_text(_("Females: %d") % females)
|
|
|
|
self.doc.end_paragraph()
|
|
|
|
|
|
|
|
self.doc.start_paragraph("SR-Normal")
|
|
|
|
self.doc.write_text(_("Individuals with unknown gender: %d") % unknowns)
|
|
|
|
self.doc.end_paragraph()
|
|
|
|
|
|
|
|
self.doc.start_paragraph("SR-Normal")
|
|
|
|
self.doc.write_text(_("Individuals with incomplete names: %d") %
|
|
|
|
incomp_names)
|
|
|
|
self.doc.end_paragraph()
|
|
|
|
|
|
|
|
self.doc.start_paragraph("SR-Normal")
|
|
|
|
self.doc.write_text(_("Individuals missing birth dates: %d") %
|
|
|
|
missing_bday)
|
|
|
|
self.doc.end_paragraph()
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2008-03-30 08:02:56 +05:30
|
|
|
self.doc.start_paragraph("SR-Normal")
|
|
|
|
self.doc.write_text(_("Disconnected individuals: %d") % disconnected)
|
|
|
|
self.doc.end_paragraph()
|
|
|
|
|
|
|
|
self.doc.start_paragraph("SR-Normal")
|
|
|
|
self.doc.write_text(_("Unique surnames: %d") % len(namelist))
|
|
|
|
self.doc.end_paragraph()
|
|
|
|
|
|
|
|
self.doc.start_paragraph("SR-Normal")
|
|
|
|
self.doc.write_text(_("Individuals with media objects: %d") %
|
|
|
|
with_media)
|
|
|
|
self.doc.end_paragraph()
|
|
|
|
|
|
|
|
def summarize_families(self):
|
|
|
|
"""
|
|
|
|
Write a summary of all the families in the database.
|
|
|
|
"""
|
|
|
|
self.doc.start_paragraph("SR-Heading")
|
|
|
|
self.doc.write_text(_("Family Information"))
|
|
|
|
self.doc.end_paragraph()
|
|
|
|
|
|
|
|
self.doc.start_paragraph("SR-Normal")
|
2009-07-08 21:41:20 +05:30
|
|
|
self.doc.write_text(_("Number of families: %d") % self.__db.get_number_of_families())
|
2008-03-30 08:02:56 +05:30
|
|
|
self.doc.end_paragraph()
|
|
|
|
|
|
|
|
def summarize_media(self):
|
|
|
|
"""
|
|
|
|
Write a summary of all the media in the database.
|
|
|
|
"""
|
|
|
|
total_media = 0
|
2009-08-09 22:39:32 +05:30
|
|
|
size_in_bytes = 0
|
2008-03-30 08:02:56 +05:30
|
|
|
notfound = []
|
|
|
|
|
|
|
|
self.doc.start_paragraph("SR-Heading")
|
|
|
|
self.doc.write_text(_("Media Objects"))
|
|
|
|
self.doc.end_paragraph()
|
|
|
|
|
|
|
|
total_media = len(self.__db.get_media_object_handles())
|
|
|
|
for media_id in self.__db.get_media_object_handles():
|
|
|
|
media = self.__db.get_object_from_handle(media_id)
|
|
|
|
try:
|
2009-09-11 00:19:48 +05:30
|
|
|
size_in_bytes += posixpath.getsize(
|
|
|
|
media_path_full(self.__db, media.get_path()))
|
2008-03-30 08:02:56 +05:30
|
|
|
except:
|
|
|
|
notfound.append(media.get_path())
|
|
|
|
|
|
|
|
self.doc.start_paragraph("SR-Normal")
|
|
|
|
self.doc.write_text(_("Number of unique media objects: %d") %
|
|
|
|
total_media)
|
|
|
|
self.doc.end_paragraph()
|
|
|
|
|
|
|
|
self.doc.start_paragraph("SR-Normal")
|
2009-08-09 22:39:32 +05:30
|
|
|
self.doc.write_text(_("Total size of media objects: %d bytes") % size_in_bytes)
|
2008-03-30 08:02:56 +05:30
|
|
|
self.doc.end_paragraph()
|
2003-05-21 23:36:41 +05:30
|
|
|
|
2008-03-30 08:02:56 +05:30
|
|
|
if len(notfound) > 0:
|
|
|
|
self.doc.start_paragraph("SR-Heading")
|
|
|
|
self.doc.write_text(_("Missing Media Objects"))
|
|
|
|
self.doc.end_paragraph()
|
|
|
|
|
|
|
|
for media_path in notfound:
|
|
|
|
self.doc.start_paragraph("SR-Normal")
|
|
|
|
self.doc.write_text(media_path)
|
|
|
|
self.doc.end_paragraph()
|
|
|
|
|
2003-05-21 23:36:41 +05:30
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
2008-03-30 08:02:56 +05:30
|
|
|
# SummaryOptions
|
2003-05-21 23:36:41 +05:30
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
2008-03-30 08:02:56 +05:30
|
|
|
class SummaryOptions(MenuReportOptions):
|
|
|
|
"""
|
|
|
|
SummaryOptions provides the options for the SummaryReport.
|
|
|
|
"""
|
|
|
|
def __init__(self, name, dbase):
|
|
|
|
MenuReportOptions.__init__(self, name, dbase)
|
|
|
|
|
|
|
|
def add_menu_options(self, menu):
|
|
|
|
"""
|
|
|
|
Add options to the menu for the marker report.
|
|
|
|
"""
|
|
|
|
pass
|
2006-06-02 06:10:54 +05:30
|
|
|
|
2008-03-30 08:02:56 +05:30
|
|
|
def make_default_style(self, default_style):
|
|
|
|
"""Make the default output style for the Summary Report."""
|
2009-05-30 03:55:44 +05:30
|
|
|
font = FontStyle()
|
2008-03-30 08:02:56 +05:30
|
|
|
font.set_size(16)
|
2009-05-30 03:55:44 +05:30
|
|
|
font.set_type_face(FONT_SANS_SERIF)
|
2008-03-30 08:02:56 +05:30
|
|
|
font.set_bold(1)
|
2009-05-30 03:55:44 +05:30
|
|
|
para = ParagraphStyle()
|
2008-03-30 08:02:56 +05:30
|
|
|
para.set_header_level(1)
|
|
|
|
para.set_bottom_border(1)
|
|
|
|
para.set_top_margin(ReportUtils.pt2cm(3))
|
|
|
|
para.set_bottom_margin(ReportUtils.pt2cm(3))
|
|
|
|
para.set_font(font)
|
2009-05-30 03:55:44 +05:30
|
|
|
para.set_alignment(PARA_ALIGN_CENTER)
|
2008-03-30 08:02:56 +05:30
|
|
|
para.set_description(_("The style used for the title of the page."))
|
|
|
|
default_style.add_paragraph_style("SR-Title", para)
|
|
|
|
|
2009-05-30 03:55:44 +05:30
|
|
|
font = FontStyle()
|
2008-03-30 08:02:56 +05:30
|
|
|
font.set_size(12)
|
|
|
|
font.set_bold(True)
|
2009-05-30 03:55:44 +05:30
|
|
|
para = ParagraphStyle()
|
2008-03-30 08:02:56 +05:30
|
|
|
para.set_font(font)
|
|
|
|
para.set_top_margin(0)
|
|
|
|
para.set_description(_('The basic style used for sub-headings.'))
|
|
|
|
default_style.add_paragraph_style("SR-Heading", para)
|
|
|
|
|
2009-05-30 03:55:44 +05:30
|
|
|
font = FontStyle()
|
2008-03-30 08:02:56 +05:30
|
|
|
font.set_size(12)
|
2009-05-30 03:55:44 +05:30
|
|
|
para = ParagraphStyle()
|
2008-03-30 08:02:56 +05:30
|
|
|
para.set(first_indent=-0.75, lmargin=.75)
|
|
|
|
para.set_font(font)
|
|
|
|
para.set_top_margin(ReportUtils.pt2cm(3))
|
|
|
|
para.set_bottom_margin(ReportUtils.pt2cm(3))
|
|
|
|
para.set_description(_('The basic style used for the text display.'))
|
|
|
|
default_style.add_paragraph_style("SR-Normal", para)
|