![]() |
#1 |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 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 |
![]() |
![]() |
![]() |
#2 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 24,905
Karma: 47303824
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'); 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. |
![]() |
![]() |
Advert | |
|
![]() |
#3 |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,327
Karma: 5306
Join Date: Jan 2014
Device: none
|
Where do I put it in and how ... I need some more guidance
![]() |
![]() |
![]() |
![]() |
#4 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 24,905
Karma: 47303824
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. |
![]() |
![]() |
![]() |
#5 |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 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 ... |
![]() |
![]() |
Advert | |
|
![]() |
#6 | |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,327
Karma: 5306
Join Date: Jan 2014
Device: none
|
is this the correct way:
Quote:
|
|
![]() |
![]() |
![]() |
#7 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 13,309
Karma: 78876004
Join Date: Nov 2007
Location: Toronto
Device: Libra H2O, Libra Colour
|
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'); 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. |
![]() |
![]() |
![]() |
#8 |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 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?
|
![]() |
![]() |
![]() |
#9 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 13,309
Karma: 78876004
Join Date: Nov 2007
Location: Toronto
Device: Libra H2O, Libra Colour
|
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'); |
![]() |
![]() |
![]() |
#10 | |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,327
Karma: 5306
Join Date: Jan 2014
Device: none
|
Then, isn't this correct?
Quote:
|
|
![]() |
![]() |
![]() |
#11 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 24,905
Karma: 47303824
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'); Code:
shelf_name=cmp(words, 1000, 'Short Story', 'Novel', 'Novel'); Then Code:
shelf_name=cmp(words, 5000, shelf_name, 'Medium', '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'); |
![]() |
![]() |
![]() |
#12 |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 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?
|
![]() |
![]() |
![]() |
#13 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 13,309
Karma: 78876004
Join Date: Nov 2007
Location: Toronto
Device: Libra H2O, Libra Colour
|
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'); 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. |
![]() |
![]() |
![]() |
#14 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,336
Karma: 8012652
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) Code:
first_matching_compare(words, 7500, 'Short Story', 17500, 'Novella', 40000, 'Novel', 'Long') Code:
first_matching_compare(v, gt_eq1, lt1, val1, gt_eq2, lt2, val2, ..., elseval) Code:
first_matching_compare(words, 0, 7500, 'Short Story', 17500, 40000, 'Novel', 7500, 17500, 'Novella', 'Long') Which of these two is better? Would anyone use either of them? |
![]() |
![]() |
![]() |
#15 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 24,905
Karma: 47303824
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) |
![]() |
![]() |
![]() |
|
![]() |
||||
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 |