Fixed bug #2598: Cloud gramplets didn't show exactly the right set of names

svn: r11616
This commit is contained in:
Doug Blank 2009-01-13 01:33:20 +00:00
parent 2fadd11aab
commit 48fb1c94f4
2 changed files with 66 additions and 33 deletions

View File

@ -301,6 +301,7 @@ class SurnameCloudGramplet(Gramplet):
def main(self):
self.set_text(_("Processing...") + "\n")
yield True
people = self.dbstate.db.get_person_handles(sort_handles=False)
surnames = {}
representative_handle = {}
@ -334,8 +335,6 @@ class SurnameCloudGramplet(Gramplet):
for (count, surname) in surname_sort:
cloud_names.append( (count, surname) )
cloud_values.append( count )
if cnt > self.top_size:
break
cnt += 1
cloud_names.sort(lambda a,b: cmp(a[1], b[1]))
counts = list(set(cloud_values))
@ -343,8 +342,27 @@ class SurnameCloudGramplet(Gramplet):
counts.reverse()
line = 0
### All done!
# Now, find out how many we can display without going over top_size:
totals = {}
for (count, givensubname) in cloud_names: # givensubname_sort:
totals[count] = totals.get(count, 0) + 1
sums = totals.keys()
sums.sort()
sums.reverse()
total = 0
include_greater_than = 0
for s in sums:
if total + totals[s] <= self.top_size:
total += totals[s]
else:
include_greater_than = s
break
# Ok, now we can show those counts > include_greater_than:
print
showing = 0
self.set_text("")
for (count, surname) in cloud_names: # surname_sort:
if count > include_greater_than:
if len(surname) == 0:
text = Config.get(Config.NO_SURNAME_TEXT)
else:
@ -355,11 +373,10 @@ class SurnameCloudGramplet(Gramplet):
int((float(count)/total) * 100),
count))
self.append_text(" ")
line += 1
if line >= self.top_size:
break
self.append_text(("\n" + _("Total unique surnames") + ": %d\n") %
showing += 1
self.append_text(("\n\n" + _("Total unique surnames") + ": %d\n") %
total_surnames)
self.append_text((_("Total surnames showing") + ": %d\n") % showing)
self.append_text((_("Total people") + ": %d") % total_people, "begin")
class RelativesGramplet(Gramplet):

View File

@ -52,6 +52,7 @@ class GivenNameCloudGramplet(Gramplet):
def main(self):
self.set_text(_("Processing...") + "\n")
yield True
people = self.dbstate.db.get_person_handles(sort_handles=False)
givensubnames = {}
representative_handle = {}
@ -75,7 +76,7 @@ class GivenNameCloudGramplet(Gramplet):
for givensubname in givensubnames:
givensubname_sort.append( (givensubnames[givensubname], givensubname) )
total += givensubnames[givensubname]
if cnt % 350 == 0:
if cnt % 100 == 0:
yield True
cnt += 1
total_givensubnames = cnt
@ -86,8 +87,6 @@ class GivenNameCloudGramplet(Gramplet):
for (count, givensubname) in givensubname_sort:
cloud_names.append( (count, givensubname) )
cloud_values.append( count )
if cnt > self.top_size:
break
cnt += 1
cloud_names.sort(lambda a,b: cmp(a[1], b[1]))
counts = list(set(cloud_values))
@ -95,8 +94,26 @@ class GivenNameCloudGramplet(Gramplet):
counts.reverse()
line = 0
### All done!
# Now, find out how many we can display without going over top_size:
totals = {}
for (count, givensubname) in cloud_names: # givensubname_sort:
totals[count] = totals.get(count, 0) + 1
sums = totals.keys()
sums.sort()
sums.reverse()
total = 0
include_greater_than = 0
for s in sums:
if total + totals[s] <= self.top_size:
total += totals[s]
else:
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:
if count > include_greater_than:
if len(givensubname) == 0:
text = Config.get(Config.NO_SURNAME_TEXT)
else:
@ -107,11 +124,10 @@ class GivenNameCloudGramplet(Gramplet):
int((float(count)/total) * 100),
count))
self.append_text(" ")
line += 1
if line >= self.top_size:
break
self.append_text(("\n" + _("Total unique given names") + ": %d\n") %
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)
self.append_text((_("Total people") + ": %d") % total_people, "begin")
register(type="gramplet",