2002-10-20 14:25:16 +00:00
|
|
|
#
|
|
|
|
# count_anc.py - Ancestor counting plugin for gramps
|
|
|
|
#
|
|
|
|
# Copyright (C) 2001 Jesper Zedlitz
|
2006-03-09 20:49:29 +00:00
|
|
|
# Copyright (C) 2004-2006 Donald Allingham
|
2002-10-20 14:25:16 +00:00
|
|
|
#
|
|
|
|
# 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 02:20:39 +00:00
|
|
|
# $Id$
|
|
|
|
|
2002-10-20 14:25:16 +00:00
|
|
|
"View/Number of ancestors"
|
|
|
|
|
2005-01-02 23:48:39 +00:00
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# standard python modules
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
2002-10-20 14:25:16 +00:00
|
|
|
import os
|
2006-04-06 22:02:46 +00:00
|
|
|
from gettext import gettext as _
|
2005-01-02 23:48:39 +00:00
|
|
|
from sets import Set
|
2006-04-29 23:17:58 +00:00
|
|
|
from math import pow
|
2002-10-20 14:25:16 +00:00
|
|
|
|
2005-01-02 23:48:39 +00:00
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GNOME/GTK modules
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
2002-10-20 14:25:16 +00:00
|
|
|
import gtk.glade
|
|
|
|
|
2005-01-02 23:48:39 +00:00
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GRAMPS modules
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
import Utils
|
2006-03-11 01:12:06 +00:00
|
|
|
from PluginUtils import Report, register_report
|
2002-10-20 14:25:16 +00:00
|
|
|
|
2005-01-02 23:48:39 +00:00
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
2002-10-20 14:25:16 +00:00
|
|
|
class CountAncestors:
|
|
|
|
|
|
|
|
def __init__(self,database,person):
|
|
|
|
|
|
|
|
text = ""
|
2002-12-14 05:07:09 +00:00
|
|
|
glade_file = "%s/summary.glade" % os.path.dirname(__file__)
|
2003-08-17 02:14:33 +00:00
|
|
|
topDialog = gtk.glade.XML(glade_file,"summary","gramps")
|
2002-10-20 14:25:16 +00:00
|
|
|
topDialog.signal_autoconnect({
|
|
|
|
"destroy_passed_object" : Utils.destroy_passed_object,
|
|
|
|
})
|
2004-10-24 01:09:12 +00:00
|
|
|
thisgen = Set()
|
2004-10-25 02:37:18 +00:00
|
|
|
all = Set()
|
2004-10-24 01:09:12 +00:00
|
|
|
allgen = 0
|
2006-04-29 23:17:58 +00:00
|
|
|
total_theoretical = 0
|
2004-10-24 01:09:12 +00:00
|
|
|
thisgen.add(person.get_handle())
|
|
|
|
|
2004-02-14 05:40:30 +00:00
|
|
|
title = _("Number of ancestors of \"%s\" by generation") % person.get_primary_name().get_name()
|
2004-05-07 02:20:39 +00:00
|
|
|
thisgensize = 1
|
2006-04-30 21:43:45 +00:00
|
|
|
gen = 0
|
2004-05-07 02:20:39 +00:00
|
|
|
while thisgensize > 0:
|
|
|
|
thisgensize = 0
|
|
|
|
if thisgen:
|
|
|
|
thisgensize = len( thisgen )
|
2006-04-30 21:43:45 +00:00
|
|
|
gen += 1
|
|
|
|
theoretical = pow(2, ( gen - 1 ) )
|
2006-04-29 23:17:58 +00:00
|
|
|
total_theoretical += theoretical
|
|
|
|
percent = ( thisgensize / theoretical ) * 100
|
2002-10-20 14:25:16 +00:00
|
|
|
if thisgensize == 1 :
|
2006-04-29 23:17:58 +00:00
|
|
|
text += _("Generation %d has 1 individual. (%3.2f%%)\n") % (gen,percent)
|
2002-10-20 14:25:16 +00:00
|
|
|
else:
|
2006-04-29 23:17:58 +00:00
|
|
|
text += _("Generation %d has %d individuals. (%3.2f%%)\n") % (gen,thisgensize,percent)
|
2002-10-20 14:25:16 +00:00
|
|
|
temp = thisgen
|
2004-10-24 01:09:12 +00:00
|
|
|
thisgen = Set()
|
2004-07-28 02:29:07 +00:00
|
|
|
for person_handle in temp:
|
2004-08-07 05:16:57 +00:00
|
|
|
person = database.get_person_from_handle(person_handle)
|
2004-07-28 02:29:07 +00:00
|
|
|
family_handle = person.get_main_parents_family_handle()
|
|
|
|
if family_handle:
|
2004-08-19 21:35:16 +00:00
|
|
|
family = database.get_family_from_handle(family_handle)
|
2004-07-28 02:29:07 +00:00
|
|
|
father_handle = family.get_father_handle()
|
|
|
|
mother_handle = family.get_mother_handle()
|
2004-10-25 02:37:18 +00:00
|
|
|
if father_handle and father_handle not in all:
|
2004-10-24 01:09:12 +00:00
|
|
|
thisgen.add(father_handle)
|
2004-10-25 02:37:18 +00:00
|
|
|
all.add(father_handle)
|
|
|
|
if mother_handle and mother_handle not in all:
|
2004-10-24 01:09:12 +00:00
|
|
|
thisgen.add(mother_handle)
|
2004-10-25 02:37:18 +00:00
|
|
|
all.add(mother_handle)
|
2004-10-24 01:09:12 +00:00
|
|
|
allgen += len(thisgen)
|
2006-04-29 23:17:58 +00:00
|
|
|
|
|
|
|
if( total_theoretical != 1 ):
|
|
|
|
percent = ( (allgen) / (total_theoretical-1) ) * 100
|
|
|
|
else:
|
|
|
|
percent = 0
|
|
|
|
|
2006-04-30 21:43:45 +00:00
|
|
|
text += _("Total ancestors in generations 2 to %d is %d. (%3.2f%%)\n") % (gen,allgen,percent)
|
2002-10-20 14:25:16 +00:00
|
|
|
|
|
|
|
top = topDialog.get_widget("summary")
|
2006-05-14 18:07:03 +00:00
|
|
|
top.set_title(_("Number of ancestors report"))
|
2002-10-20 14:25:16 +00:00
|
|
|
textwindow = topDialog.get_widget("textwindow")
|
2003-05-01 23:35:27 +00:00
|
|
|
topDialog.get_widget("title").set_text(title)
|
2002-12-14 05:07:09 +00:00
|
|
|
textwindow.get_buffer().set_text(text)
|
2002-10-20 14:25:16 +00:00
|
|
|
top.show()
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
register_report(
|
2005-01-02 23:48:39 +00:00
|
|
|
name = 'count_ancestors',
|
2005-12-06 06:38:09 +00:00
|
|
|
category = Report.CATEGORY_VIEW,
|
2005-01-02 23:48:39 +00:00
|
|
|
report_class = CountAncestors,
|
|
|
|
options_class = None,
|
|
|
|
modes = Report.MODE_GUI,
|
|
|
|
translated_name = _("Number of ancestors"),
|
|
|
|
status = _("Beta"),
|
|
|
|
description= _("Counts number of ancestors of selected person")
|
2002-10-20 14:25:16 +00:00
|
|
|
)
|