ehsk commited on
Commit
2ea702b
·
1 Parent(s): bd8fe60

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -9
app.py CHANGED
@@ -10,11 +10,13 @@ DATA_FILE = "data/gwf_2017-2021_specter2_base.json"
10
  THEMES = {"cluster": "fall", "year": "mint", "source": "phase"}
11
 
12
 
13
- def decorated_to_string(list_of_things):
14
- if len(list_of_things) > 2:
15
- return ", ".join(list_of_things[:-1]) + ", and " + list_of_things[-1]
 
 
16
  else:
17
- return " and ".join(list_of_things)
18
 
19
 
20
  def load_df(data_file: os.PathLike):
@@ -25,10 +27,9 @@ def load_df(data_file: os.PathLike):
25
  df["year"] = df["year"].astype(int)
26
 
27
  df["authors_trimmed"] = df.authors.apply(
28
- lambda row: [(x[x.index(",") + 1:].strip() + " " + x.split(",")[0].strip()) if "," in x else x for x in row]
29
- )
30
- df["authors_trimmed"] = df.authors_trimmed.apply(
31
- lambda row: decorated_to_string(row[:5]) + (" et al." if len(row) > 5 else "")
32
  )
33
 
34
  if "publication_type" in df.columns:
@@ -114,4 +115,4 @@ fig.update_layout(
114
  fig.update_xaxes(title="")
115
  fig.update_yaxes(title="")
116
 
117
- st.plotly_chart(fig, use_container_width=True)
 
10
  THEMES = {"cluster": "fall", "year": "mint", "source": "phase"}
11
 
12
 
13
+ def to_string_authors(list_of_authors):
14
+ if len(list_of_authors) > 6:
15
+ return ", ".join(list_of_authors[:6]) + ", et al."
16
+ elif len(list_of_authors) > 2:
17
+ return ", ".join(list_of_authors[:-1]) + ", and " + list_of_authors[-1]
18
  else:
19
+ return " and ".join(list_of_authors)
20
 
21
 
22
  def load_df(data_file: os.PathLike):
 
27
  df["year"] = df["year"].astype(int)
28
 
29
  df["authors_trimmed"] = df.authors.apply(
30
+ lambda row: to_string_authors(
31
+ [(x[x.index(",") + 1 :].strip() + " " + x.split(",")[0].strip()) if "," in x else x for x in row]
32
+ )
 
33
  )
34
 
35
  if "publication_type" in df.columns:
 
115
  fig.update_xaxes(title="")
116
  fig.update_yaxes(title="")
117
 
118
+ st.plotly_chart(fig, use_container_width=True)