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 05-04-2014, 08:36 AM   #1
Tanjamuse
Wizard
Tanjamuse , Klaatu Barada Niktu!Tanjamuse , Klaatu Barada Niktu!Tanjamuse , Klaatu Barada Niktu!Tanjamuse , Klaatu Barada Niktu!Tanjamuse , Klaatu Barada Niktu!Tanjamuse , Klaatu Barada Niktu!Tanjamuse , Klaatu Barada Niktu!Tanjamuse , Klaatu Barada Niktu!Tanjamuse , Klaatu Barada Niktu!Tanjamuse , Klaatu Barada Niktu!Tanjamuse , Klaatu Barada Niktu!
 
Posts: 1,327
Karma: 5306
Join Date: Jan 2014
Device: none
Custom Column with word count index

Hi.

I need help to create a custom column for my fanfiction, based on word count and category. Like below 1000 words would be a short story, from 1000 to 5000 would be a novel, 5000 to 20000 would be a medium and 20000 to 50000 would be long and +50000 would be an epic.

I hope this makes sense, and that someone might know how to make that custom column and can guide me through it

Thanks
Tanjamuse is offline   Reply With Quote
Old 05-04-2014, 09:22 AM   #2
davidfor
Grand Sorcerer
davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.
 
Posts: 24,907
Karma: 47303748
Join Date: Jul 2011
Location: Sydney, Australia
Device: Kobo:Touch,Glo, AuraH2O, GloHD,AuraONE, ClaraHD, Libra H2O; tolinoepos
I have a custom column that does a similar thing with the following code in it:
Code:
program: 
words=raw_field('#words');
shelf_name=cmp(words, 7500, 'Short Story', 'Novelette', 'Novelette');
shelf_name=cmp(words, 17500, shelf_name, 'Novella', 'Novella');
shelf_name=cmp(words, 40000, shelf_name, 'Novel', 'Novel');
The "cmp" lines compare the value of "words" with the number and return the first value if there are less words, the second if the are the same and third if there more.

You can change the word count to test against and the text to be used to match what you want. As you have four ranges, you will want to add an extra line.
davidfor is offline   Reply With Quote
Advert
Old 05-04-2014, 09:22 AM   #3
Tanjamuse
Wizard
Tanjamuse , Klaatu Barada Niktu!Tanjamuse , Klaatu Barada Niktu!Tanjamuse , Klaatu Barada Niktu!Tanjamuse , Klaatu Barada Niktu!Tanjamuse , Klaatu Barada Niktu!Tanjamuse , Klaatu Barada Niktu!Tanjamuse , Klaatu Barada Niktu!Tanjamuse , Klaatu Barada Niktu!Tanjamuse , Klaatu Barada Niktu!Tanjamuse , Klaatu Barada Niktu!Tanjamuse , Klaatu Barada Niktu!
 
Posts: 1,327
Karma: 5306
Join Date: Jan 2014
Device: none
Where do I put it in and how ... I need some more guidance
Tanjamuse is offline   Reply With Quote
Old 05-04-2014, 09:30 AM   #4
davidfor
Grand Sorcerer
davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.
 
Posts: 24,907
Karma: 47303748
Join Date: Jul 2011
Location: Sydney, Australia
Device: Kobo:Touch,Glo, AuraH2O, GloHD,AuraONE, ClaraHD, Libra H2O; tolinoepos
You need to add a custom column like you did for the word count. The column type for it is "Column built from other columns". When you select this type, there will be another field called "Template". The template code goes into this field.

I forgot to say that the "#words" in the second line needs to be replaced with the lookup name for you word count column.
davidfor is offline   Reply With Quote
Old 05-04-2014, 09:31 AM   #5
Tanjamuse
Wizard
Tanjamuse , Klaatu Barada Niktu!Tanjamuse , Klaatu Barada Niktu!Tanjamuse , Klaatu Barada Niktu!Tanjamuse , Klaatu Barada Niktu!Tanjamuse , Klaatu Barada Niktu!Tanjamuse , Klaatu Barada Niktu!Tanjamuse , Klaatu Barada Niktu!Tanjamuse , Klaatu Barada Niktu!Tanjamuse , Klaatu Barada Niktu!Tanjamuse , Klaatu Barada Niktu!Tanjamuse , Klaatu Barada Niktu!
 
