0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

streamlitでsave

Last updated at Posted at 2023-11-05

myApp.py


json

import json
import streamlit as st
import pandas as pd
import matplotlib.pyplot as plt
import datetime
import time
import pathlib

def main():
    pass

if __name__ == "__main__":
    main()

pages/01_eva.py


import json
import streamlit as st
import pandas as pd
import matplotlib.pyplot as plt
import datetime
import time
import pathlib

# ページ設定===========================================================================================================
import json
import streamlit as st
import pandas as pd
import matplotlib.pyplot as plt
import datetime
import time
import pathlib



def main():

    # ページ設定===========================================================================================================
    st.header('sensor_comp紐づけツール')

    # ファイル処理=============================================================================================================
    # 初回起動時や、JSONの形がおかしかった場合には,保存用JSONファイルを初期化する処理が必要
    pass

    #comp_dbの呼び出し
    with open('./dataset_common/comp_db.json', 'r', encoding='utf-8') as fr:
        comp_db_json = json.load(fr)

    #加速度計-評価対象機器の呼び出し
    with open('./dataset_acoustic/acc_evaluate_comp.json', 'r', encoding='utf-8') as fr:
        acc_evaluate_json = json.load(fr)

    # 変数定義==============================================================================================================
    comp_list = list(comp_db_json.keys())
    acc_list = ['acc1', 'acc2', 'acc3'] #いずれは自動取得したい

    # メイン処理=============================================================================================================
    # accの数だけマルチセレクトboxを作成
    for acc_name in acc_list:
        evaluate_list_saved = acc_evaluate_json[acc_name] #そのaccでの評価対象機器リスト(保存済み)を取得
        acc_evaluate_json[acc_name] = st.multiselect(acc_name, options=comp_list, default=evaluate_list_saved)

    #一次保存
    if st.button('一次保存', key='my_button2'):
        with open('./dataset_acoustic/acc_evaluate_comp.json', 'w', encoding='utf-8') as fw:
            json.dump(acc_evaluate_json, fw, indent=4)
        st.write('一次保存完了')
        st.write('最終保存時刻: ', str(datetime.datetime.now().strftime('%Y/%m/%d, %H:%M')))


if __name__ == '__main__':
    main()

acc_evaluate_comp.json

#表を作成


comp_db.json

{
    "acc1": [
        "comp1",
        "comp3"
    ],
    "acc2": [
        "comp1",
        "comp2"
    ],
    "acc3": [
        "comp3"
    ]
}

{
    "comp1": {
        "mass_kg": 10,
        "x_rand": [40, 100, 400, 2000],
        "y_rand": [0.05, 0.2, 0.2, 0.03]
    },
    "comp2": {
        "mass_kg": 20,
        "x_rand": [40, 70, 200, 300, 1000, 2000],
        "y_rand": [0.05, 0.2, 0.2, 0.1, 0.1, 0.03]
    },
    "comp3": {
        "mass_kg": 20,
        "x_rand": [40, 250, 500, 2000],
        "y_rand": [0.05, 0.1, 0.1, 0.03]
    }

}


0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?