|
1 | 1 | const configs = new reports.HTTPArchiveReports() |
2 | 2 | const metrics = configs.listMetrics() |
3 | 3 |
|
| 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 | + |
4 | 19 | const iterations = [] |
| 20 | +// dates |
5 | 21 | 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 | + }) |
10 | 41 | }) |
11 | 42 | } |
12 | 43 |
|
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 => ` |
24 | 53 | --DELETE FROM ${ctx.self()} |
25 | 54 | --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 | + ) |
30 | 59 | }) |
31 | 60 | } else { |
32 | 61 | 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} |
39 | 67 | WHERE date = '${params.date}'; |
40 | 68 |
|
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 | + ) |
46 | 73 | }) |
47 | 74 | } |
0 commit comments