| | import streamlit as st |
| | import pandas as pd |
| | import matplotlib.pyplot as plt |
| | import random |
| |
|
| | |
| | sample_player_names = ["Alice", "Bob", "Charlie", "Diana", "Ethan", "Fiona", "George", "Hannah", "Ivan", "Julia", "Aisha", "Carlos", "Mei", "Raj", "Lerato", "Dmitry", "Isabella", "Yuto", "Chloe", "Tariq"] |
| |
|
| |
|
| | |
| | def generate_fibonacci_sequence(max_value): |
| | sequence = [0, 1] |
| | while sequence[-1] + sequence[-2] <= max_value: |
| | sequence.append(sequence[-1] + sequence[-2]) |
| | return sequence |
| |
|
| | def plot_graph(data, title): |
| | fig, ax = plt.subplots() |
| | |
| | |
| | for _, row in data.iterrows(): |
| | ax.scatter(x=row['User Value'], y=row['Complexity'], alpha=0.5, label=row['Player']) |
| |
|
| | |
| | ax.set_xlim(0, 55) |
| | ax.set_ylim(0, 55) |
| |
|
| | |
| | ax.axhline(y=27.5, color='gray', linestyle='--') |
| | ax.axvline(x=27.5, color='gray', linestyle='--') |
| |
|
| | |
| | ax.set_xlabel("User Value") |
| | ax.set_ylabel("Complexity") |
| | ax.set_title(title) |
| |
|
| | |
| | ax.legend() |
| | ax.grid(True) |
| |
|
| | return fig |
| |
|
| |
|
| |
|
| |
|
| |
|
| | |
| | def display_pitch_and_review(pitcher, player_names, max_fibonacci_value, fibonacci_numbers): |
| | with st.container(): |
| | |
| | project_key = f'project_{pitcher}' |
| | if project_key not in st.session_state: |
| | st.session_state[project_key] = '' |
| | project_name = st.text_input(f"Project Name by {pitcher}", st.session_state[project_key]) |
| |
|
| | |
| | for reviewer in player_names: |
| | if reviewer != pitcher: |
| | st.write(f"{reviewer}'s Review") |
| |
|
| | |
| | complexity_key = f'complexity_{pitcher}_{reviewer}' |
| | user_value_key = f'user_value_{pitcher}_{reviewer}' |
| | funding_key = f'funding_{pitcher}_{reviewer}' |
| |
|
| | |
| | if complexity_key not in st.session_state: |
| | st.session_state[complexity_key] = random.choice(fibonacci_numbers) |
| | if user_value_key not in st.session_state: |
| | st.session_state[user_value_key] = random.choice(fibonacci_numbers) |
| | if funding_key not in st.session_state: |
| | st.session_state[funding_key] = random.choice(fibonacci_numbers) |
| |
|
| | |
| | complexity = st.slider(f"Complexity for {project_name}", 0, max_fibonacci_value, st.session_state[complexity_key], key=complexity_key) |
| | user_value = st.slider(f"User Value for {project_name}", 0, max_fibonacci_value, st.session_state[user_value_key], key=user_value_key) |
| | funding_points = st.slider(f"Funding Points for {project_name}", 0, max_fibonacci_value, st.session_state[funding_key], key=funding_key) |
| |
|
| | |
| | new_row = { |
| | "Player": reviewer, |
| | "Project": project_name, |
| | "Complexity": complexity, |
| | "User Value": user_value, |
| | "Funding Points": funding_points |
| | } |
| | st.session_state['game_data'] = pd.concat([st.session_state['game_data'], pd.DataFrame([new_row])], ignore_index=True) |
| |
|
| | |
| | def update_game_data(pitcher, project_name, player_names, max_fibonacci_value): |
| | for reviewer in player_names: |
| | if reviewer != pitcher: |
| | complexity_key = f'complexity_{pitcher}_{reviewer}' |
| | user_value_key = f'user_value_{pitcher}_{reviewer}' |
| | funding_key = f'funding_{pitcher}_{reviewer}' |
| |
|
| | new_row = { |
| | "Player": reviewer, |
| | "Project": project_name, |
| | "Complexity": st.session_state[complexity_key], |
| | "User Value": st.session_state[user_value_key], |
| | "Funding Points": st.session_state[funding_key] |
| | } |
| | st.session_state['game_data'] = pd.concat([st.session_state['game_data'], pd.DataFrame([new_row])], ignore_index=True) |
| |
|
| |
|
| | |
| | st.title("The Big Idea: Pitch Practice Game") |
| |
|
| | |
| | number_of_players = st.sidebar.number_input("Enter number of players", 2, 10, 4) |
| |
|
| | |
| | if 'player_names' not in st.session_state or st.sidebar.button("Initialize/Change Player Names"): |
| | st.session_state['player_names'] = [st.sidebar.text_input(f"Name of player {i+1}", value=random.choice(sample_player_names), key=f'player_{i}') for i in range(number_of_players)] |
| | else: |
| | |
| | for i in range(number_of_players): |
| | st.session_state['player_names'][i] = st.sidebar.text_input(f"Name of player {i+1}", value=st.session_state['player_names'][i], key=f'player_{i}') |
| |
|
| | |
| | player_names = st.session_state['player_names'] |
| |
|
| | |
| | if 'game_data' not in st.session_state: |
| | st.session_state['game_data'] = pd.DataFrame(columns=["Player", "Project", "Complexity", "User Value", "Funding Points"]) |
| |
|
| | |
| | fibonacci_numbers = generate_fibonacci_sequence(55) |
| | max_fibonacci_value = max(fibonacci_numbers) |
| |
|
| | |
| | if 'selected_pitcher' in st.session_state and st.session_state['selected_pitcher']: |
| | display_pitch_and_review(st.session_state['selected_pitcher'], player_names, max_fibonacci_value, fibonacci_numbers) |
| | if st.button("Save Reviews"): |
| | update_game_data(st.session_state['selected_pitcher'], st.session_state[f'project_{st.session_state["selected_pitcher"]}'], player_names, max_fibonacci_value) |
| | st.session_state['selected_pitcher'] = None |
| |
|
| | |
| | for i, pitcher in enumerate(player_names): |
| | if st.sidebar.button(f"{pitcher}'s Pitch", key=f'pitch_{pitcher}_{i}'): |
| | st.session_state['selected_pitcher'] = pitcher |
| |
|
| |
|
| | |
| | if st.sidebar.button("Show Results"): |
| | st.write(st.session_state['game_data']) |
| | fig = plot_graph(st.session_state['game_data'], "Project Complexity vs User Value") |
| | st.pyplot(fig) |
| |
|
| | if st.sidebar.button("Restart Game"): |
| | st.session_state['game_data'] = pd.DataFrame(columns=["Player", "Project", "Complexity", "User Value", "Funding Points"]) |
| | |
| | for key in list(st.session_state.keys()): |
| | del st.session_state[key] |
| |
|
| | |
| | if not all(player_names): |
| | st.sidebar.warning("Please enter names for all players.") |