Posts: 1,327
Karma: 5306
Join Date: Jan 2014
Device: none
I'll give it a try and then return

Thanks for the quick help ...
Tanjamuse is offline   Reply With Quote
Advert
Old 05-04-2014, 09:38 AM   #6
Tanjamuse
Wizard
Tanjamuse , Klaatu Barada Niktu!Tanjamuse , Klaatu Barada Niktu!Tanjamuse , Klaatu Barada Niktu!Tanjamuse , Klaatu Barada Niktu!Tanjamuse , Klaatu Barada Niktu!Tanjamuse , Klaatu Barada Niktu!Tanjamuse , Klaatu Barada Niktu!Tanjamuse , Klaatu Barada Niktu!Tanjamuse , Klaatu Barada Niktu!Tanjamuse , Klaatu Barada Niktu!Tanjamuse , Klaatu Barada Niktu!
 
Posts: 1,327
Karma: 5306
Join Date: Jan 2014
Device: none
is this the correct way:

Quote:
program:
words=raw_field('#words');
shelf_name=cmp(words, 1000, 'Short Story', 'Novelette', 'Novelette');
shelf_name=cmp(words, 5000, 'Novel', 'Novella', 'Novella');
shelf_name=cmp(words, 20000, 'Medium', 'Novel', 'Novel'); shelf_name=cmp(words, 40000, 'Long', 'Novel', 'Novel'); shelf_name=cmp(words, 100000, 'Epic', 'Novel', 'Novel');
Tanjamuse is offline   Reply With Quote
Old 05-04-2014, 09:54 AM   #7
PeterT
Grand Sorcerer
PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.
 
PeterT's Avatar
 
Posts: 12,168
Karma: 73448616
Join Date: Nov 2007
Location: Toronto
Device: Nexus 7, Clara, Touch, Tolino EPOS
try
Code:
program:
words=raw_field('#words');
shelf_name=cmp(words, 1000, 'Short Story', 'Novel', 'Novel');
shelf_name=cmp(words, 5000, shelf_name, 'Medium', 'Medium');
shelf_name=cmp(words, 20000, shelf_name, 'Long', 'Long');
shelf_name=cmp(words, 50000, shelf_name, 'Epic', 'Epic');
The idea is
If the words are < 1000 then use Short Story else Novel
If the words are < 5000 then use the already set name (either Short Story or Novel) else use Medium
If the words are < 20000 then use the already set name (either Short Story, Novel or Medium) else use Long
If the words are < 50000 then use the already set name (either Short Story, Novel, Medium or Long) else use Epic

Last edited by PeterT; 05-04-2014 at 10:04 AM.
PeterT is offline   Reply With Quote
Old 05-04-2014, 09:57 AM   #8
Tanjamuse
Wizard
Tanjamuse , Klaatu Barada Niktu!Tanjamuse , Klaatu Barada Niktu!Tanjamuse , Klaatu Barada Niktu!Tanjamuse , Klaatu Barada Niktu!Tanjamuse , Klaatu Barada Niktu!Tanjamuse , Klaatu Barada Niktu!Tanjamuse , Klaatu Barada Niktu!Tanjamuse , Klaatu Barada Niktu!Tanjamuse , Klaatu Barada Niktu!Tanjamuse , Klaatu Barada Niktu!Tanjamuse , Klaatu Barada Niktu!
 
Posts: 1,327
Karma: 5306
Join Date: Jan 2014
Device: none
Would it be possible to make the epic more than 75.000 words and then the 50.000 long and 5000 novel?
Tanjamuse is offline   Reply With Quote
Old 05-04-2014, 10:10 AM   #9
PeterT
Grand Sorcerer
PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.
 
PeterT's Avatar
 
