Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion templates/build-success-trend/build-success-trend.sql
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ SELECT
ROUND(100.0 * COUNT(DISTINCT CASE WHEN buildOutcome = 'Succeeded' THEN buildId END)
/ COUNT(DISTINCT buildId), 1) AS success_rate_pct,
COUNT(DISTINCT path) AS unique_repos
FROM trace
FROM traces
WHERE buildOutcome IS NOT NULL
GROUP BY DATE_TRUNC('month', CAST(buildStartTime AS TIMESTAMP))
ORDER BY month;
5 changes: 3 additions & 2 deletions templates/build-tool-distribution/build-tool-distribution.sql
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
-- Compatible with: AWS Athena, Trino, PostgreSQL, and other standard SQL engines.

-- Query 1: Build tool summary — repos per build tool

SELECT
CASE
WHEN buildMavenVersion IS NOT NULL AND buildMavenVersion != '' THEN 'Maven'
Expand All @@ -18,7 +19,7 @@ SELECT
END AS build_tool,
COUNT(DISTINCT path) AS repos,
COUNT(DISTINCT buildId) AS builds
FROM trace
FROM traces
WHERE buildOutcome = 'Succeeded'
GROUP BY 1
ORDER BY repos DESC;
Expand All @@ -45,7 +46,7 @@ SELECT
) AS tool_version,
COUNT(DISTINCT path) AS repos,
COUNT(DISTINCT buildId) AS builds
FROM trace
FROM traces
WHERE buildOutcome = 'Succeeded'
GROUP BY 1, 2
ORDER BY build_tool, repos DESC;
7 changes: 4 additions & 3 deletions templates/commit-activity/commit-activity.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
-- Commit Activity
--
-- Monthly committed output: successful commits, repos changed, and estimated hours saved.
-- Data source: mod git commit trace, or any later-stage trace.
-- Data source: mod git commit traces (type = 'commit').
--
-- Compatible with: AWS Athena, Trino, PostgreSQL, and other engines supporting DATE_TRUNC.
-- Replace 'month' with 'week', 'quarter', or 'year' to change granularity.
Expand All @@ -17,8 +17,9 @@ FROM (
MAX(commitStartTime) AS commitStartTime,
MAX(path) AS path,
MAX(runEstimatedEffortTimeSavingsMs) AS runEstimatedEffortTimeSavingsMs
FROM trace
WHERE commitOutcome = 'Succeeded'
FROM traces
WHERE type = 'commit'
AND commitOutcome = 'Succeeded'
GROUP BY commitId
) commits
GROUP BY DATE_TRUNC('month', CAST(commitStartTime AS TIMESTAMP))
Expand Down
7 changes: 4 additions & 3 deletions templates/commit-trend/commit-trend.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
-- Commit Trend
--
-- Monthly trend correlating recipe execution with committed code impact.
-- Data source: mod git commit trace, or any later-stage trace.
-- Data source: mod git commit traces (type = 'commit').
--
-- Compatible with: AWS Athena, Trino, PostgreSQL, and other engines supporting DATE_TRUNC.
-- Replace 'month' with 'week', 'quarter', or 'year' to change granularity.
Expand All @@ -15,7 +15,8 @@ SELECT
COUNT(DISTINCT path) AS repos_with_commits,
COUNT(DISTINCT CASE WHEN commitOutcome = 'Succeeded' THEN commitId END) AS successful_commits,
ROUND(SUM(runEstimatedEffortTimeSavingsMs) / 3600000.0, 1) AS estimated_hours_saved
FROM trace
WHERE commitOutcome IS NOT NULL
FROM traces
WHERE type = 'commit'
AND commitOutcome IS NOT NULL
GROUP BY DATE_TRUNC('month', CAST(commitStartTime AS TIMESTAMP))
ORDER BY month;
63 changes: 46 additions & 17 deletions templates/dashboard-kpis/dashboard-kpis.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,60 @@
-- Data source: mod git commit trace for full metrics, or mod run trace for run-only metrics.
--
-- Compatible with: AWS Athena, Trino, PostgreSQL, and other standard SQL engines.
--
-- Run-stage columns are re-emitted by every later-stage trace (apply, add, commit), so a
-- single run can appear on several rows. Both queries below first collapse to one row per
-- (runId, path) -- one repository's participation in one run -- before summing, so the
-- totals are not inflated. Counts of commits still work because the inner query keeps the
-- commit columns, which only later-stage traces carry.

-- Query 1: Summary KPIs (single row, all-time totals)

