Upload 3 files
Browse files- README.md +29 -13
- app.py +990 -0
- requirements.txt +5 -3
README.md
CHANGED
|
@@ -1,19 +1,35 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
-
colorTo:
|
| 6 |
-
sdk:
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
- streamlit
|
| 10 |
pinned: false
|
| 11 |
-
|
| 12 |
---
|
| 13 |
|
| 14 |
-
#
|
| 15 |
|
| 16 |
-
|
| 17 |
|
| 18 |
-
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
title: Meridia Frontier TRS Simulator
|
| 3 |
+
emoji: π’
|
| 4 |
+
colorFrom: blue
|
| 5 |
+
colorTo: blue
|
| 6 |
+
sdk: streamlit
|
| 7 |
+
sdk_version: 1.32.0
|
| 8 |
+
app_file: app.py
|
|
|
|
| 9 |
pinned: false
|
| 10 |
+
license: mit
|
| 11 |
---
|
| 12 |
|
| 13 |
+
# The Meridia Frontier β TRS Simulator
|
| 14 |
|
| 15 |
+
A gamified Time Release Study (TRS) simulator for customs policy analysis.
|
| 16 |
|
| 17 |
+
## Features
|
| 18 |
+
- πΊ **Isometric Port View** β Live Phaser.js game canvas showing Azure Port, Vortex Air Terminal & Stone Pass
|
| 19 |
+
- π **Japan-style TRS Charts** β Stacked bar breakdown of release time segments
|
| 20 |
+
- π **Audit Ledger** β Full CSV export of every simulated Bill of Entry
|
| 21 |
+
- β **Policy Levers** β Advance Filing, RMS Facilitation, AEO Enrollment, PGA Single Window, Deferred Duty, Auto-OOC
|
| 22 |
+
|
| 23 |
+
## How to use
|
| 24 |
+
1. Adjust policy sliders in the sidebar
|
| 25 |
+
2. Click **RUN SIMULATION**
|
| 26 |
+
3. Watch cargo dots appear on the isometric port map
|
| 27 |
+
4. Switch to **TRS REPORT** tab for the stacked bar chart
|
| 28 |
+
5. Download the **Audit Ledger CSV** for full data
|
| 29 |
+
|
| 30 |
+
## Tech Stack
|
| 31 |
+
- `SimPy` β Discrete event simulation engine
|
| 32 |
+
- `Streamlit` β Web framework
|
| 33 |
+
- `Phaser.js 3` β Isometric game rendering (via st.components)
|
| 34 |
+
- `Plotly` β TRS analytics charts
|
| 35 |
+
- `Pandas` β CSV export
|
app.py
ADDED
|
@@ -0,0 +1,990 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import simpy
|
| 3 |
+
import numpy as np
|
| 4 |
+
import pandas as pd
|
| 5 |
+
import plotly.graph_objects as go
|
| 6 |
+
import json
|
| 7 |
+
import random
|
| 8 |
+
from dataclasses import dataclass, field
|
| 9 |
+
from typing import List, Optional
|
| 10 |
+
import time
|
| 11 |
+
|
| 12 |
+
st.set_page_config(
|
| 13 |
+
page_title="Meridia Frontier β TRS Simulator",
|
| 14 |
+
page_icon="π’",
|
| 15 |
+
layout="wide",
|
| 16 |
+
initial_sidebar_state="expanded"
|
| 17 |
+
)
|
| 18 |
+
|
| 19 |
+
# ββ Inject custom CSS ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 20 |
+
st.markdown("""
|
| 21 |
+
<style>
|
| 22 |
+
@import url('https://fonts.googleapis.com/css2?family=Rajdhani:wght@400;500;600;700&family=Share+Tech+Mono&display=swap');
|
| 23 |
+
|
| 24 |
+
:root {
|
| 25 |
+
--meridia-dark: #0a0e1a;
|
| 26 |
+
--meridia-navy: #0d1b2a;
|
| 27 |
+
--meridia-blue: #1a3a5c;
|
| 28 |
+
--meridia-cyan: #00d4ff;
|
| 29 |
+
--meridia-gold: #f5a623;
|
| 30 |
+
--meridia-green: #00ff88;
|
| 31 |
+
--meridia-red: #ff4757;
|
| 32 |
+
--meridia-text: #c8d8e8;
|
| 33 |
+
--meridia-muted: #5a7a9a;
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
html, body, [class*="css"] {
|
| 37 |
+
font-family: 'Rajdhani', sans-serif;
|
| 38 |
+
background-color: var(--meridia-dark) !important;
|
| 39 |
+
color: var(--meridia-text) !important;
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
.stApp { background: var(--meridia-dark) !important; }
|
| 43 |
+
|
| 44 |
+
/* Sidebar */
|
| 45 |
+
[data-testid="stSidebar"] {
|
| 46 |
+
background: linear-gradient(180deg, #0d1b2a 0%, #0a0e1a 100%) !important;
|
| 47 |
+
border-right: 1px solid #1a3a5c !important;
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
/* Metrics */
|
| 51 |
+
[data-testid="stMetric"] {
|
| 52 |
+
background: rgba(0,212,255,0.05) !important;
|
| 53 |
+
border: 1px solid rgba(0,212,255,0.2) !important;
|
| 54 |
+
border-radius: 8px !important;
|
| 55 |
+
padding: 12px !important;
|
| 56 |
+
}
|
| 57 |
+
[data-testid="stMetricValue"] { color: var(--meridia-cyan) !important; font-family: 'Share Tech Mono' !important; font-size: 1.8rem !important; }
|
| 58 |
+
[data-testid="stMetricLabel"] { color: var(--meridia-muted) !important; font-size: 0.75rem !important; letter-spacing: 0.1em !important; }
|
| 59 |
+
[data-testid="stMetricDelta"] { font-family: 'Share Tech Mono' !important; }
|
| 60 |
+
|
| 61 |
+
/* Sliders */
|
| 62 |
+
[data-testid="stSlider"] > div > div > div > div {
|
| 63 |
+
background: var(--meridia-cyan) !important;
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
/* Buttons */
|
| 67 |
+
.stButton > button {
|
| 68 |
+
background: linear-gradient(135deg, #1a3a5c, #0d1b2a) !important;
|
| 69 |
+
border: 1px solid var(--meridia-cyan) !important;
|
| 70 |
+
color: var(--meridia-cyan) !important;
|
| 71 |
+
font-family: 'Rajdhani', sans-serif !important;
|
| 72 |
+
font-weight: 600 !important;
|
| 73 |
+
letter-spacing: 0.1em !important;
|
| 74 |
+
border-radius: 4px !important;
|
| 75 |
+
transition: all 0.2s !important;
|
| 76 |
+
}
|
| 77 |
+
.stButton > button:hover {
|
| 78 |
+
background: rgba(0,212,255,0.15) !important;
|
| 79 |
+
box-shadow: 0 0 12px rgba(0,212,255,0.3) !important;
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
/* Section headers */
|
| 83 |
+
h1, h2, h3 { font-family: 'Rajdhani', sans-serif !important; letter-spacing: 0.05em !important; }
|
| 84 |
+
h1 { color: var(--meridia-cyan) !important; }
|
| 85 |
+
h2 { color: var(--meridia-gold) !important; }
|
| 86 |
+
h3 { color: var(--meridia-text) !important; }
|
| 87 |
+
|
| 88 |
+
/* Tabs */
|
| 89 |
+
[data-testid="stTabs"] button {
|
| 90 |
+
font-family: 'Rajdhani', sans-serif !important;
|
| 91 |
+
font-weight: 600 !important;
|
| 92 |
+
letter-spacing: 0.08em !important;
|
| 93 |
+
color: var(--meridia-muted) !important;
|
| 94 |
+
}
|
| 95 |
+
[data-testid="stTabs"] button[aria-selected="true"] {
|
| 96 |
+
color: var(--meridia-cyan) !important;
|
| 97 |
+
border-bottom-color: var(--meridia-cyan) !important;
|
| 98 |
+
}
|
| 99 |
+
|
| 100 |
+
/* Dataframe */
|
| 101 |
+
[data-testid="stDataFrame"] { border: 1px solid #1a3a5c !important; }
|
| 102 |
+
|
| 103 |
+
/* Scrollbar */
|
| 104 |
+
::-webkit-scrollbar { width: 4px; }
|
| 105 |
+
::-webkit-scrollbar-track { background: var(--meridia-dark); }
|
| 106 |
+
::-webkit-scrollbar-thumb { background: var(--meridia-blue); border-radius: 2px; }
|
| 107 |
+
|
| 108 |
+
.port-badge {
|
| 109 |
+
display: inline-block;
|
| 110 |
+
padding: 2px 10px;
|
| 111 |
+
border-radius: 20px;
|
| 112 |
+
font-size: 0.7rem;
|
| 113 |
+
font-weight: 700;
|
| 114 |
+
letter-spacing: 0.1em;
|
| 115 |
+
text-transform: uppercase;
|
| 116 |
+
}
|
| 117 |
+
|
| 118 |
+
.glow-text { text-shadow: 0 0 10px rgba(0,212,255,0.5); }
|
| 119 |
+
</style>
|
| 120 |
+
""", unsafe_allow_html=True)
|
| 121 |
+
|
| 122 |
+
|
| 123 |
+
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 124 |
+
# DATA MODEL
|
| 125 |
+
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 126 |
+
|
| 127 |
+
@dataclass
|
| 128 |
+
class BoE:
|
| 129 |
+
shipment_id: str
|
| 130 |
+
port_type: str # Sea / Air / Land
|
| 131 |
+
filing_type: str # Advance / Normal
|
| 132 |
+
pga_involved: bool
|
| 133 |
+
aeo_status: str # T1 / T2 / T3 / None
|
| 134 |
+
machine_release: bool = False
|
| 135 |
+
t_arrival: float = 0.0
|
| 136 |
+
t_filed: float = 0.0
|
| 137 |
+
t_assessed: float = 0.0
|
| 138 |
+
t_payment: float = 0.0
|
| 139 |
+
t_ooc: float = 0.0
|
| 140 |
+
|
| 141 |
+
@property
|
| 142 |
+
def total_hours(self): return max(self.t_ooc - self.t_arrival, 0)
|
| 143 |
+
@property
|
| 144 |
+
def seg_filing(self): return max(self.t_filed - self.t_arrival, 0)
|
| 145 |
+
@property
|
| 146 |
+
def seg_assessment(self): return max(self.t_assessed - self.t_filed, 0)
|
| 147 |
+
@property
|
| 148 |
+
def seg_payment(self): return max(self.t_payment - self.t_assessed, 0)
|
| 149 |
+
@property
|
| 150 |
+
def seg_logistics(self): return max(self.t_ooc - self.t_payment, 0)
|
| 151 |
+
|
| 152 |
+
|
| 153 |
+
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 154 |
+
# SIMPY SIMULATION ENGINE
|
| 155 |
+
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 156 |
+
|
| 157 |
+
def run_simulation(params: dict) -> List[BoE]:
|
| 158 |
+
"""Core SimPy discrete-event simulation of Meridia's three ports."""
|
| 159 |
+
results: List[BoE] = []
|
| 160 |
+
rng = np.random.default_rng(42)
|
| 161 |
+
|
| 162 |
+
env = simpy.Environment()
|
| 163 |
+
|
| 164 |
+
# Resources
|
| 165 |
+
officers_sea = simpy.Resource(env, capacity=params["officers_sea"])
|
| 166 |
+
officers_air = simpy.Resource(env, capacity=params["officers_air"])
|
| 167 |
+
officers_land = simpy.Resource(env, capacity=params["officers_land"])
|
| 168 |
+
|
| 169 |
+
PORT_CONFIG = {
|
| 170 |
+
"Sea": {"volume": 50, "resource": officers_sea, "speed_mult": 1.0},
|
| 171 |
+
"Air": {"volume": 10, "resource": officers_air, "speed_mult": 0.5},
|
| 172 |
+
"Land": {"volume": 25, "resource": officers_land, "speed_mult": 0.75},
|
| 173 |
+
}
|
| 174 |
+
|
| 175 |
+
counter = [0]
|
| 176 |
+
|
| 177 |
+
def process_boe(env, port_type, cfg):
|
| 178 |
+
counter[0] += 1
|
| 179 |
+
sid = f"BoE-{port_type[0]}{counter[0]:04d}"
|
| 180 |
+
|
| 181 |
+
# Determine attributes
|
| 182 |
+
is_advance = rng.random() < (params["advance_filing_pct"] / 100)
|
| 183 |
+
is_aeo = rng.random() < (params["aeo_enrollment_pct"] / 100)
|
| 184 |
+
is_pga = rng.random() < 0.35 # 35% PGA involvement
|
| 185 |
+
aeo_status = rng.choice(["T1","T2","T3"]) if is_aeo else "None"
|
| 186 |
+
green = rng.random() < (params["rms_facilitation_pct"] / 100)
|
| 187 |
+
|
| 188 |
+
boe = BoE(
|
| 189 |
+
shipment_id=sid,
|
| 190 |
+
port_type=port_type,
|
| 191 |
+
filing_type="Advance" if is_advance else "Normal",
|
| 192 |
+
pga_involved=is_pga,
|
| 193 |
+
aeo_status=aeo_status,
|
| 194 |
+
)
|
| 195 |
+
|
| 196 |
+
boe.t_arrival = env.now
|
| 197 |
+
|
| 198 |
+
# ββ Stage 1: Arrival β Filing ββββββββββββββββββββββββββββββββββββββ
|
| 199 |
+
if is_advance:
|
| 200 |
+
filing_delay = 0
|
| 201 |
+
else:
|
| 202 |
+
filing_delay = rng.gamma(shape=2, scale=12) * cfg["speed_mult"]
|
| 203 |
+
yield env.timeout(filing_delay)
|
| 204 |
+
boe.t_filed = env.now
|
| 205 |
+
|
| 206 |
+
# ββ Stage 2: Assessment ββββββββββββββββββββββββββββββββββββββββββββ
|
| 207 |
+
if green:
|
| 208 |
+
assess_delay = 0 # Green channel: skip
|
| 209 |
+
else:
|
| 210 |
+
with cfg["resource"].request() as req:
|
| 211 |
+
yield req
|
| 212 |
+
if is_aeo:
|
| 213 |
+
assess_delay = rng.gamma(shape=2, scale=2) * cfg["speed_mult"]
|
| 214 |
+
else:
|
| 215 |
+
assess_delay = rng.gamma(shape=2, scale=4) * cfg["speed_mult"]
|
| 216 |
+
# Physical exam
|
| 217 |
+
if rng.random() < 0.15 and not green:
|
| 218 |
+
assess_delay += rng.gamma(shape=3, scale=8) * cfg["speed_mult"]
|
| 219 |
+
yield env.timeout(assess_delay)
|
| 220 |
+
boe.t_assessed = env.now
|
| 221 |
+
|
| 222 |
+
# ββ Stage 3: Payment / PGA ββββββββββββββββββββββββββββββββββββββββ
|
| 223 |
+
if is_aeo and params["deferred_duty"]:
|
| 224 |
+
payment_delay = 0
|
| 225 |
+
else:
|
| 226 |
+
base_pay = rng.gamma(shape=2, scale=3)
|
| 227 |
+
if is_pga and not params["pga_single_window"]:
|
| 228 |
+
base_pay *= 4.0 # Big amber expansion
|
| 229 |
+
elif is_pga and params["pga_single_window"]:
|
| 230 |
+
base_pay *= 1.4
|
| 231 |
+
payment_delay = base_pay * cfg["speed_mult"]
|
| 232 |
+
yield env.timeout(payment_delay)
|
| 233 |
+
boe.t_payment = env.now
|
| 234 |
+
|
| 235 |
+
# ββ Stage 4: Out-of-Charge ββββββββββββββββββββββββββββββββββββββββ
|
| 236 |
+
if green and params["auto_ooc"]:
|
| 237 |
+
logistics_delay = 0
|
| 238 |
+
boe.machine_release = True
|
| 239 |
+
else:
|
| 240 |
+
logistics_delay = rng.gamma(shape=2, scale=1.5) * cfg["speed_mult"]
|
| 241 |
+
yield env.timeout(logistics_delay)
|
| 242 |
+
boe.t_ooc = env.now
|
| 243 |
+
|
| 244 |
+
results.append(boe)
|
| 245 |
+
|
| 246 |
+
def port_generator(env, port_type, cfg):
|
| 247 |
+
"""Generate shipments for a port with Poisson inter-arrivals."""
|
| 248 |
+
for _ in range(cfg["volume"]):
|
| 249 |
+
env.process(process_boe(env, port_type, cfg))
|
| 250 |
+
interarrival = rng.exponential(scale=1.5)
|
| 251 |
+
yield env.timeout(interarrival)
|
| 252 |
+
|
| 253 |
+
for ptype, cfg in PORT_CONFIG.items():
|
| 254 |
+
env.process(port_generator(env, ptype, cfg))
|
| 255 |
+
|
| 256 |
+
env.run(until=500)
|
| 257 |
+
return results
|
| 258 |
+
|
| 259 |
+
|
| 260 |
+
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 261 |
+
# PHASER.JS ISOMETRIC GAME VIEW
|
| 262 |
+
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 263 |
+
|
| 264 |
+
def build_phaser_scene(results: List[BoE], params: dict) -> str:
|
| 265 |
+
"""Generate the Phaser.js isometric port visualization."""
|
| 266 |
+
|
| 267 |
+
art_h = round(params["avg_art"], 1) if results else 0
|
| 268 |
+
fac_pct = round(params["green_pct"], 1) if results else 0
|
| 269 |
+
aeo_pct = round(params["aeo_pct"], 1) if results else 0
|
| 270 |
+
mach_pct = round(params["machine_pct"], 1) if results else 0
|
| 271 |
+
target48 = round(params["target48_pct"], 1) if results else 0
|
| 272 |
+
ship_count = len([r for r in results if r.port_type=="Sea"]) if results else 0
|
| 273 |
+
air_count = len([r for r in results if r.port_type=="Air"]) if results else 0
|
| 274 |
+
land_count = len([r for r in results if r.port_type=="Land"]) if results else 0
|
| 275 |
+
|
| 276 |
+
# Shipment status data for visualization
|
| 277 |
+
if results:
|
| 278 |
+
statuses = []
|
| 279 |
+
for r in results[:60]:
|
| 280 |
+
if r.total_hours < 3: s = "fast"
|
| 281 |
+
elif r.total_hours < 24: s = "ok"
|
| 282 |
+
elif r.total_hours < 48: s = "slow"
|
| 283 |
+
else: s = "delayed"
|
| 284 |
+
statuses.append({"id": r.shipment_id, "port": r.port_type,
|
| 285 |
+
"hours": round(r.total_hours, 1), "status": s,
|
| 286 |
+
"machine": r.machine_release})
|
| 287 |
+
else:
|
| 288 |
+
statuses = []
|
| 289 |
+
|
| 290 |
+
statuses_json = json.dumps(statuses)
|
| 291 |
+
|
| 292 |
+
return f"""<!DOCTYPE html>
|
| 293 |
+
<html>
|
| 294 |
+
<head>
|
| 295 |
+
<meta charset="utf-8">
|
| 296 |
+
<style>
|
| 297 |
+
* {{ margin:0; padding:0; box-sizing:border-box; }}
|
| 298 |
+
body {{
|
| 299 |
+
background: #0a0e1a;
|
| 300 |
+
font-family: 'Rajdhani', 'Share Tech Mono', monospace;
|
| 301 |
+
overflow: hidden;
|
| 302 |
+
width: 100%;
|
| 303 |
+
height: 520px;
|
| 304 |
+
}}
|
| 305 |
+
@import url('https://fonts.googleapis.com/css2?family=Rajdhani:wght@600;700&family=Share+Tech+Mono&display=swap');
|
| 306 |
+
|
| 307 |
+
#game-container {{
|
| 308 |
+
position: relative;
|
| 309 |
+
width: 100%;
|
| 310 |
+
height: 100%;
|
| 311 |
+
}}
|
| 312 |
+
|
| 313 |
+
#hud {{
|
| 314 |
+
position: absolute;
|
| 315 |
+
top: 0; left: 0; right: 0;
|
| 316 |
+
display: flex;
|
| 317 |
+
justify-content: space-between;
|
| 318 |
+
align-items: flex-start;
|
| 319 |
+
padding: 12px 16px;
|
| 320 |
+
pointer-events: none;
|
| 321 |
+
z-index: 10;
|
| 322 |
+
}}
|
| 323 |
+
|
| 324 |
+
.hud-panel {{
|
| 325 |
+
background: rgba(10,14,26,0.85);
|
| 326 |
+
border: 1px solid rgba(0,212,255,0.3);
|
| 327 |
+
border-radius: 6px;
|
| 328 |
+
padding: 8px 14px;
|
| 329 |
+
backdrop-filter: blur(4px);
|
| 330 |
+
}}
|
| 331 |
+
|
| 332 |
+
.hud-title {{
|
| 333 |
+
font-family: 'Rajdhani', sans-serif;
|
| 334 |
+
font-size: 9px;
|
| 335 |
+
font-weight: 700;
|
| 336 |
+
letter-spacing: 0.15em;
|
| 337 |
+
color: #5a7a9a;
|
| 338 |
+
text-transform: uppercase;
|
| 339 |
+
margin-bottom: 2px;
|
| 340 |
+
}}
|
| 341 |
+
|
| 342 |
+
.hud-value {{
|
| 343 |
+
font-family: 'Share Tech Mono', monospace;
|
| 344 |
+
font-size: 22px;
|
| 345 |
+
font-weight: 400;
|
| 346 |
+
color: #00d4ff;
|
| 347 |
+
line-height: 1;
|
| 348 |
+
}}
|
| 349 |
+
|
| 350 |
+
.hud-value.good {{ color: #00ff88; }}
|
| 351 |
+
.hud-value.warn {{ color: #f5a623; }}
|
| 352 |
+
.hud-value.bad {{ color: #ff4757; }}
|
| 353 |
+
|
| 354 |
+
.hud-sub {{
|
| 355 |
+
font-size: 9px;
|
| 356 |
+
color: #5a7a9a;
|
| 357 |
+
margin-top: 2px;
|
| 358 |
+
font-family: 'Rajdhani', sans-serif;
|
| 359 |
+
letter-spacing: 0.05em;
|
| 360 |
+
}}
|
| 361 |
+
|
| 362 |
+
.hud-row {{ display: flex; gap: 10px; }}
|
| 363 |
+
|
| 364 |
+
#bottom-hud {{
|
| 365 |
+
position: absolute;
|
| 366 |
+
bottom: 0; left: 0; right: 0;
|
| 367 |
+
display: flex;
|
| 368 |
+
gap: 8px;
|
| 369 |
+
padding: 10px 16px;
|
| 370 |
+
z-index: 10;
|
| 371 |
+
pointer-events: none;
|
| 372 |
+
}}
|
| 373 |
+
|
| 374 |
+
.port-stat {{
|
| 375 |
+
background: rgba(10,14,26,0.85);
|
| 376 |
+
border: 1px solid rgba(0,212,255,0.2);
|
| 377 |
+
border-radius: 6px;
|
| 378 |
+
padding: 6px 12px;
|
| 379 |
+
display: flex;
|
| 380 |
+
align-items: center;
|
| 381 |
+
gap: 8px;
|
| 382 |
+
}}
|
| 383 |
+
|
| 384 |
+
.port-dot {{ width: 8px; height: 8px; border-radius: 50%; }}
|
| 385 |
+
.port-dot.sea {{ background: #00d4ff; box-shadow: 0 0 6px #00d4ff; }}
|
| 386 |
+
.port-dot.air {{ background: #f5a623; box-shadow: 0 0 6px #f5a623; }}
|
| 387 |
+
.port-dot.land {{ background: #00ff88; box-shadow: 0 0 6px #00ff88; }}
|
| 388 |
+
|
| 389 |
+
.port-name {{
|
| 390 |
+
font-size: 10px;
|
| 391 |
+
font-weight: 700;
|
| 392 |
+
letter-spacing: 0.1em;
|
| 393 |
+
color: #c8d8e8;
|
| 394 |
+
font-family: 'Rajdhani', sans-serif;
|
| 395 |
+
}}
|
| 396 |
+
|
| 397 |
+
.port-count {{
|
| 398 |
+
font-size: 14px;
|
| 399 |
+
font-family: 'Share Tech Mono', monospace;
|
| 400 |
+
color: #00d4ff;
|
| 401 |
+
}}
|
| 402 |
+
|
| 403 |
+
#ticker {{
|
| 404 |
+
position: absolute;
|
| 405 |
+
top: 50%; left: 50%;
|
| 406 |
+
transform: translate(-50%, -50%);
|
| 407 |
+
pointer-events: none;
|
| 408 |
+
z-index: 5;
|
| 409 |
+
text-align: center;
|
| 410 |
+
}}
|
| 411 |
+
|
| 412 |
+
#clock {{
|
| 413 |
+
font-family: 'Share Tech Mono', monospace;
|
| 414 |
+
font-size: 13px;
|
| 415 |
+
color: rgba(0,212,255,0.4);
|
| 416 |
+
letter-spacing: 0.2em;
|
| 417 |
+
}}
|
| 418 |
+
|
| 419 |
+
canvas {{ display: block; }}
|
| 420 |
+
#phaser-canvas {{ width: 100% !important; height: 100% !important; }}
|
| 421 |
+
</style>
|
| 422 |
+
</head>
|
| 423 |
+
<body>
|
| 424 |
+
<div id="game-container">
|
| 425 |
+
<div id="hud">
|
| 426 |
+
<div class="hud-panel">
|
| 427 |
+
<div class="hud-title">Average Release Time</div>
|
| 428 |
+
<div class="hud-value {'good' if art_h < 24 else 'warn' if art_h < 48 else 'bad'}">{art_h}h</div>
|
| 429 |
+
<div class="hud-sub">NTFAP Target: 48h</div>
|
| 430 |
+
</div>
|
| 431 |
+
|
| 432 |
+
<div class="hud-row">
|
| 433 |
+
<div class="hud-panel">
|
| 434 |
+
<div class="hud-title">Green Channel</div>
|
| 435 |
+
<div class="hud-value {'good' if fac_pct > 60 else 'warn'}">{fac_pct}%</div>
|
| 436 |
+
<div class="hud-sub">Facilitated</div>
|
| 437 |
+
</div>
|
| 438 |
+
<div class="hud-panel">
|
| 439 |
+
<div class="hud-title">Machine Release</div>
|
| 440 |
+
<div class="hud-value {'good' if mach_pct > 40 else 'warn'}">{mach_pct}%</div>
|
| 441 |
+
<div class="hud-sub">Auto-OOC</div>
|
| 442 |
+
</div>
|
| 443 |
+
<div class="hud-panel">
|
| 444 |
+
<div class="hud-title">Target β€48h</div>
|
| 445 |
+
<div class="hud-value {'good' if target48 > 80 else 'warn' if target48 > 60 else 'bad'}">{target48}%</div>
|
| 446 |
+
<div class="hud-sub">Achievement</div>
|
| 447 |
+
</div>
|
| 448 |
+
</div>
|
| 449 |
+
|
| 450 |
+
<div class="hud-panel">
|
| 451 |
+
<div class="hud-title">AEO Enrolled</div>
|
| 452 |
+
<div class="hud-value {'good' if aeo_pct > 50 else 'warn'}">{aeo_pct}%</div>
|
| 453 |
+
<div class="hud-sub">Trusted Traders</div>
|
| 454 |
+
</div>
|
| 455 |
+
</div>
|
| 456 |
+
|
| 457 |
+
<div id="bottom-hud">
|
| 458 |
+
<div class="port-stat">
|
| 459 |
+
<div class="port-dot sea"></div>
|
| 460 |
+
<span class="port-name">AZURE PORT</span>
|
| 461 |
+
<span class="port-count">{ship_count}</span>
|
| 462 |
+
</div>
|
| 463 |
+
<div class="port-stat">
|
| 464 |
+
<div class="port-dot air"></div>
|
| 465 |
+
<span class="port-name">VORTEX AIR</span>
|
| 466 |
+
<span class="port-count">{air_count}</span>
|
| 467 |
+
</div>
|
| 468 |
+
<div class="port-stat">
|
| 469 |
+
<div class="port-dot land"></div>
|
| 470 |
+
<span class="port-name">STONE PASS</span>
|
| 471 |
+
<span class="port-count">{land_count}</span>
|
| 472 |
+
</div>
|
| 473 |
+
<div id="clock" class="port-stat" style="margin-left:auto; border-color: rgba(0,212,255,0.15);">
|
| 474 |
+
<span id="sim-clock" style="font-family:'Share Tech Mono',monospace; font-size:12px; color:#5a7a9a; letter-spacing:0.15em;">MERIDIA β SIM ACTIVE</span>
|
| 475 |
+
</div>
|
| 476 |
+
</div>
|
| 477 |
+
|
| 478 |
+
<script src="https://cdn.jsdelivr.net/npm/phaser@3.60.0/dist/phaser.min.js"></script>
|
| 479 |
+
<script>
|
| 480 |
+
const STATUSES = {statuses_json};
|
| 481 |
+
const RUNNING = {'true' if results else 'false'};
|
| 482 |
+
|
| 483 |
+
// ββ Colour palette ββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 484 |
+
const C = {{
|
| 485 |
+
fast: 0x00ff88,
|
| 486 |
+
ok: 0x00d4ff,
|
| 487 |
+
slow: 0xf5a623,
|
| 488 |
+
delayed: 0xff4757,
|
| 489 |
+
sea: 0x00d4ff,
|
| 490 |
+
air: 0xf5a623,
|
| 491 |
+
land: 0x00ff88,
|
| 492 |
+
grid: 0x1a3a5c,
|
| 493 |
+
dark: 0x0a0e1a,
|
| 494 |
+
water: 0x0d2340,
|
| 495 |
+
sand: 0x1a2e40,
|
| 496 |
+
building:0x152840,
|
| 497 |
+
}};
|
| 498 |
+
|
| 499 |
+
class MeridiaScene extends Phaser.Scene {{
|
| 500 |
+
constructor() {{ super({{ key: 'MeridiaScene' }}); }}
|
| 501 |
+
|
| 502 |
+
preload() {{}}
|
| 503 |
+
|
| 504 |
+
create() {{
|
| 505 |
+
const W = this.scale.width;
|
| 506 |
+
const H = this.scale.height;
|
| 507 |
+
|
| 508 |
+
// ββ Sky gradient background ββββββββββββββββββββββββββββββββββββββββ
|
| 509 |
+
const bg = this.add.graphics();
|
| 510 |
+
bg.fillGradientStyle(0x0a0e1a, 0x0a0e1a, 0x0d2340, 0x0d2340, 1);
|
| 511 |
+
bg.fillRect(0, 0, W, H);
|
| 512 |
+
|
| 513 |
+
// ββ Stars βββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 514 |
+
const stars = this.add.graphics();
|
| 515 |
+
stars.fillStyle(0xffffff, 0.6);
|
| 516 |
+
for (let i = 0; i < 80; i++) {{
|
| 517 |
+
const x = Phaser.Math.Between(0, W);
|
| 518 |
+
const y = Phaser.Math.Between(0, H * 0.5);
|
| 519 |
+
const r = Math.random() < 0.1 ? 1.5 : 0.8;
|
| 520 |
+
stars.fillCircle(x, y, r);
|
| 521 |
+
}}
|
| 522 |
+
|
| 523 |
+
// ββ Isometric grid helper βββββββββββββββββββββββββββββββββββββββββ
|
| 524 |
+
const ISO_W = 48, ISO_H = 24;
|
| 525 |
+
|
| 526 |
+
const toIso = (col, row) => {{
|
| 527 |
+
return {{
|
| 528 |
+
x: W/2 + (col - row) * ISO_W / 2,
|
| 529 |
+
y: 140 + (col + row) * ISO_H / 2
|
| 530 |
+
}};
|
| 531 |
+
}};
|
| 532 |
+
|
| 533 |
+
const drawTile = (gfx, col, row, color, alpha=1, h=0) => {{
|
| 534 |
+
const p = toIso(col, row);
|
| 535 |
+
const pts = [
|
| 536 |
+
p.x, p.y - h,
|
| 537 |
+
p.x+ISO_W/2, p.y+ISO_H/2 - h,
|
| 538 |
+
p.x, p.y+ISO_H - h,
|
| 539 |
+
p.x-ISO_W/2, p.y+ISO_H/2 - h,
|
| 540 |
+
];
|
| 541 |
+
gfx.fillStyle(color, alpha);
|
| 542 |
+
gfx.fillPoints(pts.reduce((a,v,i)=> i%2===0?[...a,{{x:pts[i],y:pts[i+1]}}]:a,[]), true);
|
| 543 |
+
// Left face (darker)
|
| 544 |
+
if (h > 0) {{
|
| 545 |
+
const lpts = [
|
| 546 |
+
p.x-ISO_W/2, p.y+ISO_H/2 - h,
|
| 547 |
+
p.x, p.y+ISO_H - h,
|
| 548 |
+
p.x, p.y+ISO_H,
|
| 549 |
+
p.x-ISO_W/2, p.y+ISO_H/2,
|
| 550 |
+
];
|
| 551 |
+
gfx.fillStyle(Phaser.Display.Color.ValueToColor(color).darken(30).color, alpha);
|
| 552 |
+
gfx.fillPoints(lpts.reduce((a,v,i)=> i%2===0?[...a,{{x:lpts[i],y:lpts[i+1]}}]:a,[]), true);
|
| 553 |
+
// Right face
|
| 554 |
+
const rpts = [
|
| 555 |
+
p.x, p.y+ISO_H - h,
|
| 556 |
+
p.x+ISO_W/2, p.y+ISO_H/2 - h,
|
| 557 |
+
p.x+ISO_W/2, p.y+ISO_H/2,
|
| 558 |
+
p.x, p.y+ISO_H,
|
| 559 |
+
];
|
| 560 |
+
gfx.fillStyle(Phaser.Display.Color.ValueToColor(color).darken(15).color, alpha);
|
| 561 |
+
gfx.fillPoints(rpts.reduce((a,v,i)=> i%2===0?[...a,{{x:rpts[i],y:rpts[i+1]}}]:a,[]), true);
|
| 562 |
+
}}
|
| 563 |
+
}};
|
| 564 |
+
|
| 565 |
+
const terrain = this.add.graphics();
|
| 566 |
+
|
| 567 |
+
// ββ Water tiles (left zone β Azure Port) ββββββββββββββββββββββββββ
|
| 568 |
+
for (let r = 0; r < 8; r++) {{
|
| 569 |
+
for (let c = 0; c < 5; c++) {{
|
| 570 |
+
drawTile(terrain, c-3, r, C.water, 0.9);
|
| 571 |
+
}}
|
| 572 |
+
}}
|
| 573 |
+
|
| 574 |
+
// ββ Land tiles ββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 575 |
+
for (let r = 0; r < 8; r++) {{
|
| 576 |
+
for (let c = 2; c < 12; c++) {{
|
| 577 |
+
const shade = (c+r) % 2 === 0 ? 0x1a2e40 : 0x162838;
|
| 578 |
+
drawTile(terrain, c, r, shade, 1);
|
| 579 |
+
}}
|
| 580 |
+
}}
|
| 581 |
+
|
| 582 |
+
// ββ Buildings (customs offices) βββββββββββββββββββββββββββββββββββ
|
| 583 |
+
const buildings = this.add.graphics();
|
| 584 |
+
|
| 585 |
+
const drawBuilding = (col, row, w, d, h, color) => {{
|
| 586 |
+
for (let dc=0; dc<w; dc++) {{
|
| 587 |
+
for (let dr=0; dr<d; dr++) {{
|
| 588 |
+
drawTile(buildings, col+dc, row+dr, color, 1, h);
|
| 589 |
+
}}
|
| 590 |
+
}}
|
| 591 |
+
}};
|
| 592 |
+
|
| 593 |
+
// Azure Port customs hall
|
| 594 |
+
drawBuilding(3, 1, 2, 2, 18, 0x1a4a6c);
|
| 595 |
+
// Vortex Air terminal
|
| 596 |
+
drawBuilding(7, 1, 3, 2, 14, 0x2a3a5c);
|
| 597 |
+
// Stone Pass checkpoint
|
| 598 |
+
drawBuilding(3, 5, 2, 2, 12, 0x1a4a3c);
|
| 599 |
+
|
| 600 |
+
// ββ Port labels ββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 601 |
+
const labelStyle = {{
|
| 602 |
+
fontFamily: 'Rajdhani, sans-serif',
|
| 603 |
+
fontSize: '10px',
|
| 604 |
+
fontStyle: 'bold',
|
| 605 |
+
color: '#5a9abf',
|
| 606 |
+
letterSpacing: 2,
|
| 607 |
+
}};
|
| 608 |
+
|
| 609 |
+
const p1 = toIso(3.5, 0);
|
| 610 |
+
this.add.text(p1.x, p1.y - 30, 'AZURE PORT', {{ ...labelStyle, color: '#00d4ff' }}).setOrigin(0.5);
|
| 611 |
+
|
| 612 |
+
const p2 = toIso(8.5, 0);
|
| 613 |
+
this.add.text(p2.x, p2.y - 24, 'VORTEX AIR', {{ ...labelStyle, color: '#f5a623' }}).setOrigin(0.5);
|
| 614 |
+
|
| 615 |
+
const p3 = toIso(4, 5.5);
|
| 616 |
+
this.add.text(p3.x, p3.y - 22, 'STONE PASS', {{ ...labelStyle, color: '#00ff88' }}).setOrigin(0.5);
|
| 617 |
+
|
| 618 |
+
// ββ Cargo dots (animated, colour by status) ββββββββββββββββββββββββ
|
| 619 |
+
if (RUNNING && STATUSES.length > 0) {{
|
| 620 |
+
const portOrigins = {{
|
| 621 |
+
Sea: {{ col: 1.5, row: 3 }},
|
| 622 |
+
Air: {{ col: 8.5, row: 3 }},
|
| 623 |
+
Land: {{ col: 4, row: 6 }},
|
| 624 |
+
}};
|
| 625 |
+
|
| 626 |
+
STATUSES.forEach((s, i) => {{
|
| 627 |
+
const orig = portOrigins[s.port];
|
| 628 |
+
const col = orig.col + (Math.random()-0.5)*2.5;
|
| 629 |
+
const row = orig.row + (Math.random()-0.5)*2.0;
|
| 630 |
+
const pos = toIso(col, row);
|
| 631 |
+
|
| 632 |
+
const color = C[s.status];
|
| 633 |
+
const gfx = this.add.graphics();
|
| 634 |
+
|
| 635 |
+
gfx.fillStyle(color, 0.9);
|
| 636 |
+
gfx.fillCircle(pos.x, pos.y, 5);
|
| 637 |
+
gfx.lineStyle(1, color, 0.4);
|
| 638 |
+
gfx.strokeCircle(pos.x, pos.y, 9);
|
| 639 |
+
|
| 640 |
+
if (s.machine) {{
|
| 641 |
+
gfx.lineStyle(1, 0xffffff, 0.6);
|
| 642 |
+
gfx.strokeCircle(pos.x, pos.y, 13);
|
| 643 |
+
}}
|
| 644 |
+
|
| 645 |
+
// Pulse animation
|
| 646 |
+
this.tweens.add({{
|
| 647 |
+
targets: gfx,
|
| 648 |
+
alpha: {{ from: 0.5, to: 1 }},
|
| 649 |
+
duration: 800 + i * 40,
|
| 650 |
+
yoyo: true,
|
| 651 |
+
repeat: -1,
|
| 652 |
+
ease: 'Sine.easeInOut',
|
| 653 |
+
}});
|
| 654 |
+
|
| 655 |
+
// Float vertically
|
| 656 |
+
this.tweens.add({{
|
| 657 |
+
targets: gfx,
|
| 658 |
+
y: gfx.y - 4,
|
| 659 |
+
duration: 1200 + i * 60,
|
| 660 |
+
yoyo: true,
|
| 661 |
+
repeat: -1,
|
| 662 |
+
ease: 'Sine.easeInOut',
|
| 663 |
+
}});
|
| 664 |
+
|
| 665 |
+
// Tooltip on hover
|
| 666 |
+
const hitZone = this.add.circle(pos.x, pos.y, 14, 0xffffff, 0)
|
| 667 |
+
.setInteractive({{ useHandCursor: true }});
|
| 668 |
+
|
| 669 |
+
const tooltip = this.add.text(pos.x + 16, pos.y - 16,
|
| 670 |
+
`${{s.id}}\\n${{s.port}} | ${{s.hours}}h | ${{s.status.toUpperCase()}}`,
|
| 671 |
+
{{
|
| 672 |
+
fontFamily: 'Share Tech Mono, monospace',
|
| 673 |
+
fontSize: '9px',
|
| 674 |
+
color: '#c8d8e8',
|
| 675 |
+
backgroundColor: '#0a0e1aee',
|
| 676 |
+
padding: {{ x:6, y:4 }},
|
| 677 |
+
lineSpacing: 3,
|
| 678 |
+
}}
|
| 679 |
+
).setVisible(false).setDepth(100);
|
| 680 |
+
|
| 681 |
+
hitZone.on('pointerover', () => tooltip.setVisible(true));
|
| 682 |
+
hitZone.on('pointerout', () => tooltip.setVisible(false));
|
| 683 |
+
}});
|
| 684 |
+
}} else {{
|
| 685 |
+
// Idle state β gentle floating dots
|
| 686 |
+
for (let i=0; i<12; i++) {{
|
| 687 |
+
const col = Math.random()*10 - 1;
|
| 688 |
+
const row = Math.random()*7;
|
| 689 |
+
const pos = toIso(col, row);
|
| 690 |
+
const gfx = this.add.graphics();
|
| 691 |
+
gfx.fillStyle(0x1a3a5c, 0.7);
|
| 692 |
+
gfx.fillCircle(pos.x, pos.y, 4);
|
| 693 |
+
this.tweens.add({{
|
| 694 |
+
targets: gfx, alpha: {{from:0.2, to:0.7}},
|
| 695 |
+
duration: 1500+i*200, yoyo:true, repeat:-1,
|
| 696 |
+
}});
|
| 697 |
+
}}
|
| 698 |
+
}}
|
| 699 |
+
|
| 700 |
+
// ββ Ship in water ββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 701 |
+
const shipGfx = this.add.graphics();
|
| 702 |
+
const sp = toIso(-1, 3);
|
| 703 |
+
shipGfx.fillStyle(0x2a5a8c, 1);
|
| 704 |
+
shipGfx.fillRect(sp.x-20, sp.y-6, 40, 12);
|
| 705 |
+
shipGfx.fillStyle(0x3a7abf, 1);
|
| 706 |
+
shipGfx.fillRect(sp.x-8, sp.y-14, 16, 8);
|
| 707 |
+
|
| 708 |
+
this.tweens.add({{
|
| 709 |
+
targets: shipGfx, y: '-=3',
|
| 710 |
+
duration: 2000, yoyo: true, repeat: -1, ease: 'Sine.easeInOut',
|
| 711 |
+
}});
|
| 712 |
+
|
| 713 |
+
// ββ Legend βββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 714 |
+
const lg = this.add.graphics();
|
| 715 |
+
const lx = W - 130, ly = H - 110;
|
| 716 |
+
[[C.fast,'<3h FAST'],[C.ok,'<24h OK'],[C.slow,'<48h SLOW'],[C.delayed,'>48h LATE']].forEach(([col,lbl],i) => {{
|
| 717 |
+
lg.fillStyle(col, 1);
|
| 718 |
+
lg.fillCircle(lx, ly + i*20, 5);
|
| 719 |
+
this.add.text(lx+12, ly+i*20-7, lbl, {{
|
| 720 |
+
fontFamily:'Rajdhani,sans-serif', fontSize:'10px',
|
| 721 |
+
fontStyle:'bold', color:'#5a7a9a', letterSpacing:1,
|
| 722 |
+
}});
|
| 723 |
+
}});
|
| 724 |
+
}}
|
| 725 |
+
|
| 726 |
+
update() {{
|
| 727 |
+
// Update simulated clock
|
| 728 |
+
const el = document.getElementById('sim-clock');
|
| 729 |
+
if (el) {{
|
| 730 |
+
const now = new Date();
|
| 731 |
+
el.textContent = now.toLocaleTimeString('en-GB') + ' | MERIDIA FRONTIER';
|
| 732 |
+
}}
|
| 733 |
+
}}
|
| 734 |
+
}}
|
| 735 |
+
|
| 736 |
+
new Phaser.Game({{
|
| 737 |
+
type: Phaser.AUTO,
|
| 738 |
+
parent: 'game-container',
|
| 739 |
+
width: '100%',
|
| 740 |
+
height: 520,
|
| 741 |
+
transparent: true,
|
| 742 |
+
backgroundColor: '#0a0e1a',
|
| 743 |
+
scale: {{
|
| 744 |
+
mode: Phaser.Scale.FIT,
|
| 745 |
+
autoCenter: Phaser.Scale.CENTER_BOTH,
|
| 746 |
+
}},
|
| 747 |
+
scene: [MeridiaScene],
|
| 748 |
+
canvas: document.createElement('canvas'),
|
| 749 |
+
}});
|
| 750 |
+
</script>
|
| 751 |
+
</div>
|
| 752 |
+
</body>
|
| 753 |
+
</html>"""
|
| 754 |
+
|
| 755 |
+
|
| 756 |
+
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 757 |
+
# TRS STACKED BAR CHART
|
| 758 |
+
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 759 |
+
|
| 760 |
+
def build_trs_chart(results: List[BoE]) -> go.Figure:
|
| 761 |
+
ports = ["Sea (Azure Port)", "Air (Vortex)", "Land (Stone Pass)", "ALL PORTS"]
|
| 762 |
+
port_map = {"Sea": "Sea (Azure Port)", "Air": "Air (Vortex)", "Land": "Land (Stone Pass)"}
|
| 763 |
+
|
| 764 |
+
data = {p: {"filing": [], "assessment": [], "payment": [], "logistics": []} for p in ports}
|
| 765 |
+
|
| 766 |
+
for r in results:
|
| 767 |
+
pk = port_map[r.port_type]
|
| 768 |
+
data[pk]["filing"].append(r.seg_filing)
|
| 769 |
+
data[pk]["assessment"].append(r.seg_assessment)
|
| 770 |
+
data[pk]["payment"].append(r.seg_payment)
|
| 771 |
+
data[pk]["logistics"].append(r.seg_logistics)
|
| 772 |
+
data["ALL PORTS"]["filing"].append(r.seg_filing)
|
| 773 |
+
data["ALL PORTS"]["assessment"].append(r.seg_assessment)
|
| 774 |
+
data["ALL PORTS"]["payment"].append(r.seg_payment)
|
| 775 |
+
data["ALL PORTS"]["logistics"].append(r.seg_logistics)
|
| 776 |
+
|
| 777 |
+
avgs = {p: {seg: np.mean(v) if v else 0 for seg, v in segs.items()} for p, segs in data.items()}
|
| 778 |
+
|
| 779 |
+
segs = [
|
| 780 |
+
("filing", "Pre-arrival / Filing", "#1a4a8c"),
|
| 781 |
+
("assessment", "Customs Assessment", "#2a7abf"),
|
| 782 |
+
("payment", "Trade Action / PGA / Duty","#f5a623"),
|
| 783 |
+
("logistics", "Post-clearance Logistics", "#3a5a7a"),
|
| 784 |
+
]
|
| 785 |
+
|
| 786 |
+
fig = go.Figure()
|
| 787 |
+
for seg_key, seg_name, color in segs:
|
| 788 |
+
fig.add_trace(go.Bar(
|
| 789 |
+
name=seg_name,
|
| 790 |
+
x=ports,
|
| 791 |
+
y=[avgs[p][seg_key] for p in ports],
|
| 792 |
+
marker_color=color,
|
| 793 |
+
text=[f"{avgs[p][seg_key]:.1f}h" for p in ports],
|
| 794 |
+
textposition="inside",
|
| 795 |
+
textfont=dict(family="Share Tech Mono, monospace", size=10, color="white"),
|
| 796 |
+
))
|
| 797 |
+
|
| 798 |
+
# 48h target line
|
| 799 |
+
fig.add_hline(y=48, line_dash="dash", line_color="#ff4757", line_width=1.5,
|
| 800 |
+
annotation_text="48h NTFAP Target", annotation_font_color="#ff4757",
|
| 801 |
+
annotation_font_size=10)
|
| 802 |
+
fig.add_hline(y=24, line_dash="dot", line_color="#f5a623", line_width=1,
|
| 803 |
+
annotation_text="24h Air Target", annotation_font_color="#f5a623",
|
| 804 |
+
annotation_font_size=10)
|
| 805 |
+
|
| 806 |
+
fig.update_layout(
|
| 807 |
+
barmode="stack",
|
| 808 |
+
plot_bgcolor="#0d1b2a",
|
| 809 |
+
paper_bgcolor="#0a0e1a",
|
| 810 |
+
font=dict(family="Rajdhani, sans-serif", color="#c8d8e8"),
|
| 811 |
+
title=dict(text="MERIDIA TRS β RELEASE TIME BREAKDOWN BY PORT",
|
| 812 |
+
font=dict(size=14, color="#00d4ff", family="Rajdhani"),
|
| 813 |
+
x=0.5),
|
| 814 |
+
xaxis=dict(gridcolor="#1a3a5c", linecolor="#1a3a5c"),
|
| 815 |
+
yaxis=dict(gridcolor="#1a3a5c", linecolor="#1a3a5c",
|
| 816 |
+
title="Hours", titlefont=dict(color="#5a7a9a")),
|
| 817 |
+
legend=dict(orientation="h", y=-0.2, font=dict(size=10)),
|
| 818 |
+
margin=dict(t=50, b=80, l=50, r=20),
|
| 819 |
+
height=380,
|
| 820 |
+
)
|
| 821 |
+
return fig
|
| 822 |
+
|
| 823 |
+
|
| 824 |
+
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 825 |
+
# STREAMLIT UI
|
| 826 |
+
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 827 |
+
|
| 828 |
+
def main():
|
| 829 |
+
# ββ Header βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 830 |
+
st.markdown("""
|
| 831 |
+
<div style='text-align:center; padding: 1rem 0 0.5rem;'>
|
| 832 |
+
<h1 style='font-family:Rajdhani,sans-serif; font-size:2.2rem; letter-spacing:0.15em;
|
| 833 |
+
color:#00d4ff; text-shadow: 0 0 20px rgba(0,212,255,0.4); margin:0;'>
|
| 834 |
+
β THE MERIDIA FRONTIER
|
| 835 |
+
</h1>
|
| 836 |
+
<p style='color:#5a7a9a; font-size:0.8rem; letter-spacing:0.2em; margin:4px 0 0;
|
| 837 |
+
font-family:Rajdhani,sans-serif;'>
|
| 838 |
+
TIME RELEASE STUDY β GAMIFIED CUSTOMS SIMULATOR
|
| 839 |
+
</p>
|
| 840 |
+
</div>
|
| 841 |
+
<hr style='border:none; border-top: 1px solid #1a3a5c; margin: 0.75rem 0;'>
|
| 842 |
+
""", unsafe_allow_html=True)
|
| 843 |
+
|
| 844 |
+
# ββ Sidebar Controls ββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 845 |
+
with st.sidebar:
|
| 846 |
+
st.markdown("### β POLICY LEVERS")
|
| 847 |
+
st.markdown("<p style='color:#5a7a9a;font-size:0.72rem;letter-spacing:0.1em;'>ADJUST PARAMETERS & RUN SIM</p>", unsafe_allow_html=True)
|
| 848 |
+
|
| 849 |
+
st.markdown("**Filing & Risk**")
|
| 850 |
+
advance_pct = st.slider("Advance Filing %", 0, 100, 40, key="adv")
|
| 851 |
+
rms_pct = st.slider("RMS Facilitation %", 0, 100, 50, key="rms")
|
| 852 |
+
aeo_pct = st.slider("AEO Enrollment %", 0, 100, 30, key="aeo")
|
| 853 |
+
|
| 854 |
+
st.markdown("**System Enablers**")
|
| 855 |
+
pga_sw = st.toggle("PGA Single Window", value=False, key="pga")
|
| 856 |
+
deferred = st.toggle("Deferred Duty (AEO)", value=False, key="def")
|
| 857 |
+
auto_ooc = st.toggle("Auto Out-of-Charge", value=False, key="ooc")
|
| 858 |
+
|
| 859 |
+
st.markdown("**Officer Capacity**")
|
| 860 |
+
officers_sea = st.slider("Sea Officers", 1, 20, 8, key="osea")
|
| 861 |
+
officers_air = st.slider("Air Officers", 1, 10, 4, key="oair")
|
| 862 |
+
officers_land = st.slider("Land Officers", 1, 15, 6, key="oland")
|
| 863 |
+
|
| 864 |
+
st.markdown("---")
|
| 865 |
+
run_btn = st.button("βΆ RUN SIMULATION", use_container_width=True)
|
| 866 |
+
reset_btn = st.button("βΊ RESET", use_container_width=True)
|
| 867 |
+
|
| 868 |
+
# ββ Session state ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 869 |
+
if "results" not in st.session_state:
|
| 870 |
+
st.session_state.results = []
|
| 871 |
+
if "sim_params" not in st.session_state:
|
| 872 |
+
st.session_state.sim_params = {}
|
| 873 |
+
if reset_btn:
|
| 874 |
+
st.session_state.results = []
|
| 875 |
+
st.session_state.sim_params = {}
|
| 876 |
+
|
| 877 |
+
if run_btn:
|
| 878 |
+
params = dict(
|
| 879 |
+
advance_filing_pct=advance_pct,
|
| 880 |
+
rms_facilitation_pct=rms_pct,
|
| 881 |
+
aeo_enrollment_pct=aeo_pct,
|
| 882 |
+
pga_single_window=pga_sw,
|
| 883 |
+
deferred_duty=deferred,
|
| 884 |
+
auto_ooc=auto_ooc,
|
| 885 |
+
officers_sea=officers_sea,
|
| 886 |
+
officers_air=officers_air,
|
| 887 |
+
officers_land=officers_land,
|
| 888 |
+
)
|
| 889 |
+
with st.spinner("Simulating Meridia port activity..."):
|
| 890 |
+
results = run_simulation(params)
|
| 891 |
+
|
| 892 |
+
# Compute summary stats
|
| 893 |
+
arts = [r.total_hours for r in results]
|
| 894 |
+
green_results = [r for r in results if r.seg_assessment == 0 and r.seg_filing == 0]
|
| 895 |
+
aeo_results = [r for r in results if r.aeo_status != "None"]
|
| 896 |
+
machine_results = [r for r in results if r.machine_release]
|
| 897 |
+
|
| 898 |
+
params["avg_art"] = np.mean(arts) if arts else 0
|
| 899 |
+
params["green_pct"] = len(green_results) / len(results) * 100 if results else 0
|
| 900 |
+
params["aeo_pct"] = len(aeo_results) / len(results) * 100 if results else 0
|
| 901 |
+
params["machine_pct"] = len(machine_results)/ len(results) * 100 if results else 0
|
| 902 |
+
params["target48_pct"] = len([a for a in arts if a <= 48]) / len(arts) * 100 if arts else 0
|
| 903 |
+
|
| 904 |
+
st.session_state.results = results
|
| 905 |
+
st.session_state.sim_params = params
|
| 906 |
+
|
| 907 |
+
results = st.session_state.results
|
| 908 |
+
sim_params = st.session_state.sim_params
|
| 909 |
+
|
| 910 |
+
# οΏ½οΏ½β Main content tabs βββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 911 |
+
tab1, tab2, tab3 = st.tabs(["πΊ PORT VIEW", "π TRS REPORT", "π AUDIT LEDGER"])
|
| 912 |
+
|
| 913 |
+
with tab1:
|
| 914 |
+
# Phaser.js game
|
| 915 |
+
html_src = build_phaser_scene(results, sim_params)
|
| 916 |
+
st.components.v1.html(html_src, height=530, scrolling=False)
|
| 917 |
+
|
| 918 |
+
if not results:
|
| 919 |
+
st.info("Configure policy levers in the sidebar and click **RUN SIMULATION** to activate the port.")
|
| 920 |
+
else:
|
| 921 |
+
st.markdown("---")
|
| 922 |
+
col1, col2, col3, col4 = st.columns(4)
|
| 923 |
+
col1.metric("Avg Release Time", f"{sim_params['avg_art']:.1f}h",
|
| 924 |
+
f"{48 - sim_params['avg_art']:.1f}h vs 48h target")
|
| 925 |
+
col2.metric("Green Channel", f"{sim_params['green_pct']:.0f}%", "Facilitated")
|
| 926 |
+
col3.metric("Machine Release", f"{sim_params['machine_pct']:.0f}%","Auto-OOC")
|
| 927 |
+
col4.metric("Target β€48h", f"{sim_params['target48_pct']:.0f}%","Achieved")
|
| 928 |
+
|
| 929 |
+
with tab2:
|
| 930 |
+
if not results:
|
| 931 |
+
st.info("Run the simulation first to generate the TRS report.")
|
| 932 |
+
else:
|
| 933 |
+
fig = build_trs_chart(results)
|
| 934 |
+
st.plotly_chart(fig, use_container_width=True)
|
| 935 |
+
|
| 936 |
+
# Insights
|
| 937 |
+
art = sim_params["avg_art"]
|
| 938 |
+
st.markdown("### π POLICY INSIGHTS")
|
| 939 |
+
col_a, col_b = st.columns(2)
|
| 940 |
+
with col_a:
|
| 941 |
+
if art < 3:
|
| 942 |
+
st.success("π **Jaigaon LCS Efficiency Achieved!** ART < 3h β world-class performance.")
|
| 943 |
+
elif art < 24:
|
| 944 |
+
st.success(f"β
ART {art:.1f}h β Air terminal target achieved.")
|
| 945 |
+
elif art < 48:
|
| 946 |
+
st.warning(f"β ART {art:.1f}h β Below 48h target but can improve.")
|
| 947 |
+
else:
|
| 948 |
+
st.error(f"π¨ ART {art:.1f}h β Exceeds NTFAP 48h target. Enable Advance Filing + Facilitation.")
|
| 949 |
+
|
| 950 |
+
with col_b:
|
| 951 |
+
if sim_params.get("aeo_pct", 0) == 0:
|
| 952 |
+
st.warning("PGA without Single Window detected" if not pga_sw else "")
|
| 953 |
+
pga_on = advance_pct > 60 and rms_pct > 60
|
| 954 |
+
if pga_on:
|
| 955 |
+
st.success("β
Advance Filing + Facilitation combo active β optimal path.")
|
| 956 |
+
else:
|
| 957 |
+
st.info("π‘ Tip: Set Advance Filing + RMS Facilitation both above 60% to reach Jaigaon-level ART.")
|
| 958 |
+
|
| 959 |
+
with tab3:
|
| 960 |
+
if not results:
|
| 961 |
+
st.info("Run the simulation first to populate the audit ledger.")
|
| 962 |
+
else:
|
| 963 |
+
df = pd.DataFrame([{
|
| 964 |
+
"Shipment_ID": r.shipment_id,
|
| 965 |
+
"Port_Type": r.port_type,
|
| 966 |
+
"Filing_Type": r.filing_type,
|
| 967 |
+
"PGA_Involved": r.pga_involved,
|
| 968 |
+
"AEO_Status": r.aeo_status,
|
| 969 |
+
"Machine_Release":r.machine_release,
|
| 970 |
+
"Filing_h": round(r.seg_filing, 2),
|
| 971 |
+
"Assessment_h": round(r.seg_assessment, 2),
|
| 972 |
+
"Payment_h": round(r.seg_payment, 2),
|
| 973 |
+
"Logistics_h": round(r.seg_logistics, 2),
|
| 974 |
+
"Total_Hours": round(r.total_hours, 2),
|
| 975 |
+
} for r in results])
|
| 976 |
+
|
| 977 |
+
st.dataframe(df, use_container_width=True, height=400)
|
| 978 |
+
|
| 979 |
+
csv = df.to_csv(index=False).encode("utf-8")
|
| 980 |
+
st.download_button(
|
| 981 |
+
"β¬ Download Meridia_TRS_Ledger.csv",
|
| 982 |
+
data=csv,
|
| 983 |
+
file_name="Meridia_TRS_Ledger.csv",
|
| 984 |
+
mime="text/csv",
|
| 985 |
+
use_container_width=True,
|
| 986 |
+
)
|
| 987 |
+
|
| 988 |
+
|
| 989 |
+
if __name__ == "__main__":
|
| 990 |
+
main()
|
requirements.txt
CHANGED
|
@@ -1,3 +1,5 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
|
|
|
|
|
|
|
|
| 1 |
+
streamlit>=1.32.0
|
| 2 |
+
simpy>=4.1.1
|
| 3 |
+
numpy>=1.26.0
|
| 4 |
+
pandas>=2.2.0
|
| 5 |
+
plotly>=5.20.0
|