-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtools.py
53 lines (39 loc) · 1.26 KB
/
tools.py
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
import os
import streamlit as st
import pandas as pd
from typing import List
from config import TESTDATA_PATH, EXAMPLE
from io import StringIO
def fund(listTemp, n):
result = []
for i in range(0, len(listTemp), n):
temp = listTemp[i:i + n]
result.append(temp)
return result
def get_files(path=TESTDATA_PATH):
return os.listdir(path)
@st.cache
def get_data(path):
path = os.path.join(TESTDATA_PATH, path)
test_data = pd.read_csv(path)
return test_data
def get_example(id):
return EXAMPLE[id]
def get_test_data(data_type):
test_data = pd.DataFrame()
if data_type == '上传测试数据':
st.write("参考数据格式: ")
st.dataframe(pd.read_csv(StringIO(get_example(1)), sep="\t"))
uploaded_file = st.file_uploader("Choose a file")
if uploaded_file is not None:
test_data = pd.read_csv(uploaded_file)
with st.expander("预览测试数据"):
st.dataframe(test_data)
else:
_test = st.selectbox("选择测试数据", get_files())
test_data = get_data(_test)
return test_data
@st.cache
def convert_df(df):
# IMPORTANT: Cache the conversion to prevent computation on every rerun
return df.to_csv(index=False).encode('utf-8')