Spaces:
Sleeping
Sleeping
mihaeladuta commited on
Commit ·
9a4e516
1
Parent(s): 11134c7
Improve efficiency for research grup and cache data.
Browse files- data/ResearchGroups_ppreprocessed.csv.gz +2 -2
- src/codebook.py +4 -0
- src/pages/1_Research_Groups.py +8 -13
- src/read_write.py +5 -12
data/ResearchGroups_ppreprocessed.csv.gz
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:cd0e4c2400cfee4dd11bddb54aead00760f140ccd0f45b12a32392d3a2231746
|
| 3 |
+
size 27500
|
src/codebook.py
CHANGED
|
@@ -12,6 +12,10 @@ COL_INST_CODE = 'Institution UKPRN code'
|
|
| 12 |
COL_INST_NAME = 'Institution'
|
| 13 |
COL_RG_CODE = 'Research group code'
|
| 14 |
COL_RG_NAME = 'Research group'
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
# about the outputs
|
| 16 |
COL_OUTPUT_TYPE_CODE = 'Output type code'
|
| 17 |
COL_OUTPUT_TYPE_NAME = 'Output type'
|
|
|
|
| 12 |
COL_INST_NAME = 'Institution'
|
| 13 |
COL_RG_CODE = 'Research group code'
|
| 14 |
COL_RG_NAME = 'Research group'
|
| 15 |
+
# about the submissions
|
| 16 |
+
COL_MULT_SUB_LETTER = 'Multiple submission letter'
|
| 17 |
+
COL_MULT_SUB_NAME = 'Multiple submission name'
|
| 18 |
+
COL_JOINT_SUB = 'Joint submission'
|
| 19 |
# about the outputs
|
| 20 |
COL_OUTPUT_TYPE_CODE = 'Output type code'
|
| 21 |
COL_OUTPUT_TYPE_NAME = 'Output type'
|
src/pages/1_Research_Groups.py
CHANGED
|
@@ -9,18 +9,13 @@ import visualisations as vis
|
|
| 9 |
|
| 10 |
|
| 11 |
page_title = "Research Groups"
|
| 12 |
-
|
| 13 |
st.title(page_title)
|
| 14 |
|
| 15 |
with st.spinner(rw.PROC_TEXT):
|
| 16 |
-
(dset, _) = rw.get_data(rw.DATA_PPROC_RGROUPS
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
cb.COL_UOA_NAME,
|
| 21 |
-
cb.COL_RG_NAME
|
| 22 |
-
]
|
| 23 |
-
dset = dset.loc[:, columns]
|
| 24 |
|
| 25 |
dset_to_print = pd.DataFrame.from_dict(
|
| 26 |
{
|
|
@@ -33,7 +28,7 @@ dset_to_print.columns = ["count"]
|
|
| 33 |
pd.set_option("display.max_colwidth", None)
|
| 34 |
st.dataframe(dset_to_print)
|
| 35 |
|
| 36 |
-
tabs = st.tabs(["Charts"
|
| 37 |
|
| 38 |
with tabs[0]:
|
| 39 |
st.markdown("Select from the charts below to view the "
|
|
@@ -64,6 +59,6 @@ with tabs[0]:
|
|
| 64 |
)
|
| 65 |
|
| 66 |
|
| 67 |
-
with tabs[1]:
|
| 68 |
-
|
| 69 |
-
|
|
|
|
| 9 |
|
| 10 |
|
| 11 |
page_title = "Research Groups"
|
|
|
|
| 12 |
st.title(page_title)
|
| 13 |
|
| 14 |
with st.spinner(rw.PROC_TEXT):
|
| 15 |
+
(dset, _) = rw.get_data(rw.DATA_PPROC_RGROUPS,
|
| 16 |
+
categories_columns=[cb.COL_RG_NAME])
|
| 17 |
+
for column in dset.columns:
|
| 18 |
+
print(f"{column}: {dset[column].dtype}")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
dset_to_print = pd.DataFrame.from_dict(
|
| 21 |
{
|
|
|
|
| 28 |
pd.set_option("display.max_colwidth", None)
|
| 29 |
st.dataframe(dset_to_print)
|
| 30 |
|
| 31 |
+
tabs = st.tabs(["Charts"])
|
| 32 |
|
| 33 |
with tabs[0]:
|
| 34 |
st.markdown("Select from the charts below to view the "
|
|
|
|
| 59 |
)
|
| 60 |
|
| 61 |
|
| 62 |
+
# with tabs[1]:
|
| 63 |
+
# dset_explore = dataframe_explorer(dset)
|
| 64 |
+
# # st.dataframe(dset_explore, use_container_width=False)
|
src/read_write.py
CHANGED
|
@@ -22,13 +22,13 @@ DATA_PPROC_RESULTS = f"{DATA_PATH}Results{DATA_PPROCESS}{DATA_EXT}"
|
|
| 22 |
|
| 23 |
PROC_TEXT = "Processing request..."
|
| 24 |
|
| 25 |
-
|
| 26 |
-
def get_data(fname,
|
| 27 |
""" Read a csv file and return a dataset and a list of institution names.
|
| 28 |
|
| 29 |
Args:
|
| 30 |
fname (str): Filename of the csv file to read.
|
| 31 |
-
|
| 32 |
|
| 33 |
Returns:
|
| 34 |
tuple: A tuple containing:
|
|
@@ -38,12 +38,13 @@ def get_data(fname, do_sort=True):
|
|
| 38 |
|
| 39 |
# defines types to read
|
| 40 |
dtype = {cb.COL_INST_CODE: 'category',
|
|
|
|
| 41 |
cb.COL_PANEL_NAME: 'category',
|
| 42 |
cb.COL_UOA_NAME: 'category'
|
| 43 |
}
|
| 44 |
# binned percentages and various categories, depending on file
|
| 45 |
binned_perc_columns = []
|
| 46 |
-
categories_columns = []
|
| 47 |
if "Results_" in fname:
|
| 48 |
binned_perc_columns = [cb.COL_RESULTS_1star_BINNED,
|
| 49 |
cb.COL_RESULTS_2star_BINNED,
|
|
@@ -52,11 +53,6 @@ def get_data(fname, do_sort=True):
|
|
| 52 |
cb.COL_RESULTS_UNCLASSIFIED_BINNED,
|
| 53 |
cb.COL_RESULTS_PERC_STAFF_SUBMITTED_BINNED
|
| 54 |
]
|
| 55 |
-
elif "Outputs_" in fname:
|
| 56 |
-
categories_columns = [cb.COL_OUTPUT_TYPE_NAME,
|
| 57 |
-
cb.COL_OPEN_ACCESS
|
| 58 |
-
]
|
| 59 |
-
|
| 60 |
for column in binned_perc_columns:
|
| 61 |
dtype[column] = 'category'
|
| 62 |
|
|
@@ -76,9 +72,6 @@ def get_data(fname, do_sort=True):
|
|
| 76 |
# get institution names as list
|
| 77 |
inst_names = dset[cb.COL_INST_NAME].unique()
|
| 78 |
|
| 79 |
-
if do_sort:
|
| 80 |
-
inst_names.sort()
|
| 81 |
-
|
| 82 |
return (dset, inst_names)
|
| 83 |
|
| 84 |
|
|
|
|
| 22 |
|
| 23 |
PROC_TEXT = "Processing request..."
|
| 24 |
|
| 25 |
+
@st.cache_data
|
| 26 |
+
def get_data(fname, categories_columns=[]):
|
| 27 |
""" Read a csv file and return a dataset and a list of institution names.
|
| 28 |
|
| 29 |
Args:
|
| 30 |
fname (str): Filename of the csv file to read.
|
| 31 |
+
categories_columns (list): List of columns to be read as categories.
|
| 32 |
|
| 33 |
Returns:
|
| 34 |
tuple: A tuple containing:
|
|
|
|
| 38 |
|
| 39 |
# defines types to read
|
| 40 |
dtype = {cb.COL_INST_CODE: 'category',
|
| 41 |
+
cb.COL_INST_NAME: 'category',
|
| 42 |
cb.COL_PANEL_NAME: 'category',
|
| 43 |
cb.COL_UOA_NAME: 'category'
|
| 44 |
}
|
| 45 |
# binned percentages and various categories, depending on file
|
| 46 |
binned_perc_columns = []
|
| 47 |
+
# categories_columns = []
|
| 48 |
if "Results_" in fname:
|
| 49 |
binned_perc_columns = [cb.COL_RESULTS_1star_BINNED,
|
| 50 |
cb.COL_RESULTS_2star_BINNED,
|
|
|
|
| 53 |
cb.COL_RESULTS_UNCLASSIFIED_BINNED,
|
| 54 |
cb.COL_RESULTS_PERC_STAFF_SUBMITTED_BINNED
|
| 55 |
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
for column in binned_perc_columns:
|
| 57 |
dtype[column] = 'category'
|
| 58 |
|
|
|
|
| 72 |
# get institution names as list
|
| 73 |
inst_names = dset[cb.COL_INST_NAME].unique()
|
| 74 |
|
|
|
|
|
|
|
|
|
|
| 75 |
return (dset, inst_names)
|
| 76 |
|
| 77 |
|