import streamlit as st import pandas as pd import matplotlib.pyplot as plt import random # Sample player names sample_player_names = ["Alice", "Bob", "Charlie", "Diana", "Ethan", "Fiona", "George", "Hannah", "Ivan", "Julia", "Aisha", "Carlos", "Mei", "Raj", "Lerato", "Dmitry", "Isabella", "Yuto", "Chloe", "Tariq"] # Generate Fibonacci sequence up to a maximum value 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() # Plotting data points for _, row in data.iterrows(): ax.scatter(x=row['User Value'], y=row['Complexity'], alpha=0.5, label=row['Player']) # Swap X and Y # Setting axis limits ax.set_xlim(0, 55) ax.set_ylim(0, 55) # Drawing lines for quadrants ax.axhline(y=27.5, color='gray', linestyle='--') ax.axvline(x=27.5, color='gray', linestyle='--') # Axis labels and title ax.set_xlabel("User Value") # Swapped label ax.set_ylabel("Complexity") # Swapped label ax.set_title(title) # Adding a grid and legend ax.legend() ax.grid(True) return fig # Function to display pitch and review for a player def display_pitch_and_review(pitcher, player_names, max_fibonacci_value, fibonacci_numbers): with st.container(): # Project Name 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]) # Other players review the pitch for reviewer in player_names: if reviewer != pitcher: st.write(f"{reviewer}'s Review") # Define keys for each input complexity_key = f'complexity_{pitcher}_{reviewer}' user_value_key = f'user_value_{pitcher}_{reviewer}' funding_key = f'funding_{pitcher}_{reviewer}' # Initialize session state variables with randomized default values if not exist 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) # Sliders with session state 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) # Save review data 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) # Function to update game data 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) # Initialize Streamlit app st.title("The Big Idea: Pitch Practice Game") # Number of players number_of_players = st.sidebar.number_input("Enter number of players", 2, 10, 4) # Initialize player names in session state if not present 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: # Display existing names for editing 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}') # Use the player names from session state player_names = st.session_state['player_names'] # Initialize game data if not present 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 for scoring fibonacci_numbers = generate_fibonacci_sequence(55) max_fibonacci_value = max(fibonacci_numbers) # Display pitch and review based on the selected player 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 # Reset after saving # Sidebar buttons for each player's pitch 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 # Show Results and Restart Game buttons in the sidebar 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"]) # Optionally clear all session state for key in list(st.session_state.keys()): del st.session_state[key] # Ensure all players are named before proceeding if not all(player_names): st.sidebar.warning("Please enter names for all players.")