diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b4aad9943..fa74e5eeb 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -4,7 +4,7 @@ on: # push: # branches: [ main, master ] pull_request: - branches: [ main, master ] + branches: [ main, master, develop ] jobs: test: @@ -25,17 +25,13 @@ jobs: - name: Lint with flake8 run: | - flake8 day5/演習3 --count --select=E9,F63,F7,F82 --show-source --statistics - flake8 day5/演習3 --count --exit-zero --max-complexity=10 --max-line-length=88 --statistics + flake8 day5/演習2 --count --select=E9,F63,F7,F82 --show-source --statistics + flake8 day5/演習2 --count --exit-zero --max-complexity=10 --max-line-length=88 --statistics - name: Format check with black run: | - black --check day5/演習3 - - - name: Run data tests - run: | - pytest day5/演習3/tests/test_data.py -v - - - name: Run model tests + black --check day5/演習2 + + - name: Run pytest on main.py run: | - pytest day5/演習3/tests/test_model.py -v + pytest day5/演習2/main.py -v diff --git a/day1/01_streamlit_UI/app.py b/day1/01_streamlit_UI/app.py index dcfbe6fec..4907914fb 100644 --- a/day1/01_streamlit_UI/app.py +++ b/day1/01_streamlit_UI/app.py @@ -1,203 +1,88 @@ import streamlit as st -import pandas as pd -import numpy as np +import random import time +import pandas as pd +import altair as alt # ============================================ # ページ設定 # ============================================ -# st.set_page_config( -# page_title="Streamlit デモ", -# layout="wide", -# initial_sidebar_state="expanded" -# ) +st.set_page_config( + page_title="おみくじアプリ", + layout="wide", + initial_sidebar_state="expanded" +) # ============================================ # タイトルと説明 # ============================================ -st.title("Streamlit 初心者向けデモ") -st.markdown("### コメントを解除しながらStreamlitの機能を学びましょう") -st.markdown("このデモコードでは、コメントアウトされた部分を順番に解除しながらUIの変化を確認できます。") +st.title("🎋 おみくじアプリ") +st.markdown("名前を入力して、おみくじを引いてみましょう🎲") # ============================================ # サイドバー # ============================================ -st.sidebar.header("デモのガイド") -st.sidebar.info("コードのコメントを解除して、Streamlitのさまざまな機能を確認しましょう。") +st.sidebar.header("おみくじガイド") +st.sidebar.info("名前を入力し、『おみくじを引く』ボタンをクリックしてください。 過去の結果を詳細な時間軸で確認できます。") # ============================================ -# 基本的なUI要素 +# セッションステート初期化 # ============================================ -st.header("基本的なUI要素") - -# テキスト入力 -st.subheader("テキスト入力") -name = st.text_input("あなたの名前", "ゲスト") -st.write(f"こんにちは、{name}さん!") - -# ボタン -# st.subheader("ボタン") -# if st.button("クリックしてください"): -# st.success("ボタンがクリックされました!") - -# チェックボックス -# st.subheader("チェックボックス") -# if st.checkbox("チェックを入れると追加コンテンツが表示されます"): -# st.info("これは隠れたコンテンツです!") - -# スライダー -# st.subheader("スライダー") -# age = st.slider("年齢", 0, 100, 25) -# st.write(f"あなたの年齢: {age}") - -# セレクトボックス -# st.subheader("セレクトボックス") -# option = st.selectbox( -# "好きなプログラミング言語は?", -# ["Python", "JavaScript", "Java", "C++", "Go", "Rust"] -# ) -# st.write(f"あなたは{option}を選びました") +if 'history' not in st.session_state: + st.session_state.history = [] # 過去の結果を保存(time, result) # ============================================ -# レイアウト +# おみくじ機能 # ============================================ -# st.header("レイアウト") - -# カラム -# st.subheader("カラムレイアウト") -# col1, col2 = st.columns(2) -# with col1: -# st.write("これは左カラムです") -# st.number_input("数値を入力", value=10) -# with col2: -# st.write("これは右カラムです") -# st.metric("メトリクス", "42", "2%") - -# タブ -# st.subheader("タブ") -# tab1, tab2 = st.tabs(["第1タブ", "第2タブ"]) -# with tab1: -# st.write("これは第1タブの内容です") -# with tab2: -# st.write("これは第2タブの内容です") - -# エクスパンダー -# st.subheader("エクスパンダー") -# with st.expander("詳細を表示"): -# st.write("これはエクスパンダー内の隠れたコンテンツです") -# st.code("print('Hello, Streamlit!')") - -# ============================================ -# データ表示 -# ============================================ -# st.header("データの表示") - -# サンプルデータフレームを作成 -# df = pd.DataFrame({ -# '名前': ['田中', '鈴木', '佐藤', '高橋', '伊藤'], -# '年齢': [25, 30, 22, 28, 33], -# '都市': ['東京', '大阪', '福岡', '札幌', '名古屋'] -# }) - -# データフレーム表示 -# st.subheader("データフレーム") -# st.dataframe(df, use_container_width=True) - -# テーブル表示 -# st.subheader("テーブル") -# st.table(df) - -# メトリクス表示 -# st.subheader("メトリクス") -# col1, col2, col3 = st.columns(3) -# col1.metric("温度", "23°C", "1.5°C") -# col2.metric("湿度", "45%", "-5%") -# col3.metric("気圧", "1013hPa", "0.1hPa") - -# ============================================ -# グラフ表示 -# ============================================ -# st.header("グラフの表示") - -# ラインチャート -# st.subheader("ラインチャート") -# chart_data = pd.DataFrame( -# np.random.randn(20, 3), -# columns=['A', 'B', 'C']) -# st.line_chart(chart_data) - -# バーチャート -# st.subheader("バーチャート") -# chart_data = pd.DataFrame({ -# 'カテゴリ': ['A', 'B', 'C', 'D'], -# '値': [10, 25, 15, 30] -# }).set_index('カテゴリ') -# st.bar_chart(chart_data) - -# ============================================ -# インタラクティブ機能 -# ============================================ -# st.header("インタラクティブ機能") - -# プログレスバー -# st.subheader("プログレスバー") -# progress = st.progress(0) -# if st.button("進捗をシミュレート"): -# for i in range(101): -# time.sleep(0.01) -# progress.progress(i / 100) -# st.balloons() - -# ファイルアップロード -# st.subheader("ファイルアップロード") -# uploaded_file = st.file_uploader("ファイルをアップロード", type=["csv", "txt"]) -# if uploaded_file is not None: -# # ファイルのデータを表示 -# bytes_data = uploaded_file.getvalue() -# st.write(f"ファイルサイズ: {len(bytes_data)} bytes") -# -# # CSVの場合はデータフレームとして読み込む -# if uploaded_file.name.endswith('.csv'): -# df = pd.read_csv(uploaded_file) -# st.write("CSVデータのプレビュー:") -# st.dataframe(df.head()) - -# ============================================ -# カスタマイズ -# ============================================ -# st.header("スタイルのカスタマイズ") +name = st.text_input("あなたの名前", "ゲスト") +st.write(f"こんにちは、{name}さん🎋") + +st.subheader("おみくじを引く") +if st.button("おみくじを引く!"): + with st.spinner("運勢を占っています..."): + time.sleep(1.5) + fortunes = ["大吉", "中吉", "小吉", "凶", "大凶"] + probabilities = [0.2, 0.3, 0.3, 0.15, 0.05] + result = random.choices(fortunes, probabilities)[0] + timestamp = pd.Timestamp.now() + st.session_state.history.append({'time': timestamp, 'result': result}) + st.success(f"{result}が出ました!🎉") + st.balloons() + +# ============================================ +# 結果の推移グラフ (詳細時間軸 vs 運勢カテゴリ) +# ============================================ +st.subheader("おみくじ結果の推移") +if st.session_state.history: + df = pd.DataFrame(st.session_state.history) + # Altairでプロット: x軸に年月日時分秒を表示 + chart = alt.Chart(df).mark_line(point=True).encode( + x=alt.X('time:T', title='時間', axis=alt.Axis(format='%Y-%m-%d %H:%M:%S')), + y=alt.Y('result:N', title='運勢', sort=["大吉", "中吉", "小吉", "凶", "大凶"]), + tooltip=[alt.Tooltip('time:T', title='日時', format='%Y-%m-%d %H:%M:%S'), 'result:N'] + ).properties(width=800, height=400) + st.altair_chart(chart, use_container_width=True) +else: + st.info("まだおみくじを引いていません。") + +# おみくじ詳細のエクスパンダー +with st.expander("おみくじの説明を表示"): + st.write( + "- **大吉**: 全てが順調に進むでしょう。\n" + "- **中吉**: 良いことも悪いこともほどほどです。\n" + "- **小吉**: 小さな幸運がありますが、慎重に。\n" + "- **凶**: 用心深く過ごしましょう。\n" + "- **大凶**: 大きな試練があるかもしれません。" + ) # カスタムCSS -# st.markdown(""" -# -# """, unsafe_allow_html=True) -# -# st.markdown('

