View Single Post
Old 01-18-2022, 04:32 AM   #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: 12,495
Karma: 8065348
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by Penny_Dreadful View Post
I edited the code a bit so I could use the default rating column and change the colour for each number of stars.



Code:
program: 

     r = $rating;
 

     if r >=#5 then '#2EAB64'
     elif r >=#4 then '#94E4C9'
     elif r >=#3 then '#FE657D'    
     elif r >=#2 then '#FCB2A9'
     elif r >=#1 then '#FEDC78'
 

     fi
FWIW: this template will have better performance because the sequence of comparisons is done in python instead of the template interpreter.
Code:
program:
	first_matching_cmp(
		$rating,
		1.1, '#FEDC78',
		2.1, '#94E4C9',
		3.1, '#FE657D',
		4.1, '#94E4C9',
			 '#2EAB64')
I used 1.1 instead of 1 etc. because the comparisons are 'less than'. I should have made it <= when I added first_matching_cmp() to the template language. Oh well, too late now.
chaley is offline   Reply With Quote