SELECT
COUNT(DISTINCT runId) AS total_recipe_runs,
COUNT(DISTINCT CASE WHEN commitOutcome = 'Succeeded' THEN commitId END) AS total_commits,
COUNT(DISTINCT developer) AS unique_users,
COUNT(DISTINCT runRecipeId) AS unique_recipes,
SUM(runFilesWithFixResults) AS files_changed,
ROUND(SUM(runEstimatedEffortTimeSavingsMs) / 3600000.0, 1) AS estimated_hours_saved
FROM trace
WHERE runOutcome IS NOT NULL;
COUNT(DISTINCT runId) AS total_recipe_runs,
COUNT(DISTINCT committedCommitId) AS total_commits,
COUNT(DISTINCT developer) AS unique_users,
COUNT(DISTINCT runRecipeId) AS unique_recipes,
SUM(runFilesWithFixResults) AS files_changed,
ROUND(SUM(runEstimatedEffortTimeSavingsMs) / 3600000.0, 1) AS estimated_hours_saved
FROM (
SELECT
runId,
path,
MAX(developer) AS developer,
MAX(runRecipeId) AS runRecipeId,
MAX(runFilesWithFixResults) AS runFilesWithFixResults,
MAX(runEstimatedEffortTimeSavingsMs) AS runEstimatedEffortTimeSavingsMs,
MAX(CASE WHEN commitOutcome = 'Succeeded' THEN commitId END) AS committedCommitId
FROM traces
WHERE runOutcome IS NOT NULL
GROUP BY runId, path
) runs;

-- Query 2: Monthly Trend
-- Replace 'month' with 'week', 'quarter', or 'year' to change granularity.

SELECT
DATE_TRUNC('month', CAST(runStartTime AS TIMESTAMP)) AS month,
COUNT(DISTINCT runId) AS recipe_runs,
COUNT(DISTINCT CASE WHEN commitOutcome = 'Succeeded' THEN commitId END) AS commits,
COUNT(DISTINCT developer) AS unique_users,
COUNT(DISTINCT runRecipeId) AS unique_recipes,
SUM(runFilesWithFixResults) AS files_changed,
ROUND(SUM(runEstimatedEffortTimeSavingsMs) / 3600000.0, 1) AS estimated_hours_saved
FROM trace
WHERE runOutcome IS NOT NULL
DATE_TRUNC('month', CAST(runStartTime AS TIMESTAMP)) AS month,
COUNT(DISTINCT runId) AS recipe_runs,
COUNT(DISTINCT committedCommitId) AS commits,
COUNT(DISTINCT developer) AS unique_users,
COUNT(DISTINCT runRecipeId) AS unique_recipes,
SUM(runFilesWithFixResults) AS files_changed,
ROUND(SUM(runEstimatedEffortTimeSavingsMs) / 3600000.0, 1) AS estimated_hours_saved
FROM (
SELECT
runId,
path,
MAX(runStartTime) AS runStartTime,
MAX(developer) AS developer,
MAX(runRecipeId) AS runRecipeId,
MAX(runFilesWithFixResults) AS runFilesWithFixResults,
MAX(runEstimatedEffortTimeSavingsMs) AS runEstimatedEffortTimeSavingsMs,
MAX(CASE WHEN commitOutcome = 'Succeeded' THEN commitId END) AS committedCommitId
FROM traces
WHERE runOutcome IS NOT NULL
GROUP BY runId, path
) runs
GROUP BY DATE_TRUNC('month', CAST(runStartTime AS TIMESTAMP))
ORDER BY month;
2 changes: 1 addition & 1 deletion templates/recipe-run-trend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Monthly adoption trend showing how Moderne usage is growing over time.

## Data Source

This report uses trace data produced by **`mod run`**. Any later-stage command (`mod git apply`, `mod git commit`, `mod git push`) also includes run-stage data and will work with this query.
This report uses trace data produced by **`mod run`**. Later-stage commands (`mod git apply`, `mod git add`, `mod git commit`) re-emit the same run-stage columns, so the query pins `type = 'run'` to count each run once.

See the [trace.csv data dictionary](../../data-dictionary/trace-csv.md) for the full column reference.

