Register Guidelines E-Books Search Today's Posts Mark Forums Read

 User Name Remember Me? Password

 05-14-2017, 06:54 PM #1 bttrflii Junior Member   Posts: 9 Karma: 348 Join Date: May 2017 Device: Kindle Voyage Metadata Plugboard Series Numbers I've been using the Metadata Plugboard to include series information when I transfer books from my computer to my Kindle, but I have been unable to figure out how to get books with decimal places in the series information to sort properly because they lack the leading 0. This is probably best shown by example, so... Plugboard template: {series}{series_index:0>2s| |: }{title} Whole-number example on my Kindle: Series-Name 03: Title Another whole-number example: Series-Name 10: Title Decimal-number example on my Kindle: Series-Name 2.50: Title This means of course that 2.50 sorts *after* both the 03 and the 10 because the leading 0 is missing. Is there any way to get the 2.50 to be 02.50 without making 03 and 10 into 03.00 and 10.00? Not all series have the decimal books, and putting decimals in every series would get cluttered. Thanks everyone. :) Edit: Solution given by chaley in post #7. Last edited by bttrflii; 05-16-2017 at 01:12 PM.
05-14-2017, 07:16 PM   #2
jackie_w
Grand Sorcerer

Posts: 5,270
Karma: 12221060
Join Date: Sep 2009
Location: UK
Device: PRS-350, Kobo: Aura6", H2O, GloHD, KA1, ClaraHD, Forma
Quote:
 Originally Posted by bttrflii I've been using the Metadata Plugboard to include series information when I transfer books from my computer to my Kindle, but I have been unable to figure out how to get books with decimal places in the series information to sort properly because they lack the leading 0. This is probably best shown by example, so... Plugboard template: {series}{series_index:0>2s| |: }{title} Whole-number example on my Kindle: Series-Name 03: Title Another whole-number example: Series-Name 10: Title Decimal-number example on my Kindle: Series-Name 2.50: Title This means of course that 2.50 sorts *after* both the 03 and the 10 because the leading 0 is missing. Is there any way to get the 2.50 to be 02.50 without making 03 and 10 into 03.00 and 10.00? Not all series have the decimal books, and putting decimals in every series would get cluttered. Thanks everyone.
You could try something like:
{series}{series_index:0>5.2f| |: }{title}

05-15-2017, 12:09 AM   #3
bttrflii
Junior Member

Posts: 9
Karma: 348
Join Date: May 2017
Device: Kindle Voyage
Quote:
 Originally Posted by jackie_w You could try something like: {series}{series_index:0>5.2f| |: }{title}
Thank you, jackie_w, but unfortunately that turns the 03 and 10 numbers into 03.00 and 10.00, which I would really like to avoid. I'd like to have only the 2.50 change into 02.50 if possible.

05-15-2017, 02:32 AM   #4
theducks
Well trained by Cats

Posts: 24,569
Karma: 34133263
Join Date: Aug 2009
Location: The Central Coast of California
Device: K4NT(RIP), Galaxy Tab A, Kobo Aura2
Quote:
 Originally Posted by bttrflii Thank you, jackie_w, but unfortunately that turns the 03 and 10 numbers into 03.00 and 10.00, which I would really like to avoid. I'd like to have only the 2.50 change into 02.50 if possible.
You don't do it that way and your Kindle (ASCII) sort will be off.
You need the leading 0 for single digit indexes

05-15-2017, 10:59 AM   #5
bttrflii
Junior Member

Posts: 9
Karma: 348
Join Date: May 2017
Device: Kindle Voyage
Quote:
 Originally Posted by theducks You don't do it that way and your Kindle (ASCII) sort will be off. You need the leading 0 for single digit indexes
I can't quite figure out what you're trying to say. I *DO* want the leading zero, and I currently get a leading zero when the series number is a whole number. What I'm asking is how to get a leading zero in front of partial numbers as well, without adding three extra characters (a decimal and two zeroes) to all of the whole numbers.

05-15-2017, 09:50 PM   #6
theducks
Well trained by Cats

Posts: 24,569
Karma: 34133263
Join Date: Aug 2009
Location: The Central Coast of California
Device: K4NT(RIP), Galaxy Tab A, Kobo Aura2
Quote:
 Originally Posted by bttrflii I can't quite figure out what you're trying to say. I *DO* want the leading zero, and I currently get a leading zero when the series number is a whole number. What I'm asking is how to get a leading zero in front of partial numbers as well, without adding three extra characters (a decimal and two zeroes) to all of the whole numbers.
