updateDelays = (ts)=>{
let interp = (x0, x1, t0, t1, ti) => {
if(x0 == x1){
return x0;
}
if(t0 == t1) {
return (x0+x1)/2
}
if(ti<t0){
ti=t0
}
if(ti>t1){
ti=t1
}
return x0 + (x1-x0)*(ti-t0)/(t1-t0)
}
currentDelays.length = 0
_.each(allDelays, (d)=>{
if(d.actual_0 <= ts && d.arrival_actual_1 >= ts){
currentDelays.push(d)
const ratioCur = (ts-d.actual_0)/(d.arrival_actual_1-d.actual_0)
const ratioSched = (ts+d.arrival_delta_seconds_1*1000-d.actual_0)/(d.arrival_actual_1-d.actual_0)
const pos = d.path.interpolatePosition(ratioCur)
const posSched = d.path.interpolatePosition(ratioSched)
d.curPos = {
lat : pos.lat,
lon : pos.lon,
schedPath : d.path.interpolatePartial(ratioCur, ratioSched)
}
}
})
const n = stats.histogramDelayPerMinute.length
_.times(n, (i)=> {stats.histogramDelayPerMinute[i].pc=0})
_.each(currentDelays, (d) => {
let i = Math.max(0, Math.floor(d.arrival_delta_seconds_1/60))
if(i>= n){
return
}
stats.histogramDelayPerMinute[i].pc+=1
})
const tot = currentDelays.length
_.times(n, (i)=> {stats.histogramDelayPerMinute[i].pc=stats.histogramDelayPerMinute[i].pc/tot});
stats.cancelled.count = _.chain(allDelays)
.filter('is_cancelled')
.filter((d) => d.time_0 <= selectedTimestamp && d.arrival_time_1 >= selectedTimestamp)
.size()
.value()
}