-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Completing reports migration #41
Draft
max-ostapenko
wants to merge
10
commits into
main
Choose a base branch
from
standard_reports
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,073
−56
Draft
Changes from 2 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
8854387
fix discrepancies
max-ostapenko bf90fd8
lenses
max-ostapenko 65062af
Merge branch 'main' into standard_reports
max-ostapenko 5637e83
sql updated
max-ostapenko 55adcf4
lenses path
max-ostapenko 385e426
spelling fix
max-ostapenko 1b3678c
all metrics in the same table
max-ostapenko e2ce0dd
aggregated tables
max-ostapenko 6bb7ce4
storage sync script
max-ostapenko 28cebce
Merge branch 'main' into standard_reports
max-ostapenko File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,74 @@ | ||
const configs = new reports.HTTPArchiveReports() | ||
const metrics = configs.listMetrics() | ||
|
||
// Adjust start and end dates to update reports retrospectively | ||
const startDate = '2024-12-01' // constants.currentMonth; | ||
const endDate = '2024-12-01' // constants.currentMonth; | ||
|
||
const lenses = { | ||
all: '', | ||
top1k: 'AND rank <= 1000', | ||
top10k: 'AND rank <= 10000', | ||
top100k: 'AND rank <= 100000', | ||
top1m: 'AND rank <= 1000000', | ||
drupal: 'AND \'Drupal\' IN UNNEST(technologies.technology)', | ||
magento: 'AND \'Magento\' IN UNNEST(technologies.technology)', | ||
wordpress: 'AND \'WordPress\' IN UNNEST(technologies.technology)' | ||
} | ||
|
||
const iterations = [] | ||
// dates | ||
for ( | ||
let month = constants.currentMonth; month >= constants.currentMonth; month = constants.fnPastMonth(month)) { | ||
iterations.push({ | ||
date: month, | ||
devRankFilter: constants.devRankFilter | ||
let date = endDate; | ||
date >= startDate; | ||
date = constants.fnPastMonth(date) | ||
) { | ||
// metrics | ||
metrics.forEach(metric => { | ||
// timeseries and histograms | ||
metric.SQL.forEach(sql => { | ||
// lenses | ||
for (const [key, value] of Object.entries(lenses)) { | ||
iterations.push({ | ||
date, | ||
metric, | ||
sql, | ||
lense: { key, value }, | ||
devRankFilter: constants.devRankFilter | ||
}) | ||
} | ||
}) | ||
}) | ||
} | ||
|
||
if (iterations.length === 1) { | ||
const params = iterations[0] | ||
metrics.forEach(metric => { | ||
metric.SQL.forEach(sql => { | ||
publish(metric.id + '_' + sql.type, { | ||
type: 'incremental', | ||
protected: true, | ||
bigquery: sql.type === 'histogram' ? { partitionBy: 'date', clusterBy: ['client'] } : {}, | ||
schema: 'reports', | ||
tags: ['crawl_complete'] | ||
}).preOps(ctx => ` | ||
if (startDate === endDate) { | ||
iterations.forEach((params, i) => { | ||
publish(params.metric.id + '_' + params.sql.type + '_' + params.lense.key, { | ||
type: 'incremental', | ||
protected: true, | ||
bigquery: params.sql.type === 'histogram' ? { partitionBy: 'date', clusterBy: ['client'] } : {}, | ||
schema: 'reports', | ||
tags: ['crawl_complete', 'reports'] | ||
}).preOps(ctx => ` | ||
--DELETE FROM ${ctx.self()} | ||
--WHERE date = '${params.date}'; | ||
`).query(ctx => ` | ||
/* {"dataform_trigger": "report_complete", "date": "${params.date}", "name": "${metric.id}", "type": "${sql.type}"} */` + | ||
sql.query(ctx, params)) | ||
}) | ||
`).query(ctx => ` | ||
/* {"dataform_trigger": "report_complete", "date": "${params.date}", "name": "${params.metric.id}", "type": "${params.sql.type}", "lense": "${params.lense.key}"} */` + | ||
params.sql.query(ctx, params) | ||
) | ||
}) | ||
} else { | ||
iterations.forEach((params, i) => { | ||
metrics.forEach(metric => { | ||
metric.SQL.forEach(sql => { | ||
operate(metric.id + '_' + sql.type + '_' + params.date, { | ||
tags: ['crawl_complete'] | ||
}).queries(ctx => ` | ||
DELETE FROM reports.${metric.id}_${sql.type} | ||
operate( | ||
params.metric.id + '_' + params.sql.type + '_' + params.lense.key + '_' + params.date) | ||
.tags(['crawl_complete', 'reports']) | ||
.queries(ctx => ` | ||
DELETE FROM reports.${params.metric.id}_${params.sql.type} | ||
WHERE date = '${params.date}'; | ||
|
||
/* {"dataform_trigger": "report_complete", "date": "${params.date}", "name": "${metric.id}", "type": "${sql.type}"} */ | ||
INSERT INTO reports.${metric.id}_${sql.type}` + | ||
sql.query(ctx, params)) | ||
}) | ||
}) | ||
/* {"dataform_trigger": "report_complete", "date": "${params.date}", "name": "${params.metric.id}", "type": "${params.sql.type}", "lense": "${params.lense.key}"} */ | ||
INSERT INTO reports.${params.metric.id}_${params.sql.type}` + | ||
params.sql.query(ctx, params) | ||
) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO: remove hardcoded dates.