Sephfox commited on
Commit
60a321b
·
verified ·
1 Parent(s): 16eb022

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -10
app.py CHANGED
@@ -173,13 +173,13 @@ class Environment:
173
  count = len([cell for cell in self.cells if cell.modifications])
174
  self.population_history[cell_type].append(count)
175
 
176
- def get_visualization_data(self):
177
  cell_data = {
178
- "prokaryote": {"x": [], "y": [], "size": [], "color": "lightblue"},
179
- "early_eukaryote": {"x": [], "y": [], "size": [], "color": "green"},
180
- "advanced_eukaryote": {"x": [], "y": [], "size": [], "color": "red"},
181
- "plant_like": {"x": [], "y": [], "size": [], "color": "darkgreen"},
182
- "modified": {"x": [], "y": [], "size": [], "color": "purple"}
183
  }
184
 
185
  for cell in self.cells:
@@ -191,26 +191,48 @@ class Environment:
191
  return cell_data, self.population_history
192
 
193
  def setup_figure(env):
194
- fig = make_subplots(rows=1, cols=2, subplot_titles=("Cell Distribution", "Population Over Time"))
 
 
 
 
 
 
195
 
196
  # Cell distribution
197
  for cell_type, data in env.get_visualization_data()[0].items():
198
  fig.add_trace(go.Scatter(
199
  x=data["x"], y=data["y"], mode='markers',
200
- marker=dict(color=data["color"], size=data["size"]),
201
  name=cell_type
202
  ), row=1, col=1)
203
 
204
- # Population over time
205
  for cell_type, counts in env.population_history.items():
206
  fig.add_trace(go.Scatter(y=counts, mode='lines', name=cell_type), row=1, col=2)
207
 
 
 
 
 
 
 
 
 
 
 
 
 
208
  fig.update_xaxes(title_text="X", row=1, col=1)
209
  fig.update_yaxes(title_text="Y", row=1, col=1)
210
  fig.update_xaxes(title_text="Time", row=1, col=2)
211
  fig.update_yaxes(title_text="Population", row=1, col=2)
212
 
213
- fig.update_layout(height=600, width=1200, title_text="Advanced Cell Evolution Simulation")
 
 
 
 
214
 
215
  return fig
216
 
@@ -247,6 +269,11 @@ if st.button("Run Simulation"):
247
 
248
  for i, (cell_type, counts) in enumerate(population_history.items()):
249
  fig.data[i+5].y = counts # +5 because we have 5 cell types in the first subplot
 
 
 
 
 
250
 
251
  fig.layout.title.text = f"Advanced Cell Evolution Simulation (Time: {env.time})"
252
 
 
173
  count = len([cell for cell in self.cells if cell.modifications])
174
  self.population_history[cell_type].append(count)
175
 
176
+ def get_visualization_data(self):
177
  cell_data = {
178
+ "prokaryote": {"x": [], "y": [], "size": [], "color": "lightblue", "symbol": "circle"},
179
+ "early_eukaryote": {"x": [], "y": [], "size": [], "color": "green", "symbol": "square"},
180
+ "advanced_eukaryote": {"x": [], "y": [], "size": [], "color": "red", "symbol": "diamond"},
181
+ "plant_like": {"x": [], "y": [], "size": [], "color": "darkgreen", "symbol": "star"},
182
+ "modified": {"x": [], "y": [], "size": [], "color": "purple", "symbol": "cross"}
183
  }
184
 
185
  for cell in self.cells:
 
191
  return cell_data, self.population_history
192
 
193
  def setup_figure(env):
194
+ cell_types = ["prokaryote", "early_eukaryote", "advanced_eukaryote", "plant_like", "modified"]
195
+ fig = make_subplots(rows=2, cols=3,
196
+ subplot_titles=("Cell Distribution", "Total Population",
197
+ "Prokaryotes", "Early Eukaryotes",
198
+ "Advanced Eukaryotes", "Plant-like & Modified"),
199
+ vertical_spacing=0.1,
200
+ horizontal_spacing=0.05)
201
 
202
  # Cell distribution
203
  for cell_type, data in env.get_visualization_data()[0].items():
204
  fig.add_trace(go.Scatter(
205
  x=data["x"], y=data["y"], mode='markers',
206
+ marker=dict(color=data["color"], size=data["size"], symbol=data["symbol"]),
207
  name=cell_type
208
  ), row=1, col=1)
209
 
210
+ # Total population over time
211
  for cell_type, counts in env.population_history.items():
212
  fig.add_trace(go.Scatter(y=counts, mode='lines', name=cell_type), row=1, col=2)
213
 
214
+ # Individual population charts
215
+ for i, cell_type in enumerate(cell_types):
216
+ if cell_type == "modified":
217
+ fig.add_trace(go.Scatter(y=env.population_history[cell_type], mode='lines',
218
+ name=cell_type, line=dict(color="purple")), row=2, col=3)
219
+ elif cell_type == "plant_like":
220
+ fig.add_trace(go.Scatter(y=env.population_history[cell_type], mode='lines',
221
+ name=cell_type, line=dict(color="darkgreen")), row=2, col=3)
222
+ else:
223
+ fig.add_trace(go.Scatter(y=env.population_history[cell_type], mode='lines',
224
+ name=cell_type), row=2, col=i+1)
225
+
226
  fig.update_xaxes(title_text="X", row=1, col=1)
227
  fig.update_yaxes(title_text="Y", row=1, col=1)
228
  fig.update_xaxes(title_text="Time", row=1, col=2)
229
  fig.update_yaxes(title_text="Population", row=1, col=2)
230
 
231
+ for i in range(1, 4):
232
+ fig.update_xaxes(title_text="Time", row=2, col=i)
233
+ fig.update_yaxes(title_text="Population", row=2, col=i)
234
+
235
+ fig.update_layout(height=800, width=1200, title_text="Advanced Cell Evolution Simulation")
236
 
237
  return fig
238
 
 
269
 
270
  for i, (cell_type, counts) in enumerate(population_history.items()):
271
  fig.data[i+5].y = counts # +5 because we have 5 cell types in the first subplot
272
+ if cell_type != "modified" and cell_type != "plant_like":
273
+ fig.data[i+10].y = counts # Update individual population charts
274
+ else:
275
+ fig.data[13].y = population_history["plant_like"]
276
+ fig.data[14].y = population_history["modified"]
277
 
278
  fig.layout.title.text = f"Advanced Cell Evolution Simulation (Time: {env.time})"
279