Posts: 12,168
Karma: 73448616
Join Date: Nov 2007
Location: Toronto
Device: Nexus 7, Clara, Touch, Tolino EPOS
One additional idea might be for those books with no word count
Code:
program:
words=raw_field('#words');
shelf_name=cmp(words, 0, 'No Word Count', 'No Word Count', 'Short Story');
shelf_name=cmp(words, 1000, shelf_name, 'Novel', 'Novel');
shelf_name=cmp(words, 5000, shelf_name, 'Medium', 'Medium');
shelf_name=cmp(words, 20000, shelf_name, 'Long', 'Long');
shelf_name=cmp(words, 50000, shelf_name, 'Epic', 'Epic');
PeterT is offline   Reply With Quote
Old 05-04-2014, 10:14 AM   #10
Tanjamuse
Wizard
Tanjamuse , Klaatu Barada Niktu!Tanjamuse , Klaatu Barada Niktu!Tanjamuse , Klaatu Barada Niktu!Tanjamuse , Klaatu Barada Niktu!Tanjamuse , Klaatu Barada Niktu!Tanjamuse , Klaatu Barada Niktu!Tanjamuse , Klaatu Barada Niktu!Tanjamuse , Klaatu Barada Niktu!Tanjamuse , Klaatu Barada Niktu!Tanjamuse , Klaatu Barada Niktu!Tanjamuse , Klaatu Barada Niktu!
 
Posts: 1,327
Karma: 5306
Join Date: Jan 2014
Device: none
Then, isn't this correct?
Quote:
program:
words=raw_field('#words');
shelf_name=cmp(words, 1000, 'Short Story', 'Novel', 'Novel');
shelf_name=cmp(words, 5000, shelf_name, 'Novel', 'Novel');
shelf_name=cmp(words, 10000, shelf_name, 'medium', 'medium');
shelf_name=cmp(words, 20000, shelf_name, 'Long', 'Long');
shelf_name=cmp(words, 50000, shelf_name, 'Epic', 'Epic');
Tanjamuse is offline   Reply With Quote
Old 05-04-2014, 10:15 AM   #11
davidfor
Grand Sorcerer
davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.
 
Posts: 24,907
Karma: 47303748
Join Date: Jul 2011
Location: Sydney, Australia
Device: Kobo:Touch,Glo, AuraH2O, GloHD,AuraONE, ClaraHD, Libra H2O; tolinoepos
PeterT and I are cross posting here. But...

You can set the word counts and descriptions to whatever you want. But, I would suggest starting with the set I posted first. I did what you are doing some time ago and these are what I found to be the generally accepted counts for the different lengths. But, adding a "Long novel" or "Epic" makes sense.

Doing that would put it something like.

Code:
program: 
words=raw_field('#words');
shelf_name=cmp(words, 7500, 'Short Story', 'Novelette', 'Novelette');
shelf_name=cmp(words, 17500, shelf_name, 'Novella', 'Novella');
shelf_name=cmp(words, 40000, shelf_name, 'Novel', 'Novel');
shelf_name=cmp(words, 50000, shelf_name, 'Long', 'Long');
shelf_name=cmp(words, 75000, shelf_name, 'Epic', 'Epic');
And to explain how this works:

Code:
shelf_name=cmp(words, 1000, 'Short Story', 'Novel', 'Novel');
That says, if the number of words is less than 1000, set shelf_name to 'Short Story'. If the number of words is equal to 1000 or greater than 1000, set shelf_name to 'Novel'.

Then
Code:
shelf_name=cmp(words, 5000, shelf_name, 'Medium', 'Medium');
says, if the number of words is less than 5000, set shelf_name to whatever the variable shelf_name already is. That means use whatever it was set to in the previous line. But, if the number of words is equal to 5000 or greater than 5000, set shelf_name to 'Medium'.

The following lines repeat this pattern. The column will display the result of the last line of code.

That means I could add an extra line at the end for all the likes of Tolkein and George RR Martin:

Code:
shelf_name=cmp(words, 200000, shelf_name, 'Far to long Fantasy Novel', 'Far to long Fantasy Novel');
davidfor is offline   Reply With Quote
Old 05-04-2014, 10:23 AM   #12
Tanjamuse
Wizard
Tanjamuse , Klaatu Barada Niktu!Tanjamuse , Klaatu Barada Niktu!Tanjamuse , Klaatu Barada Niktu!Tanjamuse , Klaatu Barada Niktu!Tanjamuse , Klaatu Barada Niktu!Tanjamuse , Klaatu Barada Niktu!Tanjamuse , Klaatu Barada Niktu!Tanjamuse , Klaatu Barada Niktu!Tanjamuse , Klaatu Barada Niktu!Tanjamuse , Klaatu Barada Niktu!Tanjamuse , Klaatu Barada Niktu!
 
