Spaces:
Runtime error
Runtime error
File size: 24,423 Bytes
4088a7c d933a8b 4088a7c d933a8b 4088a7c d933a8b 4088a7c d933a8b 4088a7c d933a8b 4088a7c d933a8b 4088a7c | 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 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 | {% extends "base.html" %}
{% block page_title %}Create Scenario{% endblock %}
{% block content %}
<div class="page-header">
<h2>Create New Scenario</h2>
<p>Build a simulation or optimization across Media, Consumer Promo & Trade buckets</p>
</div>
<!-- ═══════════════════════════════════════════════════════════════
STEP 1: Scenario Configuration
═══════════════════════════════════════════════════════════════ -->
<div class="section-header">
<h3>⚙ Step 1: Scenario Configuration</h3>
<span class="section-subtitle">Define scope, type, and objectives</span>
</div>
<div class="screen-filters" style="margin-bottom:6px;">
<div class="filter-group">
<label>Scenario Name</label>
<input type="text" id="scenarioName" placeholder="My Scenario" class="sim-input" style="width:160px;">
</div>
<div class="filter-group">
<label>Type</label>
<select id="scenarioType" onchange="toggleScenarioType()">
<option value="simulation">Simulation</option>
<option value="optimization">Optimization</option>
</select>
</div>
<div class="filter-group">
<label>Retailer</label>
<select id="scopeRetailer">
{% for r in sim_retailers %}
<option value="{{ r.value }}" {{ 'selected' if r.value == 'Shoppers Drug Mart' }}>{{ r.label }}</option>
{% endfor %}
</select>
</div>
<div class="filter-group">
<label>Category</label>
<select id="scopeCategory" onchange="onCategoryChange()">
{% for c in sim_categories %}
<option value="{{ c.value }}" {{ 'selected' if c.value == 'Foods' }}>{{ c.label }}</option>
{% endfor %}
</select>
</div>
<div class="filter-group">
<label>Brand</label>
<select id="scopeBrand" onchange="onBrandChange()">
{% for b in sim_brands %}
<option value="{{ b.value }}" data-cat="{{ b.category }}" {{ 'selected' if b.value == 'Brand 1' }}>{{ b.label }}</option>
{% endfor %}
</select>
</div>
<div class="filter-group">
<label>Start</label>
<input type="date" id="scopeStart" value="2025-01-06" class="sim-input">
</div>
<div class="filter-group">
<label>End</label>
<input type="date" id="scopeEnd" value="2025-06-30" class="sim-input">
</div>
</div>
<!-- Optimization-only fields -->
<div id="optimFields" style="display:none;">
<div class="screen-filters" style="margin-bottom:6px;">
<div class="filter-group">
<label>Objective</label>
<select id="objective">
<option value="maximize_revenue">Maximize Revenue</option>
<option value="maximize_roas">Maximize ROAS</option>
<option value="volume_growth">Volume Growth Target</option>
<option value="profit_max">Profit Maximization</option>
</select>
</div>
<div class="filter-group">
<label>Business KPI</label>
<select id="businessKPI">
{% for k in sim_kpis %}
<option value="{{ k.value }}">{{ k.label }}</option>
{% endfor %}
</select>
</div>
<div class="filter-group">
<label>Growth Target (%)</label>
<input type="number" id="targetGrowth" value="5" min="1" max="50" class="sim-input" style="width:80px;">
</div>
<div class="filter-group">
<label>Total Budget ($)</label>
<input type="number" id="totalBudget" placeholder="Auto" class="sim-input" style="width:130px;">
</div>
</div>
</div>
<!-- ═══════════════════════════════════════════════════════════════
STEP 2: THREE-BUCKET ALLOCATION
═══════════════════════════════════════════════════════════════ -->
<div class="section-header">
<h3>💰 Step 2: Marketing Mix Allocation</h3>
<span class="section-subtitle">Configure Media, Consumer Promo, and Trade investments</span>
</div>
<!-- Tab Navigation for 3 Buckets -->
<div class="bucket-tabs" style="display:flex;gap:0;margin-bottom:0;border-bottom:2px solid rgba(255,255,255,0.08);">
<button class="bucket-tab active" data-bucket="media" onclick="switchBucket('media')">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" style="width:16px;height:16px;"><rect x="2" y="3" width="20" height="14" rx="2"/><line x1="8" y1="21" x2="16" y2="21"/><line x1="12" y1="17" x2="12" y2="21"/></svg>
Media
</button>
<button class="bucket-tab" data-bucket="promo" onclick="switchBucket('promo')">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" style="width:16px;height:16px;"><path d="M20.59 13.41l-7.17 7.17a2 2 0 0 1-2.83 0L2 12V2h10l8.59 8.59a2 2 0 0 1 0 2.82z"/><line x1="7" y1="7" x2="7.01" y2="7"/></svg>
Consumer Promo
</button>
<button class="bucket-tab" data-bucket="trade" onclick="switchBucket('trade')">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" style="width:16px;height:16px;"><rect x="1" y="3" width="15" height="13"/><polygon points="16 8 20 8 23 11 23 16 16 16 16 8"/><circle cx="5.5" cy="18.5" r="2.5"/><circle cx="18.5" cy="18.5" r="2.5"/></svg>
Trade Promo
</button>
</div>
<!-- ── Media Bucket ──────────────────────────────────── -->
<div id="bucket-media" class="bucket-panel" style="display:block;">
<div class="table-container" style="margin-bottom:12px;">
<div class="table-header">
<h3>Media Channel Allocation</h3>
<span style="color:#9ca3af;font-size:12px;">Set spend per channel (TV, Digital, etc.)</span>
</div>
<div id="mediaSliders" style="padding:16px;">
{% for ch in media_channels %}
<div class="slider-row" style="display:grid;grid-template-columns:140px 1fr 200px;align-items:center;gap:12px;margin-bottom:10px;">
<label style="font-weight:600;color:#e0e0e0;font-size:13px;">{{ ch }}</label>
<input type="range" class="media-slider" data-channel="{{ ch }}"
min="0" max="{{ (media_spend_data.get(ch, 500000) * 3)|int }}"
step="{{ (media_spend_data.get(ch, 500000) / 100)|int or 1000 }}"
value="{{ media_spend_data.get(ch, 200000)|int }}"
oninput="updateMediaLabel(this)">
<div style="display:flex;align-items:center;gap:8px;justify-content:flex-end;">
<span class="media-val" style="font-weight:600;color:var(--accent-teal);min-width:90px;text-align:right;">${{ '{:,.0f}'.format(media_spend_data.get(ch, 200000)) }}</span>
<input type="number" class="media-input" data-channel="{{ ch }}"
value="{{ media_spend_data.get(ch, 200000)|int }}" min="0"
style="width:100px;" class="sim-input"
onchange="syncMediaSlider(this)">
</div>
</div>
{% endfor %}
{% if not media_channels %}
<div style="color:#6b7280;text-align:center;padding:20px;">No media channels found in data. Using defaults.</div>
{% endif %}
<div style="border-top:1px solid rgba(255,255,255,0.08);margin-top:8px;padding-top:8px;display:flex;justify-content:space-between;align-items:center;">
<strong style="color:#c98500;">Total Media Spend:</strong>
<strong id="totalMediaSpend" style="color:#c98500;font-size:16px;">$0</strong>
</div>
</div>
</div>
</div>
<!-- ── Consumer Promo Bucket ─────────────────────────── -->
<div id="bucket-promo" class="bucket-panel" style="display:none;">
<div class="table-container" style="margin-bottom:12px;">
<div class="table-header">
<h3>Consumer Promo Events</h3>
<button class="btn-apply" onclick="addPromoEvent()" style="font-size:12px;padding:4px 12px;">+ Add Promo Event</button>
</div>
<div class="table-wrapper">
<table class="data-table" id="promoEventsTable">
<thead>
<tr>
<th>PPG</th>
<th>Mechanic</th>
<th>Offer Spec</th>
<th>Feature</th>
<th>Display</th>
<th>Start</th>
<th>End</th>
<th>Action</th>
</tr>
</thead>
<tbody id="promoEventsBody">
<tr id="noPromoRow"><td colspan="8" style="text-align:center;color:#6b7280;padding:14px;">No promo events. Click "+ Add Promo Event" to create events with BOGO, TPR, Multi-Buy, or Dollar Off mechanics.</td></tr>
</tbody>
</table>
</div>
</div>
</div>
<!-- ── Trade Bucket ──────────────────────────────────── -->
<div id="bucket-trade" class="bucket-panel" style="display:none;">
<div class="table-container" style="margin-bottom:12px;">
<div class="table-header">
<h3>Trade Promo Events</h3>
<button class="btn-apply" onclick="addTradeEvent()" style="font-size:12px;padding:4px 12px;">+ Add Trade Event</button>
</div>
<div class="table-wrapper">
<table class="data-table" id="tradeEventsTable">
<thead>
<tr>
<th>Event Name</th>
<th>Trade Mechanic</th>
<th>Retailer</th>
<th>Start</th>
<th>End</th>
<th class="num">Spend ($)</th>
<th>Action</th>
</tr>
</thead>
<tbody id="tradeEventsBody">
<tr id="noTradeRow"><td colspan="7" style="text-align:center;color:#6b7280;padding:14px;">No trade events. Click "+ Add Trade Event" to create Off-invoice, Bill-back, Scan-down, etc.</td></tr>
</tbody>
</table>
</div>
</div>
</div>
<!-- ── Run / Save Buttons ────────────────────────────── -->
<div style="display:flex;gap:12px;margin:16px 0 20px;">
<button class="btn-apply" onclick="runScenario()" style="padding:10px 32px;font-size:14px;">
▶ Run Scenario
</button>
<button class="btn-apply" id="runOptimBtn" onclick="runOptimization()" style="padding:10px 24px;font-size:14px;display:none;">
🔄 Run Optimization
</button>
<button class="btn-apply" onclick="saveScenario()" id="saveBtn" style="padding:10px 24px;font-size:14px;opacity:0.5;pointer-events:none;">
💾 Save Scenario
</button>
</div>
<!-- ═══════════════════════════════════════════════════════════════
STEP 3: RESULTS
═══════════════════════════════════════════════════════════════ -->
<div id="resultsSection" style="display:none;">
<div class="section-header">
<h3>📊 Step 3: Results</h3>
<span class="section-subtitle">Simulation output across all 3 buckets</span>
</div>
<!-- KPI Cards -->
<div class="kpi-grid" id="createKpiGrid"></div>
<!-- Budget + Waterfall -->
<div class="charts-grid">
<div class="chart-container">
<div class="chart-header">
<span class="chart-title">Budget Allocation by Bucket</span>
<div class="chart-actions"><button class="chart-action-btn" onclick="expandChart('chart_budget')" title="Fullscreen"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polyline points="15 3 21 3 21 9"/><polyline points="9 21 3 21 3 15"/><line x1="21" y1="3" x2="14" y2="10"/><line x1="3" y1="21" x2="10" y2="14"/></svg></button></div>
</div>
<div class="chart-area" id="chart_budget"></div>
</div>
<div class="chart-container">
<div class="chart-header">
<span class="chart-title">Revenue Impact Waterfall</span>
<div class="chart-actions"><button class="chart-action-btn" onclick="expandChart('chart_waterfall')" title="Fullscreen"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polyline points="15 3 21 3 21 9"/><polyline points="9 21 3 21 3 15"/><line x1="21" y1="3" x2="14" y2="10"/><line x1="3" y1="21" x2="10" y2="14"/></svg></button></div>
</div>
<div class="chart-area" id="chart_waterfall"></div>
</div>
</div>
<!-- Media Channels + Trade -->
<div class="charts-grid" id="mediaTradeCharts" style="display:none;">
<div class="chart-container">
<div class="chart-header">
<span class="chart-title">Media Channel Performance (Spend vs Response)</span>
<div class="chart-actions"><button class="chart-action-btn" onclick="expandChart('chart_media')" title="Fullscreen"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polyline points="15 3 21 3 21 9"/><polyline points="9 21 3 21 3 15"/><line x1="21" y1="3" x2="14" y2="10"/><line x1="3" y1="21" x2="10" y2="14"/></svg></button></div>
</div>
<div class="chart-area" id="chart_media"></div>
</div>
<div class="chart-container" id="tradeChartContainer" style="display:none;">
<div class="chart-header">
<span class="chart-title">Trade Events (Spend vs Incremental Revenue)</span>
<div class="chart-actions"><button class="chart-action-btn" onclick="expandChart('chart_trade')" title="Fullscreen"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polyline points="15 3 21 3 21 9"/><polyline points="9 21 3 21 3 15"/><line x1="21" y1="3" x2="14" y2="10"/><line x1="3" y1="21" x2="10" y2="14"/></svg></button></div>
</div>
<div class="chart-area" id="chart_trade"></div>
</div>
</div>
<!-- Promo Calendar + PPG Summary -->
<div class="charts-grid" id="promoCharts" style="display:none;">
<div class="chart-container">
<div class="chart-header">
<span class="chart-title">Promo & Trade Calendar</span>
<div class="chart-actions"><button class="chart-action-btn" onclick="expandChart('chart_promo_cal')" title="Fullscreen"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polyline points="15 3 21 3 21 9"/><polyline points="9 21 3 21 3 15"/><line x1="21" y1="3" x2="14" y2="10"/><line x1="3" y1="21" x2="10" y2="14"/></svg></button></div>
</div>
<div class="chart-area" id="chart_promo_cal"></div>
</div>
<div class="chart-container">
<div class="chart-header">
<span class="chart-title">PPG Performance (iGP & Volume Lift)</span>
<div class="chart-actions"><button class="chart-action-btn" onclick="expandChart('chart_ppg')" title="Fullscreen"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polyline points="15 3 21 3 21 9"/><polyline points="9 21 3 21 3 15"/><line x1="21" y1="3" x2="14" y2="10"/><line x1="3" y1="21" x2="10" y2="14"/></svg></button></div>
</div>
<div class="chart-area" id="chart_ppg"></div>
</div>
</div>
<!-- Optimization Charts -->
<div id="optimCharts" style="display:none;">
<div class="section-header">
<h3>🎯 Optimization Results</h3>
<span class="section-subtitle">Current vs Optimized allocation across Media & Trade</span>
</div>
<div class="charts-grid">
<div class="chart-container">
<div class="chart-header">
<span class="chart-title">Current vs Optimized Allocation</span>
<div class="chart-actions"><button class="chart-action-btn" onclick="expandChart('chart_optim_donuts')" title="Fullscreen"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polyline points="15 3 21 3 21 9"/><polyline points="9 21 3 21 3 15"/><line x1="21" y1="3" x2="14" y2="10"/><line x1="3" y1="21" x2="10" y2="14"/></svg></button></div>
</div>
<div class="chart-area" id="chart_optim_donuts"></div>
</div>
<div class="chart-container">
<div class="chart-header">
<span class="chart-title">Reallocation Revenue Waterfall</span>
<div class="chart-actions"><button class="chart-action-btn" onclick="expandChart('chart_reallocation')" title="Fullscreen"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polyline points="15 3 21 3 21 9"/><polyline points="9 21 3 21 3 15"/><line x1="21" y1="3" x2="14" y2="10"/><line x1="3" y1="21" x2="10" y2="14"/></svg></button></div>
</div>
<div class="chart-area" id="chart_reallocation"></div>
</div>
</div>
<div class="charts-grid">
<div class="chart-container full-width">
<div class="chart-header">
<span class="chart-title">Sensitivity Analysis (Tornado)</span>
<div class="chart-actions"><button class="chart-action-btn" onclick="expandChart('chart_tornado')" title="Fullscreen"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polyline points="15 3 21 3 21 9"/><polyline points="9 21 3 21 3 15"/><line x1="21" y1="3" x2="14" y2="10"/><line x1="3" y1="21" x2="10" y2="14"/></svg></button></div>
</div>
<div class="chart-area" id="chart_tornado"></div>
</div>
</div>
<!-- Optimized Promo Calendar -->
<div class="charts-grid" id="optCalendarSection" style="display:none;">
<div class="chart-container">
<div class="chart-header">
<span class="chart-title">⭐ Optimized Promo Calendar</span>
</div>
<div class="chart-area" id="chart_opt_calendar"></div>
</div>
<div class="chart-container">
<div class="chart-header">
<span class="chart-title">Optimized PPG Performance</span>
</div>
<div class="chart-area" id="chart_opt_ppg"></div>
</div>
</div>
<!-- Optimization Detail Table -->
<div class="table-container">
<div class="table-header"><h3>Optimization Detail</h3></div>
<div class="table-wrapper">
<table class="data-table" id="optimTable">
<thead>
<tr>
<th>Bucket</th>
<th>Channel / Mechanic</th>
<th class="num">Current Spend</th>
<th class="num">Optimized Spend</th>
<th class="num">Change</th>
<th class="num">Current Response</th>
<th class="num">Optimized Response</th>
<th class="num">Incremental</th>
<th class="num">Cur. ROAS</th>
<th class="num">Opt. ROAS</th>
</tr>
</thead>
<tbody id="optimBody"></tbody>
</table>
</div>
</div>
</div>
<!-- PPG Summary Table (Simulation) -->
<div id="ppgTableSection" style="display:none;">
<div class="table-container">
<div class="table-header"><h3>PPG Financial Summary</h3></div>
<div class="table-wrapper">
<table class="data-table" id="ppgTable">
<thead>
<tr>
<th>PPG</th>
<th class="num">Baseline Units</th>
<th class="num">Total Units</th>
<th class="num">Incremental</th>
<th class="num">Lift %</th>
<th class="num">iGTS</th>
<th class="num">iNTS</th>
<th class="num">iGP</th>
<th class="num">ROI</th>
</tr>
</thead>
<tbody id="ppgBody"></tbody>
</table>
</div>
</div>
</div>
<!-- Media Summary Table -->
<div id="mediaTableSection" style="display:none;">
<div class="table-container">
<div class="table-header"><h3>Media Channel Detail</h3></div>
<div class="table-wrapper">
<table class="data-table" id="mediaTable">
<thead>
<tr>
<th>Channel</th>
<th class="num">Spend</th>
<th class="num">Response</th>
<th class="num">ROAS</th>
<th class="num">Marginal Return</th>
<th class="num">Saturation %</th>
</tr>
</thead>
<tbody id="mediaBody"></tbody>
</table>
</div>
</div>
</div>
</div>
<style>
.sim-input{padding:6px 10px;border-radius:6px;border:1px solid rgba(255,255,255,0.1);background:var(--bg-primary);color:var(--text-primary);font-size:13px;}
.bucket-tabs{display:flex;gap:0;margin-bottom:0;border-bottom:2px solid rgba(255,255,255,0.08);}
.bucket-tab{padding:10px 20px;background:none;border:none;color:var(--text-muted);font-size:13px;font-weight:600;cursor:pointer;display:flex;align-items:center;gap:6px;border-bottom:2px solid transparent;transition:all 0.2s;}
.bucket-tab:hover{color:var(--text-primary);background:rgba(255,255,255,0.03);}
.bucket-tab.active{color:var(--text-primary);border-bottom-color:var(--text-primary);background:rgba(255,255,255,0.04);}
.slider-row input[type="range"]{-webkit-appearance:none;height:6px;border-radius:3px;background:rgba(255,255,255,0.12);outline:none;}
.slider-row input[type="range"]::-webkit-slider-thumb{-webkit-appearance:none;width:18px;height:18px;border-radius:50%;background:var(--accent-gradient);cursor:pointer;border:2px solid var(--bg-primary);}
.slider-row input[type="number"]{padding:4px 8px;border-radius:4px;border:1px solid rgba(255,255,255,0.1);background:var(--bg-primary);color:var(--text-primary);font-size:12px;}
</style>
{% endblock %}
{% block scripts %}
<script>
</script>
<script src="{{ url_for('static', filename='js/strategy_create.js') }}"></script>
{% endblock %}
|