Bug 3018: remove calls to keys() and values() dictionary method where possible

svn: r12579
This commit is contained in:
Gerald Britton
2009-05-27 17:33:45 +00:00
parent 1edada53d0
commit 81a0848490
11 changed files with 60 additions and 49 deletions

View File

@@ -132,7 +132,8 @@ class GenChart(object):
new_y = 0
for key, i in self.array.iteritems():
old_y = key
if self.not_blank(i.values()):
print __name__, i
if self.not_blank(i.itervalues()):
self.compress_map[old_y] = new_y
new_array[new_y] = i
x = 0

View File

@@ -534,19 +534,15 @@ class StatisticsChart(Report):
"""creates & stores a sorted index for the items"""
# sort by item keys
index = data.keys()
index.sort()
if reverse:
index.reverse()
index = sorted(data, reverse=True if reverse else False)
if sort == _options.SORT_VALUE:
# set for the sorting function
self.lookup_items = data
# then sort by value
index.sort(self.lookup_compare)
if reverse:
index.reverse()
index.sort(self.lookup_compare,
reverse=True if reverse else False)
return index

View File

@@ -200,8 +200,9 @@ class AgeStatsGramplet(Gramplet):
def compute_stats(self, hash):
""" Returns the statistics of a dictionary of data """
print "compute_stats", hash
hashkeys = sorted(hash)
count = sum(hash.values())
count = sum(hash.itervalues())
sumval = sum([k * hash[k] for k in hash])
minval = min(hashkeys)
maxval = max(hashkeys)
@@ -239,6 +240,7 @@ class AgeStatsGramplet(Gramplet):
where the key is the age, and the value stored is the count.
"""
# first, binify:
print "create_bargraph", hash
bin = [0] * (max_val/bin_size)
for value, hash_value in hash.iteritems():
bin[value/bin_size] += hash_value
@@ -246,22 +248,36 @@ class AgeStatsGramplet(Gramplet):
max_bin = float(max(bin))
if max_bin != 0:
i = 0
self.append_text("--------" + self.format("", graph_width-4, fill = "-", borders="++") + "-----\n")
self.append_text(column.center(8) + self.format(title, graph_width-4, align="center") + " % " + "\n")
self.append_text("--------" + self.format("", graph_width-4, fill = "-", borders="++") + "-----\n")
self.append_text("--------" +
self.format("", graph_width-4, fill = "-", borders="++") +
"-----\n")
self.append_text(column.center(8) +
self.format(title, graph_width-4, align="center") +
" % " + "\n")
self.append_text("--------" +
self.format("", graph_width-4, fill = "-", borders="++") +
"-----\n")
for bin in bin:
self.append_text((" %3d-%3d" % (i * 5, (i+1)* 5,)))
selected = self.make_handles_set(i * 5, (i+1) *5, handles)
self.link(self.format("X" * int(bin/max_bin * (graph_width-4)), graph_width-4),
self.link(self.format("X" * int(bin/max_bin * (graph_width-4)),
graph_width-4),
'PersonList',
selected,
tooltip=_("Double-click to see %d people") % len(selected))
procent = float(len(selected))/(float(sum(hash.values())))*100
tooltip=_("Double-click to see %d people") %
len(selected))
procent = (float(len(selected)) /
(float(sum(hash.itervalues())))*100)
self.append_text(locale.format("%#5.2f", procent))
self.append_text("\n")
i += 1
self.append_text("--------" + self.format("", graph_width-4, fill = "-", borders="++") + "-----\n")
self.append_text(" % " + self.ticks(graph_width-4, start = 0, stop = int(max_bin/(float(sum(hash.values())))*100)) + "\n\n")
self.append_text("--------" +
self.format("", graph_width-4, fill = "-", borders="++") +
"-----\n")
self.append_text(" % " +
self.ticks(graph_width-4, start = 0,
stop = int(max_bin/(float(sum(hash.itervalues())))*100)) +
"\n\n")
self.append_text(self.compute_stats(hash))
self.append_text("\n")

View File

@@ -101,8 +101,7 @@ class GivenNameCloudGramplet(Gramplet):
totals = {}
for (count, givensubname) in cloud_names: # givensubname_sort:
totals[count] = totals.get(count, 0) + 1
sums = sorted(totals)
sums.reverse()
sums = sorted(totals, reverse=True)
total = 0
include_greater_than = 0
for s in sums:

View File

@@ -114,8 +114,7 @@ class SurnameCloudGramplet(Gramplet):
totals = {}
for (count, givensubname) in cloud_names: # givensubname_sort:
totals[count] = totals.get(count, 0) + 1
sums = sorted(totals)
sums.reverse()
sums = sorted(totals, reverse=True)
total = 0
include_greater_than = 0
for s in sums:

View File

@@ -107,19 +107,19 @@ def set_font_families():
families = pangocairo.cairo_font_map_get_default().list_families()
family_names = [family.get_name() for family in families]
fam = [f for f in _TTF_FREEFONT.values() if f in family_names]
fam = [f for f in _TTF_FREEFONT.itervalues() if f in family_names]
if len(fam) == len(_TTF_FREEFONT):
font_families = _TTF_FREEFONT
log.debug('Using FreeFonts: %s' % font_families)
return
fam = [f for f in _MS_TTFONT.values() if f in family_names]
fam = [f for f in _MS_TTFONT.itervalues() if f in family_names]
if len(fam) == len(_MS_TTFONT):
font_families = _MS_TTFONT
log.debug('Using MS TrueType fonts: %s' % font_families)
return
fam = [f for f in _GNOME_FONT.values() if f in family_names]
fam = [f for f in _GNOME_FONT.itervalues() if f in family_names]
if len(fam) == len(_GNOME_FONT):
font_families = _GNOME_FONT
log.debug('Using Gnome fonts: %s' % font_families)
@@ -1584,4 +1584,4 @@ def register_plugin():
)
)
register_plugin()
register_plugin()

View File

@@ -180,9 +180,9 @@ class DetAncestorReport(Report):
for family_handle in person.get_family_handle_list():
family = self.database.get_family_from_handle(family_handle)
mother_handle = family.get_mother_handle()
if mother_handle is None or \
mother_handle not in self.map.values() or \
person.get_gender() == gen.lib.Person.FEMALE:
if (mother_handle is None or
mother_handle not in self.map.itervalues() or
person.get_gender() == gen.lib.Person.FEMALE):
# The second test above also covers the 1. person's
# mate, which is not an ancestor and as such is not
# included in the self.map dictionary

View File

@@ -92,11 +92,12 @@ class NumberOfAncestorsReport(Report):
while thisgensize > 0:
thisgensize = 0
if thisgen != {}:
thisgensize = len(thisgen.values())
thisgensize = len(thisgen)
gen += 1
theoretical = math.pow(2, ( gen - 1 ) )
total_theoretical += theoretical
percent = '(%s%%)' % locale.format('%3.2f', ((sum(thisgen.values()) / theoretical ) * 100))
percent = '(%s%%)' % locale.format('%3.2f',
((sum(thisgen.itervalues()) / theoretical ) * 100))
# TC # English return something like:
# Generation 3 has 2 individuals. (50.00%)
@@ -132,7 +133,8 @@ class NumberOfAncestorsReport(Report):
person_data
if( total_theoretical != 1 ):
percent = '(%3.2f%%)' % (( sum(all_people.values()) / (total_theoretical-1) ) * 100)
percent = '(%3.2f%%)' % (( sum(all_people.itervalues())
/ (total_theoretical-1) ) * 100)
else:
percent = 0