| 58 | } |
| 59 | |
| 60 | public sampleData(graphId: string, sampleSize: number, start: number = null, end: number = null): GraphPoint[] { |
| 61 | let data: GraphPoint[] = this.data[graphId]; |
| 62 | if (!data) { return []; } |
| 63 | |
| 64 | if (start === null) { start = 0; } |
| 65 | if (end == null) { end = new Date().getTime(); } |
| 66 | |
| 67 | data = data.filter((gp) => gp.timestamp >= start && gp.timestamp <= end); |
| 68 | |
| 69 | if (data.length > sampleSize * 1.5) { |
| 70 | const sampleRate = Math.round(data.length / sampleSize); |
| 71 | data = data.filter((gp, idx) => idx % sampleRate === 0); |
| 72 | } |
| 73 | |
| 74 | return data; |
| 75 | } |
| 76 | |
| 77 | public oldestPoint(graphId: string): GraphPoint { |
| 78 | return this.data[graphId] ? this.data[graphId][0] : null; |