sorry
5.2 means 5 places total 2 digits dot 2 digits
if you need 3 digits to the left: 6.2
if you need 3 digits to the right: 6.3

BTW I use {series_index:0>5.2f|| - }{title} on my K4

(and I discovered the hard way )
-{series_index:0>5.2f|| - }{title} causes a reverse sort

05-16-2017, 04:27 AM   #7
chaley
Grumpy old git

Posts: 9,063
Karma: 2737964
Join Date: Jan 2010
Location: UK
Device: Many android devices
Quote:
 Originally Posted by bttrflii I can't quite figure out what you're trying to say. I *DO* want the leading zero, and I currently get a leading zero when the series number is a whole number. What I'm asking is how to get a leading zero in front of partial numbers as well, without adding three extra characters (a decimal and two zeroes) to all of the whole numbers.
It is possible to do what you want, but it requires making a custom column "Made from other columns" to compute the value.

Make the column and use the following as the template:
Code:
```program:
si = field('series_index');
format = contains(si, '\.', '{0:06.2f}',  '{0:03d}');
format_number(si, format)```
Assuming the lookup name for this new column is #myseries_index, then use {#myseries_index} in the plugboard where you currently use series_index.

05-16-2017, 01:10 PM   #8
bttrflii
Junior Member

Posts: 9
Karma: 348
Join Date: May 2017
Device: Kindle Voyage
Quote:
 Originally Posted by chaley It is possible to do what you want, but it requires making a custom column "Made from other columns" to compute the value.
I'm quite comfortable with custom columns, and your solution is just what I needed. :) I changed the "6.2f" and "3d" to "5.2f" and "2d" respectively since I never have series that make it to 100, but with that minor tweak it's doing exactly what I wanted, and I now have sortable series information in book titles that are sent to my Kindle, and it's done without clutter for those series without decimal places.

Thank you SO MUCH, chaley!!!

05-16-2017, 01:25 PM   #9
chaley
Grumpy old git

Posts: 9,063
Karma: 2737964
Join Date: Jan 2010
Location: UK
Device: Many android devices
Quote:
 Originally Posted by bttrflii I'm quite comfortable with custom columns, and your solution is just what I needed. I changed the "6.2f" and "3d" to "5.2f" and "2d" respectively since I never have series that make it to 100, but with that minor tweak it's doing exactly what I wanted, and I now have sortable series information in book titles that are sent to my Kindle, and it's done without clutter for those series without decimal places. Thank you SO MUCH, chaley!!!
You are welcome.

A note, because I should write this somewhere ...

While working on other calibre stuff today I made a change to the format_date function. The change will appear in calibre V3. Up to now the format_number template had to be enclosed in { } characters, meaning that format_number couldn't be used in Template Program Mode because the TPM template evaluator can't handle sub-templates. That is why I said you needed to use a General Program Mode template.

