From eccc5bb5dbbe4bb696f88fa92b5704f6ac9ca17a Mon Sep 17 00:00:00 2001 From: Brian Matherly Date: Tue, 24 Jul 2007 03:22:19 +0000 Subject: [PATCH] Contribution from Johan Gonqvist : The "number of ancestors" report only takes different persons into account. (#0001076) svn: r8765 --- ChangeLog | 5 +++++ src/plugins/CountAncestors.py | 36 +++++++++++++++++------------------ 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/ChangeLog b/ChangeLog index e5e536ec1..76470f0f5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2007-07-23 Johan Gonqvist + * src/plugins/CountAncestors.py: + The "number of ancestors" report only takes different persons into account. + (#0001076) + 2007-07-23 Johan Gonqvist * src/plugins/NarrativeWeb.py: Make URL handling on win32 work as in NarrativeWeb.py. (#0001087) diff --git a/src/plugins/CountAncestors.py b/src/plugins/CountAncestors.py index 35c1a311f..d7c4c2093 100644 --- a/src/plugins/CountAncestors.py +++ b/src/plugins/CountAncestors.py @@ -3,6 +3,7 @@ # # Copyright (C) 2001 Jesper Zedlitz # Copyright (C) 2004-2006 Donald Allingham +# Copyright (C) 2007 Johan Gonqvist # # 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 @@ -68,11 +69,11 @@ class CountAncestors(ManagedWindow.ManagedWindow): topDialog.signal_autoconnect({ "destroy_passed_object" : self.close, }) - thisgen = set() - all = set() - allgen = 0 + thisgen = {} + all = {} + total_theoretical = 0 - thisgen.add(person.get_handle()) + thisgen[person.get_handle()]=1 window = topDialog.get_widget("summary") @@ -83,12 +84,12 @@ class CountAncestors(ManagedWindow.ManagedWindow): gen = 0 while thisgensize > 0: thisgensize = 0 - if thisgen: - thisgensize = len( thisgen ) + if thisgen != {}: + thisgensize = len(thisgen.values()) gen += 1 theoretical = pow(2, ( gen - 1 ) ) total_theoretical += theoretical - percent = ( thisgensize / theoretical ) * 100 + percent = ( sum(thisgen.values()) / theoretical ) * 100 if thisgensize == 1 : text += _("Generation %d has 1 individual. (%3.2f%%)\n") \ % (gen,percent) @@ -96,29 +97,28 @@ class CountAncestors(ManagedWindow.ManagedWindow): text += _("Generation %d has %d individuals. (%3.2f%%)\n")\ % (gen,thisgensize,percent) temp = thisgen - thisgen = set() - for person_handle in temp: + thisgen = {} + for person_handle in temp.keys(): person = database.get_person_from_handle(person_handle) family_handle = person.get_main_parents_family_handle() if family_handle: family = database.get_family_from_handle(family_handle) father_handle = family.get_father_handle() mother_handle = family.get_mother_handle() - if father_handle and father_handle not in all: - thisgen.add(father_handle) - all.add(father_handle) - if mother_handle and mother_handle not in all: - thisgen.add(mother_handle) - all.add(mother_handle) - allgen += len(thisgen) + if father_handle: + thisgen[father_handle] = thisgen.get(father_handle, 0) + temp[person_handle] + all[father_handle] = all.get(father_handle, 0) + temp[person_handle] + if mother_handle: + thisgen[mother_handle] = thisgen.get(mother_handle, 0) + temp[person_handle] + all[mother_handle] = all.get(mother_handle, 0) + temp[person_handle] if( total_theoretical != 1 ): - percent = ( (allgen) / (total_theoretical-1) ) * 100 + percent = ( sum(all.values()) / (total_theoretical-1) ) * 100 else: percent = 0 text += _("Total ancestors in generations 2 to %d is %d. (%3.2f%%)\n")\ - % (gen,allgen,percent) + % (gen, len(all.keys()) ,percent) textwindow = topDialog.get_widget("textwindow") textwindow.get_buffer().set_text(text)