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): def main(self):
self.set_text(_("Processing...") + "\n") self.set_text(_("Processing...") + "\n")
yield True
people = self.dbstate.db.get_person_handles(sort_handles=False) people = self.dbstate.db.get_person_handles(sort_handles=False)
surnames = {} surnames = {}
representative_handle = {} representative_handle = {}
@ -334,8 +335,6 @@ class SurnameCloudGramplet(Gramplet):
for (count, surname) in surname_sort: for (count, surname) in surname_sort:
cloud_names.append( (count, surname) ) cloud_names.append( (count, surname) )
cloud_values.append( count ) cloud_values.append( count )
if cnt > self.top_size:
break
cnt += 1 cnt += 1
cloud_names.sort(lambda a,b: cmp(a[1], b[1])) cloud_names.sort(lambda a,b: cmp(a[1], b[1]))
counts = list(set(cloud_values)) counts = list(set(cloud_values))
@ -343,23 +342,41 @@ class SurnameCloudGramplet(Gramplet):
counts.reverse() counts.reverse()
line = 0 line = 0
### All done! ### 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("") self.set_text("")
for (count, surname) in cloud_names: # surname_sort: for (count, surname) in cloud_names: # surname_sort:
if len(surname) == 0: if count > include_greater_than:
text = Config.get(Config.NO_SURNAME_TEXT) if len(surname) == 0:
else: text = Config.get(Config.NO_SURNAME_TEXT)
text = surname else:
size = make_tag_size(count, counts) text = surname
self.link(text, 'Surname', representative_handle[surname], size, size = make_tag_size(count, counts)
"%s, %d%% (%d)" % (text, self.link(text, 'Surname', representative_handle[surname], size,
int((float(count)/total) * 100), "%s, %d%% (%d)" % (text,
count)) int((float(count)/total) * 100),
self.append_text(" ") count))
line += 1 self.append_text(" ")
if line >= self.top_size: showing += 1
break self.append_text(("\n\n" + _("Total unique surnames") + ": %d\n") %
self.append_text(("\n" + _("Total unique surnames") + ": %d\n") %
total_surnames) total_surnames)
self.append_text((_("Total surnames showing") + ": %d\n") % showing)
self.append_text((_("Total people") + ": %d") % total_people, "begin") self.append_text((_("Total people") + ": %d") % total_people, "begin")
class RelativesGramplet(Gramplet): class RelativesGramplet(Gramplet):

View File

@ -52,6 +52,7 @@ class GivenNameCloudGramplet(Gramplet):
def main(self): def main(self):
self.set_text(_("Processing...") + "\n") self.set_text(_("Processing...") + "\n")
yield True
people = self.dbstate.db.get_person_handles(sort_handles=False) people = self.dbstate.db.get_person_handles(sort_handles=False)
givensubnames = {} givensubnames = {}
representative_handle = {} representative_handle = {}
@ -75,7 +76,7 @@ class GivenNameCloudGramplet(Gramplet):
for givensubname in givensubnames: for givensubname in givensubnames:
givensubname_sort.append( (givensubnames[givensubname], givensubname) ) givensubname_sort.append( (givensubnames[givensubname], givensubname) )
total += givensubnames[givensubname] total += givensubnames[givensubname]
if cnt % 350 == 0: if cnt % 100 == 0:
yield True yield True
cnt += 1 cnt += 1
total_givensubnames = cnt total_givensubnames = cnt
@ -86,8 +87,6 @@ class GivenNameCloudGramplet(Gramplet):
for (count, givensubname) in givensubname_sort: for (count, givensubname) in givensubname_sort:
cloud_names.append( (count, givensubname) ) cloud_names.append( (count, givensubname) )
cloud_values.append( count ) cloud_values.append( count )
if cnt > self.top_size:
break
cnt += 1 cnt += 1
cloud_names.sort(lambda a,b: cmp(a[1], b[1])) cloud_names.sort(lambda a,b: cmp(a[1], b[1]))
counts = list(set(cloud_values)) counts = list(set(cloud_values))
@ -95,23 +94,40 @@ class GivenNameCloudGramplet(Gramplet):
counts.reverse() counts.reverse()
line = 0 line = 0
### All done! ### 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("") self.set_text("")
for (count, givensubname) in cloud_names: # givensubname_sort: for (count, givensubname) in cloud_names: # givensubname_sort:
if len(givensubname) == 0: if count > include_greater_than:
text = Config.get(Config.NO_SURNAME_TEXT) if len(givensubname) == 0:
else: text = Config.get(Config.NO_SURNAME_TEXT)
text = givensubname else:
size = make_tag_size(count, counts) text = givensubname
self.link(text, 'Given', text, size, size = make_tag_size(count, counts)
"%s, %d%% (%d)" % (text, self.link(text, 'Given', text, size,
int((float(count)/total) * 100), "%s, %d%% (%d)" % (text,
count)) int((float(count)/total) * 100),
self.append_text(" ") count))
line += 1 self.append_text(" ")
if line >= self.top_size: showing += 1
break self.append_text(("\n\n" + _("Total unique given names") + ": %d\n") %
self.append_text(("\n" + _("Total unique given names") + ": %d\n") %
total_givensubnames) total_givensubnames)
self.append_text((_("Total given names showing") + ": %d\n") % showing)
self.append_text((_("Total people") + ": %d") % total_people, "begin") self.append_text((_("Total people") + ": %d") % total_people, "begin")
register(type="gramplet", register(type="gramplet",