Expand Down
7 changes: 4 additions & 3 deletions templates/recipe-run-trend/recipe-run-trend.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
-- Recipe Run Trend
--
-- Monthly adoption trend: recipe runs, distinct recipes, and unique users over time.
-- Data source: mod run trace, or any later-stage trace.
-- Data source: mod run traces (type = 'run').
--
-- Compatible with: AWS Athena, Trino, PostgreSQL, and other engines supporting DATE_TRUNC.
-- Replace 'month' with 'week', 'quarter', or 'year' to change granularity.
Expand All @@ -11,7 +11,8 @@ SELECT
COUNT(DISTINCT runId) AS recipe_runs,
COUNT(DISTINCT runRecipeId) AS distinct_recipes,
COUNT(DISTINCT developer) AS unique_users
FROM trace
WHERE runOutcome IS NOT NULL
FROM traces
WHERE type = 'run'
AND runOutcome IS NOT NULL
GROUP BY DATE_TRUNC('month', CAST(runStartTime AS TIMESTAMP))
ORDER BY month;
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
--
-- Monthly security remediation trend: committed fixes, repos fixed,
-- files remediated, hours saved, and distinct security recipes over time.
-- Data source: mod git commit trace (commit-stage traces include run-stage data).
-- Data source: mod git commit traces (type = 'commit'); they carry the run-stage columns.
--
-- Compatible with: AWS Athena, Trino, PostgreSQL, and other engines supporting DATE_TRUNC.
-- Replace 'month' with 'week', 'quarter', or 'year' to change granularity.
Expand All @@ -25,8 +25,9 @@ FROM (
MAX(runRecipeId) AS runRecipeId,
MAX(runFilesWithFixResults) AS runFilesWithFixResults,
MAX(runEstimatedEffortTimeSavingsMs) AS runEstimatedEffortTimeSavingsMs
FROM trace
WHERE commitOutcome = 'Succeeded'
FROM traces
WHERE type = 'commit'
AND commitOutcome = 'Succeeded'
AND (runRecipeId LIKE 'org.openrewrite.java.security.%'
OR runRecipeId LIKE 'org.openrewrite.staticanalysis.%')
GROUP BY commitId
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
-- Top Recipes with Commits
--
-- Recipes ranked by committed code changes — shows which recipes deliver real results.
-- Data source: mod git commit trace, or any later-stage trace.
-- Data source: mod git commit traces (type = 'commit').
--
-- Compatible with: AWS Athena, Trino, PostgreSQL, and other standard SQL engines.

Expand All @@ -11,7 +11,8 @@ SELECT
COUNT(DISTINCT commitId) AS commits,
COUNT(DISTINCT developer) AS unique_users,
ROUND(SUM(runEstimatedEffortTimeSavingsMs) / 3600000.0, 1) AS estimated_hours_saved
FROM trace
WHERE commitOutcome = 'Succeeded'
FROM traces
WHERE type = 'commit'
AND commitOutcome = 'Succeeded'
GROUP BY runRecipeId
ORDER BY commits DESC;
2 changes: 1 addition & 1 deletion templates/top-recipes/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Most-used recipes ranked by run count and unique users — shows which recipes a

## Data Source

This report uses trace data produced by **`mod run`**. Any later-stage command (`mod git apply`, `mod git commit`, `mod git push`) also includes run-stage data and will work with this query.
This report uses trace data produced by **`mod run`**. Later-stage commands (`mod git apply`, `mod git add`, `mod git commit`) re-emit the same run-stage columns, so the query pins `type = 'run'` to count each run once.

See the [trace.csv data dictionary](../../data-dictionary/trace-csv.md) for the full column reference.

Expand Down
7 changes: 4 additions & 3 deletions templates/top-recipes/top-recipes.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
-- Top Recipes
--
-- Most-used recipes ranked by run count, unique users, and repos searched.
-- Data source: mod run trace, or any later-stage trace.
-- Data source: mod run traces (type = 'run').
--
-- Compatible with: AWS Athena, Trino, PostgreSQL, and other standard SQL engines.

Expand All @@ -11,7 +11,8 @@ SELECT
COUNT(DISTINCT runId) AS recipe_runs,
COUNT(DISTINCT developer) AS unique_users,
COUNT(DISTINCT path) AS repos_searched
FROM trace
WHERE runOutcome IS NOT NULL
FROM traces
WHERE type = 'run'
AND runOutcome IS NOT NULL
GROUP BY runRecipeId
ORDER BY recipe_runs DESC;
2 changes: 1 addition & 1 deletion templates/top-users/top-users.sql
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ SELECT
developer,
COUNT(DISTINCT runId) AS recipe_runs,
COUNT(DISTINCT CASE WHEN commitOutcome = 'Succeeded' THEN commitId END) AS commits
FROM trace
FROM traces
WHERE runOutcome IS NOT NULL
GROUP BY developer
ORDER BY recipe_runs DESC;