-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathtime-series.js
54 lines (44 loc) · 1.31 KB
/
time-series.js
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
#!/usr/bin/env node
/*
calibre v5.0.0+ required
This example will fetch time series data for a given site for the past 7 days
and group the data by test profile.
*/
import { TimeSeries } from 'calibre'
const main = async () => {
const site = 'calibre'
const to = new Date()
const from = new Date()
const metrics = [
'lighthouse-performance-score',
'first-contentful-paint',
'consistently-interactive'
]
from.setDate(to.getDate() - 7)
const timeSeries = await TimeSeries.list({
site,
from: from.toUTCString(),
to: to.toUTCString(),
measurements: metrics
})
const { pages, testProfiles, times, series, measurements } = timeSeries
const page = pages[0]
console.log(`Time series data for ${page.name} (${page.url})`)
testProfiles.forEach(testProfile => {
console.log('')
console.log(`${testProfile.name}`)
series
.filter(series => series.profile === testProfile.uuid)
.forEach(series => {
const measurement = measurements.find(
measurement => measurement.name === series.measurement
)
console.log(` ${measurement.label}`)
times.forEach((time, index) => {
const value = series.values[index]
console.log(` ${time.timestamp} - ${time.name} - ${value}`)
})
})
})
}
main()