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_users_analysis_graph(id_bibrec, ips):
    """For a given id_bibrec, classify cern users and other users
    Draw a percentage graphic reprentation"""
    cern_users = 0
    other_users = 0
    coordinates_list = []
    #compute users repartition
    for ip in ips:
        if 2307522817 <= ip <= 2307588095 or 2156724481 <= ip <= 2156789759:
            cern_users += 1
        else:
            other_users += 1
    tot = float(cern_users+other_users)
    #prepare coordinates list
    coordinates_list.append((1, str(float(cern_users)/tot*100)))
    coordinates_list.append((3, str(float(other_users)/tot*100)))
    #write coordinates in a temporary file
    graph_source_file, y_max = write_coordinates_in_tmp_file([coordinates_list])
    #result2 example: [/path/to-invenio/var/www/img/tmpeC9GP5,'100.0']
    #the file contains e.g.
    #1 100.0
    #3 0.0
    #plot the graph
    graph_file = create_temporary_image(id_bibrec, 'download_users',
                                        graph_source_file, ' ',
                                        'User distribution', (0, 0), y_max,
                                        [], [], [1, 3])
    return graph_file, graph_source_file
Exemplo n.º 3
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_users_analysis_graph(id_bibrec, ips):
    """For a given id_bibrec, classify cern users and other users
    Draw a percentage graphic reprentation"""
    cern_users = 0
    other_users = 0
    coordinates_list = []
    #compute users repartition
    for ip in ips:
        if 2307522817 <= ip <= 2307588095 or 2156724481 <= ip <= 2156789759:
            cern_users += 1
        else:
            other_users += 1
    tot = float(cern_users + other_users)
    #prepare coordinates list
    coordinates_list.append((1, str(float(cern_users) / tot * 100)))
    coordinates_list.append((3, str(float(other_users) / tot * 100)))
    #write coordinates in a temporary file
    graph_source_file, y_max = write_coordinates_in_tmp_file(
        [coordinates_list])
    #result2 example: [/path/to-invenio/var/www/img/tmpeC9GP5,'100.0']
    #the file contains e.g.
    #1 100.0
    #3 0.0
    #plot the graph
    graph_file = create_temporary_image(id_bibrec, 'download_users',
                                        graph_source_file, ' ',
                                        'User distribution', (0, 0), y_max, [],
                                        [], [1, 3])
    return graph_file, graph_source_file
Exemplo n.º 5
0
def create_citation_graph(recid, dest_dir):
    coordinates = calculate_citation_history_coordinates(recid)
    if coordinates:
        years = calculate_citation_graphe_x_coordinates(recid)

        coordinates_file, max_y = write_coordinates_in_tmp_file([coordinates])
        try:
            graph_file = create_temporary_image(recid,
                    'citation', coordinates_file, 'Year', 'Times cited',
                    [0, 0], max_y, [], ' ', years, dest_dir=dest_dir)
        finally:
            # Always delete the coordinates file
            if coordinates_file:
                os.unlink(coordinates_file)

        if graph_file and os.path.exists(graph_file):
            return graph_file
def create_citation_graph(recid, dest_dir):
    coordinates = calculate_citation_history_coordinates(recid)
    if coordinates:
        years = calculate_citation_graphe_x_coordinates(recid)

        coordinates_file, max_y = write_coordinates_in_tmp_file([coordinates])
        try:
            graph_file = create_temporary_image(recid,
                    'citation', coordinates_file, 'Year', 'Times cited',
                    [0, 0], max_y, [], ' ', years, dest_dir=dest_dir)
        finally:
            # Always delete the coordinates file
            if coordinates_file:
                os.unlink(coordinates_file)

        if graph_file and os.path.exists(graph_file):
            return graph_file
def create_graph_image(graph_file_name, graph_data):
    """
    Creates a new graph image with the given data.
    @param graph_file_name: str (graph image name)
    @param graph_data: list (data for the graph plot)
    @return: str (full name of the graph image)
    """
    res = ''
    if not os.path.exists("%s/img/tmp" % (CFG_WEBDIR)):
        os.mkdir("%s/img/tmp" % (CFG_WEBDIR))
    if not os.path.exists("%s/img/tmp/%s" % (CFG_WEBDIR, graph_file_name[0])):
        os.mkdir("%s/img/tmp/%s" % (CFG_WEBDIR, graph_file_name[0]))
    datas_info = write_coordinates_in_tmp_file([graph_data])
    years = [tup[0] for tup in graph_data]
    graph = create_temporary_image(graph_file_name, 'pubs_per_year', datas_info[0], 'Year',
                                            'Times published', [0, 0], datas_info[1], [], ' ', years)
    graph_image = graph[0]
    graph_source_file = graph[1]
    if graph_image and graph_source_file and os.path.exists(graph_source_file):
        os.unlink(datas_info[0])
        res = graph_image
    return res
def draw_downloads_statistics(id_bibrec, id_bibdoc_list):
    """Create a graph of download history using a temporary file to store datas
    and a new png file for each id_bibrec to store the image of the graph which will
    be referenced by html code."""

    intervals = []
    #used to name the different curves when len(id_bibdoc_list)>1
    docfile_name_list = []
    #used to name the uniquecurve when len(id_bibdoc_list)=0 or > cfg_id_bibdoc_id_bibrec
    record_name = ""
    record_name_query = run_sql("select value from bibrec_bib24x,bib24x where id_bibrec=%s and id_bibxxx=id;" % id_bibrec)
    if record_name_query:
        record_name = record_name_query[0][0]
    #list of lists of tuples: [[("09/2004",4),..],[(..,..)]..]
    #Each list element of the list is represented by a curve
    #each elem of each list is a point on the graph
    coordinates_list = []


    #If the document is not stored in internally it has id_bibrec 0 and no creation date
    #In this case the beginning date is the first time the document has been downloaded
    local_time = time.localtime()
    local_month = local_time.tm_mon
    local_year = local_time.tm_year

    creation_date_res = run_sql("""SELECT DATE_FORMAT(creation_date,"%%Y-%%m") FROM bibrec WHERE id=%s;""" % id_bibrec)
    if creation_date_res == ():
        creation_date_res = run_sql("""SELECT DATE_FORMAT(MIN(download_time),"%%Y-%%m") FROM rnkDOWNLOADS where id_bibrec=%s;""" % id_bibrec)
    if creation_date_res == (('0000-00',),):
        creation_date_year = local_year - 1
        creation_date_month = local_month
    else :
        creation_date_year, creation_date_month = string.split(creation_date_res[0][0], "-")
        creation_date_year = int(creation_date_year)
        creation_date_month = int(creation_date_month)


    #create intervals and corresponding values
    res = create_tic_intervals(local_year, local_month, creation_date_year, creation_date_month)
    intervals = res[1]
    tic_list = res[0]

    if id_bibdoc_list == []:
        coordinates_list.append(create_list_tuple_data(intervals, id_bibrec))
        docfile_name_list = record_name
    else :
        for i in range(len(id_bibdoc_list)):
            datas = create_list_tuple_data(intervals, id_bibrec, id_bibdoc_query_addition="and id_bibdoc=%s" % id_bibdoc_list[i])
            coordinates_list.append(datas)
            docname = run_sql("select docname from bibrec_bibdoc where id_bibdoc=%s and id_bibrec=%s;" % (id_bibdoc_list[i], id_bibrec))
            docfile_name_list.append(docname[0][0])
        #In case of multiple id_bibdocs datas_max will be used to draw a line which is the total of the others lines
        if not (len(intervals)==1 or len(id_bibdoc_list)==1):
            datas_max = create_list_tuple_total(intervals, coordinates_list)
            coordinates_list.append(datas_max)
    #write coordinates_list in a temporary file
    graph_source_file, y_max = write_coordinates_in_tmp_file(coordinates_list)
    #Use create the graph from the temporary file
    graph_file = create_temporary_image(id_bibrec, 'download_history',
                                        graph_source_file, ' ',
                                        'Times downloaded', [0, 0], y_max,
                                        id_bibdoc_list, docfile_name_list,
                                        tic_list)
    return graph_file, graph_source_file
