From: Benny M. <ben...@gm...> - 2013-05-11 08:15:26
|
plist = self.database.get_person_handles(sort_handles=True) 2013/4/30 Matthias Basler <mat...@ea...> > Hi all, > > I've been successfully playing around with a custom report and have it > customized to my needs. However one problem remains: Whenever I choose more > than one person, the order of the people in the report follows a pattern > that I cannot make sense of. > > I believe the order I get is: > 1. Main person is the first one (if included in report) > 2. The rest is sorted alphabetically by family name > 3. Within a family name I could not identify any real sorting (neither > forename nor ID nor age or anything). > > For example, if I print a report about my family it starts with me, then > one sibling, then my mother, then my father, then another sibling. Doesn't > make sense to me. > > I can see that the individual complete report uses following lines to get > the people list: > plist = self.database.get_person_handles(sort_handles=True) > > My questions are: > 1. What are the rules of the default sorting mechanism? > We store stuff in a nosql type of database. The values you obtain are from a btree, so as stored in the database, not usefull to display like that. > 2. Can I influence the sorting mechanism, f.e. by changing the above call? > sort_handles=True sorts on handles, but that is useless also. If you want sorting from the database, you need to access the people via the surname table, but there are no exposed APIs for that now. As Gramps starts with long lists of which people select pieces, access is now based on obtaining the entire list, then sorting in the code as it is needed. So that is what you need to do also. We should however provide some faster name based sorted access. For every access like that, we need to construct secondary indexes though in the database, which is overhead we only want to add if really needed. Fast sorted access via the surname tables should be not to difficult to create though... Anyway, for now, use the fast access, so plist = self.database.get_person_handles(sort_handles=True) is not ok, you obtain the entire database, sort happened in code, then returns data sorted in a way you do not need. Doing plist = self.database.get_person_handles(sort_handles=False) only transverses the database. You then use plist for your own use. Faster still is with a cursor with self.database.get_person_cursor as cursor: for key, data in cursor: person = Person.unserialize(data) # select what to do with this person, determine your own sorting Whatever you do, with the current access in Gramps, you will tranverse all people in the database. Don't worry about that though, because it is fast, it has always been done like that. Benny 3. Is there an option somewhere in Gramps (which I have so far overlooked) > which allows a user to customize the sorting application-wide for all > reports? > > If the above fails I could try to write my own sorting algorithm and apply > it afterwards to the list I get from the above call. But I see this as a > last resort. > > Matthias Basler > mat...@ea... > > > ------------------------------------------------------------------------------ > Introducing AppDynamics Lite, a free troubleshooting tool for Java/.NET > Get 100% visibility into your production application - at no cost. > Code-level diagnostics for performance bottlenecks with <2% overhead > Download for free and get started troubleshooting in minutes. > http://p.sf.net/sfu/appdyn_d2d_ap1 > _______________________________________________ > Gramps-devel mailing list > Gra...@li... > https://lists.sourceforge.net/lists/listinfo/gramps-devel > |