これはカスタムCSSでスタイリングされたテキストです!

', unsafe_allow_html=True) - -# ============================================ -# デモの使用方法 -# ============================================ -st.divider() -st.subheader("このデモの使い方") st.markdown(""" -1. コードエディタでコメントアウトされた部分を見つけます(#で始まる行) -2. 確認したい機能のコメントを解除します(先頭の#を削除) -3. 変更を保存して、ブラウザで結果を確認します -4. 様々な組み合わせを試して、UIがどのように変化するか確認しましょう -""") - -st.code(""" -# コメントアウトされた例: -# if st.button("クリックしてください"): -# st.success("ボタンがクリックされました!") - -# コメントを解除した例: -if st.button("クリックしてください"): - st.success("ボタンがクリックされました!") -""") \ No newline at end of file + +""", unsafe_allow_html=True) +st.markdown('

おみくじを楽しんでください!

', unsafe_allow_html=True) diff --git "a/day5/\346\274\224\347\277\2222/main.py" "b/day5/\346\274\224\347\277\2222/main.py" index 776b70e75..c7126938f 100644 --- "a/day5/\346\274\224\347\277\2222/main.py" +++ "b/day5/\346\274\224\347\277\2222/main.py" @@ -21,7 +21,7 @@ def load_titanic_data(path=None): return pd.read_csv(path) else: # ローカルのファイル - local_path = "data/Titanic.csv" + local_path = "/content/lecture-ai-engineering/day5/演習2/data/Titanic.csv" if os.path.exists(local_path): return pd.read_csv(local_path)