Skip to content

Commit bf90fd8

Browse files
committed
lenses
1 parent 8854387 commit bf90fd8

1 file changed

Lines changed: 57 additions & 30 deletions

File tree

Lines changed: 57 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,74 @@
11
const configs = new reports.HTTPArchiveReports()
22
const metrics = configs.listMetrics()
33

4+
// Adjust start and end dates to update reports retrospectively
5+
const startDate = '2024-12-01' // constants.currentMonth;
6+
const endDate = '2024-12-01' // constants.currentMonth;
7+
8+
const lenses = {
9+
all: '',
10+
top1k: 'AND rank <= 1000',
11+
top10k: 'AND rank <= 10000',
12+
top100k: 'AND rank <= 100000',
13+
top1m: 'AND rank <= 1000000',
14+
drupal: 'AND \'Drupal\' IN UNNEST(technologies.technology)',
15+
magento: 'AND \'Magento\' IN UNNEST(technologies.technology)',
16+
wordpress: 'AND \'WordPress\' IN UNNEST(technologies.technology)'
17+
}
18+
419
const iterations = []
20+
// dates
521
for (
6-
let month = constants.currentMonth; month >= constants.currentMonth; month = constants.fnPastMonth(month)) {
7-
iterations.push({
8-
date: month,
9-
devRankFilter: constants.devRankFilter
22+
let date = endDate;
23+
date >= startDate;
24+
date = constants.fnPastMonth(date)
25+
) {
26+
// metrics
27+
metrics.forEach(metric => {
28+
// timeseries and histograms
29+
metric.SQL.forEach(sql => {
30+
// lenses
31+
for (const [key, value] of Object.entries(lenses)) {
32+
iterations.push({
33+
date,
34+
metric,
35+
sql,
36+
lense: { key, value },
37+
devRankFilter: constants.devRankFilter
38+
})
39+
}
40+
})
1041
})
1142
}
1243

13-
if (iterations.length === 1) {
14-
const params = iterations[0]
15-
metrics.forEach(metric => {
16-
metric.SQL.forEach(sql => {
17-
publish(metric.id + '_' + sql.type, {
18-
type: 'incremental',
19-
protected: true,
20-
bigquery: sql.type === 'histogram' ? { partitionBy: 'date', clusterBy: ['client'] } : {},
21-
schema: 'reports',
22-
tags: ['crawl_complete']
23-
}).preOps(ctx => `
44+
if (startDate === endDate) {
45+
iterations.forEach((params, i) => {
46+
publish(params.metric.id + '_' + params.sql.type + '_' + params.lense.key, {
47+
type: 'incremental',
48+
protected: true,
49+
bigquery: params.sql.type === 'histogram' ? { partitionBy: 'date', clusterBy: ['client'] } : {},
50+
schema: 'reports',
51+
tags: ['crawl_complete', 'reports']
52+
}).preOps(ctx => `
2453
--DELETE FROM ${ctx.self()}
2554
--WHERE date = '${params.date}';
26-
`).query(ctx => `
27-
/* {"dataform_trigger": "report_complete", "date": "${params.date}", "name": "${metric.id}", "type": "${sql.type}"} */` +
28-
sql.query(ctx, params))
29-
})
55+
`).query(ctx => `
56+
/* {"dataform_trigger": "report_complete", "date": "${params.date}", "name": "${params.metric.id}", "type": "${params.sql.type}", "lense": "${params.lense.key}"} */` +
57+
params.sql.query(ctx, params)
58+
)
3059
})
3160
} else {
3261
iterations.forEach((params, i) => {
33-
metrics.forEach(metric => {
34-
metric.SQL.forEach(sql => {
35-
operate(metric.id + '_' + sql.type + '_' + params.date, {
36-
tags: ['crawl_complete']
37-
}).queries(ctx => `
38-
DELETE FROM reports.${metric.id}_${sql.type}
62+
operate(
63+
params.metric.id + '_' + params.sql.type + '_' + params.lense.key + '_' + params.date)
64+
.tags(['crawl_complete', 'reports'])
65+
.queries(ctx => `
66+
DELETE FROM reports.${params.metric.id}_${params.sql.type}
3967
WHERE date = '${params.date}';
4068
41-
/* {"dataform_trigger": "report_complete", "date": "${params.date}", "name": "${metric.id}", "type": "${sql.type}"} */
42-
INSERT INTO reports.${metric.id}_${sql.type}` +
43-
sql.query(ctx, params))
44-
})
45-
})
69+
/* {"dataform_trigger": "report_complete", "date": "${params.date}", "name": "${params.metric.id}", "type": "${params.sql.type}", "lense": "${params.lense.key}"} */
70+
INSERT INTO reports.${params.metric.id}_${params.sql.type}` +
71+
params.sql.query(ctx, params)
72+
)
4673
})
4774
}

0 commit comments

Comments
 (0)