def main(self): # return false finishes """ Generator which will be run in the background. """ self._boxes = [0] * (self.max_generations + 1) self._generations = {} self.gui.buffer.set_text("") active_handle = self.get_active('Person') if active_handle is None: return active_person = self.dbstate.db.get_person_from_handle(active_handle) #no wrap in Gramplet self.no_wrap() if active_person is None: return self.process_person(active_person.handle, 1, "f") # father self.process_person(active_person.handle, 0, "a") # active #FIXME: should be 1? self.process_person(active_person.handle, 1, "m") # mother gens = sorted(self._generations) self.append_text(_("\nBreakdown by generation:\n")) all = [active_person.handle] percent_sign = _("percent sign or text string|%") for g in gens: yield True count = len(self._generations[g]) handles = self._generations[g] self.append_text(" ") if g == 0: self.link(_("Generation 1"), 'PersonList', handles, tooltip=_("Double-click to see people in generation")) percent = glocale.format( '%.2f', 100) + percent_sign self.append_text(_(" has 1 of 1 individual (%(percent)s complete)\n") % {'percent': percent}) else: all.extend(handles) self.link(_("Generation %d") % g, 'PersonList', handles, tooltip=_("Double-click to see people in generation %d") % g) percent = glocale.format('%.2f', float(count)/2**(g-1) * 100) + percent_sign self.append_text( # translators: leave all/any {...} untranslated ngettext(" has {count_person} of {max_count_person} " "individuals ({percent} complete)\n", " has {count_person} of {max_count_person} " "individuals ({percent} complete)\n", 2**(g-1) ).format(count_person=count, max_count_person=2**(g-1), percent=percent) ) self.link(_("All generations"), 'PersonList', all, tooltip=_("Double-click to see all generations")) self.append_text( # translators: leave all/any {...} untranslated ngettext(" have {number_of} individual\n", " have {number_of} individuals\n", len(all) ).format(number_of=len(all)) ) # Set to a fixed font if self.box_mode == "UTF": start, end = self.gui.buffer.get_bounds() self.gui.buffer.apply_tag_by_name("fixed", start, end) self.append_text("", scroll_to="begin")
def create_bargraph(self, hash, handles, title, column, graph_width, bin_size, max_val): """ Create a bargraph based on the data in hash. hash is a dict, like: hash = {12: 4, 20: 6, 35: 13, 50: 5} where the key is the age, and the value stored is the count. """ # first, binify: #print "create_bargraph", hash bin = [0] * int(max_val / bin_size) for value, hash_value in hash.items(): bin[int(value / bin_size)] += hash_value text = "" 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") 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), 'PersonList', selected, tooltip=_("Double-click to see %d people") % len(selected)) procent = (float(len(selected)) / (float(sum(hash.values()))) * 100) self.append_text(glocale.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.compute_stats(hash))
def create_bargraph(self, hash, handles, title, column, graph_width, bin_size, max_val): """ Create a bargraph based on the data in hash. hash is a dict, like: hash = {12: 4, 20: 6, 35: 13, 50: 5} where the key is the age, and the value stored is the count. """ # first, binify: #print "create_bargraph", hash bin = [0] * int(max_val/bin_size) for value, hash_value in hash.items(): bin[int(value/bin_size)] += hash_value text = "" 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") 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), 'PersonList', selected, tooltip=_("Double-click to see %d people") % len(selected)) procent = (float(len(selected)) / (float(sum(hash.values())))*100) self.append_text(glocale.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.compute_stats(hash))
def main(self): # return false finishes """ Generator which will be run in the background. """ self._boxes = [0] * (self.max_generations + 1) self._generations = {} self.gui.buffer.set_text("") active_handle = self.get_active('Person') if active_handle is None: return active_person = self.dbstate.db.get_person_from_handle(active_handle) #no wrap in Gramplet self.no_wrap() if active_person is None: return self.process_person(active_person.handle, 1, "f") # father self.process_person(active_person.handle, 0, "a") # active #FIXME: should be 1? self.process_person(active_person.handle, 1, "m") # mother gens = sorted(self._generations) self.append_text(_("\nBreakdown by generation:\n")) all = [active_person.handle] percent_sign = _("percent sign or text string|%") for g in gens: yield True count = len(self._generations[g]) handles = self._generations[g] self.append_text(" ") if g == 0: self.link( _("Generation 1"), 'PersonList', handles, tooltip=_("Double-click to see people in generation")) percent = glocale.format('%.2f', 100) + percent_sign self.append_text( _(" has 1 of 1 individual (%(percent)s complete)\n") % {'percent': percent}) else: all.extend(handles) self.link( _("Generation %d") % g, 'PersonList', handles, tooltip=_("Double-click to see people in generation %d") % g) percent = glocale.format( '%.2f', float(count) / 2**(g - 1) * 100) + percent_sign self.append_text( # translators: leave all/any {...} untranslated ngettext( " has {count_person} of {max_count_person} " "individuals ({percent} complete)\n", " has {count_person} of {max_count_person} " "individuals ({percent} complete)\n", 2**(g - 1)).format(count_person=count, max_count_person=2**(g - 1), percent=percent)) self.link(_("All generations"), 'PersonList', all, tooltip=_("Double-click to see all generations")) self.append_text( # translators: leave all/any {...} untranslated ngettext(" have {number_of} individual\n", " have {number_of} individuals\n", len(all)).format(number_of=len(all))) # Set to a fixed font if self.box_mode == "UTF": start, end = self.gui.buffer.get_bounds() self.gui.buffer.apply_tag_by_name("fixed", start, end) self.append_text("", scroll_to="begin")