Browse Source

add routing and redirection to failure/success pages. Fix RPS calculations

main
Stephanie Gredell 4 months ago
parent
commit
ee265eebf3
  1. 17
      router/handlers/simulation.go
  2. 36
      static/app.js
  3. 13
      static/commands.js
  4. 24
      static/failure.html
  5. 23
      static/success.html

17
router/handlers/simulation.go

@ -144,13 +144,22 @@ func calculateMetrics(snapshots []*simulation.TickSnapshot, design design.Design @@ -144,13 +144,22 @@ func calculateMetrics(snapshots []*simulation.TickSnapshot, design design.Design
totalHealthy := 0
totalNodes := 0
// Build map of outgoing connections to identify final destinations
outgoingConnections := make(map[string]bool)
for _, conn := range design.Connections {
outgoingConnections[conn.Source] = true
}
// Calculate aggregate metrics across all snapshots
for _, snapshot := range snapshots {
// Count total requests processed in this tick
for _, requests := range snapshot.Emitted {
totalRequests += len(requests)
for _, req := range requests {
totalLatency += req.LatencyMS
for nodeID, requests := range snapshot.Emitted {
// Only count requests from final destination nodes (no outgoing connections)
if !outgoingConnections[nodeID] {
totalRequests += len(requests)
for _, req := range requests {
totalLatency += req.LatencyMS
}
}
}

36
static/app.js

@ -213,41 +213,7 @@ export class CanvasApp { @@ -213,41 +213,7 @@ export class CanvasApp {
return {};
}
showResults(result) {
const metrics = result.metrics;
let message = '';
// Level validation results
if (result.levelName) {
if (result.passed) {
message += `Level "${result.levelName}" PASSED!\n`;
message += `Score: ${result.score}/100\n\n`;
} else {
message += `Level "${result.levelName}" FAILED\n`;
message += `Score: ${result.score}/100\n\n`;
}
// Add detailed feedback
if (result.Feedback && result.Feedback.length > 0) {
message += result.Feedback.join('\n') + '\n\n';
}
} else {
message += `Simulation Complete!\n\n`;
}
// Performance metrics
message += `Performance Metrics:\n`;
message += `• Throughput: ${metrics.throughput} req/sec\n`;
message += `• Avg Latency: ${metrics.latency_avg}ms\n`;
message += `• Availability: ${metrics.availability.toFixed(1)}%\n`;
message += `• Monthly Cost: $${metrics.cost_monthly}\n\n`;
message += `Timeline: ${result.timeline.length} ticks simulated`;
alert(message);
// TODO: Later replace with redirect to results page or modal
console.log('Full simulation data:', result);
}
// showResults function removed - now handled by redirect to success/failure pages
showError(errorMessage) {
alert(`Simulation Error:\n\n${errorMessage}\n\nPlease check your design and try again.`);

13
static/commands.js

@ -292,16 +292,9 @@ export class RunSimulationCommand extends Command { @@ -292,16 +292,9 @@ export class RunSimulationCommand extends Command {
return;
}
// Fallback: try to parse as JSON for backward compatibility
const result = await response.json();
console.log('result', result);
if (result.passed && result.success) {
console.log('Simulation successful:', result);
app.showResults(result);
} else {
console.error('Simulation failed:', result.Error);
app.showError(result.Error || 'Simulation failed');
}
// If we get here, something went wrong - the server should always redirect
console.error('Unexpected response from server - expected redirect but got:', response.status);
app.showError('Unexpected server response. Please try again.');
} catch (error) {
console.error('Network error:', error);

24
static/failure.html

@ -125,6 +125,12 @@ @@ -125,6 +125,12 @@
50% { opacity: 0.8; }
}
.header-logo-container {
display: flex;
align-items: center;
gap: 12px;
}
.header-text {
font-size: 24px;
margin: 0;
@ -132,6 +138,19 @@ @@ -132,6 +138,19 @@
transition: all 3s ease-in-out;
}
.beta-pill {
background: linear-gradient(45deg, #ff6b35, #f7931e);
color: white;
padding: 4px 8px;
border-radius: 12px;
font-size: 0.7rem;
font-weight: 700;
text-transform: uppercase;
letter-spacing: 0.5px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
transition: all 3s ease-in-out;
}
.recovering .header-text {
text-shadow: 0 0 10px rgba(0, 255, 136, 0.8)
}
@ -636,7 +655,10 @@ @@ -636,7 +655,10 @@
<div class="screen-overlay"></div>
<div class="header">
<h1 class="header-text">System Design Game</h1>
<div class="header-logo-container">
<h1 class="header-text">System Design Game</h1>
<div class="beta-pill">BETA</div>
</div>
</div>
<div class="failure-container">

23
static/success.html

@ -77,11 +77,29 @@ body { @@ -77,11 +77,29 @@ body {
justify-content: space-between;
}
.header-logo-container {
display: flex;
align-items: center;
gap: 12px;
}
.header-text {
font-size: 24px;
margin: 0;
}
.beta-pill {
background: linear-gradient(45deg, #ff6b35, #f7931e);
color: white;
padding: 4px 8px;
border-radius: 12px;
font-size: 0.7rem;
font-weight: 700;
text-transform: uppercase;
letter-spacing: 0.5px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}
#main-content {
display: flex;
flex-direction: row;
@ -579,7 +597,10 @@ input[name="tab"] { @@ -579,7 +597,10 @@ input[name="tab"] {
<body>
<div id="page-container">
<div id="sd-header">
<h1 class="header-text">System Design Game</h1>
<div class="header-logo-container">
<h1 class="header-text">System Design Game</h1>
<div class="beta-pill">BETA</div>
</div>
<div class="userbox">
<div class="status-indicator" style="color: var(--color-text-accent); font-weight: bold;">
✅ SYSTEM SUCCESS

Loading…
Cancel
Save