def create_citation_history_graph_and_box(recid, ln=CFG_SITE_LANG):
    """Create graph with citation history for record RECID (into a
       temporary file) and return HTML box refering to that image.
       Called by Detailed record pages.
    """

    _ = gettext_set_language(ln)

    html_result = ""
    if cfg_bibrank_print_citation_history:
        coordinates = calculate_citation_history_coordinates(recid)
        if coordinates:
            html_head = """<br /><table><tr><td class="blocknote">%s</td></tr></table>""" % _("Citation history:")
            graphe_file_name = 'citation_%s_stats.png' % str(recid)
            remove_old_img(graphe_file_name)
            years = calculate_citation_graphe_x_coordinates(recid)
            years.sort()
            datas_info = write_coordinates_in_tmp_file([coordinates])
            graphe = create_temporary_image(recid, 'citation', datas_info[0], 'Year', 'Times cited', [0,0], datas_info[1], [], ' ', years)
            graphe_image = graphe[0]
            graphe_source_file = graphe[1]
            if graphe_image and graphe_source_file:
                if os.path.exists(graphe_source_file):
                    os.unlink(datas_info[0])
                    html_graphe_code = """<p>%s"""% html_command(graphe_image)
                html_result = html_head + html_graphe_code
    return html_result
Exemplo n.º 2
0
def create_citation_history_graph_and_box(recid, ln=CFG_SITE_LANG):
    """Create graph with citation history for record RECID (into a
       temporary file) and return HTML box refering to that image.
       Called by Detailed record pages.
    """

    _ = gettext_set_language(ln)

    html_result = ""
    if cfg_bibrank_print_citation_history:
        coordinates = calculate_citation_history_coordinates(recid)
        if coordinates:
            html_head = """<br /><table><tr><td class="blocknote">%s</td></tr></table>""" % _(
                "Citation history:")
            graphe_file_name = 'citation_%s_stats.png' % str(recid)
            remove_old_img(graphe_file_name)
            years = calculate_citation_graphe_x_coordinates(recid)
            years.sort()
            datas_info = write_coordinates_in_tmp_file([coordinates])
            graphe = create_temporary_image(recid, 'citation', datas_info[0],
                                            'Year', 'Times cited', [0, 0],
                                            datas_info[1], [], ' ', years)
            graphe_image = graphe[0]
            graphe_source_file = graphe[1]
            if graphe_image and graphe_source_file:
                if os.path.exists(graphe_source_file):
                    os.unlink(datas_info[0])
                    html_graphe_code = """<p>%s""" % html_command(graphe_image)
                html_result = html_head + html_graphe_code
    return html_result
