2002-10-20 19:55:16 +05:30
|
|
|
#
|
|
|
|
# count_anc.py - Ancestor counting plugin for gramps
|
|
|
|
#
|
|
|
|
# Copyright (C) 2001 Jesper Zedlitz
|
2006-03-10 02:19:29 +05:30
|
|
|
# Copyright (C) 2004-2006 Donald Allingham
|
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$
|
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
"View/Number of ancestors"
|
|
|
|
|
2005-01-03 05:18:39 +05:30
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# standard python modules
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
2002-10-20 19:55:16 +05:30
|
|
|
import os
|
2006-04-07 03:32:46 +05:30
|
|
|
from gettext import gettext as _
|
2006-04-30 04:47:58 +05:30
|
|
|
from math import pow
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2005-01-03 05:18:39 +05:30
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GNOME/GTK modules
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
2002-10-20 19:55:16 +05:30
|
|
|
import gtk.glade
|
|
|
|
|
2005-01-03 05:18:39 +05:30
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GRAMPS modules
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
2006-06-01 10:09:40 +05:30
|
|
|
from PluginUtils import register_report
|
2006-06-02 06:10:54 +05:30
|
|
|
from ReportBase import CATEGORY_VIEW, MODE_GUI
|
|
|
|
import ManagedWindow
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2005-01-03 05:18:39 +05:30
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
2006-06-02 06:10:54 +05:30
|
|
|
class CountAncestors(ManagedWindow.ManagedWindow):
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2006-06-02 06:10:54 +05:30
|
|
|
def __init__(self,dbstate,uistate,person):
|
|
|
|
self.title = _('Ancestors of "%s"') \
|
|
|
|
% person.get_primary_name().get_name()
|
|
|
|
|
|
|
|
ManagedWindow.ManagedWindow.__init__(self,uistate,[],self.__class__)
|
|
|
|
|
|
|
|
database = dbstate.db
|
2002-10-20 19:55:16 +05:30
|
|
|
text = ""
|
2002-12-14 10:37:09 +05:30
|
|
|
glade_file = "%s/summary.glade" % os.path.dirname(__file__)
|
2003-08-17 07:44:33 +05:30
|
|
|
topDialog = gtk.glade.XML(glade_file,"summary","gramps")
|
2002-10-20 19:55:16 +05:30
|
|
|
topDialog.signal_autoconnect({
|
2006-06-02 06:10:54 +05:30
|
|
|
"destroy_passed_object" : self.close,
|
2002-10-20 19:55:16 +05:30
|
|
|
})
|
2006-06-02 06:10:54 +05:30
|
|
|
thisgen = set()
|
|
|
|
all = set()
|
2004-10-24 06:39:12 +05:30
|
|
|
allgen = 0
|
2006-04-30 04:47:58 +05:30
|
|
|
total_theoretical = 0
|
2004-10-24 06:39:12 +05:30
|
|
|
thisgen.add(person.get_handle())
|
|
|
|
|
2006-05-14 23:47:10 +05:30
|
|
|
|
2006-06-02 06:10:54 +05:30
|
|
|
window = topDialog.get_widget("summary")
|
2006-05-14 23:47:10 +05:30
|
|
|
title = topDialog.get_widget("title")
|
2006-06-02 06:10:54 +05:30
|
|
|
self.set_window(window,title,self.title)
|
2006-05-14 23:47:10 +05:30
|
|
|
|
2004-05-07 07:50:39 +05:30
|
|
|
thisgensize = 1
|
2006-05-01 03:13:45 +05:30
|
|
|
gen = 0
|
2004-05-07 07:50:39 +05:30
|
|
|
while thisgensize > 0:
|
|
|
|
thisgensize = 0
|
|
|
|
if thisgen:
|
|
|
|
thisgensize = len( thisgen )
|
2006-05-01 03:13:45 +05:30
|
|
|
gen += 1
|
|
|
|
theoretical = pow(2, ( gen - 1 ) )
|
2006-04-30 04:47:58 +05:30
|
|
|
total_theoretical += theoretical
|
|
|
|
percent = ( thisgensize / theoretical ) * 100
|
2002-10-20 19:55:16 +05:30
|
|
|
if thisgensize == 1 :
|
2006-06-02 06:10:54 +05:30
|
|
|
text += _("Generation %d has 1 individual. (%3.2f%%)\n") \
|
|
|
|
% (gen,percent)
|
2002-10-20 19:55:16 +05:30
|
|
|
else:
|
2006-06-02 06:10:54 +05:30
|
|
|
text += _("Generation %d has %d individuals. (%3.2f%%)\n")\
|
|
|
|
% (gen,thisgensize,percent)
|
2002-10-20 19:55:16 +05:30
|
|
|
temp = thisgen
|
2006-06-02 06:10:54 +05:30
|
|
|
thisgen = set()
|
2004-07-28 07:59:07 +05:30
|
|
|
for person_handle in temp:
|
2004-08-07 10:46:57 +05:30
|
|
|
person = database.get_person_from_handle(person_handle)
|
2004-07-28 07:59:07 +05:30
|
|
|
family_handle = person.get_main_parents_family_handle()
|
|
|
|
if family_handle:
|
2004-08-20 03:05:16 +05:30
|
|
|
family = database.get_family_from_handle(family_handle)
|
2004-07-28 07:59:07 +05:30
|
|
|
father_handle = family.get_father_handle()
|
|
|
|
mother_handle = family.get_mother_handle()
|
2004-10-25 08:07:18 +05:30
|
|
|
if father_handle and father_handle not in all:
|
2004-10-24 06:39:12 +05:30
|
|
|
thisgen.add(father_handle)
|
2004-10-25 08:07:18 +05:30
|
|
|
all.add(father_handle)
|
|
|
|
if mother_handle and mother_handle not in all:
|
2004-10-24 06:39:12 +05:30
|
|
|
thisgen.add(mother_handle)
|
2004-10-25 08:07:18 +05:30
|
|
|
all.add(mother_handle)
|
2004-10-24 06:39:12 +05:30
|
|
|
allgen += len(thisgen)
|
2006-04-30 04:47:58 +05:30
|
|
|
|
|
|
|
if( total_theoretical != 1 ):
|
|
|
|
percent = ( (allgen) / (total_theoretical-1) ) * 100
|
|
|
|
else:
|
|
|
|
percent = 0
|
|
|
|
|
2006-06-02 06:10:54 +05:30
|
|
|
text += _("Total ancestors in generations 2 to %d is %d. (%3.2f%%)\n")\
|
|
|
|
% (gen,allgen,percent)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
textwindow = topDialog.get_widget("textwindow")
|
2002-12-14 10:37:09 +05:30
|
|
|
textwindow.get_buffer().set_text(text)
|
2006-06-02 06:10:54 +05:30
|
|
|
self.show()
|
|
|
|
|
|
|
|
def build_menu_names(self,obj):
|
|
|
|
return (self.title,None)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
register_report(
|
2005-01-03 05:18:39 +05:30
|
|
|
name = 'count_ancestors',
|
2006-06-01 10:09:40 +05:30
|
|
|
category = CATEGORY_VIEW,
|
2005-01-03 05:18:39 +05:30
|
|
|
report_class = CountAncestors,
|
|
|
|
options_class = None,
|
2006-06-01 10:09:40 +05:30
|
|
|
modes = MODE_GUI,
|
2005-01-03 05:18:39 +05:30
|
|
|
translated_name = _("Number of ancestors"),
|
2006-06-02 06:10:54 +05:30
|
|
|
status = _("Stable"),
|
2005-01-03 05:18:39 +05:30
|
|
|
description= _("Counts number of ancestors of selected person")
|
2002-10-20 19:55:16 +05:30
|
|
|
)
|