3_test.py 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. """IMU放置于人体模型后的motion capture分析,包括离线、在线。读入或在线接入数据进行波形绘制、数据分析及分析结果的人体模型渲染和结果图表"""
  2. import streamlit as st
  3. import os
  4. from datetime import datetime
  5. from db import subject
  6. from db import test
  7. from components.remove_style import hide_footer
  8. from device.peripheral.manager import get_serial_ports
  9. import page_utils
  10. def _create_test(conn, subjects):
  11. with st.form("test_form"):
  12. st.write("创建训练")
  13. position = st.selectbox("训练部位", ['右手', '左手'])
  14. hand_com = st.selectbox("气动手COM口", get_serial_ports())
  15. finger_model_names = st.multiselect("气动手手势", list(page_utils.fingermodel_trans.keys()))
  16. owner_name = st.selectbox("用户", subjects.name.to_list())
  17. model_path = page_utils.file_selector(os.path.join(f'./static/models/{owner_name}'))
  18. submitted = st.form_submit_button("开始训练")
  19. if submitted:
  20. start_time = datetime.strptime(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), "%Y-%m-%d %H:%M:%S")
  21. test_new = {"position": position,
  22. "finger_model": ','.join([page_utils.fingermodel_trans[f] for f in finger_model_names]),
  23. "start_time": start_time,
  24. "owner_name": owner_name,
  25. "model_path": model_path}
  26. test.create_test(conn, test_new)
  27. # TODO: run a psychopy process
  28. return owner_name
  29. def render():
  30. st.set_page_config(
  31. page_title="自由手势训练", page_icon=":chart_with_upwards_trend:"
  32. )
  33. hide_footer()
  34. st.markdown("# 自由手势训练")
  35. st.sidebar.success("训练")
  36. conn = st.connection("sql_app", type="sql")
  37. test.create_table(conn)
  38. subjects = subject.get_subjects(conn)
  39. sub_name = _create_test(conn, subjects)
  40. if sub_name:
  41. tests = test.get_tests(conn, sub_name)
  42. st.write("# 训练列表")
  43. st.dataframe(tests)
  44. render()