def draw_downloads_statistics(id_bibrec, id_bibdoc_list):
    """Create a graph of download history using a temporary file to store datas
    and a new png file for each id_bibrec to store the image of the graph which will
    be referenced by html code."""

    intervals = []
    #used to name the different curves when len(id_bibdoc_list)>1
    docfile_name_list = []
    #used to name the uniquecurve when len(id_bibdoc_list)=0 or > cfg_id_bibdoc_id_bibrec
    record_name = ""
    record_name_query = run_sql(
        "select value from bibrec_bib24x,bib24x where id_bibrec=%s and id_bibxxx=id;"
        % id_bibrec)
    if record_name_query:
        record_name = record_name_query[0][0]
    #list of lists of tuples: [[("09/2004",4),..],[(..,..)]..]
    #Each list element of the list is represented by a curve
    #each elem of each list is a point on the graph
    coordinates_list = []

    #If the document is not stored in internally it has id_bibrec 0 and no creation date
    #In this case the beginning date is the first time the document has been downloaded
    local_time = time.localtime()
    local_month = local_time.tm_mon
    local_year = local_time.tm_year

    creation_date_res = run_sql(
        """SELECT DATE_FORMAT(creation_date,"%%Y-%%m") FROM bibrec WHERE id=%s;"""
        % id_bibrec)
    if creation_date_res == ():
        creation_date_res = run_sql(
            """SELECT DATE_FORMAT(MIN(download_time),"%%Y-%%m") FROM rnkDOWNLOADS where id_bibrec=%s;"""
            % id_bibrec)
    if creation_date_res == (('0000-00', ), ):
        creation_date_year = local_year - 1
        creation_date_month = local_month
    else:
        creation_date_year, creation_date_month = string.split(
            creation_date_res[0][0], "-")
        creation_date_year = int(creation_date_year)
        creation_date_month = int(creation_date_month)

    #create intervals and corresponding values
    res = create_tic_intervals(local_year, local_month, creation_date_year,
                               creation_date_month)
    intervals = res[1]
    tic_list = res[0]

    if id_bibdoc_list == []:
        coordinates_list.append(create_list_tuple_data(intervals, id_bibrec))
        docfile_name_list = record_name
    else:
        for i in range(len(id_bibdoc_list)):
            datas = create_list_tuple_data(
                intervals,
                id_bibrec,
                id_bibdoc_query_addition="and id_bibdoc=%s" %
                id_bibdoc_list[i])
            coordinates_list.append(datas)
            docname = run_sql(
                "select docname from bibrec_bibdoc where id_bibdoc=%s and id_bibrec=%s;"
                % (id_bibdoc_list[i], id_bibrec))
            docfile_name_list.append(docname[0][0])
        #In case of multiple id_bibdocs datas_max will be used to draw a line which is the total of the others lines
        if not (len(intervals) == 1 or len(id_bibdoc_list) == 1):
            datas_max = create_list_tuple_total(intervals, coordinates_list)
            coordinates_list.append(datas_max)
    #write coordinates_list in a temporary file
    graph_source_file, y_max = write_coordinates_in_tmp_file(coordinates_list)
    #Use create the graph from the temporary file
    graph_file = create_temporary_image(id_bibrec, 'download_history',
                                        graph_source_file, ' ',
                                        'Times downloaded', [0, 0], y_max,
                                        id_bibdoc_list, docfile_name_list,
                                        tic_list)
    return graph_file, graph_source_file