Gender stats are wrong on some imports. Added tool to rebuild the gender statistics

svn: r20302
This commit is contained in:
Benny Malengier
2012-08-31 13:35:14 +00:00
parent 6a76f51f75
commit 7d96db40ed
6 changed files with 187 additions and 13 deletions

View File

@@ -22,6 +22,7 @@ pkgpython_PYTHON = \
ownereditor.py \
patchnames.py \
rebuild.py \
rebuildgenderstat.py \
rebuildrefmap.py \
relcalc.py \
removeunused.py \

View File

@@ -67,17 +67,17 @@ class DumpGenderStats(tool.Tool, ManagedWindow):
]
treeview = Gtk.TreeView()
model = ListModel(treeview,titles)
model = ListModel(treeview, titles)
for entry in stats_list:
model.add(entry,entry[0])
model.add(entry, entry[0])
window = Gtk.Window()
window.set_default_size(400,300)
window.set_default_size(400, 300)
s = Gtk.ScrolledWindow()
s.add(treeview)
window.add(s)
window.show_all()
self.set_window(window,None,self.label)
self.set_window(window, None, self.label)
self.show()
else:
@@ -99,5 +99,5 @@ class DumpGenderStatsOptions(tool.ToolOptions):
Defines options and provides handling interface.
"""
def __init__(self, name,person_id=None):
tool.ToolOptions.__init__(self, name,person_id)
def __init__(self, name, person_id=None):
tool.ToolOptions.__init__(self, name, person_id)

View File

@@ -0,0 +1,129 @@
#
# Gramps - a GTK+/GNOME based genealogy program
#
# Copyright (C) 2012 Benny Malengier
#
# 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
#
# $Id$
# Written by Alex Roitman
"Rebuild gender stat values"
#-------------------------------------------------------------------------
#
# python modules
#
#-------------------------------------------------------------------------
from gen.ggettext import gettext as _
#------------------------------------------------------------------------
#
# Set up logging
#
#------------------------------------------------------------------------
import logging
log = logging.getLogger(".RebuildGenderStat")
#-------------------------------------------------------------------------
#
# gtk modules
#
#-------------------------------------------------------------------------
#-------------------------------------------------------------------------
#
# GRAMPS modules
#
#-------------------------------------------------------------------------
from gui.plug import tool
from gui.dialog import OkDialog
from gen.updatecallback import UpdateCallback
from gen.lib import Name
#-------------------------------------------------------------------------
#
# runTool
#
#-------------------------------------------------------------------------
COLUMN_GENDER = 2
COLUMN_NAME = 3
COLUMN_ALTNAMES = 4
class RebuildGenderStat(tool.Tool, UpdateCallback):
def __init__(self, dbstate, uistate, options_class, name, callback=None):
tool.Tool.__init__(self, dbstate, options_class, name)
if self.db.readonly:
return
self.db.disable_signals()
if uistate:
self.callback = uistate.pulse_progressbar
uistate.set_busy_cursor(True)
uistate.progress.show()
uistate.push_message(dbstate, _("Rebuilding gender statistics for name gender guessing..."))
else:
self.callback = None
print "Rebuilding gender statistics for name gender guessing..."
UpdateCallback.__init__(self, self.callback)
self.set_total(self.db.get_number_of_people())
self.rebuild_genderstats()
self.reset()
if uistate:
uistate.set_busy_cursor(False)
uistate.progress.hide()
OkDialog(_("Gender statistics rebuilt"),
_('Gender statistics for name gender guessing have been rebuilt.'),
parent=uistate.window)
else:
print "Gender statistics for name gender guessing have been rebuilt."
self.db.enable_signals()
def rebuild_genderstats(self):
"""
Function to rebuild the gender stats
"""
self.db.genderStats.clear_stats()
with self.db.get_person_cursor() as cursor:
#loop over database and store the sort field, and the handle, and
#allow for a third iter
for key, data in cursor:
rawprimname = data[COLUMN_NAME]
rawaltnames = data[COLUMN_ALTNAMES]
primary_name = Name().unserialize(rawprimname).get_first_name()
alternate_names = [Name().unserialize(name).get_first_name()
for name in rawaltnames]
self.db.genderStats.count_name(primary_name, data[COLUMN_GENDER])
#------------------------------------------------------------------------
#
#
#
#------------------------------------------------------------------------
class RebuildGenderStatOptions(tool.ToolOptions):
"""
Defines options and provides handling interface.
"""
def __init__(self, name, person_id=None):
tool.ToolOptions.__init__(self, name, person_id)

View File

@@ -365,7 +365,7 @@ tool_modes = [TOOL_MODE_GUI, TOOL_MODE_CLI]
#------------------------------------------------------------------------
#
# Rebuild Secondary Indices
# Rebuild Reference Maps
#
#------------------------------------------------------------------------
@@ -385,6 +385,28 @@ optionclass = 'RebuildRefMapOptions',
tool_modes = [TOOL_MODE_GUI, TOOL_MODE_CLI]
)
#------------------------------------------------------------------------
#
# Rebuild Gender Statistics
#
#------------------------------------------------------------------------
register(TOOL,
id = 'rebuild_genstats',
name = _("Rebuild Gender Statistics"),
description = _("Rebuilds gender statistics for name gender guessing..."),
version = '1.0',
gramps_target_version = '4.0',
status = STABLE,
fname = 'rebuildgenderstat.py',
authors = ["Benny Malengier"],
authors_email = ["benny.malengier@gramps-project.org"],
category = TOOL_DBFIX,
toolclass = 'RebuildGenderStat',
optionclass = 'RebuildGenderStatOptions',
tool_modes = [TOOL_MODE_GUI, TOOL_MODE_CLI]
)
#------------------------------------------------------------------------
#
# Relationship Calculator