The change is that if a format template does not contain a { character then it is now assumed to be a number format specification and is treated accordingly. This means that starting with calibre V3, the following will work, eliminating the need for the extra column.
Code:
`{series_index:'format_number(\$, contains(\$, '\.', '06.2f',  '03d'))'}`
Of course, current format_number templates will continue to work.

05-17-2017, 04:11 PM   #10
bttrflii
Junior Member

Posts: 9
Karma: 348
Join Date: May 2017
Device: Kindle Voyage
Quote:
 Originally Posted by chaley [...]This means that starting with calibre V3, the following will work, eliminating the need for the extra column.[...]
That is awesome news! I'm sure others who'd hoped to have more control will appreciate this as much as I do, and I'll be sure to simplify my plugboard once I have calibre v3 installed. :) Thank you once more.

 06-02-2017, 01:27 AM #11 stuckinoh08 Junior Member   Posts: 5 Karma: 10 Join Date: Aug 2012 Device: Kindle Paperwhite So I am looking to do what the OP and sort series correctly with decimals. Currently I am using the following plugboard: Code: `program:no_decimal = template('{series}{series_index:0>2s| | - }{title}');has_decimal = template('{series}{series_index:0>4.1f| | - }{title}');contains(field('series_index'),'\.',has_decimal,no_decimal)` Now, for all intents and purposes this works, except for one small caviat... When sorting a series of decimals, it sorts the whole number last. What I mean by this is this: Series_Name 01 - Title Series_Name 02.1 - Title Series_Name 02.2 - Title Series_Name 02 - Title Series_Name 03 - Title Now this isn't a huge issue, at least they a grouped together, and not 10 books apart, but it is a minor annoyance. I thought I would give Post #7's solution a try and unfortunately, it still sorts in the same manor. Any advice?
06-02-2017, 02:39 AM   #12
theducks
Well trained by Cats

Posts: 24,569
Karma: 34133263
Join Date: Aug 2009
Location: The Central Coast of California
Device: K4NT(RIP), Galaxy Tab A, Kobo Aura2
Quote:
 Originally Posted by stuckinoh08 So I am looking to do what the OP and sort series correctly with decimals. Currently I am using the following plugboard: Code: `program:no_decimal = template('{series}{series_index:0>2s| | - }{title}');has_decimal = template('{series}{series_index:0>4.1f| | - }{title}');contains(field('series_index'),'\.',has_decimal,no_decimal)` Now, for all intents and purposes this works, except for one small caviat... When sorting a series of decimals, it sorts the whole number last. What I mean by this is this: Series_Name 01 - Title Series_Name 02.1 - Title Series_Name 02.2 - Title Series_Name 02 - Title Series_Name 03 - Title Now this isn't a huge issue, at least they a grouped together, and not 10 books apart, but it is a minor annoyance. I thought I would give Post #7's solution a try and unfortunately, it still sorts in the same manor. Any advice?
This is on the device?
ASCII sort rules usually prevail The shorter string version ( without the .# )should be first

I know (the hard way ) the Kindle treats a - before a number as a minus, so you get a descending order -5, -4,-3,-2..

06-03-2017, 01:21 AM   #13
stuckinoh08
Junior Member

Posts: 5
Karma: 10
Join Date: Aug 2012
Device: Kindle Paperwhite
Quote:
 Originally Posted by theducks This is on the device? ASCII sort rules usually prevail The shorter string version ( without the .# )should be first I know (the hard way ) the Kindle treats a - before a number as a minus, so you get a descending order -5, -4,-3,-2..

This issue is on the device (Paperwhite). If I plug the same template into a custom column, the sorting is done correctly. In regards to your comment about '-' preceding a number, that makes sense. However the '-', in this case, comes after the number so it should have no such effect. Would you suggest swapping out for a ':' to be safe? For what it's worth, when I used #7's fix, I used ':' and ended up with the same issue.

I considered the possibility that the error arises from the fact that the whole number values aren't followed by '.0'. I can manually test this, but seems odd.

Thoughts?

06-03-2017, 11:37 AM   #14
theducks
Well trained by Cats

Posts: 24,569
Karma: 34133263
Join Date: Aug 2009
Location: The Central Coast of California
Device: K4NT(RIP), Galaxy Tab A, Kobo Aura2
Quote:
 Originally Posted by stuckinoh08 More info: This issue is on the device (Paperwhite). If I plug the same template into a custom column, the sorting is done correctly. In regards to your comment about '-' preceding a number, that makes sense. However the '-', in this case, comes after the number so it should have no such effect. Would you suggest swapping out for a ':' to be safe? For what it's worth, when I used #7's fix, I used ':' and ended up with the same issue. I considered the possibility that the error arises from the fact that the whole number values aren't followed by '.0'. I can manually test this, but seems odd. Thoughts?
I use "Collections" for my Series name, and place the series_index before the Title. using the plugboard. (including the series was just too long for my K4NT screen)
Code:
`{series_index:0>5.2f|| - }{title}`
10.00 - Title
Not optimal, but it fits on the screen

01-18-2020, 10:20 PM   #15
wildfire070
Junior Member

Posts: 3
Karma: 10
Join Date: May 2012
Device: Kindle Voyage
Quote:
 Originally Posted by chaley It is possible to do what you want, but it requires making a custom column "Made from other columns" to compute the value. Make the column and use the following as the template: Code: ```program: si = field('series_index'); format = contains(si, '\.', '{0:06.2f}', '{0:03d}'); format_number(si, format)``` Assuming the lookup name for this new column is #myseries_index, then use {#myseries_index} in the plugboard where you currently use series_index.
Can somebody walk me through how to implement this? I'm new to customizing Calibre and not sure where to start. Thanks!