Gender stats are wrong on some imports. Added tool to rebuild the gender statistics
svn: r20302
This commit is contained in:
parent
6a76f51f75
commit
7d96db40ed
@ -677,6 +677,7 @@ src/plugins/tool/ownereditor.py
|
||||
src/plugins/tool/patchnames.py
|
||||
src/plugins/tool/rebuild.py
|
||||
src/plugins/tool/rebuildrefmap.py
|
||||
src/plugins/tool/rebuildgenderstat.py
|
||||
src/plugins/tool/relcalc.py
|
||||
src/plugins/tool/removeunused.py
|
||||
src/plugins/tool/reorderids.py
|
||||
|
@ -2,6 +2,7 @@
|
||||
# Gramps - a GTK+/GNOME based genealogy program
|
||||
#
|
||||
# Copyright (C) 2000-2005 Donald N. Allingham
|
||||
# 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
|
||||
@ -53,6 +54,10 @@ class GenderStats(object):
|
||||
def save_stats(self):
|
||||
return self.stats
|
||||
|
||||
def clear_stats(self):
|
||||
self.stats = {}
|
||||
return self.stats
|
||||
|
||||
def _get_key (self, person):
|
||||
name = person.get_primary_name().get_first_name()
|
||||
return self._get_key_from_name (name)
|
||||
@ -65,17 +70,29 @@ class GenderStats(object):
|
||||
return self.stats[name]
|
||||
return (0, 0, 0)
|
||||
|
||||
def count_name (self, name, gender):
|
||||
"""count a given name under gender in the gender stats
|
||||
"""
|
||||
keyname = self._get_key_from_name(name)
|
||||
if not keyname:
|
||||
return
|
||||
|
||||
self._set_stats(keyname, gender)
|
||||
|
||||
def count_person (self, person, undo = 0):
|
||||
if not person:
|
||||
return
|
||||
# Let the Person do their own counting later
|
||||
|
||||
name = self._get_key (person)
|
||||
if not name:
|
||||
keyname = self._get_key (person)
|
||||
if not keyname:
|
||||
return
|
||||
|
||||
gender = person.get_gender()
|
||||
(male, female, unknown) = self.name_stats (name)
|
||||
self._set_stats(keyname, gender, undo)
|
||||
|
||||
def _set_stats (self, keyname, gender, undo=0):
|
||||
(male, female, unknown) = self.name_stats (keyname)
|
||||
if not undo:
|
||||
increment = 1
|
||||
else:
|
||||
@ -83,13 +100,18 @@ class GenderStats(object):
|
||||
|
||||
if gender == Person.MALE:
|
||||
male += increment
|
||||
if male < 0:
|
||||
male = 0
|
||||
elif gender == Person.FEMALE:
|
||||
female += increment
|
||||
if female < 0:
|
||||
female = 0
|
||||
elif gender == Person.UNKNOWN:
|
||||
unknown += increment
|
||||
if unknown < 0:
|
||||
unknown = 0
|
||||
|
||||
self.stats[name] = (male, female, unknown)
|
||||
return
|
||||
self.stats[keyname] = (male, female, unknown)
|
||||
|
||||
def uncount_person (self, person):
|
||||
return self.count_person (person, undo = 1)
|
||||
@ -113,4 +135,3 @@ class GenderStats(object):
|
||||
return Person.FEMALE
|
||||
|
||||
return Person.UNKNOWN
|
||||
|
||||
|
@ -22,6 +22,7 @@ pkgpython_PYTHON = \
|
||||
ownereditor.py \
|
||||
patchnames.py \
|
||||
rebuild.py \
|
||||
rebuildgenderstat.py \
|
||||
rebuildrefmap.py \
|
||||
relcalc.py \
|
||||
removeunused.py \
|
||||
|
129
src/plugins/tool/rebuildgenderstat.py
Normal file
129
src/plugins/tool/rebuildgenderstat.py
Normal 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)
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user