def create_download_history_graph_and_box(id_bibrec, ln=CFG_SITE_LANG):
    """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:
    if CFG_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?
        id_bibdocs &= id_existing_bibdocs

        history_analysis_results = ()
        if not id_bibdocs:
            pass
        elif len(id_bibdocs) <= CFG_ID_BIBDOC_ID_BIBREC and 0 not in id_bibdocs:
            history_analysis_results = draw_downloads_statistics(id_bibrec, list(id_bibdocs))
        else:
            history_analysis_results = draw_downloads_statistics(id_bibrec, [])
        if history_analysis_results and history_analysis_results[0]:
            graph_path = history_analysis_results[0][history_analysis_results[0].rfind('/')+1:]
            if CFG_BIBRANK_SHOW_DOWNLOAD_GRAPHS == 2:
                graph_file_history = CFG_WEBDIR + "/img/" + graph_path
                html_content += """<tr><td valign=center align=center>%s</td>""" % open(graph_file_history).read()
            else:  # gnuplot
                graph_file_history = CFG_SITE_URL + "/img/" + graph_path
                html_content += """<tr><td valign=center align=center><img src='%s'/></td>""" % graph_file_history
            file_to_close_history = history_analysis_results[1]
            if file_to_close_history :
                if os.path.exists(file_to_close_history):
                    os.unlink(file_to_close_history)
        if html_content != "":
            out += """<br/><br/><table><tr><td class="blocknote">
                      %s</td></tr><tr><td>
                      <table border="0" cellspacing="1" cellpadding="1">""" % _("Download history:")
            out += html_content + "</table></td></tr></table>"

    if CFG_BIBRANK_SHOW_DOWNLOAD_GRAPHS_CLIENT_IP_DISTRIBUTION:
        # do we show also user IP repartition?
        html_content = ""
        remove_old_img("download")
        #Users analysis graph
        ips = database_tuples_to_single_list(run_sql("select client_host from rnkDOWNLOADS where id_bibrec=%s;" % id_bibrec))
        if ips:
            users_analysis_results = create_users_analysis_graph(id_bibrec, ips)
            if users_analysis_results[0]:
                file_to_close_users = users_analysis_results[1]
                if CFG_BIBRANK_SHOW_DOWNLOAD_GRAPHS_CLIENT_IP_DISTRIBUTION == 1:
                    html_content += """<tr><td valign=center align=center><img src='%s/img/%s' align="center" alt=""></td>""" % (CFG_SITE_URL, users_analysis_results[0])
                elif CFG_BIBRANK_SHOW_DOWNLOAD_GRAPHS_CLIENT_IP_DISTRIBUTION == 2:
                    html_content += """<tr><td valign=center align=center>%s</td>""" % open(CFG_WEBDIR + "/img/"  + users_analysis_results[0]).read()
                if file_to_close_users:
                    if os.path.exists(file_to_close_users):
                        os.unlink(file_to_close_users)
        if html_content != "":
            out += """<br/><br/><table><tr><td class="blocknote">
                      %s</td></tr><tr><td>
                      <table border="0" cellspacing="1" cellpadding="1">""" % _("Download user distribution:")
            out += html_content
            out += "</table></td></tr></table>"

    # return html code used by get_file or search_engine
    return out
def create_download_history_graph_and_box(id_bibrec, ln=CFG_SITE_LANG):
    """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:
    if CFG_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?
        id_bibdocs &= id_existing_bibdocs

        history_analysis_results = ()
        if not id_bibdocs:
            pass
        elif len(
                id_bibdocs) <= CFG_ID_BIBDOC_ID_BIBREC and 0 not in id_bibdocs:
            history_analysis_results = draw_downloads_statistics(
                id_bibrec, list(id_bibdocs))
        else:
            history_analysis_results = draw_downloads_statistics(id_bibrec, [])
        if history_analysis_results and history_analysis_results[0]:
            if CFG_BIBRANK_SHOW_DOWNLOAD_GRAPHS == 2:
                graph_file_history = CFG_WEBDIR + "/img/" + history_analysis_results[
                    0]
                html_content += """<tr><td valign=center align=center>%s</td>""" % open(
                    graph_file_history).read()
            else:  # gnuplot
                graph_file_history = CFG_SITE_URL + "/img/" + history_analysis_results[
                    0]
                html_content += """<tr><td valign=center align=center><img src='%s'/></td>""" % graph_file_history
            file_to_close_history = history_analysis_results[1]
            if file_to_close_history:
                if os.path.exists(file_to_close_history):
                    os.unlink(file_to_close_history)
        if html_content != "":
            out += """<br/><br/><table><tr><td class="blocknote">
                      %s</td></tr><tr><td>
                      <table border="0" cellspacing="1" cellpadding="1">""" % _(
                "Download history:")
            out += html_content + "</table></td></tr></table>"

    if CFG_BIBRANK_SHOW_DOWNLOAD_GRAPHS_CLIENT_IP_DISTRIBUTION:
        # do we show also user IP repartition?
        html_content = ""
        remove_old_img("download")
        #Users analysis graph
        ips = database_tuples_to_single_list(
            run_sql(
                "select client_host from rnkDOWNLOADS where id_bibrec=%s;" %
                id_bibrec))
        if ips:
            users_analysis_results = create_users_analysis_graph(
                id_bibrec, ips)
            if users_analysis_results[0]:
                file_to_close_users = users_analysis_results[1]
                if CFG_BIBRANK_SHOW_DOWNLOAD_GRAPHS_CLIENT_IP_DISTRIBUTION == 1:
                    html_content += """<tr><td valign=center align=center><img src='%s/img/%s' align="center" alt=""></td>""" % (
                        CFG_SITE_URL, users_analysis_results[0])
                elif CFG_BIBRANK_SHOW_DOWNLOAD_GRAPHS_CLIENT_IP_DISTRIBUTION == 2:
                    html_content += """<tr><td valign=center align=center>%s</td>""" % open(
                        CFG_WEBDIR + "/img/" +
                        users_analysis_results[0]).read()
                if file_to_close_users:
                    if os.path.exists(file_to_close_users):
                        os.unlink(file_to_close_users)
        if html_content != "":
            out += """<br/><br/><table><tr><td class="blocknote">
                      %s</td></tr><tr><td>
                      <table border="0" cellspacing="1" cellpadding="1">""" % _(
                "Download user distribution:")
            out += html_content
            out += "</table></td></tr></table>"

    # return html code used by get_file or search_engine
    return out