-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
260 lines (226 loc) · 7.39 KB
/
Copy pathindex.html
File metadata and controls
260 lines (226 loc) · 7.39 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>Kings Cross — External Demand Intelligence</title>
<style>
body{
margin:0;
font-family:system-ui,-apple-system,Segoe UI,Roboto,Helvetica,Arial;
background:#0b0f14;
color:#e5e7eb;
}
.wrap{max-width:1100px;margin:auto;padding:18px}
h1{font-size:20px;margin:0 0 6px}
h2{font-size:14px;margin:0 0 8px}
.muted{color:#9ca3af;font-size:13px}
.grid{display:grid;grid-template-columns:300px 1fr;gap:14px;margin-top:12px}
.card{background:#111827;border-radius:10px;padding:12px}
.pill{
display:inline-block;
padding:2px 8px;
border-radius:999px;
font-size:11px;
background:#1f2937;
margin-right:6px;
}
.pill.good{background:#064e3b}
.pill.warn{background:#78350f}
.pill.bad{background:#7f1d1d}
.item{padding:8px;border-radius:8px;cursor:pointer;margin-bottom:6px}
.item:hover{background:#1f2937}
.item.active{background:#1e40af}
.small{font-size:12px}
canvas{width:100%}
</style>
</head>
<body>
<div class="wrap">
<h1>External Demand & Disruption Intelligence</h1>
<div class="muted" id="lastUpdated">Loading…</div>
<div class="grid">
<!-- LEFT PANEL -->
<div class="card">
<h2>Focus points (activity clusters)</h2>
<div id="venueList"></div>
<div class="muted small" id="venuesMeta"></div>
</div>
<!-- RIGHT PANEL -->
<div class="card">
<h2 id="venueTitle">Area overview</h2>
<div id="headline" style="font-size:18px;margin-bottom:8px">—</div>
<!-- Drivers -->
<h2>External drivers</h2>
<ul id="drivers" class="small"></ul>
<!-- Implications -->
<h2 style="margin-top:10px">Operational implications</h2>
<ul id="implications" class="small"></ul>
<!-- Chart -->
<h2 style="margin-top:10px">Pressure outlook (next 12h)</h2>
<div style="position:relative">
<canvas id="venueChart" height="220"></canvas>
</div>
<!-- Seasonal anomalies -->
<h2 style="margin-top:12px">Demand deviations</h2>
<div id="seasonalExplainer" class="muted small">Loading signals…</div>
</div>
</div>
</div>
<script>
/* ---------------- Utilities ---------------- */
async function loadJSON(p){
try{const r=await fetch(p,{cache:"no-store"});return r.ok?await r.json():null}catch{return null}
}
function clamp(n,min,max){return Math.max(min,Math.min(max,n))}
function norm(s){return String(s||"").toLowerCase()}
/* ---------------- State ---------------- */
let dashboard={},history=[],forecast=[],anomalies=[]
let venues=[],activeVenue=null
/* ---------------- Confidence ---------------- */
function calcConfidence(v){
let c=0.45
if(v.rating>=4.4) c+=0.15
if((v.reviews||0)>=200) c+=0.1
if(v.distance_km<0.5) c+=0.1
if(history.length>=24) c+=0.1
return clamp(c,0.4,0.95)
}
/* ---------------- Multipliers ---------------- */
function venueMultiplier(v){
const tr=v.transit_reliance||0.8
return clamp(0.8+tr*0.35,0.8,1.25)
}
function areaNow(){
return history.at(-1)?.busyness ?? forecast[0]?.busyness ?? 55
}
function focusNow(){
return activeVenue ? Math.round(areaNow()*venueMultiplier(activeVenue)) : areaNow()
}
/* ---------------- Render focus list ---------------- */
function renderVenues(){
const el=document.getElementById("venueList")
el.innerHTML=""
venues.forEach(v=>{
const d=document.createElement("div")
d.className=`item ${activeVenue?.id===v.id?"active":""}`
d.innerHTML=`
<b>${v.name}</b><br>
<span class="pill">${v.distance_km.toFixed(2)} km</span>
<span class="pill">${v.rating?.toFixed(1)||"—"}★</span>
<span class="pill">${Math.round(calcConfidence(v)*100)}%</span>
`
d.onclick=()=>{activeVenue=v;update()}
el.appendChild(d)
})
document.getElementById("venuesMeta").textContent=
`${venues.length} activity points observed`
}
/* ---------------- Drivers ---------------- */
function pickPrimaryAnomaly(anoms){
if(!anoms?.length) return null
return anoms.slice(-1)[0]
}
function buildDrivers(){
const ul=document.getElementById("drivers")
ul.innerHTML=""
const ctx=dashboard.context||{}
const a=pickPrimaryAnomaly(anomalies)
if(a){
const p=a.persistence||"transient"
const badge=p==="established"?"bad":p==="emerging"?"warn":"good"
const li=document.createElement("li")
li.innerHTML=`
<b>Demand deviation detected</b><br>
${a.type.replaceAll("_"," ")}
· ${a.severity}
· ${Math.round(a.confidence*100)}%
· <span class="pill ${badge}">${p}</span>
`
ul.appendChild(li)
}
;[
`Seasonal phase: ${ctx.holiday_phase||"normal"}`,
`External disruption: ${dashboard.transit_pressure?.level||"—"}`,
dashboard.weather?`Weather: ${dashboard.weather.temperature_C}°C`:null
].filter(Boolean).forEach(t=>{
const li=document.createElement("li")
li.textContent=t
ul.appendChild(li)
})
}
/* ---------------- Implications ---------------- */
function buildImplications(){
const ul=document.getElementById("implications")
ul.innerHTML=""
const now=focusNow()
const msgs=now>=75
?["High congestion risk","Increased dwell pressure","Queue formation likely"]
:["Stable flow","Monitor change velocity","Normal operations"]
msgs.forEach(m=>{
const li=document.createElement("li")
li.textContent=m
ul.appendChild(li)
})
}
/* ---------------- Chart ---------------- */
function drawChart(){
const c=document.getElementById("venueChart")
const ctx=c.getContext("2d")
const w=c.width=c.offsetWidth,h=c.height
ctx.clearRect(0,0,w,h)
if(!forecast.length) return
const area=forecast.map(f=>f.busyness)
const m=activeVenue?venueMultiplier(activeVenue):1
const focus=area.map(v=>Math.round(v*m))
const xs=area.map((_,i)=>i*(w/(area.length-1)))
const y=v=>h-(v/100)*h
ctx.strokeStyle="rgba(96,165,250,.9)"
ctx.beginPath(); area.forEach((v,i)=>i?ctx.lineTo(xs[i],y(v)):ctx.moveTo(xs[i],y(v))); ctx.stroke()
ctx.strokeStyle="rgba(249,115,22,.95)"
ctx.beginPath(); focus.forEach((v,i)=>i?ctx.lineTo(xs[i],y(v)):ctx.moveTo(xs[i],y(v))); ctx.stroke()
}
/* ---------------- Seasonal explainer ---------------- */
function renderSeasonalExplainer(){
const el=document.getElementById("seasonalExplainer")
if(!anomalies.length){
el.textContent="No significant deviations detected."
return
}
el.innerHTML=anomalies.slice(-3).reverse().map(a=>`
<div style="margin-top:8px">
<b>${a.type.replaceAll("_"," ")}</b>
· ${a.severity}
· ${Math.round(a.confidence*100)}%
${a.persistence?`· ${a.persistence}`:""}
<div class="muted">${a.explanation}</div>
</div>
`).join("")
}
/* ---------------- Update ---------------- */
function update(){
document.getElementById("venueTitle").textContent=
activeVenue?activeVenue.name:"Area overview"
document.getElementById("headline").textContent=
`${focusNow()}/100 external pressure now`
buildDrivers()
buildImplications()
drawChart()
}
/* ---------------- Init ---------------- */
(async()=>{
dashboard=await loadJSON("data/kingscross_dashboard.json")||{}
history=await loadJSON("data/history/kingscross_history.json")||[]
forecast=await loadJSON("data/forecast.json")||[]
anomalies=await loadJSON("data/anomalies.json")||[]
venues=dashboard.venues||[]
document.getElementById("lastUpdated").textContent=
dashboard.timestamp?`Updated ${new Date(dashboard.timestamp).toLocaleString()}`:""
activeVenue=venues[0]||null
renderVenues()
update()
renderSeasonalExplainer()
})()
</script>
</body>
</html>