"""Create graph with citation history for record ID_BIBREC (into a
temporary file) and return HTML box refering to that image.
Called by Detailed record pages.
Notes:
if id_bibdoc=0 : its an oustide-stored document and it has no id_bibdoc --> only one line
if len(id_bibdocs) <= cfg_id_bibdoc_id_bibrec draw one line per id_bibdoc
if len(id_bibdocs) > cfg_id_bibdoc_id_bibrec draw only one line which hold simultaneously the downloads for all id_bibdoc
Each time this function is called, all the images older than 10 minutes are deleted.
"""
_=gettext_set_language(ln)
out=""
# Prepare downloads history graph:
ifCFG_BIBRANK_SHOW_DOWNLOAD_GRAPHS:
html_content=""
# remove images older than 10 minutes
remove_old_img("download")
# download count graph
id_bibdocs=intbitset(run_sql("select distinct id_bibdoc from rnkDOWNLOADS where id_bibrec=%s",(id_bibrec,)))
id_existing_bibdocs=intbitset(run_sql("SELECT id_bibdoc FROM bibrec_bibdoc JOIN bibdoc ON id_bibdoc=id WHERE id_bibrec=%s AND status<>'DELETED'",(id_bibrec,)))
## FIXME: when bibdocs are deleted we loose the stats. What shall we do with them?
sql_query="select count(*) from rnkDOWNLOADS where id_bibrec=%s%s and download_time>='%s' and download_time<'%s';"%(id_bibrec,id_bibdoc_query_addition,date1,date2)
res=run_sql(sql_query)[0][0]
list_tuple.append((elem[0],res))
#list_tuple = sort_list_tuple_by_date(list_tuple)
return(list_tuple)
defsort_list_tuple_by_date(list_tuple):
"""Sort a list of tuple of the forme ("09/2004", 3)according to the