| 36799 |
amit |
1 |
#[[<!DOCTYPE html>
|
|
|
2 |
<html lang="en">
|
|
|
3 |
<head>
|
|
|
4 |
<meta charset="utf-8">
|
|
|
5 |
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
|
6 |
<title>Route Scheduling Analytics</title>
|
|
|
7 |
<style>
|
|
|
8 |
:root{
|
|
|
9 |
--bg:#0b1120; --panel:#111a2e; --panel2:#16213c; --line:#1f2c47;
|
|
|
10 |
--txt:#e6edf7; --muted:#8ea0bd; --soft:#64759a;
|
|
|
11 |
--indigo:#6366f1; --indigo2:#818cf8; --cyan:#22d3ee; --green:#34d399;
|
|
|
12 |
--amber:#fbbf24; --red:#f87171; --pink:#f472b6;
|
|
|
13 |
--good:#34d399; --warn:#fbbf24; --bad:#f87171;
|
|
|
14 |
}
|
|
|
15 |
*{box-sizing:border-box}
|
|
|
16 |
html,body{margin:0;background:var(--bg);color:var(--txt);
|
|
|
17 |
font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Helvetica,Arial,sans-serif;
|
|
|
18 |
-webkit-font-smoothing:antialiased}
|
|
|
19 |
a{color:var(--indigo2)}
|
|
|
20 |
.wrap{max-width:1280px;margin:0 auto;padding:24px 28px 80px}
|
|
|
21 |
|
|
|
22 |
/* header */
|
|
|
23 |
header.top{display:flex;align-items:flex-end;justify-content:space-between;gap:20px;
|
|
|
24 |
padding:18px 0 22px;border-bottom:1px solid var(--line);margin-bottom:26px;flex-wrap:wrap}
|
|
|
25 |
.brand{display:flex;flex-direction:column;gap:6px}
|
|
|
26 |
.brand .eyebrow{font-size:12px;letter-spacing:.16em;text-transform:uppercase;color:var(--indigo2);font-weight:700}
|
|
|
27 |
.brand h1{margin:0;font-size:26px;font-weight:750;letter-spacing:-.01em}
|
|
|
28 |
.brand .sub{color:var(--muted);font-size:13px}
|
|
|
29 |
.hd-right{display:flex;align-items:center;gap:14px}
|
|
|
30 |
.pill{background:var(--panel2);border:1px solid var(--line);border-radius:999px;padding:8px 14px;font-size:12.5px;color:var(--muted)}
|
|
|
31 |
.pill b{color:var(--txt)}
|
|
|
32 |
button.refresh{background:linear-gradient(135deg,var(--indigo),#4f46e5);border:0;color:#fff;font-weight:650;
|
|
|
33 |
padding:9px 16px;border-radius:10px;cursor:pointer;font-size:13px;box-shadow:0 6px 18px rgba(79,70,229,.35)}
|
|
|
34 |
button.refresh:active{transform:translateY(1px)}
|
|
|
35 |
|
|
|
36 |
/* kpi row */
|
|
|
37 |
.kpis{display:grid;grid-template-columns:repeat(5,1fr);gap:14px;margin-bottom:26px}
|
|
|
38 |
.kpi{background:linear-gradient(180deg,var(--panel2),var(--panel));border:1px solid var(--line);
|
|
|
39 |
border-radius:16px;padding:16px 18px;position:relative;overflow:hidden}
|
|
|
40 |
.kpi::after{content:"";position:absolute;inset:0 0 auto 0;height:3px;background:var(--accent,var(--indigo))}
|
|
|
41 |
.kpi .label{font-size:11.5px;text-transform:uppercase;letter-spacing:.08em;color:var(--muted);font-weight:650}
|
|
|
42 |
.kpi .val{font-size:30px;font-weight:780;margin-top:8px;letter-spacing:-.02em;line-height:1}
|
|
|
43 |
.kpi .val small{font-size:15px;color:var(--muted);font-weight:600}
|
|
|
44 |
.kpi .foot{font-size:12px;color:var(--muted);margin-top:8px}
|
|
|
45 |
|
|
|
46 |
/* layout */
|
|
|
47 |
.grid{display:grid;gap:18px}
|
|
|
48 |
.g2{grid-template-columns:1fr 1fr}
|
|
|
49 |
.g3{grid-template-columns:1.3fr 1fr}
|
|
|
50 |
.card{background:var(--panel);border:1px solid var(--line);border-radius:16px;padding:20px 22px;margin-bottom:18px}
|
|
|
51 |
.card h2{margin:0 0 4px;font-size:16px;font-weight:720;letter-spacing:-.01em}
|
|
|
52 |
.card .desc{color:var(--muted);font-size:12.5px;margin:0 0 16px}
|
|
|
53 |
|
|
|
54 |
/* bars */
|
|
|
55 |
.barrow{display:grid;grid-template-columns:78px 1fr 60px;align-items:center;gap:12px;margin:9px 0}
|
|
|
56 |
.barrow .name{font-size:13px;color:var(--txt);font-weight:600}
|
|
|
57 |
.track{background:#0b1424;border-radius:8px;height:22px;position:relative;overflow:hidden;border:1px solid #16223c}
|
|
|
58 |
.fill{height:100%;border-radius:8px 0 0 8px;background:linear-gradient(90deg,var(--indigo),var(--indigo2));
|
|
|
59 |
display:flex;align-items:center;justify-content:flex-end;padding-right:7px;font-size:11px;color:#fff;font-weight:650;min-width:2px}
|
|
|
60 |
.barrow .meta{font-size:12px;color:var(--muted);text-align:right}
|
|
|
61 |
|
|
|
62 |
/* table */
|
|
|
63 |
table{width:100%;border-collapse:collapse;font-size:13px}
|
|
|
64 |
th,td{text-align:left;padding:9px 10px;border-bottom:1px solid var(--line)}
|
|
|
65 |
th{font-size:11px;text-transform:uppercase;letter-spacing:.06em;color:var(--muted);font-weight:650;cursor:pointer;user-select:none;white-space:nowrap}
|
|
|
66 |
th.num,td.num{text-align:right}
|
|
|
67 |
tbody tr:hover{background:#0e1830}
|
|
|
68 |
.lvl{display:inline-block;font-size:11px;font-weight:700;padding:2px 7px;border-radius:6px;background:#1e2a47;color:var(--indigo2)}
|
|
|
69 |
.adh{font-weight:700}
|
|
|
70 |
.meter{display:inline-block;width:64px;height:7px;border-radius:4px;background:#16223c;vertical-align:middle;margin-left:8px;overflow:hidden}
|
|
|
71 |
.meter > i{display:block;height:100%;border-radius:4px}
|
|
|
72 |
|
|
|
73 |
/* donut */
|
|
|
74 |
.donutwrap{display:flex;align-items:center;gap:22px}
|
|
|
75 |
.donut{width:148px;height:148px;border-radius:50%;flex:none;position:relative;
|
|
|
76 |
-webkit-mask:radial-gradient(circle 44px at center,transparent 98%,#000 100%);
|
|
|
77 |
mask:radial-gradient(circle 44px at center,transparent 98%,#000 100%)}
|
|
|
78 |
.donut .center{position:absolute;inset:0;display:flex;flex-direction:column;align-items:center;justify-content:center;-webkit-mask:none;mask:none}
|
|
|
79 |
.legend{display:flex;flex-direction:column;gap:9px;font-size:13px}
|
|
|
80 |
.legend .it{display:flex;align-items:center;gap:9px}
|
|
|
81 |
.dot{width:11px;height:11px;border-radius:3px;flex:none}
|
|
|
82 |
|
|
|
83 |
/* reason list */
|
|
|
84 |
.reason{display:flex;align-items:center;justify-content:space-between;gap:12px;padding:10px 0;border-bottom:1px solid var(--line)}
|
|
|
85 |
.reason .txt{font-size:13px}
|
|
|
86 |
.reason .n{font-weight:750;font-size:14px}
|
|
|
87 |
.tag{font-size:10.5px;font-weight:700;padding:2px 7px;border-radius:5px;margin-left:8px;text-transform:uppercase;letter-spacing:.04em}
|
|
|
88 |
.tag.sys{background:#3b2a13;color:var(--amber)}
|
|
|
89 |
.tag.human{background:#10331f;color:var(--green)}
|
|
|
90 |
|
|
|
91 |
/* stat tiles */
|
|
|
92 |
.tiles{display:grid;grid-template-columns:repeat(3,1fr);gap:12px}
|
|
|
93 |
.tile{background:var(--panel2);border:1px solid var(--line);border-radius:12px;padding:14px}
|
|
|
94 |
.tile .t{font-size:11px;text-transform:uppercase;letter-spacing:.06em;color:var(--muted);font-weight:600}
|
|
|
95 |
.tile .v{font-size:22px;font-weight:760;margin-top:6px}
|
|
|
96 |
.tile .v small{font-size:13px;color:var(--muted);font-weight:600}
|
|
|
97 |
|
|
|
98 |
/* dq chips */
|
|
|
99 |
.dq{display:grid;grid-template-columns:repeat(2,1fr);gap:10px}
|
|
|
100 |
.chip{display:flex;align-items:center;gap:12px;background:var(--panel2);border:1px solid var(--line);border-radius:12px;padding:12px 14px}
|
|
|
101 |
.chip .sev{width:10px;height:10px;border-radius:50%;flex:none}
|
|
|
102 |
.chip .body{flex:1}
|
|
|
103 |
.chip .ttl{font-size:13px;font-weight:600}
|
|
|
104 |
.chip .det{font-size:12px;color:var(--muted);margin-top:2px}
|
|
|
105 |
.chip .pct{font-size:18px;font-weight:760}
|
|
|
106 |
|
|
|
107 |
.callout{background:linear-gradient(135deg,#15213c,#101a31);border:1px solid #25345a;border-radius:16px;padding:20px 22px}
|
|
|
108 |
.callout h2{margin-top:0}
|
|
|
109 |
.callout ul{margin:6px 0 0;padding-left:20px;line-height:1.75;font-size:13.5px;color:#cdd8ec}
|
|
|
110 |
.callout li b{color:#fff}
|
|
|
111 |
|
|
|
112 |
.sectionlabel{font-size:12px;letter-spacing:.14em;text-transform:uppercase;color:var(--soft);font-weight:700;margin:30px 2px 12px}
|
|
|
113 |
.loading{padding:80px;text-align:center;color:var(--muted)}
|
|
|
114 |
.spinner{width:34px;height:34px;border:3px solid #22314f;border-top-color:var(--indigo2);border-radius:50%;
|
|
|
115 |
animation:spin 1s linear infinite;margin:0 auto 14px}
|
|
|
116 |
@keyframes spin{to{transform:rotate(360deg)}}
|
|
|
117 |
@media (max-width:980px){.kpis{grid-template-columns:repeat(2,1fr)}.g2,.g3{grid-template-columns:1fr}.dq{grid-template-columns:1fr}}
|
|
|
118 |
</style>
|
|
|
119 |
</head>
|
|
|
120 |
<body>
|
|
|
121 |
<div class="wrap">
|
|
|
122 |
<header class="top">
|
|
|
123 |
<div class="brand">
|
|
|
124 |
<span class="eyebrow">SmartDukaan · Field Sales</span>
|
|
|
125 |
<h1>Route Scheduling Analytics</h1>
|
|
|
126 |
<span class="sub" id="sub">Beat Plan (PJP) execution — running month</span>
|
|
|
127 |
</div>
|
|
|
128 |
<div class="hd-right">
|
|
|
129 |
<span class="pill" id="monthpill">…</span>
|
|
|
130 |
<span class="pill" id="genpill">…</span>
|
|
|
131 |
<button class="refresh" onclick="load()">↻ Refresh</button>
|
|
|
132 |
</div>
|
|
|
133 |
</header>
|
|
|
134 |
|
|
|
135 |
<div id="content">
|
|
|
136 |
<div class="loading"><div class="spinner"></div>Loading current-month data…</div>
|
|
|
137 |
</div>
|
|
|
138 |
</div>
|
|
|
139 |
|
|
|
140 |
<script>
|
|
|
141 |
var D = null;
|
|
|
142 |
|
|
|
143 |
function esc(s){return String(s==null?'':s).replace(/[&<>"]/g,function(c){return {'&':'&','<':'<','>':'>','"':'"'}[c];});}
|
|
|
144 |
function adhColor(p){ if(p>=80)return '#34d399'; if(p>=50)return '#fbbf24'; if(p>=25)return '#fb923c'; return '#f87171'; }
|
|
|
145 |
function sevColor(p,inv){ var v=inv?100-p:p; if(v>=66)return '#f87171'; if(v>=33)return '#fbbf24'; return '#34d399'; }
|
|
|
146 |
|
|
|
147 |
function load(){
|
|
|
148 |
document.getElementById('content').innerHTML='<div class="loading"><div class="spinner"></div>Loading current-month data…</div>';
|
|
|
149 |
fetch(location.pathname.replace(/\/$/,'')+'/data',{headers:{'Accept':'application/json'}})
|
|
|
150 |
.then(function(r){ if(!r.ok) throw new Error('http '+r.status); return r.json(); })
|
|
|
151 |
.then(function(j){ D=j; render(); })
|
|
|
152 |
.catch(function(e){ document.getElementById('content').innerHTML='<div class="loading">Could not load data ('+esc(e.message)+'). Are you signed in as an authorised user?</div>'; });
|
|
|
153 |
}
|
|
|
154 |
|
|
|
155 |
function render(){
|
|
|
156 |
var k=D.kpis, dq=D.dataQuality, ds=D.deferralSummary, tp=D.travelPlan, ta=D.travelActual, ld=D.leads;
|
|
|
157 |
document.getElementById('monthpill').innerHTML='Month: <b>'+esc(D.monthStart)+'</b> → <b>'+esc(D.today)+'</b>';
|
|
|
158 |
document.getElementById('genpill').innerHTML='Generated <b>'+new Date().toLocaleString()+'</b>';
|
|
|
159 |
|
|
|
160 |
var html='';
|
|
|
161 |
|
|
|
162 |
/* KPIs */
|
|
|
163 |
html+='<div class="kpis">';
|
|
|
164 |
html+=kpi('Adherence (MTD)', k.adherencePct+'<small>%</small>', k.actualElapsed+' of '+k.plannedElapsed+' planned stops', adhColor(k.adherencePct));
|
|
|
165 |
var l1=lvl('L1');
|
|
|
166 |
html+=kpi('PJP Coverage L1', (l1?l1.coveragePct:0)+'<small>%</small>', (l1?l1.withPjp+'/'+l1.totalUsers:'0')+' field reps have a plan', '#22d3ee');
|
|
|
167 |
html+=kpi('Active Beats', k.activeBeats, k.owners+' owners · '+k.scheduleRows+' day-schedules', '#818cf8');
|
|
|
168 |
html+=kpi('Auto "Missed"', ds.total, ds.systemGenerated+' system · '+ds.human+' real reasons', '#fbbf24');
|
|
|
169 |
html+=kpi('Heads Acted', ds.actioned, ds.rescheduled+' rescheduled · '+ds.cancelled+' cancelled', ds.actioned? '#34d399':'#f87171');
|
|
|
170 |
html+='</div>';
|
|
|
171 |
|
|
|
172 |
/* coverage + reps */
|
|
|
173 |
html+='<div class="sectionlabel">Plan Coverage & Adherence</div>';
|
|
|
174 |
html+='<div class="grid g3">';
|
|
|
175 |
html+='<div class="card">'+repsTable()+'</div>';
|
|
|
176 |
html+='<div class="card"><h2>PJP coverage by sales level</h2><p class="desc">Sales positions (cs.position cat 4) that have at least one scheduled beat-day this month.</p>'+coverageBars()+'</div>';
|
|
|
177 |
html+='</div>';
|
|
|
178 |
|
|
|
179 |
/* deferrals */
|
|
|
180 |
html+='<div class="sectionlabel">Deferrals & Reasons</div>';
|
|
|
181 |
html+='<div class="grid g2">';
|
|
|
182 |
html+='<div class="card"><h2>Deferral nature</h2><p class="desc">Are deferrals deliberate (real reason) or auto-flagged missed beats?</p>'+deferDonut()+'</div>';
|
|
|
183 |
html+='<div class="card"><h2>Reasons posted</h2><p class="desc">Every reason string recorded against a deferral this month.</p>'+reasonList()+'</div>';
|
|
|
184 |
html+='</div>';
|
|
|
185 |
|
|
|
186 |
/* routes + travel */
|
|
|
187 |
html+='<div class="sectionlabel">Route Appropriateness & Travel Time</div>';
|
|
|
188 |
html+='<div class="grid g2">';
|
|
|
189 |
html+='<div class="card"><h2>Distance between consecutive stops</h2><p class="desc">Straight-line distance per leg across all routed beat-days. Well-designed beats cluster geographically (mostly <15 km).</p>'+legBars()+'</div>';
|
|
|
190 |
html+='<div class="card"><h2>Expected vs actual travel</h2><p class="desc">Expected = 1.2× straight-line distance @ 25 km/h. Actual = device-recorded transit time on executed visits.</p>'+travelBlock()+'</div>';
|
|
|
191 |
html+='</div>';
|
|
|
192 |
|
|
|
193 |
/* data quality */
|
|
|
194 |
html+='<div class="sectionlabel">Data Quality & System Health</div>';
|
|
|
195 |
html+='<div class="card"><h2>Data quality signals</h2><p class="desc">Higher red = more missing / inconsistent data weakening the analytics.</p>'+dqChips()+'</div>';
|
|
|
196 |
|
|
|
197 |
/* leads */
|
|
|
198 |
html+='<div class="card"><h2>Lead pipeline usage (current month)</h2><p class="desc">Adoption of lead scheduling within beats.</p>'+
|
|
|
199 |
'<div class="tiles">'+
|
|
|
200 |
tile('Leads created', ld.leadsCreated)+
|
|
|
201 |
tile('Lead routes scheduled', ld.routesScheduled)+
|
|
|
202 |
tile('Lead approvals raised', ld.approvalsRaised)+
|
|
|
203 |
'</div></div>';
|
|
|
204 |
|
|
|
205 |
/* findings */
|
|
|
206 |
html+='<div class="callout">'+findings()+'</div>';
|
|
|
207 |
|
|
|
208 |
document.getElementById('content').innerHTML=html;
|
|
|
209 |
}
|
|
|
210 |
|
|
|
211 |
function kpi(label,val,foot,accent){
|
|
|
212 |
return '<div class="kpi" style="--accent:'+accent+'"><div class="label">'+label+'</div>'+
|
|
|
213 |
'<div class="val" style="color:'+accent+'">'+val+'</div><div class="foot">'+foot+'</div></div>';
|
|
|
214 |
}
|
|
|
215 |
function tile(t,v){ return '<div class="tile"><div class="t">'+t+'</div><div class="v">'+v+'</div></div>'; }
|
|
|
216 |
function lvl(name){ for(var i=0;i<D.coverageByLevel.length;i++){ if(D.coverageByLevel[i].level===name) return D.coverageByLevel[i]; } return null; }
|
|
|
217 |
|
|
|
218 |
function coverageBars(){
|
|
|
219 |
var rows=D.coverageByLevel, max=0; rows.forEach(function(r){ if(r.totalUsers>max)max=r.totalUsers; });
|
|
|
220 |
var h=''; rows.forEach(function(r){
|
|
|
221 |
var w = max? Math.round(100*r.withPjp/max):0;
|
|
|
222 |
var wt = max? Math.round(100*r.totalUsers/max):0;
|
|
|
223 |
h+='<div class="barrow"><div class="name">'+esc(r.level)+'</div>'+
|
|
|
224 |
'<div class="track"><div style="position:absolute;inset:0;width:'+wt+'%;background:#1a2742;border-radius:8px"></div>'+
|
|
|
225 |
'<div class="fill" style="width:'+w+'%;position:relative">'+(r.withPjp||'')+'</div></div>'+
|
|
|
226 |
'<div class="meta">'+r.withPjp+'/'+r.totalUsers+' · '+r.coveragePct+'%</div></div>';
|
|
|
227 |
});
|
|
|
228 |
h+='<p class="desc" style="margin-top:14px">Filled bar = reps <b>with</b> a plan; faint bar = total reps at that level. L4/L5 are managers and typically supervise rather than run a beat.</p>';
|
|
|
229 |
return h;
|
|
|
230 |
}
|
|
|
231 |
|
|
|
232 |
function repsTable(){
|
|
|
233 |
var rows=D.reps.slice();
|
|
|
234 |
var h='<h2>Per-rep adherence ('+rows.length+' beat owners)</h2><p class="desc">Planned vs actually checked-in stops, month-to-date. Click a header to sort.</p>';
|
|
|
235 |
h+='<div style="max-height:430px;overflow:auto"><table id="reptbl"><thead><tr>'+
|
|
|
236 |
'<th onclick="sortReps(\'name\')">Rep</th><th onclick="sortReps(\'level\')">Lvl</th>'+
|
|
|
237 |
'<th class="num" onclick="sortReps(\'plannedElapsed\')">Plan</th>'+
|
|
|
238 |
'<th class="num" onclick="sortReps(\'actual\')">Done</th>'+
|
|
|
239 |
'<th class="num" onclick="sortReps(\'adherencePct\')">Adher.</th>'+
|
|
|
240 |
'<th class="num" onclick="sortReps(\'autoMissed\')">Missed</th>'+
|
|
|
241 |
'<th class="num" onclick="sortReps(\'punchDays\')">Days</th></tr></thead><tbody>';
|
|
|
242 |
rows.forEach(function(r){
|
|
|
243 |
var c=adhColor(r.adherencePct);
|
|
|
244 |
h+='<tr><td>'+esc(r.name)+'</td><td><span class="lvl">'+esc(r.level)+'</span></td>'+
|
|
|
245 |
'<td class="num">'+r.plannedElapsed+'</td><td class="num">'+r.actual+'</td>'+
|
|
|
246 |
'<td class="num"><span class="adh" style="color:'+c+'">'+r.adherencePct+'%</span>'+
|
|
|
247 |
'<span class="meter"><i style="width:'+Math.min(100,r.adherencePct)+'%;background:'+c+'"></i></span></td>'+
|
|
|
248 |
'<td class="num"'+(r.autoMissed>0?' style="color:#fbbf24;font-weight:650"':'')+'>'+r.autoMissed+'</td>'+
|
|
|
249 |
'<td class="num">'+r.punchDays+'</td></tr>';
|
|
|
250 |
});
|
|
|
251 |
h+='</tbody></table></div>';
|
|
|
252 |
return h;
|
|
|
253 |
}
|
|
|
254 |
var sortDir={};
|
|
|
255 |
function sortReps(key){
|
|
|
256 |
sortDir[key]=!sortDir[key];
|
|
|
257 |
D.reps.sort(function(a,b){ var x=a[key],y=b[key];
|
|
|
258 |
if(typeof x==='string'){ return sortDir[key]? (''+x).localeCompare(y):(''+y).localeCompare(x); }
|
|
|
259 |
return sortDir[key]? x-y : y-x; });
|
|
|
260 |
document.querySelector('#content .g3 .card').innerHTML=repsTable();
|
|
|
261 |
}
|
|
|
262 |
|
|
|
263 |
function deferDonut(){
|
|
|
264 |
var s=D.deferralSummary, tot=s.total||1;
|
|
|
265 |
var sysPct=Math.round(100*s.systemGenerated/tot), humanPct=100-sysPct;
|
|
|
266 |
var g='conic-gradient(#fbbf24 0 '+sysPct+'%, #34d399 '+sysPct+'% 100%)';
|
|
|
267 |
var h='<div class="donutwrap"><div class="donut" style="background:'+g+'"><div class="center">'+
|
|
|
268 |
'<div style="font-size:26px;font-weight:780">'+s.total+'</div><div style="font-size:11px;color:#8ea0bd">deferrals</div></div></div>'+
|
|
|
269 |
'<div class="legend">'+
|
|
|
270 |
'<div class="it"><span class="dot" style="background:#fbbf24"></span><div><b>'+s.systemGenerated+'</b> system auto-flagged ('+sysPct+'%)<br><span style="color:#8ea0bd;font-size:12px">"Beat missed", "no punch-in", "agenda unfilled"</span></div></div>'+
|
|
|
271 |
'<div class="it"><span class="dot" style="background:#34d399"></span><div><b>'+s.human+'</b> genuine reason ('+humanPct+'%)</div></div>'+
|
|
|
272 |
'<div class="it"><span class="dot" style="background:#6366f1"></span><div><b>'+s.actioned+'</b> acted on by a head ('+s.rescheduled+' rescheduled, '+s.cancelled+' cancelled)</div></div>'+
|
|
|
273 |
'</div></div>';
|
|
|
274 |
return h;
|
|
|
275 |
}
|
|
|
276 |
|
|
|
277 |
function reasonList(){
|
|
|
278 |
var h='<div style="max-height:330px;overflow:auto">';
|
|
|
279 |
D.deferralReasons.forEach(function(r){
|
|
|
280 |
var tag=r.systemGenerated?'<span class="tag sys">system</span>':'<span class="tag human">real</span>';
|
|
|
281 |
h+='<div class="reason"><div class="txt">'+esc(r.reason)+tag+' <span style="color:#64759a;font-size:11px">('+esc(r.status)+')</span></div><div class="n">'+r.count+'</div></div>';
|
|
|
282 |
});
|
|
|
283 |
h+='</div>';
|
|
|
284 |
return h;
|
|
|
285 |
}
|
|
|
286 |
|
|
|
287 |
function legBars(){
|
|
|
288 |
var rows=D.legBuckets, max=0; rows.forEach(function(r){ if(r.count>max)max=r.count; });
|
|
|
289 |
var colors={'0-2 km':'#34d399','2-5 km':'#34d399','5-15 km':'#a3e635','15-50 km':'#fbbf24','50-200 km':'#fb923c','200 km+':'#f87171'};
|
|
|
290 |
var h=''; rows.forEach(function(r){
|
|
|
291 |
var w=max?Math.round(100*r.count/max):0; var col=colors[r.bucket]||'#6366f1';
|
|
|
292 |
h+='<div class="barrow"><div class="name">'+esc(r.bucket)+'</div>'+
|
|
|
293 |
'<div class="track"><div class="fill" style="width:'+w+'%;background:'+col+'">'+r.count+'</div></div>'+
|
|
|
294 |
'<div class="meta"></div></div>';
|
|
|
295 |
});
|
|
|
296 |
var tp=D.travelPlan;
|
|
|
297 |
h+='<div class="tiles" style="margin-top:16px">'+
|
|
|
298 |
tile('Avg leg', tp.avgLegKm+'<small> km</small>')+
|
|
|
299 |
tile('Longest leg', Math.round(tp.maxLegKm)+'<small> km</small>')+
|
|
|
300 |
tile('Legs > 15 km', tp.pctOver15+'<small>%</small>')+
|
|
|
301 |
'</div>';
|
|
|
302 |
return h;
|
|
|
303 |
}
|
|
|
304 |
|
|
|
305 |
function travelBlock(){
|
|
|
306 |
var ta=D.travelActual, tp=D.travelPlan;
|
|
|
307 |
var maxh=Math.max(ta.transitHrs,ta.estimatedHrs,1);
|
|
|
308 |
function bar(label,val,col){ var w=Math.round(100*val/maxh);
|
|
|
309 |
return '<div class="barrow" style="grid-template-columns:120px 1fr 70px"><div class="name">'+label+'</div>'+
|
|
|
310 |
'<div class="track"><div class="fill" style="width:'+w+'%;background:'+col+'"></div></div>'+
|
|
|
311 |
'<div class="meta">'+val+' h</div></div>'; }
|
|
|
312 |
var h=bar('App estimate',ta.estimatedHrs,'#6366f1')+bar('Actual transit',ta.transitHrs,'#f87171');
|
|
|
313 |
h+='<div class="tiles" style="margin-top:16px">'+
|
|
|
314 |
tile('Actual / estimate', ta.actualVsEstimateRatio+'<small>×</small>')+
|
|
|
315 |
tile('Avg transit / visit', ta.avgTransitMin+'<small> min</small>')+
|
|
|
316 |
tile('Expected drive/day', (tp.beatDays? (Math.round(tp.expectedTravelHrs/tp.beatDays*10)/10):0)+'<small> h</small>')+
|
|
|
317 |
'</div>';
|
|
|
318 |
h+='<p class="desc" style="margin-top:14px">Across the planned month, expected driving totals <b>'+Math.round(tp.expectedRoadKm)+' km</b> ('+tp.expectedTravelHrs+' h) over '+tp.beatDays+' beat-days — '+(tp.beatDays?Math.round(tp.expectedRoadKm/tp.beatDays):0)+' km/day on average.</p>';
|
|
|
319 |
return h;
|
|
|
320 |
}
|
|
|
321 |
|
|
|
322 |
function dqChips(){
|
|
|
323 |
var dq=D.dataQuality;
|
|
|
324 |
function chip(ttl,det,pct,inv){
|
|
|
325 |
var col=sevColor(pct,inv);
|
|
|
326 |
return '<div class="chip"><span class="sev" style="background:'+col+'"></span><div class="body"><div class="ttl">'+ttl+'</div><div class="det">'+det+'</div></div><div class="pct" style="color:'+col+'">'+pct+'%</div></div>';
|
|
|
327 |
}
|
|
|
328 |
var bridgePct = dq.beatOwners? Math.round(100*dq.ownersMappedToExecution/dq.beatOwners):0;
|
|
|
329 |
var h='';
|
|
|
330 |
h+=chip('Route legs missing distance','beat_route.distance_from_prev_km is NULL ('+dq.routeNullDistance+'/'+dq.routeStops+')',dq.routeNullDistancePct,false);
|
|
|
331 |
h+=chip('Visits with zero transit time',dq.zeroTransitPct+'% of '+dq.visitRecords+' franchisee visits',dq.zeroTransitPct,false);
|
|
|
332 |
h+=chip('Visits missing time-spent','time_spent is 00:00:00',dq.zeroTimeSpentPct,false);
|
|
|
333 |
h+=chip('Visits missing GPS location','visit_location empty',dq.noVisitLocationPct,false);
|
|
|
334 |
h+=chip('Visits missing battery level','battery_level not reported',dq.noBatteryPct,false);
|
|
|
335 |
h+=chip('Planning ↔ execution identity bridge',dq.ownersMappedToExecution+'/'+dq.beatOwners+' owners resolvable by email (no FK exists)',bridgePct,true);
|
|
|
336 |
var noActPct = dq.scheduledBeatDaysElapsed? Math.round(100*dq.beatDaysNoActivity/dq.scheduledBeatDaysElapsed):0;
|
|
|
337 |
h+=chip('Scheduled beat-days with no activity',dq.beatDaysNoActivity+'/'+dq.scheduledBeatDaysElapsed+' planned days had zero tracking',noActPct,false);
|
|
|
338 |
h+=chip('Distinct mark_type spellings',dq.distinctMarkTypes+' variants incl. CHECKIN-CHECKOUT vs CHECKIN_CHECKOUT & "2"',dq.distinctMarkTypes>6?80:(dq.distinctMarkTypes>3?45:10),false);
|
|
|
339 |
return '<div class="dq">'+h+'</div>';
|
|
|
340 |
}
|
|
|
341 |
|
|
|
342 |
function findings(){
|
|
|
343 |
var k=D.kpis, ds=D.deferralSummary, tp=D.travelPlan, ta=D.travelActual, dq=D.dataQuality, l1=lvl('L1');
|
|
|
344 |
var h='<h2>What the data says & what to fix</h2><ul>';
|
|
|
345 |
h+='<li><b>Routes are not geographically clustered.</b> '+tp.pctOver15+'% of legs exceed 15 km and the longest is '+Math.round(tp.maxLegKm)+' km — consecutive stops sit in different cities. Re-sequence beats by proximity (nearest-neighbour) and cap daily travel.</li>';
|
|
|
346 |
h+='<li><b>Deferrals are not real deferrals.</b> '+Math.round(100*ds.systemGenerated/(ds.total||1))+'% are system "missed beat" flags and heads acted on '+ds.actioned+'. Add a mandatory reason picker on genuine deferral and an action SLA for managers.</li>';
|
|
|
347 |
h+='<li><b>Travel is under-estimated.</b> Actual transit runs '+ta.actualVsEstimateRatio+'× the app estimate ('+ta.avgTransitMin+' min/visit). Recalibrate the planner’s speed/road-factor and persist per-leg distance & time.</li>';
|
|
|
348 |
h+='<li><b>Coverage gap.</b> '+(l1?l1.withPjp+' of '+l1.totalUsers:'?')+' L1 field reps have a plan this month; the rest run no PJP. Make a monthly PJP mandatory before month start.</li>';
|
|
|
349 |
h+='<li><b>Data plumbing is fragile.</b> '+dq.routeNullDistancePct+'% of route legs store no distance, mark_type has '+dq.distinctMarkTypes+' spellings, and planning & execution share no key (bridged only by email). Standardise mark_type, persist leg metrics, and add an auth→dtr user mapping.</li>';
|
|
|
350 |
h+='</ul>';
|
|
|
351 |
return h;
|
|
|
352 |
}
|
|
|
353 |
|
|
|
354 |
load();
|
|
|
355 |
</script>
|
|
|
356 |
</body>
|
|
|
357 |
</html>]]#
|