2009-01-06 10:34:20 +05:30
|
|
|
# Gramps - a GTK+/GNOME based genealogy program
|
|
|
|
#
|
|
|
|
# Copyright (C) 2009 Pander Musubi
|
|
|
|
# Copyright (C) 2009 Douglas S. Blank
|
|
|
|
#
|
|
|
|
# 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
|
2009-02-16 12:26:49 +05:30
|
|
|
#
|
|
|
|
# $Id$
|
|
|
|
#
|
|
|
|
#
|
2010-01-25 23:15:21 +05:30
|
|
|
from collections import defaultdict
|
2010-01-18 10:12:17 +05:30
|
|
|
from gen.ggettext import gettext as _
|
2009-01-06 10:31:17 +05:30
|
|
|
|
2009-10-26 01:59:45 +05:30
|
|
|
from gen.plug import Gramplet
|
2009-10-08 06:42:51 +05:30
|
|
|
import config
|
2009-01-06 10:31:17 +05:30
|
|
|
|
2009-07-04 01:53:41 +05:30
|
|
|
_YIELD_INTERVAL = 350
|
|
|
|
|
2009-01-06 10:31:17 +05:30
|
|
|
def make_tag_size(n, counts, mins=8, maxs=20):
|
|
|
|
# return font sizes mins to maxs
|
|
|
|
diff = maxs - mins
|
|
|
|
# based on counts (biggest to smallest)
|
|
|
|
if len(counts) > 1:
|
|
|
|
position = diff - (diff * (float(counts.index(n)) / (len(counts) - 1)))
|
|
|
|
else:
|
|
|
|
position = 0
|
|
|
|
return int(position) + mins
|
|
|
|
|
|
|
|
class GivenNameCloudGramplet(Gramplet):
|
|
|
|
def init(self):
|
2009-01-08 04:19:58 +05:30
|
|
|
self.set_tooltip(_("Double-click given name for details"))
|
2009-01-06 10:31:17 +05:30
|
|
|
self.top_size = 100 # will be overwritten in load
|
|
|
|
self.set_text(_("No Family Tree loaded."))
|
|
|
|
|
|
|
|
def db_changed(self):
|
|
|
|
self.dbstate.db.connect('person-add', self.update)
|
|
|
|
self.dbstate.db.connect('person-delete', self.update)
|
|
|
|
self.dbstate.db.connect('person-update', self.update)
|
|
|
|
|
|
|
|
def on_load(self):
|
|
|
|
if len(self.gui.data) > 0:
|
|
|
|
self.top_size = int(self.gui.data[0])
|
|
|
|
|
|
|
|
def on_save(self):
|
|
|
|
self.gui.data = [self.top_size]
|
|
|
|
|
|
|
|
def main(self):
|
|
|
|
self.set_text(_("Processing...") + "\n")
|
2009-01-13 07:03:20 +05:30
|
|
|
yield True
|
2010-01-25 23:15:21 +05:30
|
|
|
givensubnames = defaultdict(int)
|
2009-01-06 10:31:17 +05:30
|
|
|
representative_handle = {}
|
2009-07-04 01:53:41 +05:30
|
|
|
|
2009-09-03 01:40:45 +05:30
|
|
|
cnt = 0
|
|
|
|
for person in self.dbstate.db.iter_people():
|
|
|
|
allnames = [person.get_primary_name()] + person.get_alternate_names()
|
|
|
|
allnames = set(name.get_first_name().strip() for name in allnames)
|
|
|
|
for givenname in allnames:
|
|
|
|
for givensubname in givenname.split():
|
2010-01-25 23:15:21 +05:30
|
|
|
givensubnames[givensubname] += 1
|
2009-09-03 01:40:45 +05:30
|
|
|
representative_handle[givensubname] = person.handle
|
|
|
|
cnt += 1
|
2009-07-04 01:53:41 +05:30
|
|
|
if not cnt % _YIELD_INTERVAL:
|
2009-01-06 10:31:17 +05:30
|
|
|
yield True
|
2009-07-04 01:53:41 +05:30
|
|
|
|
2009-01-06 10:31:17 +05:30
|
|
|
total_people = cnt
|
|
|
|
givensubname_sort = []
|
2009-07-14 19:46:03 +05:30
|
|
|
|
|
|
|
total = cnt = 0
|
|
|
|
for givensubname in givensubnames:
|
2009-01-06 10:31:17 +05:30
|
|
|
givensubname_sort.append( (givensubnames[givensubname], givensubname) )
|
|
|
|
total += givensubnames[givensubname]
|
2009-09-03 01:40:45 +05:30
|
|
|
cnt += 1
|
2009-07-04 01:53:41 +05:30
|
|
|
if not cnt % _YIELD_INTERVAL:
|
2009-01-06 10:31:17 +05:30
|
|
|
yield True
|
2009-07-04 01:53:41 +05:30
|
|
|
|
2009-01-06 10:31:17 +05:30
|
|
|
total_givensubnames = cnt
|
2009-07-04 01:53:41 +05:30
|
|
|
givensubname_sort.sort(reverse=True)
|
2009-01-06 10:31:17 +05:30
|
|
|
cloud_names = []
|
|
|
|
cloud_values = []
|
2009-07-04 01:53:41 +05:30
|
|
|
|
2009-09-03 01:40:45 +05:30
|
|
|
for count, givensubname in givensubname_sort:
|
2009-01-06 10:31:17 +05:30
|
|
|
cloud_names.append( (count, givensubname) )
|
|
|
|
cloud_values.append( count )
|
2009-07-04 01:53:41 +05:30
|
|
|
|
|
|
|
cloud_names.sort(key=lambda k: k[1])
|
2009-09-03 01:40:45 +05:30
|
|
|
counts = sorted(set(cloud_values), reverse=True)
|
2009-01-06 10:31:17 +05:30
|
|
|
line = 0
|
|
|
|
### All done!
|
2009-01-13 07:03:20 +05:30
|
|
|
# Now, find out how many we can display without going over top_size:
|
2010-01-25 23:15:21 +05:30
|
|
|
totals = defaultdict(int)
|
2009-01-06 10:31:17 +05:30
|
|
|
for (count, givensubname) in cloud_names: # givensubname_sort:
|
2010-01-25 23:15:21 +05:30
|
|
|
totals[count] += 1
|
2009-05-27 23:03:45 +05:30
|
|
|
sums = sorted(totals, reverse=True)
|
2009-01-13 07:03:20 +05:30
|
|
|
total = 0
|
|
|
|
include_greater_than = 0
|
|
|
|
for s in sums:
|
|
|
|
if total + totals[s] <= self.top_size:
|
|
|
|
total += totals[s]
|
2009-01-06 10:31:17 +05:30
|
|
|
else:
|
2009-01-13 07:03:20 +05:30
|
|
|
include_greater_than = s
|
2009-01-06 10:31:17 +05:30
|
|
|
break
|
2009-01-13 07:03:20 +05:30
|
|
|
# Ok, now we can show those counts > include_greater_than:
|
2009-07-04 01:53:41 +05:30
|
|
|
|
2009-01-13 07:03:20 +05:30
|
|
|
self.set_text("")
|
2009-07-14 19:46:03 +05:30
|
|
|
showing = 0
|
|
|
|
for (count, givensubname) in cloud_names: # givensubname_sort:
|
2009-01-13 07:03:20 +05:30
|
|
|
if count > include_greater_than:
|
|
|
|
if len(givensubname) == 0:
|
2009-10-08 06:42:51 +05:30
|
|
|
text = config.get('preferences.no-surname-text')
|
2009-01-13 07:03:20 +05:30
|
|
|
else:
|
|
|
|
text = givensubname
|
|
|
|
size = make_tag_size(count, counts)
|
|
|
|
self.link(text, 'Given', text, size,
|
2009-01-14 03:23:33 +05:30
|
|
|
"%s, %.2f%% (%d)" %
|
|
|
|
(text,
|
|
|
|
(float(count)/total_people) * 100,
|
|
|
|
count))
|
2009-01-13 07:03:20 +05:30
|
|
|
self.append_text(" ")
|
2009-07-14 19:46:03 +05:30
|
|
|
showing += 1
|
2009-07-04 01:53:41 +05:30
|
|
|
|
2009-01-13 07:03:20 +05:30
|
|
|
self.append_text(("\n\n" + _("Total unique given names") + ": %d\n") %
|
2009-01-06 10:31:17 +05:30
|
|
|
total_givensubnames)
|
2009-01-13 07:03:20 +05:30
|
|
|
self.append_text((_("Total given names showing") + ": %d\n") % showing)
|
2009-01-06 10:31:17 +05:30
|
|
|
self.append_text((_("Total people") + ": %d") % total_people, "begin")
|