File size: 8,704 Bytes
1da1c98 d3021f0 1da1c98 b1fc4cc 1da1c98 d3021f0 1da1c98 b1fc4cc 1da1c98 b1fc4cc 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 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 |
import os
import scholarpy
import pandas as pd
import streamlit as st
import leafmap.foliumap as leafmap
import plotly.express as px
from leafmap.common import temp_file_path
if "dsl" not in st.session_state:
st.session_state["dsl"] = scholarpy.Dsl()
@st.cache_data
def get_geonames():
return scholarpy.get_geonames()
def json_to_df(json_data, transpose=False):
df = json_data.as_dataframe()
if not df.empty:
if transpose:
df = df.transpose()
out_csv = temp_file_path(".csv")
df.to_csv(out_csv, index=transpose)
df = pd.read_csv(out_csv)
os.remove(out_csv)
return df
else:
return None
def annual_pubs(pubs, col="year"):
if pubs is not None:
df = pubs[col].value_counts().sort_index()
df2 = pd.DataFrame({"year": df.index, "publications": df.values})
return df2
else:
return None
def annual_collaborators(pubs, col="year"):
if pubs is not None:
df = pubs.groupby([col]).sum()
df2 = pd.DataFrame(
{"year": df.index, "collaborators": df["authors_count"].values}
)
fig = px.bar(
df2,
x="year",
y="collaborators",
)
return fig
else:
return None
def annual_citations(pubs, col="year"):
if pubs is not None:
df = pubs.groupby([col]).sum()
df2 = pd.DataFrame({"year": df.index, "citations": df["times_cited"].values})
fig = px.bar(
df2,
x="year",
y="citations",
)
return fig
else:
return None
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 app():
st.title("Search Researchers")
dsl = st.session_state["dsl"]
row1_col1, row1_col2 = st.columns([1, 1])
with row1_col1:
name = st.text_input("Enter a researcher name:", "")
if name:
ids, names = dsl.search_researcher_by_name(name, return_list=True)
if ids.count_total > 0:
# options = ids.as_dataframe()["id"].values.tolist()
with row1_col1:
name = st.selectbox("Select a researcher id:", names)
if name:
id = name.split("|")[1].strip()
id_info = dsl.search_researcher_by_id(id, return_df=False)
info_df = json_to_df(id_info, transpose=True)
info_df.rename(
columns={info_df.columns[0]: "Type", info_df.columns[1]: "Value"},
inplace=True,
)
with row1_col1:
st.header("Researcher Information")
if not info_df.empty:
st.dataframe(info_df)
leafmap.st_download_button(
"Download data", info_df, csv_sep="\t"
)
else:
st.text("No information found")
pubs = dsl.search_pubs_by_researcher_id(id)
df = json_to_df(pubs)
# annual_df = annual_pubs(df)
if df is not None:
df1, df2 = dsl.researcher_annual_stats(
pubs, geonames_df=get_geonames()
)
df3 = scholarpy.collaborator_locations(df2)
with row1_col2:
st.header("Researcher statistics")
columns = ["pubs", "collaborators", "institutions", "cities"]
selected_columns = st.multiselect(
"Select attributes to display:", columns, columns
)
if selected_columns:
fig = scholarpy.annual_stats_barplot(df1, selected_columns)
st.plotly_chart(fig)
leafmap.st_download_button(
"Download data",
df1,
file_name="data.csv",
csv_sep="\t",
)
st.header("Map of collaborator institutions")
markdown = f"""
- Total number of collaborator institutions: **{len(df3)}**
"""
st.markdown(markdown)
m = leafmap.Map(
center=[0, 0],
zoom_start=1,
latlon_control=False,
draw_control=False,
measure_control=False,
locate_control=True,
)
m.add_points_from_xy(df3)
m.to_streamlit(height=420)
leafmap.st_download_button(
"Download data",
df3,
file_name="data.csv",
csv_sep="\t",
)
st.header("Publication counts with collaborators")
collaborators = dsl.search_researcher_collaborators(id, pubs)
markdown = f"""
- Total number of collaborators: **{len(collaborators)}**
"""
st.markdown(markdown)
st.dataframe(collaborators)
leafmap.st_download_button(
"Download data",
collaborators,
file_name="data.csv",
csv_sep="\t",
)
else:
st.text("No publications found")
with row1_col1:
st.header("Publications")
if df is not None:
citations = df["times_cited"].values.tolist()
citations.sort(reverse=True)
h_index = the_H_function(citations)
markdown = f"""
- Total number of publications: **{len(df)}**
- Total number of citations: **{df["times_cited"].sum()}**
- i10-index: **{len(df[df["times_cited"]>=10])}**
- h-index: **{h_index}**
"""
st.markdown(markdown)
st.dataframe(df)
leafmap.st_download_button(
"Download data", df, file_name="data.csv", csv_sep="\t"
)
if "journal.title" in df.columns:
st.header("Publication counts by journal")
journals = df["journal.title"].value_counts()
summary = pd.DataFrame(
{"Journal": journals.index, "Count": journals}
).reset_index(drop=True)
markdown = f"""
- Total number of journals: **{len(summary)}**
"""
st.markdown(markdown)
st.dataframe(summary)
leafmap.st_download_button(
"Download data",
summary,
file_name="data.csv",
csv_sep="\t",
)
else:
st.text("No journal publications")
else:
st.text("No publications found")
grants = dsl.search_grants_by_researcher(id)
df = grants.as_dataframe()
if not df.empty:
st.header("Grants")
st.dataframe(df)
leafmap.st_download_button(
"Download data", df, file_name="data.csv", csv_sep="\t"
)
else:
st.text("No results found.")
|