Add n_anthaver and r_anthaver modes to custom_columns_settings for averaging metadata for anthologies before setting in integer and float calibre custom columns.

This commit is contained in:
Jim Miller 2016-07-12 14:53:18 -05:00
parent 2a25aef7ac
commit 288f12afed
2 changed files with 22 additions and 3 deletions

View file

@ -1958,14 +1958,17 @@ class FanFicFarePlugin(InterfaceAction):
configuration = None
if prefs['allow_custcol_from_ini']:
configuration = get_fff_config(book['url'],options['fileform'])
# meta => custcol[,a|n|r]
# meta => custcol[,a|n|r|n_anthaver,r_anthaver]
# cliches=>\#acolumn,r
for line in configuration.getConfig('custom_columns_settings').splitlines():
if "=>" in line:
(meta,custcol) = map( lambda x: x.strip(), line.split("=>") )
flag='r'
anthaver=False
if "," in custcol:
(custcol,flag) = map( lambda x: x.strip(), custcol.split(",") )
anthaver = 'anthaver' in flag
flag=flag[0] # first char only.
if meta not in book['all_metadata']:
# if double quoted, use as a literal value.
@ -1987,8 +1990,15 @@ class FanFicFarePlugin(InterfaceAction):
if flag == 'r' or (flag == 'n' and book['added']):
if coldef['datatype'] in ('int','float'): # for favs, etc--site specific metadata.
if 'anthology_meta_list' in book and meta in book['anthology_meta_list']:
# re-split list, strip commas, convert to floats, sum up.
val = sum([ float(x.replace(",","")) for x in val.split(", ") ])
# re-split list, strip commas, convert to floats
items = [ float(x.replace(",","")) for x in val.split(", ") ]
if anthaver:
if items:
val = sum(items) / float(len(items))
else:
val = 0
else:
val = sum(items)
else:
val = unicode(val).replace(",","")
else:

View file

@ -1008,15 +1008,24 @@ cliches_label:Character Cliches
## 'mode'. 'r' to Replace any existing values, 'a' to Add to existing
## value (use with tag-like columns), and 'n' for setting on New books
## only. (Default is 'r'.)
## Literal strings can be set into custom columns using double quotes.
## Each metadata=>column mapping must be on a separate line and each
## needs to have one space at the start of each line.
## 'r_anthaver' and 'n_anthaver' can be used to indicate the same as
## 'r' and 'n' for normal downloads, but to average the metadata for
## the differents story in an anthology before setting in integer and
## float type custom columns. This can be useful for a rating column,
## for example. Default is to sum the values of all stories, and
## numChapters and numWords are always summed.
#custom_columns_settings:
# cliches=>#acolumn
# themes=>#bcolumn,a
# timeline=>#ccolumn,n
# "FanFiction"=>#collection
# rating=>#rating,r_anthaver
[efiction.esteliel.de]
## Site dedicated to these categories/characters/ships