Implement iter_people_handles methods and begin to use them
svn: r12760
This commit is contained in:
@@ -83,7 +83,7 @@ class AgeStatsGramplet(Gramplet):
|
||||
mother_handles = [[] for age in range(self.max_mother_diff)]
|
||||
father_handles = [[] for age in range(self.max_father_diff)]
|
||||
text = ""
|
||||
handles = self.dbstate.db.get_person_handles(sort_handles=False)
|
||||
handles = self.dbstate.db.iter_person_handles()
|
||||
for h in handles:
|
||||
yield True
|
||||
p = self.dbstate.db.get_person_from_handle(h)
|
||||
@@ -203,7 +203,7 @@ class AgeStatsGramplet(Gramplet):
|
||||
print "compute_stats", hash
|
||||
hashkeys = sorted(hash)
|
||||
count = sum(hash.itervalues())
|
||||
sumval = sum([k * hash[k] for k in hash])
|
||||
sumval = sum(k * hash[k] for k in hash)
|
||||
minval = min(hashkeys)
|
||||
maxval = max(hashkeys)
|
||||
median = 0
|
||||
|
||||
@@ -25,6 +25,8 @@ from gettext import gettext as _
|
||||
from DataViews import Gramplet, register
|
||||
import Config
|
||||
|
||||
_YIELD_INTERVAL = 350
|
||||
|
||||
def make_tag_size(n, counts, mins=8, maxs=20):
|
||||
# return font sizes mins to maxs
|
||||
diff = maxs - mins
|
||||
@@ -56,11 +58,11 @@ class GivenNameCloudGramplet(Gramplet):
|
||||
def main(self):
|
||||
self.set_text(_("Processing...") + "\n")
|
||||
yield True
|
||||
people = self.dbstate.db.get_person_handles(sort_handles=False)
|
||||
people = self.dbstate.db.iter_person_handles()
|
||||
givensubnames = {}
|
||||
representative_handle = {}
|
||||
cnt = 0
|
||||
for person_handle in people:
|
||||
|
||||
for cnt, person_handle in enumerate(people):
|
||||
person = self.dbstate.db.get_person_from_handle(person_handle)
|
||||
if person:
|
||||
allnames = [person.get_primary_name()] + person.get_alternate_names()
|
||||
@@ -69,32 +71,31 @@ class GivenNameCloudGramplet(Gramplet):
|
||||
for givensubname in givenname.split():
|
||||
givensubnames[givensubname] = givensubnames.get(givensubname, 0) + 1
|
||||
representative_handle[givensubname] = person_handle
|
||||
if cnt % 350 == 0:
|
||||
if not cnt % _YIELD_INTERVAL:
|
||||
yield True
|
||||
cnt += 1
|
||||
|
||||
total_people = cnt
|
||||
givensubname_sort = []
|
||||
total = 0
|
||||
cnt = 0
|
||||
for givensubname in givensubnames:
|
||||
|
||||
for cnt, givensubname in enumerate(givensubnames):
|
||||
givensubname_sort.append( (givensubnames[givensubname], givensubname) )
|
||||
total += givensubnames[givensubname]
|
||||
if cnt % 100 == 0:
|
||||
if not cnt % _YIELD_INTERVAL:
|
||||
yield True
|
||||
cnt += 1
|
||||
|
||||
total_givensubnames = cnt
|
||||
givensubname_sort.sort(lambda a,b: -cmp(a,b))
|
||||
givensubname_sort.sort(reverse=True)
|
||||
cloud_names = []
|
||||
cloud_values = []
|
||||
cnt = 0
|
||||
for (count, givensubname) in givensubname_sort:
|
||||
|
||||
for cnt, (count, givensubname) in enumerate(givensubname_sort):
|
||||
cloud_names.append( (count, givensubname) )
|
||||
cloud_values.append( count )
|
||||
cnt += 1
|
||||
cloud_names.sort(lambda a,b: cmp(a[1], b[1]))
|
||||
|
||||
cloud_names.sort(key=lambda k: k[1])
|
||||
counts = list(set(cloud_values))
|
||||
counts.sort()
|
||||
counts.reverse()
|
||||
counts.sort(reverse=True)
|
||||
line = 0
|
||||
### All done!
|
||||
# Now, find out how many we can display without going over top_size:
|
||||
@@ -111,9 +112,9 @@ class GivenNameCloudGramplet(Gramplet):
|
||||
include_greater_than = s
|
||||
break
|
||||
# Ok, now we can show those counts > include_greater_than:
|
||||
showing = 0
|
||||
|
||||
self.set_text("")
|
||||
for (count, givensubname) in cloud_names: # givensubname_sort:
|
||||
for showing, (count, givensubname) in enumerate(cloud_names): # givensubname_sort:
|
||||
if count > include_greater_than:
|
||||
if len(givensubname) == 0:
|
||||
text = Config.get(Config.NO_SURNAME_TEXT)
|
||||
@@ -126,7 +127,7 @@ class GivenNameCloudGramplet(Gramplet):
|
||||
(float(count)/total_people) * 100,
|
||||
count))
|
||||
self.append_text(" ")
|
||||
showing += 1
|
||||
|
||||
self.append_text(("\n\n" + _("Total unique given names") + ": %d\n") %
|
||||
total_givensubnames)
|
||||
self.append_text((_("Total given names showing") + ": %d\n") % showing)
|
||||
|
||||
@@ -36,6 +36,14 @@ from Utils import media_path_full
|
||||
import DateHandler
|
||||
import gen
|
||||
|
||||
#------------------------------------------------------------------------
|
||||
#
|
||||
# Constants
|
||||
#
|
||||
#------------------------------------------------------------------------
|
||||
|
||||
_YIELD_INTERVAL = 200
|
||||
|
||||
#------------------------------------------------------------------------
|
||||
#
|
||||
# Gramplet class
|
||||
@@ -58,7 +66,7 @@ class StatsGramplet(Gramplet):
|
||||
def main(self):
|
||||
self.set_text(_("Processing..."))
|
||||
database = self.dbstate.db
|
||||
personList = database.get_person_handles(sort_handles=False)
|
||||
personList = database.iter_person_handles()
|
||||
familyList = database.get_family_handles()
|
||||
|
||||
with_photos = 0
|
||||
@@ -73,7 +81,7 @@ class StatsGramplet(Gramplet):
|
||||
namelist = []
|
||||
notfound = []
|
||||
|
||||
pobjects = len(database.get_media_object_handles())
|
||||
pobjects = database.get_number_of_media_objects()
|
||||
for photo_id in database.get_media_object_handles():
|
||||
photo = database.get_object_from_handle(photo_id)
|
||||
fullname = media_path_full(database, photo.get_path())
|
||||
@@ -82,8 +90,7 @@ class StatsGramplet(Gramplet):
|
||||
except:
|
||||
notfound.append(photo.get_path())
|
||||
|
||||
cnt = 0
|
||||
for person_handle in personList:
|
||||
for cnt, person_handle in enumerate(personList):
|
||||
person = database.get_person_from_handle(person_handle)
|
||||
if not person:
|
||||
continue
|
||||
@@ -92,16 +99,17 @@ class StatsGramplet(Gramplet):
|
||||
with_photos = with_photos + 1
|
||||
total_photos = total_photos + length
|
||||
|
||||
person = database.get_person_from_handle(person_handle)
|
||||
names = [person.get_primary_name()] + person.get_alternate_names()
|
||||
for name in names:
|
||||
if name.get_first_name() == "" or name.get_group_name() == "":
|
||||
incomp_names = incomp_names + 1
|
||||
if name.get_group_name() not in namelist:
|
||||
namelist.append(name.get_group_name())
|
||||
|
||||
if ((not person.get_main_parents_family_handle()) and
|
||||
(not len(person.get_family_handle_list()))):
|
||||
disconnected = disconnected + 1
|
||||
|
||||
birth_ref = person.get_birth_ref()
|
||||
if birth_ref:
|
||||
birth = database.get_event_from_handle(birth_ref.ref)
|
||||
@@ -109,22 +117,22 @@ class StatsGramplet(Gramplet):
|
||||
missing_bday = missing_bday + 1
|
||||
else:
|
||||
missing_bday = missing_bday + 1
|
||||
|
||||
if person.get_gender() == gen.lib.Person.FEMALE:
|
||||
females = females + 1
|
||||
elif person.get_gender() == gen.lib.Person.MALE:
|
||||
males = males + 1
|
||||
else:
|
||||
unknowns += 1
|
||||
if cnt % 200 == 0:
|
||||
if not cnt % _YIELD_INTERVAL:
|
||||
yield True
|
||||
cnt += 1
|
||||
|
||||
self.clear_text()
|
||||
self.append_text(_("Individuals") + "\n")
|
||||
self.append_text("----------------------------\n")
|
||||
self.link(_("Number of individuals") + ":",
|
||||
'Filter', 'all people')
|
||||
self.append_text(" %s" % len(personList))
|
||||
self.append_text(" %s" % database.get_number_of_people())
|
||||
self.append_text("\n")
|
||||
self.link("%s:" % _("Males"), 'Filter', 'males')
|
||||
self.append_text(" %s" % males)
|
||||
|
||||
@@ -27,6 +27,14 @@ from DataViews import register, Gramplet
|
||||
from TransUtils import sgettext as _
|
||||
import Config
|
||||
|
||||
#------------------------------------------------------------------------
|
||||
#
|
||||
# Constants
|
||||
#
|
||||
#------------------------------------------------------------------------
|
||||
|
||||
_YIELD_INTERVAL = 350
|
||||
|
||||
#------------------------------------------------------------------------
|
||||
#
|
||||
# Local functions
|
||||
@@ -70,11 +78,10 @@ class SurnameCloudGramplet(Gramplet):
|
||||
def main(self):
|
||||
self.set_text(_("Processing...") + "\n")
|
||||
yield True
|
||||
people = self.dbstate.db.get_person_handles(sort_handles=False)
|
||||
people = self.dbstate.db.iter_person_handles()
|
||||
surnames = {}
|
||||
representative_handle = {}
|
||||
cnt = 0
|
||||
for person_handle in people:
|
||||
for cnt, person_handle in enumerate(people):
|
||||
person = self.dbstate.db.get_person_from_handle(person_handle)
|
||||
if person:
|
||||
allnames = [person.get_primary_name()] + person.get_alternate_names()
|
||||
@@ -82,32 +89,29 @@ class SurnameCloudGramplet(Gramplet):
|
||||
for surname in allnames:
|
||||
surnames[surname] = surnames.get(surname, 0) + 1
|
||||
representative_handle[surname] = person_handle
|
||||
if cnt % 350 == 0:
|
||||
if not cnt % _YIELD_INTERVAL:
|
||||
yield True
|
||||
cnt += 1
|
||||
|
||||
total_people = cnt
|
||||
surname_sort = []
|
||||
total = 0
|
||||
cnt = 0
|
||||
for surname in surnames:
|
||||
for cnt, surname in enumerate(surnames):
|
||||
surname_sort.append( (surnames[surname], surname) )
|
||||
total += surnames[surname]
|
||||
if cnt % 350 == 0:
|
||||
if not cnt % _YIELD_INTERVAL:
|
||||
yield True
|
||||
cnt += 1
|
||||
|
||||
total_surnames = cnt
|
||||
surname_sort.sort(lambda a,b: -cmp(a,b))
|
||||
surname_sort.sort(reverse=True)
|
||||
cloud_names = []
|
||||
cloud_values = []
|
||||
cnt = 0
|
||||
for (count, surname) in surname_sort:
|
||||
for cnt, (count, surname) in enumerate(surname_sort):
|
||||
cloud_names.append( (count, surname) )
|
||||
cloud_values.append( count )
|
||||
cnt += 1
|
||||
cloud_names.sort(lambda a,b: cmp(a[1], b[1]))
|
||||
|
||||
cloud_names.sort(key=lambda k:k[1])
|
||||
counts = list(set(cloud_values))
|
||||
counts.sort()
|
||||
counts.reverse()
|
||||
counts.sort(reverse=True)
|
||||
line = 0
|
||||
### All done!
|
||||
# Now, find out how many we can display without going over top_size:
|
||||
|
||||
@@ -27,6 +27,14 @@ from DataViews import register, Gramplet
|
||||
from TransUtils import sgettext as _
|
||||
import Config
|
||||
|
||||
#------------------------------------------------------------------------
|
||||
#
|
||||
# Constants
|
||||
#
|
||||
#------------------------------------------------------------------------
|
||||
|
||||
_YIELD_INTERVAL = 350
|
||||
|
||||
#------------------------------------------------------------------------
|
||||
#
|
||||
# Gramplet class
|
||||
@@ -54,11 +62,11 @@ class TopSurnamesGramplet(Gramplet):
|
||||
|
||||
def main(self):
|
||||
self.set_text(_("Processing...") + "\n")
|
||||
people = self.dbstate.db.get_person_handles(sort_handles=False)
|
||||
people = self.dbstate.db.iter_person_handles()
|
||||
surnames = {}
|
||||
representative_handle = {}
|
||||
cnt = 0
|
||||
for person_handle in people:
|
||||
|
||||
for cnt, person_handle in enumerate(people):
|
||||
person = self.dbstate.db.get_person_from_handle(person_handle)
|
||||
if person:
|
||||
allnames = [person.get_primary_name()] + person.get_alternate_names()
|
||||
@@ -66,32 +74,28 @@ class TopSurnamesGramplet(Gramplet):
|
||||
for surname in allnames:
|
||||
surnames[surname] = surnames.get(surname, 0) + 1
|
||||
representative_handle[surname] = person_handle
|
||||
if cnt % 350 == 0:
|
||||
if not cnt % _YIELD_INTERVAL:
|
||||
yield True
|
||||
cnt += 1
|
||||
|
||||
total_people = cnt
|
||||
surname_sort = []
|
||||
total = 0
|
||||
cnt = 0
|
||||
for surname in surnames:
|
||||
|
||||
for cnt, surname in enumerate(surnames):
|
||||
surname_sort.append( (surnames[surname], surname) )
|
||||
total += surnames[surname]
|
||||
if cnt % 350 == 0:
|
||||
if not cnt % _YIELD_INTERVAL:
|
||||
yield True
|
||||
cnt += 1
|
||||
|
||||
total_surnames = cnt
|
||||
surname_sort.sort(lambda a,b: -cmp(a,b))
|
||||
surname_sort.sort(reverse=True)
|
||||
line = 0
|
||||
### All done!
|
||||
self.set_text("")
|
||||
nosurname = Config.get(Config.NO_SURNAME_TEXT)
|
||||
for (count, surname) in surname_sort:
|
||||
if len(surname) == 0:
|
||||
text = "%s, %d%% (%d)\n" % (Config.get(Config.NO_SURNAME_TEXT),
|
||||
int((float(count)/total) * 100),
|
||||
count)
|
||||
else:
|
||||
text = "%s, %d%% (%d)\n" % (surname, int((float(count)/total) * 100),
|
||||
count)
|
||||
text = "%s, " % (surname if surname else nosurname)
|
||||
text += "%d%% (%d)\n" % (int((float(count)/total) * 100), count)
|
||||
self.append_text(" %d. " % (line + 1))
|
||||
self.link(text, 'Surname', representative_handle[surname])
|
||||
line += 1
|
||||
|
||||
Reference in New Issue
Block a user