File size: 6,978 Bytes
23e82be a028173 23e82be 00da2a7 23e82be 00da2a7 23e82be 00da2a7 23e82be 00da2a7 23e82be 00da2a7 23e82be |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
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.") |