File size: 1,691 Bytes
1da1c98
 
 
 
 
 
 
 
 
 
 
b1fc4cc
1da1c98
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b1fc4cc
1da1c98
 
 
 
 
 
 
 
b1fc4cc
1da1c98
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import dimcli
import pandas as pd
import sys
import os
import streamlit as st
import scholarpy

if "dsl" not in st.session_state:
    st.session_state["dsl"] = scholarpy.Dsl()


@st.cache_data
def the_H_function(sorted_citations_list, n=1):
    """from a list of integers [n1, n2 ..] representing publications citations,
    return the max list-position which is >= integer

    eg
    >>> the_H_function([10, 8, 5, 4, 3]) => 4
    >>> the_H_function([25, 8, 5, 3, 3]) => 3
    >>> the_H_function([1000, 20]) => 2
    """
    if sorted_citations_list and sorted_citations_list[0] >= n:
        return the_H_function(sorted_citations_list[1:], n + 1)
    else:
        return n - 1


def dim_login(key=None, endpoint=None):

    if key is None:
        KEY = os.environ.get("DIM_TOKEN")

    if endpoint is None:
        ENDPOINT = "https://app.dimensions.ai"

    try:
        dimcli.login(key=KEY, endpoint=ENDPOINT)
        dsl = dimcli.Dsl()
        return dsl
    except:
        raise Exception("Failed to login to Dimensions")


@st.cache_data
def get_pubs_df(dsl, researcher_id):

    q = """search publications where researchers.id = "{}" return publications[id+title+doi+times_cited] sort by times_cited limit 1000"""

    pubs = dsl.query(q.format(researcher_id))
    return pubs.as_dataframe()


@st.cache_data
def get_citations(df):
    return list(df.fillna(0)["times_cited"])


def app():

    dsl = st.session_state["dsl"]

    researchER_id = st.text_input("Enter researcher ID:", "ur.013632443777.66")
    df = get_pubs_df(dsl, researchER_id)
    st.dataframe(df)
    citations = get_citations(df)
    h_index = the_H_function(citations)
    st.write(f"H-index: {h_index}")