Thread: size column
View Single Post
Old 09-29-2011, 12:00 PM   #3
chaley
Grand Sorcerer
chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.
 
Posts: 12,451
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
You can get a list of the formats with their sizes using a composite custom column (column built from other columns) with the template {:'formats_sizes()'}

You can get the sum of the sizes in one of two ways.
  • The most efficient would be to write a custom template function (preferences, advanced, template functions) that sums the values returned by format_sizes. The function would be something like
    Code:
    Function name: mySum
    Arg count: 1
    Program code:
    def evaluate(self, formatter, kwargs, mi, locals, x):
    	r = 0
    	if x.strip():
    		for p in x.split(','):
    			v = p.split(':')[1]
    			r += long(v)
    	return unicode(r)
    Then you would use this function in a composite column with the template
    Code:
    {:'mySum(formats_sizes())'}
    or perhaps
    Code:
    {:'human_readable(mySum(formats_sizes()))'}
  • Easier if you are not a python programmer but definitely more of a bother to do would be to make a composite custom column containing a variant of the following template:
    Code:
    program: 
    	fs = formats_sizes();
    	v = select(fs, 'PRC');
    	v = add(v, select(fs, 'EPUB'));
    	v = add(v, select(fs, 'MOBI'));
    	v = add(v, select(fs, 'TXT'));
    	v = add(v, select(fs, 'LIT'));
    	v = format_number(v, '{0:5.0f}');
    	human_readable(v)
    Duplicate the v = add... line as many times as necessary to include all the formats of interest.
chaley is offline   Reply With Quote