Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Calibre > Library Management

Notices

Reply
 
Thread Tools Search this Thread
Old 06-19-2015, 11:37 AM   #1
lina.w
Junior Member
lina.w began at the beginning.
 
Posts: 8
Karma: 10
Join Date: Jan 2015
Device: none
Plugboard for series numbering (decimals & no decimals)

Hello all!

Before I begin, I just want to let you guys know I'm fairly new to calibre, so please be patient with me.

I have a bunch of books in series where there are novellas. I've been trying to look for a solution to get the numbering to appear as [01.5] if on the 'Series' column in calibre it appears as 1.50.

As of right now, this is what I have on my plugboard now is:
{series}{series_index:0>2s| [|] }{title}
which works just fine if the series numbering has no decimals.

So what if the series does have novellas and I want to use decimals? How would I have to change the plugboard so it changes to the way I want it to? (My guess is I would need to use an 'if statement' & 'regex', but I'm not sure 100% sure.)

Just an example of how I want the books to show up on my Kindle:
SeriesName [01] Title A
SeriesName [01.5] Title B
SeriesName [02] Title C
SeriesName [02.5] Title D
SeriesName [03] Title E

By the way, if I changed my mind and don't want a leading zero, do I just take out '0>2s'?

Thanks in advance!
lina.w is offline   Reply With Quote
Old 06-19-2015, 11:49 AM   #2
eschwartz
Ex-Helpdesk Junkie
eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.
 
eschwartz's Avatar
 
Posts: 19,422
Karma: 85397180
Join Date: Nov 2012
Location: The Beaten Path, USA, Roundworld, This Side of Infinity
Device: Kindle Touch fw5.3.7 (Wifi only)
Use the formatting operator: "4.1f" -- four characters, 2 leading, one decimal, one following the decimal.

0> -- indicates the filler symbol, and that it gets added to the > front.
eschwartz is offline   Reply With Quote
Advert
Old 06-19-2015, 12:46 PM   #3
lina.w
Junior Member
lina.w began at the beginning.
 
Posts: 8
Karma: 10
Join Date: Jan 2015
Device: none
Quote:
Originally Posted by eschwartz View Post
Use the formatting operator: "4.1f" -- four characters, 2 leading, one decimal, one following the decimal.

0> -- indicates the filler symbol, and that it gets added to the > front.
Thanks for the reply! I like the way it formats the series when there are decimal numbers

But would you happen to know how I would change it so that it only formats that way if I have decimal numbers? So numbers like 2.50 would change to 2.5, but numbers like 1, 2, 3, etc. stay like 01, 02, 03?

Sorry if I'm not providing a clear explanation!
lina.w is offline   Reply With Quote
Old 06-19-2015, 01:41 PM   #4
eschwartz
Ex-Helpdesk Junkie
eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.
 
eschwartz's Avatar
 
Posts: 19,422
Karma: 85397180
Join Date: Nov 2012
Location: The Beaten Path, USA, Roundworld, This Side of Infinity
Device: Kindle Touch fw5.3.7 (Wifi only)
I guess you could then regex the number to strip trailing zeroes and periods. But that might require raising the complexity to a General Program Mode template -- I believe formatting comes after functions.

So:

Code:
program:

formatted_series = finish_formatting(
    field('series_index'),
    '4.1f',
    '',
    ''
);
stripped_series = re(
    formatted_series,
    '^ \[(.*)[.0]+\]$',
    ' [\1] '
);

# Add together the final result
strcat(
    field('series'),
    stripped_series,
    field('title')
);
eschwartz is offline   Reply With Quote
Old 06-19-2015, 04:46 PM   #5
lina.w
Junior Member
lina.w began at the beginning.
 
Posts: 8
Karma: 10
Join Date: Jan 2015
Device: none
Quote:
Originally Posted by eschwartz View Post
I guess you could then regex the number to strip trailing zeroes and periods. But that might require raising the complexity to a General Program Mode template -- I believe formatting comes after functions.

So:

Code:
program:

formatted_series = finish_formatting(
    field('series_index'),
    '4.1f',
    '',
    ''
);
stripped_series = re(
    formatted_series,
    '^ \[(.*)[.0]+\]$',
    ' [\1] '
);

# Add together the final result
strcat(
    field('series'),
    stripped_series,
    field('title')
);
Good thing I've learned regex last semester so I can understand what is going on! Hmmm...I've pretty much copied and pasted the code you provided to the template, but this still doesn't change [01.0] to [01].

Do you mind explaining to me what '^ ' and '$' from '^ \[(.*)[.0]+\]$' does? If I remember correctly, ^ means negate? I'm not quite sure what the $ at the end does though.

Also, do we not need to escape the brackets from ' [\1] '?

Sorry for asking so many questions!

Last edited by lina.w; 06-19-2015 at 04:50 PM.
lina.w is offline   Reply With Quote
Advert
Old 06-19-2015, 04:58 PM   #6
Terisa de morgan
Grand Sorcerer
Terisa de morgan ought to be getting tired of karma fortunes by now.Terisa de morgan ought to be getting tired of karma fortunes by now.Terisa de morgan ought to be getting tired of karma fortunes by now.Terisa de morgan ought to be getting tired of karma fortunes by now.Terisa de morgan ought to be getting tired of karma fortunes by now.Terisa de morgan ought to be getting tired of karma fortunes by now.Terisa de morgan ought to be getting tired of karma fortunes by now.Terisa de morgan ought to be getting tired of karma fortunes by now.Terisa de morgan ought to be getting tired of karma fortunes by now.Terisa de morgan ought to be getting tired of karma fortunes by now.Terisa de morgan ought to be getting tired of karma fortunes by now.
 
Terisa de morgan's Avatar
 
Posts: 6,235
Karma: 11768331
Join Date: Jun 2009
Location: Madrid, Spain
Device: Kobo Clara/Aura One/Forma,XiaoMI 5, iPad, Huawei MediaPad, YotaPhone 2
^ out of an expression means beginning of text and $ the end of the text.
Terisa de morgan is offline   Reply With Quote
Old 06-19-2015, 05:10 PM   #7
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: 11,742
Karma: 6997045
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
@eschwartz: the following fragment detects float vs integer. It might eliminate the need to regexp?

Code:
program:
	dex=field('series_index');
	i=format_number(dex, "{:02d}");
	f=format_number(dex, "{:04.1f}");
	isInt=cmp(f, i, '', 'yes', '');
	result=test(isInt, i, f)
chaley is offline   Reply With Quote
Old 06-19-2015, 06:06 PM   #8
eschwartz
Ex-Helpdesk Junkie
eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.
 
eschwartz's Avatar
 
Posts: 19,422
Karma: 85397180
Join Date: Nov 2012
Location: The Beaten Path, USA, Roundworld, This Side of Infinity
Device: Kindle Touch fw5.3.7 (Wifi only)
chaley -- good idea! I haven't really used cmp before, in case you couldn't tell.


lina.w -- pretend I didn't write that. Tested this time.

Code:
program:

formatted_series = finish_formatting(
    field('series_index'),
    '0>4.1f',      #fixed
    ' [',          #fixed
    '] '           #fixed
);
stripped_series = re(
    formatted_series,
    '\.0+',        #fixed
    ''
);

# Add together the final result
strcat(
    field('series'),
    stripped_series,
    field('title')
);
Or as chaley said, because it is semantically correct as opposed to a filthy regex kludge.

Code:
program:

sidx=field('series_index');
i=format_number(sidx, "{:02d}");
f=format_number(sidx, "{:04.1f}");
isInt=cmp(f, i, '', 'yes', '');
final_sidx=finish_formatting(
    test(isInt, i, f),
    '',
    ' [',
    '] '
);

# Add together the final result
strcat(
    field('series'),
    final_sidx,
    field('title')
);

Last edited by eschwartz; 06-19-2015 at 06:12 PM.
eschwartz is offline   Reply With Quote
Old 06-19-2015, 06:10 PM   #9
eschwartz
Ex-Helpdesk Junkie
eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.
 
eschwartz's Avatar
 
Posts: 19,422
Karma: 85397180
Join Date: Nov 2012
Location: The Beaten Path, USA, Roundworld, This Side of Infinity
Device: Kindle Touch fw5.3.7 (Wifi only)
As for your questions about regex, they are fine. As Terisa said, the "^$" are beginning and ending anchors.

Certain characters like [] are reserved in regex and need to be escaped, but only in the pattern match, not the replacement text. Because we cannot replace with a pattern or character set.
eschwartz is offline   Reply With Quote
Old 06-19-2015, 06:42 PM   #10
lina.w
Junior Member
lina.w began at the beginning.
 
Posts: 8
Karma: 10
Join Date: Jan 2015
Device: none
Quote:
Originally Posted by eschwartz View Post
chaley -- good idea! I haven't really used cmp before, in case you couldn't tell.


lina.w -- pretend I didn't write that. Tested this time.

Code:
program:

formatted_series = finish_formatting(
    field('series_index'),
    '0>4.1f',      #fixed
    ' [',          #fixed
    '] '           #fixed
);
stripped_series = re(
    formatted_series,
    '\.0+',        #fixed
    ''
);

# Add together the final result
strcat(
    field('series'),
    stripped_series,
    field('title')
);
Or as chaley said, because it is semantically correct as opposed to a filthy regex kludge.

Code:
program:

sidx=field('series_index');
i=format_number(sidx, "{:02d}");
f=format_number(sidx, "{:04.1f}");
isInt=cmp(f, i, '', 'yes', '');
final_sidx=finish_formatting(
    test(isInt, i, f),
    '',
    ' [',
    '] '
);

# Add together the final result
strcat(
    field('series'),
    final_sidx,
    field('title')
);
It worked, eschwartz!! Thank you for being so patient with me and for all your help! You are the best!!

And thank you Terisa de morgan & chaley for helping out & answering my questions too. You guys are awesome!

* * e d i t e d * *

this is just a minor problem, but now that I've got the formatting the way I want to, I'm just wondering why [01.5] appears before [01]? Say if I have a series with books with the following numberings [01], [02], and [03]. If I have a novella that goes between each, it should be in this order: [01], [01.5], [02], [02.5], [03], but the current order is [01.5], [01], [02.5], [02], [03]. I'm guessing there is no way to work around fixing this, so would my only option to getting the ordering right be going back to the previous formatting method?

Last edited by lina.w; 06-19-2015 at 06:59 PM.
lina.w is offline   Reply With Quote
Old 06-20-2015, 07:46 AM   #11
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: 11,742
Karma: 6997045
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by lina.w View Post
this is just a minor problem, but now that I've got the formatting the way I want to, I'm just wondering why [01.5] appears before [01]?
Because period comes before right bracket in the standard character sort order. You can see the sort order here.
Quote:
I'm guessing there is no way to work around fixing this, so would my only option to getting the ordering right be going back to the previous formatting method?
Try putting a space before the closing bracket. The space character sorts before the period. For consistency you might put a space after the opening bracket.
chaley is offline   Reply With Quote
Old 12-31-2015, 03:41 PM   #12
PapaJohn
Enthusiast
PapaJohn began at the beginning.
 
Posts: 35
Karma: 10
Join Date: Feb 2011
Device: Kindle Paperwhite, Kobo Aura One
I have been following this thread and am totally confused.
Where and how do I input the above mentioned code into Calibre?
Sorry for sounding dumb, but I don't have a clue about programming.
Any help will be greatly appreciated.
PapaJohn is offline   Reply With Quote
Old 12-31-2015, 04:27 PM   #13
eschwartz
Ex-Helpdesk Junkie
eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.
 
eschwartz's Avatar
 
Posts: 19,422
Karma: 85397180
Join Date: Nov 2012
Location: The Beaten Path, USA, Roundworld, This Side of Infinity
Device: Kindle Touch fw5.3.7 (Wifi only)
copy-paste it into a template definition.
custom column or Metadata plugboard, they all use the same language and parser.

If you right-click an input box in the plugboards definitions, it will allow you to open the Template Editor.
eschwartz is offline   Reply With Quote
Old 01-06-2016, 05:14 AM   #14
Morrigu
Junior Member
Morrigu began at the beginning.
 
Posts: 2
Karma: 10
Join Date: Jan 2016
Device: Kindle Paper White
Quote:
Originally Posted by chaley View Post
Because period comes before right bracket in the standard character sort order. You can see the sort order here.

Try putting a space before the closing bracket. The space character sorts before the period. For consistency you might put a space after the opening bracket.
Hello,

Sorry to be dense, I know nothing of programming. I was interested in doing the same thing that the OP but can't figure out where exactly to add the spaces. I've copied the following code into the editor and have tried spaces in different spots but to no avail. (I did break it a couple of times though

To add a space would it also be ' ' ? I didn't want the [ ] that the OP used and wanted a # and I figured out how to do that. Just stuck on this bit.

Thanks for any help!

Code that I inserted:

program:

sidx=field('series_index');
i=format_number(sidx, "{:02d}");
f=format_number(sidx, "{:04.1f}");
isInt=cmp(f, i, '', 'yes', '');
final_sidx=finish_formatting(
test(isInt, i, f),
'',
' #',
' '
);

# Add together the final result
strcat(
field('series'),
final_sidx,
field('title')
);
Morrigu is offline   Reply With Quote
Old 01-20-2016, 09:14 PM   #15
fogice
Groupie
fogice is a glorious beacon of lightfogice is a glorious beacon of lightfogice is a glorious beacon of lightfogice is a glorious beacon of lightfogice is a glorious beacon of lightfogice is a glorious beacon of lightfogice is a glorious beacon of lightfogice is a glorious beacon of lightfogice is a glorious beacon of lightfogice is a glorious beacon of lightfogice is a glorious beacon of light
 
Posts: 156
Karma: 12092
Join Date: May 2014
Device: Kobo Libra 2
This thread is exactly what I was looking for, thank you everyone. But I am stuck in the same place others were; getting the display order correct.
Quote:
Originally Posted by lina.w
this is just a minor problem, but now that I've got the formatting the way I want to, I'm just wondering why [01.5] appears before [01]?
Quote:
Originally Posted by chaley View Post
Because period comes before right bracket in the standard character sort order. You can see the sort order here.
Try putting a space before the closing bracket. The space character sorts before the period. For consistency you might put a space after the opening bracket.
I have tried using ASCII characters that should sort earlier (space, comma, parenthesis) and after (colon, equals, tilde), and the sort order remains the same and incorrect. (I know that I am in a sorted view, because if I change some of the index numbers, the book positions change.)

Has anyone found a way to get them to sort properly?

(I'm using an up-to-date Kindle Voyage, if that makes a difference.)
fogice is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to have 3 decimals Arrow Library Management 3 12-16-2014 07:42 AM
Series Numbering .... GeoffC Library Management 3 05-02-2014 06:11 AM
Series numbering sometimes incorrect DrChiper Library Management 4 01-19-2012 10:56 AM
Kindle Annotations vs Plugboard rename Title with series initials/numbering Gwen Morse Devices 2 09-05-2011 12:58 PM
Series Numbering adrian1944 Calibre 3 10-17-2010 01:59 PM


All times are GMT -4. The time now is 01:40 AM.


MobileRead.com is a privately owned, operated and funded community.