Posts: 1,327
Karma: 5306
Join Date: Jan 2014
Device: none
Since I use Calibre mostly to fanfiction, wouldn't it be okay with the code I posted above?
Tanjamuse is offline   Reply With Quote
Old 05-04-2014, 02:27 PM   #13
PeterT
Grand Sorcerer
PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.
 
PeterT's Avatar
 
Posts: 12,168
Karma: 73448616
Join Date: Nov 2007
Location: Toronto
Device: Nexus 7, Clara, Touch, Tolino EPOS
Possibly a slightly "cleaner" way of coding this might be
Code:
program: 
words=raw_field('#words');
shelf_name='Short Story';
shelf_name=cmp(words, 7500, shelf_name, 'Novelette', 'Novelette');
shelf_name=cmp(words, 17500, shelf_name, 'Novella', 'Novella');
shelf_name=cmp(words, 40000, shelf_name, 'Novel', 'Novel');
shelf_name=cmp(words, 50000, shelf_name, 'Long', 'Long');
shelf_name=cmp(words, 75000, shelf_name, 'Epic', 'Epic');
The major difference here is that all the calls to cmp are coded the same way;
shelf_name=cmp(word, number, shelf_name, 'Name to Use', 'Name to Use');
where number is the upper limit on the PREVIOUS book's length
and Name to Use is the name to assign to books LONGER than number words long.
PeterT is offline   Reply With Quote
Old 05-04-2014, 02:53 PM   #14
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
Somewhat

Over the years I have seen several posts that talk about doing sequences of compares. I have considered adding a new template function to make this easier. Two questions:
1) exactly what to do? and
2) would anyone use it?

As for what to do, I see two choices. The first would be a function like first_non_empty, but doing a compare. Something like
Code:
first_matching_compare(v, lt1, val1, lt2, val2, ..., elseval)
Example:
Code:
first_matching_compare(words, 7500, 'Short Story', 17500, 'Novella', 40000, 'Novel', 'Long')
The second would be something like
Code:
first_matching_compare(v, gt_eq1, lt1, val1, gt_eq2, lt2, val2, ..., elseval)
This one would check the ranges until it found a match. Example:
Code:
first_matching_compare(words, 0, 7500, 'Short Story', 17500, 40000, 'Novel', 7500, 17500, 'Novella', 'Long')
The advantage of the second is that the values do not need to be in ascending order. The disadvantage is that it requires more typing and might in fact be more confusing.

Which of these two is better?

Would anyone use either of them?
chaley is offline   Reply With Quote
Old 05-05-2014, 05:53 AM   #15
davidfor
Grand Sorcerer
davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.
 
Posts: 24,907
Karma: 47303748
Join Date: Jul 2011
Location: Sydney, Australia
Device: Kobo:Touch,Glo, AuraH2O, GloHD,AuraONE, ClaraHD, Libra H2O; tolinoepos
chaley: I like it. My vote goes for the first version. The second version is a lot more flexible, but I think the first is much simpler to read and understand. With the second I know I would mess up the arguments and spend hours trying to sort out. And if I didn't put them in order, I would miss a range somewhere.

I sort of like the idea of having it as:

Code:
first_matching_compare(v, val1, lt1, val2, lt2,  ..., ltn, elseval)
That reads to me as: val1 if v<lt1, val2 if lt1<=v<lt2, val3 if lt2<=v<lt3 and so on until elseval if v>=ltn. But, I think that would be inconsistent with the other template functions.
davidfor is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Custom column returns value based on value of another custom column? calvin-c Calibre 3 09-14-2013 02:24 PM
Custom yes/no column built from long text column Philantrop Library Management 7 03-23-2013 07:44 PM
how to move value(s) of tag column to a custom made column zoorakhan Library Management 0 12-08-2012 03:53 AM
custom column: count number of characters (in book path) miquele Library Management 25 09-21-2012 01:54 PM
custom date column from two state column Dopedangel Library Management 7 01-03-2012 08:20 AM


All times are GMT -4. The time now is 07:11 AM.


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