https://manual.calibre-ebook.com/template_lang.html
In particular, check out the various list functions. For #1, list_difference() can remove entries. Regexes are helpful here.
If it helps to see examples, here's an old version of my #subjects composite.
Code:
program:
tags = $tags;
if
'^(Fiction|Nonfiction|Magazines & Publications)' in $#booktype
then
## Split tags or return an empty
split_tags = re(tags, '\.', ',')
else
split_tags = ''
fi;
## Removing a few unwanteds and sorting
cleaned_tags = list_sort(list_difference(
split_tags,
'[Cleanup], Fiction, Nonfiction, Magazines & Publications, Cultures & Regions, Topics',
','), 0, ',');
## Add 'Omnibus' if applicable
if
'omnibus'
in
$#admintags
then
cleaned_tags = 'Omnibus' & if cleaned_tags then ', ' & cleaned_tags fi
fi;
cleaned_tags
For #3, there really isn't a way to automatically count chapters and any method to do so would probably be fairly unreliable. I use 'Edit ToC' (a bit faster than opening the book), check there, and then manually input.