timeStreaks = {
const playerShots = realShots.filter(d => d.distance >= 0)
const results = {}
const streakQuota = 3
for (let i = 1; i <= streakQuota; i++) {
results['all'] = { shots: [shots[0]] }
results[`make-${i}`] = { shots: [] }
results[`miss-${i}`] = { shots: [] }
}
for (let i = 1; i < playerShots.length; i++) {
results['all'].shots.push(playerShots[i])
const lookBackCount = Math.min(streakQuota, i)
const lastResult = playerShots[i - 1].made
const lastResultString = lastResult ? 'make' : 'miss'
let j = 1;
while (j <= lookBackCount && playerShots[i - j].made === lastResult && Math.abs(playerShots[i - j].secondsIntoGame - playerShots[i].secondsIntoGame) < j * 180 ) {
results[`${lastResultString}-${j}`].shots.push(playerShots[i])
j++
}
}
for (const [key, r] of Object.entries(results)) {
const avgDistance = d3.mean(r.shots, s => s.distance)
const fgm = r.shots.reduce((sum, s) => s.made ? sum + 1 : sum, 0)
r.attempts = r.shots.length;
r.fgm = fgm;
r.fgpct = fgm / r.shots.length;
r.avgDistance = avgDistance;
}
return results
}