Skip to content
Snippets Groups Projects
Commit b3236d41 authored by Leah Tacke genannt Unterberg's avatar Leah Tacke genannt Unterberg
Browse files

initial

parents
Branches
No related tags found
No related merge requests found
def switch_page(page_name: str):
from streamlit.runtime.scriptrunner import RerunData, RerunException
from streamlit.source_util import get_pages
def standardize_name(name: str) -> str:
return name.lower().replace("_", " ")
page_name = standardize_name(page_name)
pages = get_pages("streamlit_app.py") # OR whatever your main page is called
for page_hash, config in pages.items():
if standardize_name(config["page_name"]) == page_name:
raise RerunException(
RerunData(
page_script_hash=page_hash,
page_name=page_name,
)
)
page_names = [standardize_name(config["page_name"]) for config in pages.values()]
raise ValueError(f"Could not find page {page_name}. Must be one of {page_names}")
\ No newline at end of file
import streamlit as st
st.title('Machine Data File Conversions')
import os
import streamlit as st
from mdata.file_formats.csv import read_machine_data
from mdata.file_formats.hdf import read_machine_data_h5
from logic.page_logic import available_widgets, generate_page
st.set_page_config(layout="wide")
st.title('Machine Data Viewer')
import_type = st.selectbox('Import Type', ['csv', 'hdf'])
files = {}
if import_type == 'csv':
csv_header_upload = st.file_uploader("Upload a header csv file", type='.csv')
csv_data_upload = st.file_uploader("Upload a data csv file", type='.csv')
files['csv_header_upload'] = csv_header_upload
files['csv_data_upload'] = csv_data_upload
elif import_type == 'hdf':
hdf_upload = st.file_uploader('Upload an HDF file', type=['.hdf', '.h5'])
files['hdf_upload'] = hdf_upload
# @st.experimental_memo
def import_hdf(f):
fn = os.path.join('uploads', f.name)
with open(fn, 'wb') as fd:
fd.write(f.getbuffer())
fd.flush()
return read_machine_data_h5(fn)
# @st.experimental_memo
def import_csv(hf, df):
return read_machine_data(hf, df, validity_checking=False)
@st.cache_data
def attempt_import(import_type, **files):
if import_type == 'csv' and files.get('csv_header_upload') is not None and files.get('csv_data_upload') is not None:
csv_header_upload = files['csv_header_upload']
csv_data_upload = files['csv_data_upload']
return import_csv(csv_header_upload, csv_data_upload)
elif import_type == 'hdf' and files.get('hdf_upload') is not None:
hdf_upload = files['hdf_upload']
return import_hdf(hdf_upload)
md = attempt_import(import_type, **files)
selected_widget = st.sidebar.selectbox('Widget', available_widgets)
if md is not None:
generate_page(md, selected_widget)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment