From 787613302d60c8f4caba86090212e10ce8aac394 Mon Sep 17 00:00:00 2001 From: bujjibabukatta Date: Sun, 14 Jun 2026 17:23:58 +0530 Subject: [PATCH] fix(dashboards): fix string team/user ID filtering in MySQL dashboards --- grafana/dashboards/mysql/dora-by-team.json | 18 +++++----- ...g-throughput-and-cycle-time-team-view.json | 36 +++++++++---------- grafana/dashboards/mysql/work-logs.json | 28 +++++++-------- 3 files changed, 41 insertions(+), 41 deletions(-) diff --git a/grafana/dashboards/mysql/dora-by-team.json b/grafana/dashboards/mysql/dora-by-team.json index 863aaac35a1..3b694a6878c 100644 --- a/grafana/dashboards/mysql/dora-by-team.json +++ b/grafana/dashboards/mysql/dora-by-team.json @@ -206,7 +206,7 @@ "format": "table", "hide": false, "rawQuery": true, - "rawSql": "-- Metric 1: Deployment Frequency\nwith last_few_calendar_months as(\n -- construct the last few calendar months within the selected time period in the top-right corner\n SELECT\n CAST(($__timeTo() - INTERVAL (H + T + U) DAY) AS date) day\n FROM\n (\n SELECT\n 0 H\n UNION\n ALL\n SELECT\n 100\n UNION\n ALL\n SELECT\n 200\n UNION\n ALL\n SELECT\n 300\n ) H\n CROSS JOIN (\n SELECT\n 0 T\n UNION\n ALL\n SELECT\n 10\n UNION\n ALL\n SELECT\n 20\n UNION\n ALL\n SELECT\n 30\n UNION\n ALL\n SELECT\n 40\n UNION\n ALL\n SELECT\n 50\n UNION\n ALL\n SELECT\n 60\n UNION\n ALL\n SELECT\n 70\n UNION\n ALL\n SELECT\n 80\n UNION\n ALL\n SELECT\n 90\n ) T\n CROSS JOIN (\n SELECT\n 0 U\n UNION\n ALL\n SELECT\n 1\n UNION\n ALL\n SELECT\n 2\n UNION\n ALL\n SELECT\n 3\n UNION\n ALL\n SELECT\n 4\n UNION\n ALL\n SELECT\n 5\n UNION\n ALL\n SELECT\n 6\n UNION\n ALL\n SELECT\n 7\n UNION\n ALL\n SELECT\n 8\n UNION\n ALL\n SELECT\n 9\n ) U\n WHERE\n ($__timeTo() - INTERVAL (H + T + U) DAY) > $__timeFrom()\n),\n_production_deployment_days as(\n -- When deploying multiple commits in one pipeline, GitLab and BitBucket may generate more than one deployment. However, DevLake consider these deployments as ONE production deployment and use the last one's finished_date as the finished date.\n SELECT\n cdc.cicd_deployment_id as deployment_id,\n max(DATE(cdc.finished_date)) as day\n FROM\n cicd_deployment_commits cdc\n JOIN commits c on cdc.commit_sha = c.sha\n join user_accounts ua on c.author_id = ua.account_id\n join users u on ua.user_id = u.id\n join team_users tu on u.id = tu.user_id\n join teams t on tu.team_id = t.id\n JOIN project_mapping pm on cdc.cicd_scope_id = pm.row_id\n and pm.`table` = 'cicd_scopes'\n WHERE\n t.name in (${team})\n and cdc.result = 'SUCCESS'\n and cdc.environment = 'PRODUCTION'\n GROUP BY\n 1\n),\n_days_weekly_deploy as(\n -- calculate the number of deployment days every week\n SELECT\n date(\n DATE_ADD(\n last_few_calendar_months.day,\n INTERVAL - WEEKDAY(last_few_calendar_months.day) DAY\n )\n ) as week,\n MAX(\n if(\n _production_deployment_days.day is not null,\n 1,\n 0\n )\n ) as weeks_deployed,\n COUNT(distinct _production_deployment_days.day) as days_deployed\n FROM\n last_few_calendar_months\n LEFT JOIN _production_deployment_days ON _production_deployment_days.day = last_few_calendar_months.day\n GROUP BY\n week\n),\n_days_monthly_deploy as(\n -- calculate the number of deployment days every month\n SELECT\n date(\n DATE_ADD(\n last_few_calendar_months.day,\n INTERVAL - DAY(last_few_calendar_months.day) + 1 DAY\n )\n ) as month,\n MAX(\n if(\n _production_deployment_days.day is not null,\n 1,\n null\n )\n ) as months_deployed,\n COUNT(distinct _production_deployment_days.day) as days_deployed\n FROM\n last_few_calendar_months\n LEFT JOIN _production_deployment_days ON _production_deployment_days.day = last_few_calendar_months.day\n GROUP BY\n month\n),\n_days_six_months_deploy AS (\n SELECT\n month,\n SUM(days_deployed) OVER (\n ORDER BY\n month ROWS BETWEEN 5 PRECEDING\n AND CURRENT ROW\n ) AS days_deployed_per_six_months,\n COUNT(months_deployed) OVER (\n ORDER BY\n month ROWS BETWEEN 5 PRECEDING\n AND CURRENT ROW\n ) AS months_deployed_count,\n ROW_NUMBER() OVER (\n PARTITION BY DATE_FORMAT(month, '%Y-%m') DIV 6\n ORDER BY\n month DESC\n ) AS rn\n FROM\n _days_monthly_deploy\n),\n_median_number_of_deployment_days_per_week_ranks as(\n SELECT\n *,\n percent_rank() over(\n order by\n days_deployed\n ) as ranks\n FROM\n _days_weekly_deploy\n),\n_median_number_of_deployment_days_per_week as(\n SELECT\n max(days_deployed) as median_number_of_deployment_days_per_week\n FROM\n _median_number_of_deployment_days_per_week_ranks\n WHERE\n ranks <= 0.5\n),\n_median_number_of_deployment_days_per_month_ranks as(\n SELECT\n *,\n percent_rank() over(\n order by\n days_deployed\n ) as ranks\n FROM\n _days_monthly_deploy\n),\n_median_number_of_deployment_days_per_month as(\n SELECT\n max(days_deployed) as median_number_of_deployment_days_per_month\n FROM\n _median_number_of_deployment_days_per_month_ranks\n WHERE\n ranks <= 0.5\n),\n_days_per_six_months_deploy_by_filter AS (\n SELECT\n month,\n days_deployed_per_six_months,\n months_deployed_count\n FROM\n _days_six_months_deploy\n WHERE\n rn % 6 = 1\n),\n_median_number_of_deployment_days_per_six_months_ranks as(\n SELECT\n *,\n percent_rank() over(\n order by\n days_deployed_per_six_months\n ) as ranks\n FROM\n _days_per_six_months_deploy_by_filter\n),\n_median_number_of_deployment_days_per_six_months as(\n SELECT\n min(days_deployed_per_six_months) as median_number_of_deployment_days_per_six_months,\n min(months_deployed_count) as is_collected\n FROM\n _median_number_of_deployment_days_per_six_months_ranks\n WHERE\n ranks >= 0.5\n),\n_metric_deployment_frequency as (\n SELECT\n 'Deployment frequency' as metric,\n CASE\n WHEN ('$dora_report') = '2023' THEN CASE\n WHEN median_number_of_deployment_days_per_week >= 5 THEN 'On-demand(elite)'\n WHEN median_number_of_deployment_days_per_week >= 1 THEN 'Between once per day and once per week(high)'\n WHEN median_number_of_deployment_days_per_month >= 1 THEN 'Between once per week and once per month(medium)'\n WHEN median_number_of_deployment_days_per_month < 1\n and is_collected is not null THEN 'Fewer than once per month(low)'\n ELSE \"N/A. Please check if you have collected deployments.\"\n END\n WHEN ('$dora_report') = '2021' THEN CASE\n WHEN median_number_of_deployment_days_per_week >= 5 THEN 'On-demand(elite)'\n WHEN median_number_of_deployment_days_per_month >= 1 THEN 'Between once per day and once per month(high)'\n WHEN median_number_of_deployment_days_per_six_months >= 1 THEN 'Between once per month and once every 6 months(medium)'\n WHEN median_number_of_deployment_days_per_six_months < 1\n and is_collected is not null THEN 'Fewer than once per six months(low)'\n ELSE \"N/A. Please check if you have collected deployments.\"\n END\n ELSE 'Invalid dora report'\n END AS value\n FROM\n _median_number_of_deployment_days_per_week,\n _median_number_of_deployment_days_per_month,\n _median_number_of_deployment_days_per_six_months\n),\n-- Metric 2: median lead time for changes\n_pr_stats as (\n -- get the cycle time of PRs deployed by the deployments finished in the selected period\n SELECT\n distinct pr.id,\n ppm.pr_cycle_time\n FROM\n pull_requests pr\n join user_accounts ua on pr.author_id = ua.account_id\n join users u on ua.user_id = u.id\n join team_users tu on u.id = tu.user_id\n join teams t on tu.team_id = t.id\n join project_pr_metrics ppm on ppm.id = pr.id\n join project_mapping pm on pr.base_repo_id = pm.row_id\n and pm.`table` = 'repos'\n join cicd_deployment_commits cdc on ppm.deployment_commit_id = cdc.id\n WHERE\n t.name in (${team})\n and pr.merged_date is not null\n and ppm.pr_cycle_time is not null\n and $__timeFilter(cdc.finished_date)\n),\n_median_change_lead_time_ranks as(\n SELECT\n *,\n percent_rank() over(\n order by\n pr_cycle_time\n ) as ranks\n FROM\n _pr_stats\n),\n_median_change_lead_time as(\n -- use median PR cycle time as the median change lead time\n SELECT\n max(pr_cycle_time) as median_change_lead_time\n FROM\n _median_change_lead_time_ranks\n WHERE\n ranks <= 0.5\n),\n_metric_change_lead_time as (\n SELECT\n 'Lead time for changes' as metric,\n CASE\n WHEN ('$dora_report') = '2023' THEN CASE\n WHEN median_change_lead_time < 24 * 60 THEN \"Less than one day(elite)\"\n WHEN median_change_lead_time < 7 * 24 * 60 THEN \"Between one day and one week(high)\"\n WHEN median_change_lead_time < 30 * 24 * 60 THEN \"Between one week and one month(medium)\"\n WHEN median_change_lead_time >= 30 * 24 * 60 THEN \"More than one month(low)\"\n ELSE \"N/A. Please check if you have collected deployments/pull_requests.\"\n END\n WHEN ('$dora_report') = '2021' THEN CASE\n WHEN median_change_lead_time < 60 THEN \"Less than one hour(elite)\"\n WHEN median_change_lead_time < 7 * 24 * 60 THEN \"Less than one week(high)\"\n WHEN median_change_lead_time < 180 * 24 * 60 THEN \"Between one week and six months(medium)\"\n WHEN median_change_lead_time >= 180 * 24 * 60 THEN \"More than six months(low)\"\n ELSE \"N/A. Please check if you have collected deployments/pull_requests.\"\n END\n ELSE 'Invalid dora report'\n END AS value\n FROM\n _median_change_lead_time\n),\n-- Metric 3: change failure rate\n_deployments as (\n -- When deploying multiple commits in one pipeline, GitLab and BitBucket may generate more than one deployment. However, DevLake consider these deployments as ONE production deployment and use the last one's finished_date as the finished date.\n SELECT\n cdc.cicd_deployment_id as deployment_id,\n max(cdc.finished_date) as deployment_finished_date\n FROM\n cicd_deployment_commits cdc\n JOIN commits c on cdc.commit_sha = c.sha\n join user_accounts ua on c.author_id = ua.account_id\n join users u on ua.user_id = u.id\n join team_users tu on u.id = tu.user_id\n join teams t on tu.team_id = t.id\n JOIN project_mapping pm on cdc.cicd_scope_id = pm.row_id\n and pm.`table` = 'cicd_scopes'\n WHERE\n t.name in (${team})\n and cdc.result = 'SUCCESS'\n and cdc.environment = 'PRODUCTION'\n GROUP BY\n 1\n HAVING\n $__timeFilter(max(cdc.finished_date))\n),\n_failure_caused_by_deployments as (\n -- calculate the number of incidents caused by each deployment\n SELECT\n d.deployment_id,\n d.deployment_finished_date,\n count(\n distinct case\n when i.id is not null then d.deployment_id\n else null\n end\n ) as has_incident\n FROM\n _deployments d\n left join project_incident_deployment_relationships pim on d.deployment_id = pim.deployment_id\n left join incidents i on pim.id = i.id\n GROUP BY\n 1,\n 2\n),\n_change_failure_rate as (\n SELECT\n case\n when count(deployment_id) is null then null\n else sum(has_incident) / count(deployment_id)\n end as change_failure_rate\n FROM\n _failure_caused_by_deployments\n),\n_is_collected_data as(\n SELECT\n CASE\n WHEN COUNT(i.id) = 0\n AND COUNT(cdc.id) = 0 THEN 'No All'\n WHEN COUNT(i.id) = 0 THEN 'No Incidents'\n WHEN COUNT(cdc.id) = 0 THEN 'No Deployments'\n END AS is_collected\n FROM\n (\n SELECT\n 1\n ) AS dummy\n LEFT JOIN incidents i ON 1 = 1\n LEFT JOIN cicd_deployment_commits cdc ON 1 = 1\n),\n_metric_cfr as (\n SELECT\n 'Change failure rate' as metric,\n CASE\n WHEN ('$dora_report') = '2023' THEN CASE\n WHEN is_collected = \"No All\" THEN \"N/A. Please check if you have collected deployments/incidents.\"\n WHEN is_collected = \"No Incidents\" THEN \"N/A. Please check if you have collected incidents.\"\n WHEN is_collected = \"No Deployments\" THEN \"N/A. Please check if you have collected deployments.\"\n WHEN change_failure_rate <=.05 THEN \"0-5%(elite)\"\n WHEN change_failure_rate <=.10 THEN \"5%-10%(high)\"\n WHEN change_failure_rate <=.15 THEN \"10%-15%(medium)\"\n WHEN change_failure_rate >.15 THEN \"> 15%(low)\"\n ELSE \"N/A. Please check if you have collected deployments/incidents.\"\n END\n WHEN ('$dora_report') = '2021' THEN CASE\n WHEN is_collected = \"No All\" THEN \"N/A. Please check if you have collected deployments/incidents.\"\n WHEN is_collected = \"No Incidents\" THEN \"N/A. Please check if you have collected incidents.\"\n WHEN is_collected = \"No Deployments\" THEN \"N/A. Please check if you have collected deployments.\"\n WHEN change_failure_rate <=.15 THEN \"0-15%(elite)\"\n WHEN change_failure_rate <=.20 THEN \"16%-20%(high)\"\n WHEN change_failure_rate <=.30 THEN \"21%-30%(medium)\"\n WHEN change_failure_rate >.30 THEN \"> 30%(low)\"\n ELSE \"N/A. Please check if you have collected deployments/incidents.\"\n END\n ELSE 'Invalid dora report'\n END AS value\n FROM\n _change_failure_rate,\n _is_collected_data\n),\n-- ***** 2023 report ***** --\n-- Metric 4: Failed deployment recovery time\n_incidents_for_deployments as (\n SELECT\n i.id as incident_id,\n i.created_date as incident_create_date,\n i.resolution_date as incident_resolution_date,\n fd.deployment_id as caused_by_deployment,\n fd.deployment_finished_date,\n date_format(fd.deployment_finished_date, '%y/%m') as deployment_finished_month\n FROM\n incidents i\n left join project_incident_deployment_relationships pim on i.id = pim.id\n join _deployments fd on pim.deployment_id = fd.deployment_id\n WHERE\n $__timeFilter(i.resolution_date)\n),\n_recovery_time_ranks as (\n SELECT\n *,\n percent_rank() over(\n order by\n TIMESTAMPDIFF(\n MINUTE,\n deployment_finished_date,\n incident_resolution_date\n )\n ) as ranks\n FROM\n _incidents_for_deployments\n),\n_median_recovery_time as (\n SELECT\n max(\n TIMESTAMPDIFF(\n MINUTE,\n deployment_finished_date,\n incident_resolution_date\n )\n ) as median_recovery_time\n FROM\n _recovery_time_ranks\n WHERE\n ranks <= 0.5\n),\n_metric_recovery_time_2023_report as(\n SELECT\n \"Failed deployment recovery time\" as metric,\n CASE\n WHEN ('$dora_report') = '2023' THEN CASE\n WHEN median_recovery_time < 60 THEN \"Less than one hour(elite)\"\n WHEN median_recovery_time < 24 * 60 THEN \"Less than one day(high)\"\n WHEN median_recovery_time < 7 * 24 * 60 THEN \"Between one day and one week(medium)\"\n WHEN median_recovery_time >= 7 * 24 * 60 THEN \"More than one week(low)\"\n ELSE \"N/A. Please check if you have collected deployments or incidents.\"\n END\n END AS median_recovery_time\n FROM\n _median_recovery_time\n),\n-- ***** 2021 report ***** --\n-- Metric 4: Median time to restore service \n_incidents as (\n -- get the incidents created within the selected time period in the top-right corner\n SELECT\n distinct i.id,\n cast(lead_time_minutes as signed) as lead_time_minutes\n FROM\n incidents i\n join project_mapping pm on i.scope_id = pm.row_id\n and pm.`table` = i.`table`\n join user_accounts ua on i.assignee_id = ua.account_id\n join users u on ua.user_id = u.id\n join team_users tu on u.id = tu.user_id\n join teams t on tu.team_id = t.id\n WHERE\n t.name in (${team})\n and $__timeFilter(i.resolution_date)\n),\n_median_mttr_ranks as(\n SELECT\n *,\n percent_rank() over(\n order by\n lead_time_minutes\n ) as ranks\n FROM\n _incidents\n),\n_median_mttr as(\n SELECT\n max(lead_time_minutes) as median_time_to_resolve\n FROM\n _median_mttr_ranks\n WHERE\n ranks <= 0.5\n),\n_metric_mttr_2021_report as(\n SELECT\n \"Time to restore service\" as metric,\n CASE\n WHEN ('$dora_report') = '2021' THEN CASE\n WHEN median_time_to_resolve < 60 THEN \"Less than one hour(elite)\"\n WHEN median_time_to_resolve < 24 * 60 THEN \"Less than one day(high)\"\n WHEN median_time_to_resolve < 7 * 24 * 60 THEN \"Between one day and one week(medium)\"\n WHEN median_time_to_resolve >= 7 * 24 * 60 THEN \"More than one week(low)\"\n ELSE \"N/A. Please check if you have collected incidents.\"\n END\n END AS median_time_to_resolve\n FROM\n _median_mttr\n),\n_metric_mrt_or_mm as(\n SELECT\n metric,\n median_recovery_time AS value\n FROM\n _metric_recovery_time_2023_report\n WHERE\n ('$dora_report') = '2023'\n UNION\n SELECT\n metric,\n median_time_to_resolve AS value\n FROM\n _metric_mttr_2021_report\n WHERE\n ('$dora_report') = '2021'\n),\n_final_results as (\n SELECT\n distinct db.id,\n db.metric,\n db.low,\n db.medium,\n db.high,\n db.elite,\n m1.metric as _metric,\n m1.value\n FROM\n dora_benchmarks db\n left join _metric_deployment_frequency m1 on db.metric = m1.metric\n WHERE\n m1.metric is not null\n and db.dora_report = ('$dora_report')\n union\n SELECT\n distinct db.id,\n db.metric,\n db.low,\n db.medium,\n db.high,\n db.elite,\n m2.metric as _metric,\n m2.value\n FROM\n dora_benchmarks db\n left join _metric_change_lead_time m2 on db.metric = m2.metric\n WHERE\n m2.metric is not null\n and db.dora_report = ('$dora_report')\n union\n SELECT\n distinct db.id,\n db.metric,\n db.low,\n db.medium,\n db.high,\n db.elite,\n m3.metric as _metric,\n m3.value\n FROM\n dora_benchmarks db\n left join _metric_cfr m3 on db.metric = m3.metric\n WHERE\n m3.metric is not null\n and db.dora_report = ('$dora_report')\n union\n SELECT\n distinct db.id,\n db.metric,\n db.low,\n db.medium,\n db.high,\n db.elite,\n m4.metric as _metric,\n m4.value\n FROM\n dora_benchmarks db\n left join _metric_mrt_or_mm m4 on db.metric = m4.metric\n WHERE\n m4.metric is not null\n and db.dora_report = ('$dora_report')\n)\nSELECT\n metric,\n case\n when low = value then low\n else null\n end as low,\n case\n when medium = value then medium\n else null\n end as medium,\n case\n when high = value then high\n else null\n end as high,\n case\n when elite = value then elite\n else null\n end as elite\nFROM\n _final_results\nORDER BY\n id", + "rawSql": "-- Metric 1: Deployment Frequency\nwith last_few_calendar_months as(\n -- construct the last few calendar months within the selected time period in the top-right corner\n SELECT\n CAST(($__timeTo() - INTERVAL (H + T + U) DAY) AS date) day\n FROM\n (\n SELECT\n 0 H\n UNION\n ALL\n SELECT\n 100\n UNION\n ALL\n SELECT\n 200\n UNION\n ALL\n SELECT\n 300\n ) H\n CROSS JOIN (\n SELECT\n 0 T\n UNION\n ALL\n SELECT\n 10\n UNION\n ALL\n SELECT\n 20\n UNION\n ALL\n SELECT\n 30\n UNION\n ALL\n SELECT\n 40\n UNION\n ALL\n SELECT\n 50\n UNION\n ALL\n SELECT\n 60\n UNION\n ALL\n SELECT\n 70\n UNION\n ALL\n SELECT\n 80\n UNION\n ALL\n SELECT\n 90\n ) T\n CROSS JOIN (\n SELECT\n 0 U\n UNION\n ALL\n SELECT\n 1\n UNION\n ALL\n SELECT\n 2\n UNION\n ALL\n SELECT\n 3\n UNION\n ALL\n SELECT\n 4\n UNION\n ALL\n SELECT\n 5\n UNION\n ALL\n SELECT\n 6\n UNION\n ALL\n SELECT\n 7\n UNION\n ALL\n SELECT\n 8\n UNION\n ALL\n SELECT\n 9\n ) U\n WHERE\n ($__timeTo() - INTERVAL (H + T + U) DAY) > $__timeFrom()\n),\n_production_deployment_days as(\n -- When deploying multiple commits in one pipeline, GitLab and BitBucket may generate more than one deployment. However, DevLake consider these deployments as ONE production deployment and use the last one's finished_date as the finished date.\n SELECT\n cdc.cicd_deployment_id as deployment_id,\n max(DATE(cdc.finished_date)) as day\n FROM\n cicd_deployment_commits cdc\n JOIN commits c on cdc.commit_sha = c.sha\n join user_accounts ua on c.author_id = ua.account_id\n join users u on ua.user_id = u.id\n join team_users tu on u.id = tu.user_id\n join teams t on tu.team_id = t.id\n JOIN project_mapping pm on cdc.cicd_scope_id = pm.row_id\n and pm.`table` = 'cicd_scopes'\n WHERE\n t.name in (${team:singlequote})\n and cdc.result = 'SUCCESS'\n and cdc.environment = 'PRODUCTION'\n GROUP BY\n 1\n),\n_days_weekly_deploy as(\n -- calculate the number of deployment days every week\n SELECT\n date(\n DATE_ADD(\n last_few_calendar_months.day,\n INTERVAL - WEEKDAY(last_few_calendar_months.day) DAY\n )\n ) as week,\n MAX(\n if(\n _production_deployment_days.day is not null,\n 1,\n 0\n )\n ) as weeks_deployed,\n COUNT(distinct _production_deployment_days.day) as days_deployed\n FROM\n last_few_calendar_months\n LEFT JOIN _production_deployment_days ON _production_deployment_days.day = last_few_calendar_months.day\n GROUP BY\n week\n),\n_days_monthly_deploy as(\n -- calculate the number of deployment days every month\n SELECT\n date(\n DATE_ADD(\n last_few_calendar_months.day,\n INTERVAL - DAY(last_few_calendar_months.day) + 1 DAY\n )\n ) as month,\n MAX(\n if(\n _production_deployment_days.day is not null,\n 1,\n null\n )\n ) as months_deployed,\n COUNT(distinct _production_deployment_days.day) as days_deployed\n FROM\n last_few_calendar_months\n LEFT JOIN _production_deployment_days ON _production_deployment_days.day = last_few_calendar_months.day\n GROUP BY\n month\n),\n_days_six_months_deploy AS (\n SELECT\n month,\n SUM(days_deployed) OVER (\n ORDER BY\n month ROWS BETWEEN 5 PRECEDING\n AND CURRENT ROW\n ) AS days_deployed_per_six_months,\n COUNT(months_deployed) OVER (\n ORDER BY\n month ROWS BETWEEN 5 PRECEDING\n AND CURRENT ROW\n ) AS months_deployed_count,\n ROW_NUMBER() OVER (\n PARTITION BY DATE_FORMAT(month, '%Y-%m') DIV 6\n ORDER BY\n month DESC\n ) AS rn\n FROM\n _days_monthly_deploy\n),\n_median_number_of_deployment_days_per_week_ranks as(\n SELECT\n *,\n percent_rank() over(\n order by\n days_deployed\n ) as ranks\n FROM\n _days_weekly_deploy\n),\n_median_number_of_deployment_days_per_week as(\n SELECT\n max(days_deployed) as median_number_of_deployment_days_per_week\n FROM\n _median_number_of_deployment_days_per_week_ranks\n WHERE\n ranks <= 0.5\n),\n_median_number_of_deployment_days_per_month_ranks as(\n SELECT\n *,\n percent_rank() over(\n order by\n days_deployed\n ) as ranks\n FROM\n _days_monthly_deploy\n),\n_median_number_of_deployment_days_per_month as(\n SELECT\n max(days_deployed) as median_number_of_deployment_days_per_month\n FROM\n _median_number_of_deployment_days_per_month_ranks\n WHERE\n ranks <= 0.5\n),\n_days_per_six_months_deploy_by_filter AS (\n SELECT\n month,\n days_deployed_per_six_months,\n months_deployed_count\n FROM\n _days_six_months_deploy\n WHERE\n rn % 6 = 1\n),\n_median_number_of_deployment_days_per_six_months_ranks as(\n SELECT\n *,\n percent_rank() over(\n order by\n days_deployed_per_six_months\n ) as ranks\n FROM\n _days_per_six_months_deploy_by_filter\n),\n_median_number_of_deployment_days_per_six_months as(\n SELECT\n min(days_deployed_per_six_months) as median_number_of_deployment_days_per_six_months,\n min(months_deployed_count) as is_collected\n FROM\n _median_number_of_deployment_days_per_six_months_ranks\n WHERE\n ranks >= 0.5\n),\n_metric_deployment_frequency as (\n SELECT\n 'Deployment frequency' as metric,\n CASE\n WHEN ('$dora_report') = '2023' THEN CASE\n WHEN median_number_of_deployment_days_per_week >= 5 THEN 'On-demand(elite)'\n WHEN median_number_of_deployment_days_per_week >= 1 THEN 'Between once per day and once per week(high)'\n WHEN median_number_of_deployment_days_per_month >= 1 THEN 'Between once per week and once per month(medium)'\n WHEN median_number_of_deployment_days_per_month < 1\n and is_collected is not null THEN 'Fewer than once per month(low)'\n ELSE \"N/A. Please check if you have collected deployments.\"\n END\n WHEN ('$dora_report') = '2021' THEN CASE\n WHEN median_number_of_deployment_days_per_week >= 5 THEN 'On-demand(elite)'\n WHEN median_number_of_deployment_days_per_month >= 1 THEN 'Between once per day and once per month(high)'\n WHEN median_number_of_deployment_days_per_six_months >= 1 THEN 'Between once per month and once every 6 months(medium)'\n WHEN median_number_of_deployment_days_per_six_months < 1\n and is_collected is not null THEN 'Fewer than once per six months(low)'\n ELSE \"N/A. Please check if you have collected deployments.\"\n END\n ELSE 'Invalid dora report'\n END AS value\n FROM\n _median_number_of_deployment_days_per_week,\n _median_number_of_deployment_days_per_month,\n _median_number_of_deployment_days_per_six_months\n),\n-- Metric 2: median lead time for changes\n_pr_stats as (\n -- get the cycle time of PRs deployed by the deployments finished in the selected period\n SELECT\n distinct pr.id,\n ppm.pr_cycle_time\n FROM\n pull_requests pr\n join user_accounts ua on pr.author_id = ua.account_id\n join users u on ua.user_id = u.id\n join team_users tu on u.id = tu.user_id\n join teams t on tu.team_id = t.id\n join project_pr_metrics ppm on ppm.id = pr.id\n join project_mapping pm on pr.base_repo_id = pm.row_id\n and pm.`table` = 'repos'\n join cicd_deployment_commits cdc on ppm.deployment_commit_id = cdc.id\n WHERE\n t.name in (${team:singlequote})\n and pr.merged_date is not null\n and ppm.pr_cycle_time is not null\n and $__timeFilter(cdc.finished_date)\n),\n_median_change_lead_time_ranks as(\n SELECT\n *,\n percent_rank() over(\n order by\n pr_cycle_time\n ) as ranks\n FROM\n _pr_stats\n),\n_median_change_lead_time as(\n -- use median PR cycle time as the median change lead time\n SELECT\n max(pr_cycle_time) as median_change_lead_time\n FROM\n _median_change_lead_time_ranks\n WHERE\n ranks <= 0.5\n),\n_metric_change_lead_time as (\n SELECT\n 'Lead time for changes' as metric,\n CASE\n WHEN ('$dora_report') = '2023' THEN CASE\n WHEN median_change_lead_time < 24 * 60 THEN \"Less than one day(elite)\"\n WHEN median_change_lead_time < 7 * 24 * 60 THEN \"Between one day and one week(high)\"\n WHEN median_change_lead_time < 30 * 24 * 60 THEN \"Between one week and one month(medium)\"\n WHEN median_change_lead_time >= 30 * 24 * 60 THEN \"More than one month(low)\"\n ELSE \"N/A. Please check if you have collected deployments/pull_requests.\"\n END\n WHEN ('$dora_report') = '2021' THEN CASE\n WHEN median_change_lead_time < 60 THEN \"Less than one hour(elite)\"\n WHEN median_change_lead_time < 7 * 24 * 60 THEN \"Less than one week(high)\"\n WHEN median_change_lead_time < 180 * 24 * 60 THEN \"Between one week and six months(medium)\"\n WHEN median_change_lead_time >= 180 * 24 * 60 THEN \"More than six months(low)\"\n ELSE \"N/A. Please check if you have collected deployments/pull_requests.\"\n END\n ELSE 'Invalid dora report'\n END AS value\n FROM\n _median_change_lead_time\n),\n-- Metric 3: change failure rate\n_deployments as (\n -- When deploying multiple commits in one pipeline, GitLab and BitBucket may generate more than one deployment. However, DevLake consider these deployments as ONE production deployment and use the last one's finished_date as the finished date.\n SELECT\n cdc.cicd_deployment_id as deployment_id,\n max(cdc.finished_date) as deployment_finished_date\n FROM\n cicd_deployment_commits cdc\n JOIN commits c on cdc.commit_sha = c.sha\n join user_accounts ua on c.author_id = ua.account_id\n join users u on ua.user_id = u.id\n join team_users tu on u.id = tu.user_id\n join teams t on tu.team_id = t.id\n JOIN project_mapping pm on cdc.cicd_scope_id = pm.row_id\n and pm.`table` = 'cicd_scopes'\n WHERE\n t.name in (${team:singlequote})\n and cdc.result = 'SUCCESS'\n and cdc.environment = 'PRODUCTION'\n GROUP BY\n 1\n HAVING\n $__timeFilter(max(cdc.finished_date))\n),\n_failure_caused_by_deployments as (\n -- calculate the number of incidents caused by each deployment\n SELECT\n d.deployment_id,\n d.deployment_finished_date,\n count(\n distinct case\n when i.id is not null then d.deployment_id\n else null\n end\n ) as has_incident\n FROM\n _deployments d\n left join project_incident_deployment_relationships pim on d.deployment_id = pim.deployment_id\n left join incidents i on pim.id = i.id\n GROUP BY\n 1,\n 2\n),\n_change_failure_rate as (\n SELECT\n case\n when count(deployment_id) is null then null\n else sum(has_incident) / count(deployment_id)\n end as change_failure_rate\n FROM\n _failure_caused_by_deployments\n),\n_is_collected_data as(\n SELECT\n CASE\n WHEN COUNT(i.id) = 0\n AND COUNT(cdc.id) = 0 THEN 'No All'\n WHEN COUNT(i.id) = 0 THEN 'No Incidents'\n WHEN COUNT(cdc.id) = 0 THEN 'No Deployments'\n END AS is_collected\n FROM\n (\n SELECT\n 1\n ) AS dummy\n LEFT JOIN incidents i ON 1 = 1\n LEFT JOIN cicd_deployment_commits cdc ON 1 = 1\n),\n_metric_cfr as (\n SELECT\n 'Change failure rate' as metric,\n CASE\n WHEN ('$dora_report') = '2023' THEN CASE\n WHEN is_collected = \"No All\" THEN \"N/A. Please check if you have collected deployments/incidents.\"\n WHEN is_collected = \"No Incidents\" THEN \"N/A. Please check if you have collected incidents.\"\n WHEN is_collected = \"No Deployments\" THEN \"N/A. Please check if you have collected deployments.\"\n WHEN change_failure_rate <=.05 THEN \"0-5%(elite)\"\n WHEN change_failure_rate <=.10 THEN \"5%-10%(high)\"\n WHEN change_failure_rate <=.15 THEN \"10%-15%(medium)\"\n WHEN change_failure_rate >.15 THEN \"> 15%(low)\"\n ELSE \"N/A. Please check if you have collected deployments/incidents.\"\n END\n WHEN ('$dora_report') = '2021' THEN CASE\n WHEN is_collected = \"No All\" THEN \"N/A. Please check if you have collected deployments/incidents.\"\n WHEN is_collected = \"No Incidents\" THEN \"N/A. Please check if you have collected incidents.\"\n WHEN is_collected = \"No Deployments\" THEN \"N/A. Please check if you have collected deployments.\"\n WHEN change_failure_rate <=.15 THEN \"0-15%(elite)\"\n WHEN change_failure_rate <=.20 THEN \"16%-20%(high)\"\n WHEN change_failure_rate <=.30 THEN \"21%-30%(medium)\"\n WHEN change_failure_rate >.30 THEN \"> 30%(low)\"\n ELSE \"N/A. Please check if you have collected deployments/incidents.\"\n END\n ELSE 'Invalid dora report'\n END AS value\n FROM\n _change_failure_rate,\n _is_collected_data\n),\n-- ***** 2023 report ***** --\n-- Metric 4: Failed deployment recovery time\n_incidents_for_deployments as (\n SELECT\n i.id as incident_id,\n i.created_date as incident_create_date,\n i.resolution_date as incident_resolution_date,\n fd.deployment_id as caused_by_deployment,\n fd.deployment_finished_date,\n date_format(fd.deployment_finished_date, '%y/%m') as deployment_finished_month\n FROM\n incidents i\n left join project_incident_deployment_relationships pim on i.id = pim.id\n join _deployments fd on pim.deployment_id = fd.deployment_id\n WHERE\n $__timeFilter(i.resolution_date)\n),\n_recovery_time_ranks as (\n SELECT\n *,\n percent_rank() over(\n order by\n TIMESTAMPDIFF(\n MINUTE,\n deployment_finished_date,\n incident_resolution_date\n )\n ) as ranks\n FROM\n _incidents_for_deployments\n),\n_median_recovery_time as (\n SELECT\n max(\n TIMESTAMPDIFF(\n MINUTE,\n deployment_finished_date,\n incident_resolution_date\n )\n ) as median_recovery_time\n FROM\n _recovery_time_ranks\n WHERE\n ranks <= 0.5\n),\n_metric_recovery_time_2023_report as(\n SELECT\n \"Failed deployment recovery time\" as metric,\n CASE\n WHEN ('$dora_report') = '2023' THEN CASE\n WHEN median_recovery_time < 60 THEN \"Less than one hour(elite)\"\n WHEN median_recovery_time < 24 * 60 THEN \"Less than one day(high)\"\n WHEN median_recovery_time < 7 * 24 * 60 THEN \"Between one day and one week(medium)\"\n WHEN median_recovery_time >= 7 * 24 * 60 THEN \"More than one week(low)\"\n ELSE \"N/A. Please check if you have collected deployments or incidents.\"\n END\n END AS median_recovery_time\n FROM\n _median_recovery_time\n),\n-- ***** 2021 report ***** --\n-- Metric 4: Median time to restore service \n_incidents as (\n -- get the incidents created within the selected time period in the top-right corner\n SELECT\n distinct i.id,\n cast(lead_time_minutes as signed) as lead_time_minutes\n FROM\n incidents i\n join project_mapping pm on i.scope_id = pm.row_id\n and pm.`table` = i.`table`\n join user_accounts ua on i.assignee_id = ua.account_id\n join users u on ua.user_id = u.id\n join team_users tu on u.id = tu.user_id\n join teams t on tu.team_id = t.id\n WHERE\n t.name in (${team:singlequote})\n and $__timeFilter(i.resolution_date)\n),\n_median_mttr_ranks as(\n SELECT\n *,\n percent_rank() over(\n order by\n lead_time_minutes\n ) as ranks\n FROM\n _incidents\n),\n_median_mttr as(\n SELECT\n max(lead_time_minutes) as median_time_to_resolve\n FROM\n _median_mttr_ranks\n WHERE\n ranks <= 0.5\n),\n_metric_mttr_2021_report as(\n SELECT\n \"Time to restore service\" as metric,\n CASE\n WHEN ('$dora_report') = '2021' THEN CASE\n WHEN median_time_to_resolve < 60 THEN \"Less than one hour(elite)\"\n WHEN median_time_to_resolve < 24 * 60 THEN \"Less than one day(high)\"\n WHEN median_time_to_resolve < 7 * 24 * 60 THEN \"Between one day and one week(medium)\"\n WHEN median_time_to_resolve >= 7 * 24 * 60 THEN \"More than one week(low)\"\n ELSE \"N/A. Please check if you have collected incidents.\"\n END\n END AS median_time_to_resolve\n FROM\n _median_mttr\n),\n_metric_mrt_or_mm as(\n SELECT\n metric,\n median_recovery_time AS value\n FROM\n _metric_recovery_time_2023_report\n WHERE\n ('$dora_report') = '2023'\n UNION\n SELECT\n metric,\n median_time_to_resolve AS value\n FROM\n _metric_mttr_2021_report\n WHERE\n ('$dora_report') = '2021'\n),\n_final_results as (\n SELECT\n distinct db.id,\n db.metric,\n db.low,\n db.medium,\n db.high,\n db.elite,\n m1.metric as _metric,\n m1.value\n FROM\n dora_benchmarks db\n left join _metric_deployment_frequency m1 on db.metric = m1.metric\n WHERE\n m1.metric is not null\n and db.dora_report = ('$dora_report')\n union\n SELECT\n distinct db.id,\n db.metric,\n db.low,\n db.medium,\n db.high,\n db.elite,\n m2.metric as _metric,\n m2.value\n FROM\n dora_benchmarks db\n left join _metric_change_lead_time m2 on db.metric = m2.metric\n WHERE\n m2.metric is not null\n and db.dora_report = ('$dora_report')\n union\n SELECT\n distinct db.id,\n db.metric,\n db.low,\n db.medium,\n db.high,\n db.elite,\n m3.metric as _metric,\n m3.value\n FROM\n dora_benchmarks db\n left join _metric_cfr m3 on db.metric = m3.metric\n WHERE\n m3.metric is not null\n and db.dora_report = ('$dora_report')\n union\n SELECT\n distinct db.id,\n db.metric,\n db.low,\n db.medium,\n db.high,\n db.elite,\n m4.metric as _metric,\n m4.value\n FROM\n dora_benchmarks db\n left join _metric_mrt_or_mm m4 on db.metric = m4.metric\n WHERE\n m4.metric is not null\n and db.dora_report = ('$dora_report')\n)\nSELECT\n metric,\n case\n when low = value then low\n else null\n end as low,\n case\n when medium = value then medium\n else null\n end as medium,\n case\n when high = value then high\n else null\n end as high,\n case\n when elite = value then elite\n else null\n end as elite\nFROM\n _final_results\nORDER BY\n id", "refId": "A", "sql": { "columns": [ @@ -325,7 +325,7 @@ "metricColumn": "none", "queryType": "randomWalk", "rawQuery": true, - "rawSql": "-- Metric 1: Deployment Frequency\nwith last_few_calendar_months as(\n-- construct the last few calendar months within the selected time period in the top-right corner\n\tSELECT CAST(($__timeTo()-INTERVAL (H+T+U) DAY) AS date) day\n\tFROM ( SELECT 0 H\n\t\t\tUNION ALL SELECT 100 UNION ALL SELECT 200 UNION ALL SELECT 300\n\t\t) H CROSS JOIN ( SELECT 0 T\n\t\t\tUNION ALL SELECT 10 UNION ALL SELECT 20 UNION ALL SELECT 30\n\t\t\tUNION ALL SELECT 40 UNION ALL SELECT 50 UNION ALL SELECT 60\n\t\t\tUNION ALL SELECT 70 UNION ALL SELECT 80 UNION ALL SELECT 90\n\t\t) T CROSS JOIN ( SELECT 0 U\n\t\t\tUNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3\n\t\t\tUNION ALL SELECT 4 UNION ALL SELECT 5 UNION ALL SELECT 6\n\t\t\tUNION ALL SELECT 7 UNION ALL SELECT 8 UNION ALL SELECT 9\n\t\t) U\n\tWHERE\n\t\t($__timeTo()-INTERVAL (H+T+U) DAY) > $__timeFrom()\n),\n\n_production_deployment_days as(\n-- When deploying multiple commits in one pipeline, GitLab and BitBucket may generate more than one deployment. However, DevLake consider these deployments as ONE production deployment and use the last one's finished_date as the finished date.\n\tSELECT\n\t\tcdc.cicd_deployment_id as deployment_id,\n\t\tmax(DATE(cdc.finished_date)) as day\n\tFROM cicd_deployment_commits cdc\n\tJOIN commits c on cdc.commit_sha = c.sha\n\tjoin user_accounts ua on c.author_id = ua.account_id\n join users u on ua.user_id = u.id\n join team_users tu on u.id = tu.user_id\n join teams t on tu.team_id = t.id\n\tJOIN project_mapping pm on cdc.cicd_scope_id = pm.row_id and pm.`table` = 'cicd_scopes'\n\tWHERE\n\t\tt.name in (${team})\n\t\tand cdc.result = 'SUCCESS'\n\t\tand cdc.environment = 'PRODUCTION'\n\tGROUP BY 1\n),\n\n_days_weekly_deploy as(\n-- calculate the number of deployment days every week\n\tSELECT\n\t\t\tdate(DATE_ADD(last_few_calendar_months.day, INTERVAL -WEEKDAY(last_few_calendar_months.day) DAY)) as week,\n\t\t\tMAX(if(_production_deployment_days.day is not null, 1, 0)) as weeks_deployed,\n\t\t\tCOUNT(distinct _production_deployment_days.day) as days_deployed\n\tFROM \n\t\tlast_few_calendar_months\n\t\tLEFT JOIN _production_deployment_days ON _production_deployment_days.day = last_few_calendar_months.day\n\tGROUP BY week\n\t),\n\n_days_monthly_deploy as(\n-- calculate the number of deployment days every month\n\tSELECT\n\t\t\tdate(DATE_ADD(last_few_calendar_months.day, INTERVAL -DAY(last_few_calendar_months.day)+1 DAY)) as month,\n\t\t\tMAX(if(_production_deployment_days.day is not null, 1, null)) as months_deployed,\n\t\t COUNT(distinct _production_deployment_days.day) as days_deployed\n\tFROM \n\t\tlast_few_calendar_months\n\t\tLEFT JOIN _production_deployment_days ON _production_deployment_days.day = last_few_calendar_months.day\n\tGROUP BY month\n\t),\n\n_days_six_months_deploy AS (\n SELECT\n month,\n SUM(days_deployed) OVER (\n ORDER BY month\n ROWS BETWEEN 5 PRECEDING AND CURRENT ROW\n ) AS days_deployed_per_six_months,\n COUNT(months_deployed) OVER (\n ORDER BY month\n ROWS BETWEEN 5 PRECEDING AND CURRENT ROW\n ) AS months_deployed_count,\n ROW_NUMBER() OVER (\n PARTITION BY DATE_FORMAT(month, '%Y-%m') DIV 6\n ORDER BY month DESC\n ) AS rn\n FROM _days_monthly_deploy\n),\n\n_median_number_of_deployment_days_per_week_ranks as(\n\tSELECT *, percent_rank() over(order by days_deployed) as ranks\n\tFROM _days_weekly_deploy\n),\n\n_median_number_of_deployment_days_per_week as(\n\tSELECT max(days_deployed) as median_number_of_deployment_days_per_week\n\tFROM _median_number_of_deployment_days_per_week_ranks\n\tWHERE ranks <= 0.5\n),\n\n_median_number_of_deployment_days_per_month_ranks as(\n\tSELECT *, percent_rank() over(order by days_deployed) as ranks\n\tFROM _days_monthly_deploy\n),\n\n_median_number_of_deployment_days_per_month as(\n\tSELECT max(days_deployed) as median_number_of_deployment_days_per_month\n\tFROM _median_number_of_deployment_days_per_month_ranks\n\tWHERE ranks <= 0.5\n),\n\n_days_per_six_months_deploy_by_filter AS (\nSELECT\n month,\n days_deployed_per_six_months,\n months_deployed_count\nFROM _days_six_months_deploy\nWHERE rn%6 = 1\n),\n\n\n_median_number_of_deployment_days_per_six_months_ranks as(\n\tSELECT *, percent_rank() over(order by days_deployed_per_six_months) as ranks\n\tFROM _days_per_six_months_deploy_by_filter\n),\n\n_median_number_of_deployment_days_per_six_months as(\n\tSELECT min(days_deployed_per_six_months) as median_number_of_deployment_days_per_six_months, min(months_deployed_count) as is_collected\n\tFROM _median_number_of_deployment_days_per_six_months_ranks\n\tWHERE ranks >= 0.5\n)\n\nSELECT \n CASE\n WHEN ('$dora_report') = '2023' THEN\n\t\t\tCASE \n\t\t\t\tWHEN median_number_of_deployment_days_per_week >= 5 THEN CONCAT(median_number_of_deployment_days_per_week, ' deployment days per week(elite)')\n\t\t\t\tWHEN median_number_of_deployment_days_per_week >= 1 THEN CONCAT(median_number_of_deployment_days_per_week, ' deployment days per week(high)')\n\t\t\t\tWHEN median_number_of_deployment_days_per_month >= 1 THEN CONCAT(median_number_of_deployment_days_per_month, ' deployment days per month(medium)')\n\t\t\t\tWHEN median_number_of_deployment_days_per_month < 1 and is_collected is not null THEN CONCAT(median_number_of_deployment_days_per_month, ' deployment days per month(low)')\n\t\t\t\tELSE \"N/A. Please check if you have collected deployments.\" END\n\t \tWHEN ('$dora_report') = '2021' THEN\n\t\t\tCASE \n\t\t\t\tWHEN median_number_of_deployment_days_per_week >= 5 THEN CONCAT(median_number_of_deployment_days_per_week, ' deployment days per week(elite)')\n\t\t\t\tWHEN median_number_of_deployment_days_per_month >= 1 THEN CONCAT(median_number_of_deployment_days_per_month, ' deployment days per month(high)')\n\t\t\t\tWHEN median_number_of_deployment_days_per_six_months >= 1 THEN CONCAT(median_number_of_deployment_days_per_six_months, ' deployment days per six months(medium)')\n\t\t\t\tWHEN median_number_of_deployment_days_per_six_months < 1 and is_collected is not null THEN CONCAT(median_number_of_deployment_days_per_six_months, ' deployment days per six months(low)')\n\t\t\t\tELSE \"N/A. Please check if you have collected deployments.\" END\n\t\tELSE 'Invalid dora report'\n\tEND AS 'Deployment Frequency'\nFROM _median_number_of_deployment_days_per_week, _median_number_of_deployment_days_per_month, _median_number_of_deployment_days_per_six_months\n\n", + "rawSql": "-- Metric 1: Deployment Frequency\nwith last_few_calendar_months as(\n-- construct the last few calendar months within the selected time period in the top-right corner\n\tSELECT CAST(($__timeTo()-INTERVAL (H+T+U) DAY) AS date) day\n\tFROM ( SELECT 0 H\n\t\t\tUNION ALL SELECT 100 UNION ALL SELECT 200 UNION ALL SELECT 300\n\t\t) H CROSS JOIN ( SELECT 0 T\n\t\t\tUNION ALL SELECT 10 UNION ALL SELECT 20 UNION ALL SELECT 30\n\t\t\tUNION ALL SELECT 40 UNION ALL SELECT 50 UNION ALL SELECT 60\n\t\t\tUNION ALL SELECT 70 UNION ALL SELECT 80 UNION ALL SELECT 90\n\t\t) T CROSS JOIN ( SELECT 0 U\n\t\t\tUNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3\n\t\t\tUNION ALL SELECT 4 UNION ALL SELECT 5 UNION ALL SELECT 6\n\t\t\tUNION ALL SELECT 7 UNION ALL SELECT 8 UNION ALL SELECT 9\n\t\t) U\n\tWHERE\n\t\t($__timeTo()-INTERVAL (H+T+U) DAY) > $__timeFrom()\n),\n\n_production_deployment_days as(\n-- When deploying multiple commits in one pipeline, GitLab and BitBucket may generate more than one deployment. However, DevLake consider these deployments as ONE production deployment and use the last one's finished_date as the finished date.\n\tSELECT\n\t\tcdc.cicd_deployment_id as deployment_id,\n\t\tmax(DATE(cdc.finished_date)) as day\n\tFROM cicd_deployment_commits cdc\n\tJOIN commits c on cdc.commit_sha = c.sha\n\tjoin user_accounts ua on c.author_id = ua.account_id\n join users u on ua.user_id = u.id\n join team_users tu on u.id = tu.user_id\n join teams t on tu.team_id = t.id\n\tJOIN project_mapping pm on cdc.cicd_scope_id = pm.row_id and pm.`table` = 'cicd_scopes'\n\tWHERE\n\t\tt.name in (${team:singlequote})\n\t\tand cdc.result = 'SUCCESS'\n\t\tand cdc.environment = 'PRODUCTION'\n\tGROUP BY 1\n),\n\n_days_weekly_deploy as(\n-- calculate the number of deployment days every week\n\tSELECT\n\t\t\tdate(DATE_ADD(last_few_calendar_months.day, INTERVAL -WEEKDAY(last_few_calendar_months.day) DAY)) as week,\n\t\t\tMAX(if(_production_deployment_days.day is not null, 1, 0)) as weeks_deployed,\n\t\t\tCOUNT(distinct _production_deployment_days.day) as days_deployed\n\tFROM \n\t\tlast_few_calendar_months\n\t\tLEFT JOIN _production_deployment_days ON _production_deployment_days.day = last_few_calendar_months.day\n\tGROUP BY week\n\t),\n\n_days_monthly_deploy as(\n-- calculate the number of deployment days every month\n\tSELECT\n\t\t\tdate(DATE_ADD(last_few_calendar_months.day, INTERVAL -DAY(last_few_calendar_months.day)+1 DAY)) as month,\n\t\t\tMAX(if(_production_deployment_days.day is not null, 1, null)) as months_deployed,\n\t\t COUNT(distinct _production_deployment_days.day) as days_deployed\n\tFROM \n\t\tlast_few_calendar_months\n\t\tLEFT JOIN _production_deployment_days ON _production_deployment_days.day = last_few_calendar_months.day\n\tGROUP BY month\n\t),\n\n_days_six_months_deploy AS (\n SELECT\n month,\n SUM(days_deployed) OVER (\n ORDER BY month\n ROWS BETWEEN 5 PRECEDING AND CURRENT ROW\n ) AS days_deployed_per_six_months,\n COUNT(months_deployed) OVER (\n ORDER BY month\n ROWS BETWEEN 5 PRECEDING AND CURRENT ROW\n ) AS months_deployed_count,\n ROW_NUMBER() OVER (\n PARTITION BY DATE_FORMAT(month, '%Y-%m') DIV 6\n ORDER BY month DESC\n ) AS rn\n FROM _days_monthly_deploy\n),\n\n_median_number_of_deployment_days_per_week_ranks as(\n\tSELECT *, percent_rank() over(order by days_deployed) as ranks\n\tFROM _days_weekly_deploy\n),\n\n_median_number_of_deployment_days_per_week as(\n\tSELECT max(days_deployed) as median_number_of_deployment_days_per_week\n\tFROM _median_number_of_deployment_days_per_week_ranks\n\tWHERE ranks <= 0.5\n),\n\n_median_number_of_deployment_days_per_month_ranks as(\n\tSELECT *, percent_rank() over(order by days_deployed) as ranks\n\tFROM _days_monthly_deploy\n),\n\n_median_number_of_deployment_days_per_month as(\n\tSELECT max(days_deployed) as median_number_of_deployment_days_per_month\n\tFROM _median_number_of_deployment_days_per_month_ranks\n\tWHERE ranks <= 0.5\n),\n\n_days_per_six_months_deploy_by_filter AS (\nSELECT\n month,\n days_deployed_per_six_months,\n months_deployed_count\nFROM _days_six_months_deploy\nWHERE rn%6 = 1\n),\n\n\n_median_number_of_deployment_days_per_six_months_ranks as(\n\tSELECT *, percent_rank() over(order by days_deployed_per_six_months) as ranks\n\tFROM _days_per_six_months_deploy_by_filter\n),\n\n_median_number_of_deployment_days_per_six_months as(\n\tSELECT min(days_deployed_per_six_months) as median_number_of_deployment_days_per_six_months, min(months_deployed_count) as is_collected\n\tFROM _median_number_of_deployment_days_per_six_months_ranks\n\tWHERE ranks >= 0.5\n)\n\nSELECT \n CASE\n WHEN ('$dora_report') = '2023' THEN\n\t\t\tCASE \n\t\t\t\tWHEN median_number_of_deployment_days_per_week >= 5 THEN CONCAT(median_number_of_deployment_days_per_week, ' deployment days per week(elite)')\n\t\t\t\tWHEN median_number_of_deployment_days_per_week >= 1 THEN CONCAT(median_number_of_deployment_days_per_week, ' deployment days per week(high)')\n\t\t\t\tWHEN median_number_of_deployment_days_per_month >= 1 THEN CONCAT(median_number_of_deployment_days_per_month, ' deployment days per month(medium)')\n\t\t\t\tWHEN median_number_of_deployment_days_per_month < 1 and is_collected is not null THEN CONCAT(median_number_of_deployment_days_per_month, ' deployment days per month(low)')\n\t\t\t\tELSE \"N/A. Please check if you have collected deployments.\" END\n\t \tWHEN ('$dora_report') = '2021' THEN\n\t\t\tCASE \n\t\t\t\tWHEN median_number_of_deployment_days_per_week >= 5 THEN CONCAT(median_number_of_deployment_days_per_week, ' deployment days per week(elite)')\n\t\t\t\tWHEN median_number_of_deployment_days_per_month >= 1 THEN CONCAT(median_number_of_deployment_days_per_month, ' deployment days per month(high)')\n\t\t\t\tWHEN median_number_of_deployment_days_per_six_months >= 1 THEN CONCAT(median_number_of_deployment_days_per_six_months, ' deployment days per six months(medium)')\n\t\t\t\tWHEN median_number_of_deployment_days_per_six_months < 1 and is_collected is not null THEN CONCAT(median_number_of_deployment_days_per_six_months, ' deployment days per six months(low)')\n\t\t\t\tELSE \"N/A. Please check if you have collected deployments.\" END\n\t\tELSE 'Invalid dora report'\n\tEND AS 'Deployment Frequency'\nFROM _median_number_of_deployment_days_per_week, _median_number_of_deployment_days_per_month, _median_number_of_deployment_days_per_six_months\n\n", "refId": "A", "select": [ [ @@ -462,7 +462,7 @@ "format": "table", "hide": false, "rawQuery": true, - "rawSql": "-- Metric 2: median lead time for changes\nwith _pr_stats as (\n-- get the cycle time of PRs deployed by the deployments finished in the selected period\n\tSELECT\n\t\tdistinct pr.id,\n\t\tppm.pr_cycle_time\n\tFROM\n\t\tpull_requests pr\n\t\tjoin user_accounts ua on pr.author_id = ua.account_id\n \tjoin users u on ua.user_id = u.id\n \tjoin team_users tu on u.id = tu.user_id\n \tjoin teams t on tu.team_id = t.id\n\t\tjoin project_pr_metrics ppm on ppm.id = pr.id\n\t\tjoin project_mapping pm on pr.base_repo_id = pm.row_id and pm.`table` = 'repos'\n\t\tjoin cicd_deployment_commits cdc on ppm.deployment_commit_id = cdc.id\n\tWHERE\n\t t.name in (${team}) \n\t\tand pr.merged_date is not null\n\t\tand ppm.pr_cycle_time is not null\n\t\tand $__timeFilter(cdc.finished_date)\n),\n\n_median_change_lead_time_ranks as(\n\tSELECT *, percent_rank() over(order by pr_cycle_time) as ranks\n\tFROM _pr_stats\n),\n\n_median_change_lead_time as(\n-- use median PR cycle time as the median change lead time\n\tSELECT max(pr_cycle_time) as median_change_lead_time\n\tFROM _median_change_lead_time_ranks\n\tWHERE ranks <= 0.5\n)\n\nSELECT \n CASE\n WHEN ('$dora_report') = '2023' THEN\n\t\t\tCASE\n\t\t\t\tWHEN median_change_lead_time < 24 * 60 THEN CONCAT(round(median_change_lead_time/60,1), \"(elite)\")\n\t\t\t\tWHEN median_change_lead_time < 7 * 24 * 60 THEN CONCAT(round(median_change_lead_time/60,1), \"(high)\")\n\t\t\t\tWHEN median_change_lead_time < 30 * 24 * 60 THEN CONCAT(round(median_change_lead_time/60,1), \"(medium)\")\n\t\t\t\tWHEN median_change_lead_time >= 30 * 24 * 60 THEN CONCAT(round(median_change_lead_time/60,1), \"(low)\")\n\t\t\t\tELSE \"N/A. Please check if you have collected deployments/pull_requests.\"\n\t\t\t\tEND\n WHEN ('$dora_report') = '2021' THEN\n\t\t CASE\n\t\t\t\tWHEN median_change_lead_time < 60 THEN CONCAT(round(median_change_lead_time/60,1), \"(elite)\")\n\t\t\t\tWHEN median_change_lead_time < 7 * 24 * 60 THEN CONCAT(round(median_change_lead_time/60,1), \"(high)\")\n\t\t\t\tWHEN median_change_lead_time < 180 * 24 * 60 THEN CONCAT(round(median_change_lead_time/60,1), \"(medium)\")\n\t\t\t\tWHEN median_change_lead_time >= 180 * 24 * 60 THEN CONCAT(round(median_change_lead_time/60,1), \"(low)\")\n\t\t\t\tELSE \"N/A. Please check if you have collected deployments/pull_requests.\"\n\t\t\t\tEND\n\t\tELSE 'Invalid dora report'\n\tEND AS median_change_lead_time\nFROM _median_change_lead_time\n\t\t\t", + "rawSql": "-- Metric 2: median lead time for changes\nwith _pr_stats as (\n-- get the cycle time of PRs deployed by the deployments finished in the selected period\n\tSELECT\n\t\tdistinct pr.id,\n\t\tppm.pr_cycle_time\n\tFROM\n\t\tpull_requests pr\n\t\tjoin user_accounts ua on pr.author_id = ua.account_id\n \tjoin users u on ua.user_id = u.id\n \tjoin team_users tu on u.id = tu.user_id\n \tjoin teams t on tu.team_id = t.id\n\t\tjoin project_pr_metrics ppm on ppm.id = pr.id\n\t\tjoin project_mapping pm on pr.base_repo_id = pm.row_id and pm.`table` = 'repos'\n\t\tjoin cicd_deployment_commits cdc on ppm.deployment_commit_id = cdc.id\n\tWHERE\n\t t.name in (${team:singlequote}) \n\t\tand pr.merged_date is not null\n\t\tand ppm.pr_cycle_time is not null\n\t\tand $__timeFilter(cdc.finished_date)\n),\n\n_median_change_lead_time_ranks as(\n\tSELECT *, percent_rank() over(order by pr_cycle_time) as ranks\n\tFROM _pr_stats\n),\n\n_median_change_lead_time as(\n-- use median PR cycle time as the median change lead time\n\tSELECT max(pr_cycle_time) as median_change_lead_time\n\tFROM _median_change_lead_time_ranks\n\tWHERE ranks <= 0.5\n)\n\nSELECT \n CASE\n WHEN ('$dora_report') = '2023' THEN\n\t\t\tCASE\n\t\t\t\tWHEN median_change_lead_time < 24 * 60 THEN CONCAT(round(median_change_lead_time/60,1), \"(elite)\")\n\t\t\t\tWHEN median_change_lead_time < 7 * 24 * 60 THEN CONCAT(round(median_change_lead_time/60,1), \"(high)\")\n\t\t\t\tWHEN median_change_lead_time < 30 * 24 * 60 THEN CONCAT(round(median_change_lead_time/60,1), \"(medium)\")\n\t\t\t\tWHEN median_change_lead_time >= 30 * 24 * 60 THEN CONCAT(round(median_change_lead_time/60,1), \"(low)\")\n\t\t\t\tELSE \"N/A. Please check if you have collected deployments/pull_requests.\"\n\t\t\t\tEND\n WHEN ('$dora_report') = '2021' THEN\n\t\t CASE\n\t\t\t\tWHEN median_change_lead_time < 60 THEN CONCAT(round(median_change_lead_time/60,1), \"(elite)\")\n\t\t\t\tWHEN median_change_lead_time < 7 * 24 * 60 THEN CONCAT(round(median_change_lead_time/60,1), \"(high)\")\n\t\t\t\tWHEN median_change_lead_time < 180 * 24 * 60 THEN CONCAT(round(median_change_lead_time/60,1), \"(medium)\")\n\t\t\t\tWHEN median_change_lead_time >= 180 * 24 * 60 THEN CONCAT(round(median_change_lead_time/60,1), \"(low)\")\n\t\t\t\tELSE \"N/A. Please check if you have collected deployments/pull_requests.\"\n\t\t\t\tEND\n\t\tELSE 'Invalid dora report'\n\tEND AS median_change_lead_time\nFROM _median_change_lead_time\n\t\t\t", "refId": "A", "sql": { "columns": [ @@ -579,7 +579,7 @@ "format": "table", "hide": false, "rawQuery": true, - "rawSql": "-- Metric 4: change failure rate\nwith _deployments as (\n -- When deploying multiple commits in one pipeline, GitLab and BitBucket may generate more than one deployment. However, DevLake consider these deployments as ONE production deployment and use the last one's finished_date as the finished date.\n SELECT\n cdc.cicd_deployment_id as deployment_id,\n max(cdc.finished_date) as deployment_finished_date\n FROM\n cicd_deployment_commits cdc\n JOIN commits c on cdc.commit_sha = c.sha\n join user_accounts ua on c.author_id = ua.account_id\n join users u on ua.user_id = u.id\n join team_users tu on u.id = tu.user_id\n join teams t on tu.team_id = t.id\n JOIN project_mapping pm on cdc.cicd_scope_id = pm.row_id\n and pm.`table` = 'cicd_scopes'\n WHERE\n t.name in (${team})\n and cdc.result = 'SUCCESS'\n and cdc.environment = 'PRODUCTION'\n GROUP BY\n 1\n HAVING\n $__timeFilter(max(cdc.finished_date))\n),\n_failure_caused_by_deployments as (\n -- calculate the number of incidents caused by each deployment\n SELECT\n d.deployment_id,\n d.deployment_finished_date,\n count(\n distinct case\n when i.id is not null then d.deployment_id\n else null\n end\n ) as has_incident\n FROM\n _deployments d\n left join project_incident_deployment_relationships pim on d.deployment_id = pim.deployment_id\n left join incidents i on pim.id = i.id\n GROUP BY\n 1,\n 2\n),\n_change_failure_rate as (\n SELECT\n case\n when count(deployment_id) is null then null\n else sum(has_incident) / count(deployment_id)\n end as change_failure_rate\n FROM\n _failure_caused_by_deployments\n),\n_is_collected_data as(\n SELECT\n CASE\n WHEN COUNT(i.id) = 0\n AND COUNT(cdc.id) = 0 THEN 'No All'\n WHEN COUNT(i.id) = 0 THEN 'No Incidents'\n WHEN COUNT(cdc.id) = 0 THEN 'No Deployments'\n END AS is_collected\n FROM\n (\n SELECT\n 1\n ) AS dummy\n LEFT JOIN incidents i ON 1 = 1\n LEFT JOIN cicd_deployment_commits cdc ON 1 = 1\n)\nSELECT\n CASE\n WHEN ('$dora_report') = '2023' THEN CASE\n WHEN is_collected = \"No All\" THEN \"N/A. Please check if you have collected deployments/incidents.\"\n WHEN is_collected = \"No Incidents\" THEN \"N/A. Please check if you have collected incidents.\"\n WHEN is_collected = \"No Deployments\" THEN \"N/A. Please check if you have collected deployments.\"\n WHEN change_failure_rate <=.05 THEN CONCAT(round(change_failure_rate * 100, 1), \"%(elite)\")\n WHEN change_failure_rate <=.10 THEN CONCAT(round(change_failure_rate * 100, 1), \"%(high)\")\n WHEN change_failure_rate <=.15 THEN CONCAT(round(change_failure_rate * 100, 1), \"%(medium)\")\n WHEN change_failure_rate >.15 THEN CONCAT(round(change_failure_rate * 100, 1), \"%(low)\")\n ELSE \"N/A. Please check if you have collected deployments/incidents.\"\n END\n WHEN ('$dora_report') = '2021' THEN CASE\n WHEN is_collected = \"No All\" THEN \"N/A. Please check if you have collected deployments/incidents.\"\n WHEN is_collected = \"No Incidents\" THEN \"N/A. Please check if you have collected incidents.\"\n WHEN is_collected = \"No Deployments\" THEN \"N/A. Please check if you have collected deployments.\"\n WHEN change_failure_rate <=.15 THEN CONCAT(round(change_failure_rate * 100, 1), \"%(elite)\")\n WHEN change_failure_rate <=.20 THEN CONCAT(round(change_failure_rate * 100, 1), \"%(high)\")\n WHEN change_failure_rate <=.30 THEN CONCAT(round(change_failure_rate * 100, 1), \"%(medium)\")\n WHEN change_failure_rate >.30 THEN CONCAT(round(change_failure_rate * 100, 1), \"%(low)\")\n ELSE \"N/A. Please check if you have collected deployments/incidents.\"\n END\n ELSE 'Invalid dora report'\n END AS change_failure_rate\nFROM\n _change_failure_rate,\n _is_collected_data", + "rawSql": "-- Metric 4: change failure rate\nwith _deployments as (\n -- When deploying multiple commits in one pipeline, GitLab and BitBucket may generate more than one deployment. However, DevLake consider these deployments as ONE production deployment and use the last one's finished_date as the finished date.\n SELECT\n cdc.cicd_deployment_id as deployment_id,\n max(cdc.finished_date) as deployment_finished_date\n FROM\n cicd_deployment_commits cdc\n JOIN commits c on cdc.commit_sha = c.sha\n join user_accounts ua on c.author_id = ua.account_id\n join users u on ua.user_id = u.id\n join team_users tu on u.id = tu.user_id\n join teams t on tu.team_id = t.id\n JOIN project_mapping pm on cdc.cicd_scope_id = pm.row_id\n and pm.`table` = 'cicd_scopes'\n WHERE\n t.name in (${team:singlequote})\n and cdc.result = 'SUCCESS'\n and cdc.environment = 'PRODUCTION'\n GROUP BY\n 1\n HAVING\n $__timeFilter(max(cdc.finished_date))\n),\n_failure_caused_by_deployments as (\n -- calculate the number of incidents caused by each deployment\n SELECT\n d.deployment_id,\n d.deployment_finished_date,\n count(\n distinct case\n when i.id is not null then d.deployment_id\n else null\n end\n ) as has_incident\n FROM\n _deployments d\n left join project_incident_deployment_relationships pim on d.deployment_id = pim.deployment_id\n left join incidents i on pim.id = i.id\n GROUP BY\n 1,\n 2\n),\n_change_failure_rate as (\n SELECT\n case\n when count(deployment_id) is null then null\n else sum(has_incident) / count(deployment_id)\n end as change_failure_rate\n FROM\n _failure_caused_by_deployments\n),\n_is_collected_data as(\n SELECT\n CASE\n WHEN COUNT(i.id) = 0\n AND COUNT(cdc.id) = 0 THEN 'No All'\n WHEN COUNT(i.id) = 0 THEN 'No Incidents'\n WHEN COUNT(cdc.id) = 0 THEN 'No Deployments'\n END AS is_collected\n FROM\n (\n SELECT\n 1\n ) AS dummy\n LEFT JOIN incidents i ON 1 = 1\n LEFT JOIN cicd_deployment_commits cdc ON 1 = 1\n)\nSELECT\n CASE\n WHEN ('$dora_report') = '2023' THEN CASE\n WHEN is_collected = \"No All\" THEN \"N/A. Please check if you have collected deployments/incidents.\"\n WHEN is_collected = \"No Incidents\" THEN \"N/A. Please check if you have collected incidents.\"\n WHEN is_collected = \"No Deployments\" THEN \"N/A. Please check if you have collected deployments.\"\n WHEN change_failure_rate <=.05 THEN CONCAT(round(change_failure_rate * 100, 1), \"%(elite)\")\n WHEN change_failure_rate <=.10 THEN CONCAT(round(change_failure_rate * 100, 1), \"%(high)\")\n WHEN change_failure_rate <=.15 THEN CONCAT(round(change_failure_rate * 100, 1), \"%(medium)\")\n WHEN change_failure_rate >.15 THEN CONCAT(round(change_failure_rate * 100, 1), \"%(low)\")\n ELSE \"N/A. Please check if you have collected deployments/incidents.\"\n END\n WHEN ('$dora_report') = '2021' THEN CASE\n WHEN is_collected = \"No All\" THEN \"N/A. Please check if you have collected deployments/incidents.\"\n WHEN is_collected = \"No Incidents\" THEN \"N/A. Please check if you have collected incidents.\"\n WHEN is_collected = \"No Deployments\" THEN \"N/A. Please check if you have collected deployments.\"\n WHEN change_failure_rate <=.15 THEN CONCAT(round(change_failure_rate * 100, 1), \"%(elite)\")\n WHEN change_failure_rate <=.20 THEN CONCAT(round(change_failure_rate * 100, 1), \"%(high)\")\n WHEN change_failure_rate <=.30 THEN CONCAT(round(change_failure_rate * 100, 1), \"%(medium)\")\n WHEN change_failure_rate >.30 THEN CONCAT(round(change_failure_rate * 100, 1), \"%(low)\")\n ELSE \"N/A. Please check if you have collected deployments/incidents.\"\n END\n ELSE 'Invalid dora report'\n END AS change_failure_rate\nFROM\n _change_failure_rate,\n _is_collected_data", "refId": "A", "sql": { "columns": [ @@ -697,7 +697,7 @@ "format": "table", "hide": false, "rawQuery": true, - "rawSql": "-- ***** 2023 report ***** --\n-- Metric 4: Failed deployment recovery time\nwith _deployments as (\n SELECT\n cdc.cicd_deployment_id as deployment_id,\n max(cdc.finished_date) as deployment_finished_date\n FROM \n cicd_deployment_commits cdc\n\t\tJOIN commits c on cdc.commit_sha = c.sha\n join user_accounts ua on c.author_id = ua.account_id\n join users u on ua.user_id = u.id\n join team_users tu on u.id = tu.user_id\n join teams t on tu.team_id = t.id\n JOIN project_mapping pm on cdc.cicd_scope_id = pm.row_id and pm.`table` = 'cicd_scopes'\n WHERE\n\t\tt.name in (${team})\n and cdc.result = 'SUCCESS'\n and cdc.environment = 'PRODUCTION'\n GROUP BY 1\n HAVING $__timeFilter(max(cdc.finished_date))\n),\n\n_incidents_for_deployments as (\n SELECT\n i.id as incident_id,\n i.created_date as incident_create_date,\n i.resolution_date as incident_resolution_date,\n fd.deployment_id as caused_by_deployment,\n fd.deployment_finished_date,\n date_format(fd.deployment_finished_date,'%y/%m') as deployment_finished_month\n FROM\n incidents i\n left join project_incident_deployment_relationships pim on i.id = pim.id\n join _deployments fd on pim.deployment_id = fd.deployment_id\n WHERE\n \t$__timeFilter(i.resolution_date)\n),\n\n_recovery_time_ranks as (\n SELECT *, percent_rank() over(order by TIMESTAMPDIFF(MINUTE, deployment_finished_date, incident_resolution_date)) as ranks\n FROM _incidents_for_deployments\n),\n\n_median_recovery_time as (\n SELECT max(TIMESTAMPDIFF(MINUTE, deployment_finished_date, incident_resolution_date)) as median_recovery_time\n FROM _recovery_time_ranks\n WHERE ranks <= 0.5\n),\n\n_metric_recovery_time_2023_report as(\n\tSELECT \n\tCASE\n\t\tWHEN ('$dora_report') = '2023' THEN\n\t\tCASE\n\t\t\tWHEN median_recovery_time < 60 THEN CONCAT(round(median_recovery_time/60,1), \"(elite)\")\n\t\t\tWHEN median_recovery_time < 24 * 60 THEN CONCAT(round(median_recovery_time/60,1), \"(high)\")\n\t\t\tWHEN median_recovery_time < 7 * 24 * 60 THEN CONCAT(round(median_recovery_time/60,1), \"(medium)\")\n\t\t\tWHEN median_recovery_time >= 7 * 24 * 60 THEN CONCAT(round(median_recovery_time/60,1), \"(low)\")\n\t\t\tELSE \"N/A. Please check if you have collected deployments or incidents.\"\n\t\tEND\n\tEND AS median_recovery_time\n\tFROM \n\t_median_recovery_time\n),\n\n-- ***** 2021 report ***** --\n-- Metric 4: Median time to restore service \n_incidents as (\n-- get the incidents created within the selected time period in the top-right corner\n\tSELECT\n\t distinct i.id,\n\t\tcast(lead_time_minutes as signed) as lead_time_minutes\n\tFROM\n\t\tincidents i\t \n\t join project_mapping pm on i.scope_id = pm.row_id and pm.`table` = i.`table`\n\t join user_accounts ua on i.assignee_id = ua.account_id\n join users u on ua.user_id = u.id\n join team_users tu on u.id = tu.user_id\n join teams t on tu.team_id = t.id\n\tWHERE\n\t t.name in (${team})\t\t\n\t\tand $__timeFilter(i.resolution_date)\n),\n\n_median_mttr_ranks as(\n\tSELECT *, percent_rank() over(order by lead_time_minutes) as ranks\n\tFROM _incidents\n),\n\n_median_mttr as(\n\tSELECT max(lead_time_minutes) as median_time_to_resolve\n\tFROM _median_mttr_ranks\n\tWHERE ranks <= 0.5\n),\n\n_metric_mttr_2021_report as(\n\tSELECT \n\tCASE\n\t\tWHEN ('$dora_report') = '2021' THEN\n\t\t\tCASE\n\t\t\t\tWHEN median_time_to_resolve < 60 THEN CONCAT(round(median_time_to_resolve/60,1), \"(elite)\")\n\t\t\t\tWHEN median_time_to_resolve < 24 * 60 THEN CONCAT(round(median_time_to_resolve/60,1), \"(high)\")\n\t\t\t\tWHEN median_time_to_resolve < 7 * 24 * 60 THEN CONCAT(round(median_time_to_resolve/60,1), \"(medium)\")\n\t\t\t\tWHEN median_time_to_resolve >= 7 * 24 * 60 THEN CONCAT(round(median_time_to_resolve/60,1), \"(low)\")\n\t\t\t\tELSE \"N/A. Please check if you have collected incidents.\"\n\t\t\tEND\n\tEND AS median_time_to_resolve\n\tFROM \n\t\t_median_mttr\n)\n\nSELECT \n median_recovery_time AS median_time_in_hour\nFROM \n _metric_recovery_time_2023_report\nWHERE \n ('$dora_report') = '2023'\nUNION\nSELECT \n median_time_to_resolve AS median_time_to_resolve\nFROM \n _metric_mttr_2021_report\nWHERE \n ('$dora_report') = '2021'\n", + "rawSql": "-- ***** 2023 report ***** --\n-- Metric 4: Failed deployment recovery time\nwith _deployments as (\n SELECT\n cdc.cicd_deployment_id as deployment_id,\n max(cdc.finished_date) as deployment_finished_date\n FROM \n cicd_deployment_commits cdc\n\t\tJOIN commits c on cdc.commit_sha = c.sha\n join user_accounts ua on c.author_id = ua.account_id\n join users u on ua.user_id = u.id\n join team_users tu on u.id = tu.user_id\n join teams t on tu.team_id = t.id\n JOIN project_mapping pm on cdc.cicd_scope_id = pm.row_id and pm.`table` = 'cicd_scopes'\n WHERE\n\t\tt.name in (${team:singlequote})\n and cdc.result = 'SUCCESS'\n and cdc.environment = 'PRODUCTION'\n GROUP BY 1\n HAVING $__timeFilter(max(cdc.finished_date))\n),\n\n_incidents_for_deployments as (\n SELECT\n i.id as incident_id,\n i.created_date as incident_create_date,\n i.resolution_date as incident_resolution_date,\n fd.deployment_id as caused_by_deployment,\n fd.deployment_finished_date,\n date_format(fd.deployment_finished_date,'%y/%m') as deployment_finished_month\n FROM\n incidents i\n left join project_incident_deployment_relationships pim on i.id = pim.id\n join _deployments fd on pim.deployment_id = fd.deployment_id\n WHERE\n \t$__timeFilter(i.resolution_date)\n),\n\n_recovery_time_ranks as (\n SELECT *, percent_rank() over(order by TIMESTAMPDIFF(MINUTE, deployment_finished_date, incident_resolution_date)) as ranks\n FROM _incidents_for_deployments\n),\n\n_median_recovery_time as (\n SELECT max(TIMESTAMPDIFF(MINUTE, deployment_finished_date, incident_resolution_date)) as median_recovery_time\n FROM _recovery_time_ranks\n WHERE ranks <= 0.5\n),\n\n_metric_recovery_time_2023_report as(\n\tSELECT \n\tCASE\n\t\tWHEN ('$dora_report') = '2023' THEN\n\t\tCASE\n\t\t\tWHEN median_recovery_time < 60 THEN CONCAT(round(median_recovery_time/60,1), \"(elite)\")\n\t\t\tWHEN median_recovery_time < 24 * 60 THEN CONCAT(round(median_recovery_time/60,1), \"(high)\")\n\t\t\tWHEN median_recovery_time < 7 * 24 * 60 THEN CONCAT(round(median_recovery_time/60,1), \"(medium)\")\n\t\t\tWHEN median_recovery_time >= 7 * 24 * 60 THEN CONCAT(round(median_recovery_time/60,1), \"(low)\")\n\t\t\tELSE \"N/A. Please check if you have collected deployments or incidents.\"\n\t\tEND\n\tEND AS median_recovery_time\n\tFROM \n\t_median_recovery_time\n),\n\n-- ***** 2021 report ***** --\n-- Metric 4: Median time to restore service \n_incidents as (\n-- get the incidents created within the selected time period in the top-right corner\n\tSELECT\n\t distinct i.id,\n\t\tcast(lead_time_minutes as signed) as lead_time_minutes\n\tFROM\n\t\tincidents i\t \n\t join project_mapping pm on i.scope_id = pm.row_id and pm.`table` = i.`table`\n\t join user_accounts ua on i.assignee_id = ua.account_id\n join users u on ua.user_id = u.id\n join team_users tu on u.id = tu.user_id\n join teams t on tu.team_id = t.id\n\tWHERE\n\t t.name in (${team:singlequote})\t\t\n\t\tand $__timeFilter(i.resolution_date)\n),\n\n_median_mttr_ranks as(\n\tSELECT *, percent_rank() over(order by lead_time_minutes) as ranks\n\tFROM _incidents\n),\n\n_median_mttr as(\n\tSELECT max(lead_time_minutes) as median_time_to_resolve\n\tFROM _median_mttr_ranks\n\tWHERE ranks <= 0.5\n),\n\n_metric_mttr_2021_report as(\n\tSELECT \n\tCASE\n\t\tWHEN ('$dora_report') = '2021' THEN\n\t\t\tCASE\n\t\t\t\tWHEN median_time_to_resolve < 60 THEN CONCAT(round(median_time_to_resolve/60,1), \"(elite)\")\n\t\t\t\tWHEN median_time_to_resolve < 24 * 60 THEN CONCAT(round(median_time_to_resolve/60,1), \"(high)\")\n\t\t\t\tWHEN median_time_to_resolve < 7 * 24 * 60 THEN CONCAT(round(median_time_to_resolve/60,1), \"(medium)\")\n\t\t\t\tWHEN median_time_to_resolve >= 7 * 24 * 60 THEN CONCAT(round(median_time_to_resolve/60,1), \"(low)\")\n\t\t\t\tELSE \"N/A. Please check if you have collected incidents.\"\n\t\t\tEND\n\tEND AS median_time_to_resolve\n\tFROM \n\t\t_median_mttr\n)\n\nSELECT \n median_recovery_time AS median_time_in_hour\nFROM \n _metric_recovery_time_2023_report\nWHERE \n ('$dora_report') = '2023'\nUNION\nSELECT \n median_time_to_resolve AS median_time_to_resolve\nFROM \n _metric_mttr_2021_report\nWHERE \n ('$dora_report') = '2021'\n", "refId": "A", "sql": { "columns": [ @@ -804,7 +804,7 @@ "format": "table", "hide": false, "rawQuery": true, - "rawSql": "-- Metric 1: Number of deployments per month\nwith _deployments as(\n-- When deploying multiple commits in one pipeline, GitLab and BitBucket may generate more than one deployment. However, DevLake consider these deployments as ONE production deployment and use the last one's finished_date as the finished date.\n\tSELECT \n\t\tdate_format(deployment_finished_date,'%y/%m') as month,\n\t\tcount(cicd_deployment_id) as deployment_count\n\tFROM (\n\t\tSELECT\n\t\t\tcdc.cicd_deployment_id,\n\t\t\tmax(cdc.finished_date) as deployment_finished_date\n\t\tFROM cicd_deployment_commits cdc\n\t\tJOIN commits c on cdc.commit_sha = c.sha\n\t join user_accounts ua on c.author_id = ua.account_id\n join users u on ua.user_id = u.id\n join team_users tu on u.id = tu.user_id\n join teams t on tu.team_id = t.id\n\t\tJOIN project_mapping pm on cdc.cicd_scope_id = pm.row_id and pm.`table` = 'cicd_scopes'\n\t\tWHERE\n\t\t\tt.name in (${team})\n\t\t\tand cdc.result = 'SUCCESS'\n\t\t\tand cdc.environment = 'PRODUCTION'\n\t\tGROUP BY 1\n\t\tHAVING $__timeFilter(max(cdc.finished_date))\n\t) _production_deployments\n\tGROUP BY 1\n)\n\nSELECT \n\tcm.month, \n\tcase when d.deployment_count is null then 0 else d.deployment_count end as 'Deployment Count'\nFROM \n\tcalendar_months cm\n\tleft join _deployments d on cm.month = d.month\nWHERE $__timeFilter(month_timestamp) ", + "rawSql": "-- Metric 1: Number of deployments per month\nwith _deployments as(\n-- When deploying multiple commits in one pipeline, GitLab and BitBucket may generate more than one deployment. However, DevLake consider these deployments as ONE production deployment and use the last one's finished_date as the finished date.\n\tSELECT \n\t\tdate_format(deployment_finished_date,'%y/%m') as month,\n\t\tcount(cicd_deployment_id) as deployment_count\n\tFROM (\n\t\tSELECT\n\t\t\tcdc.cicd_deployment_id,\n\t\t\tmax(cdc.finished_date) as deployment_finished_date\n\t\tFROM cicd_deployment_commits cdc\n\t\tJOIN commits c on cdc.commit_sha = c.sha\n\t join user_accounts ua on c.author_id = ua.account_id\n join users u on ua.user_id = u.id\n join team_users tu on u.id = tu.user_id\n join teams t on tu.team_id = t.id\n\t\tJOIN project_mapping pm on cdc.cicd_scope_id = pm.row_id and pm.`table` = 'cicd_scopes'\n\t\tWHERE\n\t\t\tt.name in (${team:singlequote})\n\t\t\tand cdc.result = 'SUCCESS'\n\t\t\tand cdc.environment = 'PRODUCTION'\n\t\tGROUP BY 1\n\t\tHAVING $__timeFilter(max(cdc.finished_date))\n\t) _production_deployments\n\tGROUP BY 1\n)\n\nSELECT \n\tcm.month, \n\tcase when d.deployment_count is null then 0 else d.deployment_count end as 'Deployment Count'\nFROM \n\tcalendar_months cm\n\tleft join _deployments d on cm.month = d.month\nWHERE $__timeFilter(month_timestamp) ", "refId": "A", "sql": { "columns": [ @@ -909,7 +909,7 @@ "format": "table", "hide": false, "rawQuery": true, - "rawSql": "-- Metric 2: median change lead time per month\nwith _pr_stats as (\n-- get the cycle time of PRs deployed by the deployments finished each month\n\tSELECT\n\t\tdistinct pr.id,\n\t\tdate_format(cdc.finished_date,'%y/%m') as month,\n\t\tppm.pr_cycle_time\n\tFROM\n\t\tpull_requests pr\n\t\tjoin user_accounts ua on pr.author_id = ua.account_id\n \tjoin users u on ua.user_id = u.id\n \tjoin team_users tu on u.id = tu.user_id\n \tjoin teams t on tu.team_id = t.id\n\t\tjoin project_pr_metrics ppm on ppm.id = pr.id\n\t\tjoin project_mapping pm on pr.base_repo_id = pm.row_id and pm.`table` = 'repos'\n\t\tjoin cicd_deployment_commits cdc on ppm.deployment_commit_id = cdc.id\n\tWHERE\n\t\tt.name in (${team}) \n\t\tand pr.merged_date is not null\n\t\tand ppm.pr_cycle_time is not null\n\t\tand $__timeFilter(cdc.finished_date)\n),\n\n_find_median_clt_each_month_ranks as(\n\tSELECT *, percent_rank() over(PARTITION BY month order by pr_cycle_time) as ranks\n\tFROM _pr_stats\n),\n\n_clt as(\n\tSELECT month, max(pr_cycle_time) as median_change_lead_time\n\tFROM _find_median_clt_each_month_ranks\n\tWHERE ranks <= 0.5\n\tgroup by month\n)\n\nSELECT \n\tcm.month,\n\tcase \n\t\twhen _clt.median_change_lead_time is null then 0 \n\t\telse _clt.median_change_lead_time/60 end as 'Median Change Lead Time In Hour'\nFROM \n\tcalendar_months cm\n\tleft join _clt on cm.month = _clt.month\nWHERE $__timeFilter(month_timestamp) ", + "rawSql": "-- Metric 2: median change lead time per month\nwith _pr_stats as (\n-- get the cycle time of PRs deployed by the deployments finished each month\n\tSELECT\n\t\tdistinct pr.id,\n\t\tdate_format(cdc.finished_date,'%y/%m') as month,\n\t\tppm.pr_cycle_time\n\tFROM\n\t\tpull_requests pr\n\t\tjoin user_accounts ua on pr.author_id = ua.account_id\n \tjoin users u on ua.user_id = u.id\n \tjoin team_users tu on u.id = tu.user_id\n \tjoin teams t on tu.team_id = t.id\n\t\tjoin project_pr_metrics ppm on ppm.id = pr.id\n\t\tjoin project_mapping pm on pr.base_repo_id = pm.row_id and pm.`table` = 'repos'\n\t\tjoin cicd_deployment_commits cdc on ppm.deployment_commit_id = cdc.id\n\tWHERE\n\t\tt.name in (${team:singlequote}) \n\t\tand pr.merged_date is not null\n\t\tand ppm.pr_cycle_time is not null\n\t\tand $__timeFilter(cdc.finished_date)\n),\n\n_find_median_clt_each_month_ranks as(\n\tSELECT *, percent_rank() over(PARTITION BY month order by pr_cycle_time) as ranks\n\tFROM _pr_stats\n),\n\n_clt as(\n\tSELECT month, max(pr_cycle_time) as median_change_lead_time\n\tFROM _find_median_clt_each_month_ranks\n\tWHERE ranks <= 0.5\n\tgroup by month\n)\n\nSELECT \n\tcm.month,\n\tcase \n\t\twhen _clt.median_change_lead_time is null then 0 \n\t\telse _clt.median_change_lead_time/60 end as 'Median Change Lead Time In Hour'\nFROM \n\tcalendar_months cm\n\tleft join _clt on cm.month = _clt.month\nWHERE $__timeFilter(month_timestamp) ", "refId": "A", "sql": { "columns": [ @@ -1033,7 +1033,7 @@ "format": "table", "hide": false, "rawQuery": true, - "rawSql": "-- Metric 4: change failure rate per month\nwith _deployments as (\n -- When deploying multiple commits in one pipeline, GitLab and BitBucket may generate more than one deployment. However, DevLake consider these deployments as ONE production deployment and use the last one's finished_date as the finished date.\n SELECT\n cdc.cicd_deployment_id as deployment_id,\n max(cdc.finished_date) as deployment_finished_date\n FROM\n cicd_deployment_commits cdc\n JOIN commits c on cdc.commit_sha = c.sha\n join user_accounts ua on c.author_id = ua.account_id\n join users u on ua.user_id = u.id\n join team_users tu on u.id = tu.user_id\n join teams t on tu.team_id = t.id\n JOIN project_mapping pm on cdc.cicd_scope_id = pm.row_id\n and pm.`table` = 'cicd_scopes'\n WHERE\n t.name in (${team})\n and cdc.result = 'SUCCESS'\n and cdc.environment = 'PRODUCTION'\n GROUP BY\n 1\n HAVING\n $__timeFilter(max(cdc.finished_date))\n),\n_failure_caused_by_deployments as (\n -- calculate the number of incidents caused by each deployment\n SELECT\n d.deployment_id,\n d.deployment_finished_date,\n count(\n distinct case\n when i.id is not null then d.deployment_id\n else null\n end\n ) as has_incident\n FROM\n _deployments d\n left join project_incident_deployment_relationships pim on d.deployment_id = pim.deployment_id\n left join incidents i on pim.id = i.id\n GROUP BY\n 1,\n 2\n),\n_change_failure_rate_for_each_month as (\n SELECT\n date_format(deployment_finished_date, '%y/%m') as month,\n case\n when count(deployment_id) is null then null\n else sum(has_incident) / count(deployment_id)\n end as change_failure_rate\n FROM\n _failure_caused_by_deployments\n GROUP BY\n 1\n)\nSELECT\n cm.month,\n cfr.change_failure_rate as 'Change Failure Rate'\nFROM\n calendar_months cm\n left join _change_failure_rate_for_each_month cfr on cm.month = cfr.month\nWHERE\n $__timeFilter(month_timestamp)", + "rawSql": "-- Metric 4: change failure rate per month\nwith _deployments as (\n -- When deploying multiple commits in one pipeline, GitLab and BitBucket may generate more than one deployment. However, DevLake consider these deployments as ONE production deployment and use the last one's finished_date as the finished date.\n SELECT\n cdc.cicd_deployment_id as deployment_id,\n max(cdc.finished_date) as deployment_finished_date\n FROM\n cicd_deployment_commits cdc\n JOIN commits c on cdc.commit_sha = c.sha\n join user_accounts ua on c.author_id = ua.account_id\n join users u on ua.user_id = u.id\n join team_users tu on u.id = tu.user_id\n join teams t on tu.team_id = t.id\n JOIN project_mapping pm on cdc.cicd_scope_id = pm.row_id\n and pm.`table` = 'cicd_scopes'\n WHERE\n t.name in (${team:singlequote})\n and cdc.result = 'SUCCESS'\n and cdc.environment = 'PRODUCTION'\n GROUP BY\n 1\n HAVING\n $__timeFilter(max(cdc.finished_date))\n),\n_failure_caused_by_deployments as (\n -- calculate the number of incidents caused by each deployment\n SELECT\n d.deployment_id,\n d.deployment_finished_date,\n count(\n distinct case\n when i.id is not null then d.deployment_id\n else null\n end\n ) as has_incident\n FROM\n _deployments d\n left join project_incident_deployment_relationships pim on d.deployment_id = pim.deployment_id\n left join incidents i on pim.id = i.id\n GROUP BY\n 1,\n 2\n),\n_change_failure_rate_for_each_month as (\n SELECT\n date_format(deployment_finished_date, '%y/%m') as month,\n case\n when count(deployment_id) is null then null\n else sum(has_incident) / count(deployment_id)\n end as change_failure_rate\n FROM\n _failure_caused_by_deployments\n GROUP BY\n 1\n)\nSELECT\n cm.month,\n cfr.change_failure_rate as 'Change Failure Rate'\nFROM\n calendar_months cm\n left join _change_failure_rate_for_each_month cfr on cm.month = cfr.month\nWHERE\n $__timeFilter(month_timestamp)", "refId": "A", "sql": { "columns": [ @@ -1143,7 +1143,7 @@ "format": "table", "hide": false, "rawQuery": true, - "rawSql": "-- ***** 2023 report ***** --\n-- Metric 4: Failed deployment recovery time\nwith _deployments as (\n SELECT\n cdc.cicd_deployment_id as deployment_id,\n max(cdc.finished_date) as deployment_finished_date\n FROM\n cicd_deployment_commits cdc\n JOIN commits c on cdc.commit_sha = c.sha\n join user_accounts ua on c.author_id = ua.account_id\n join users u on ua.user_id = u.id\n join team_users tu on u.id = tu.user_id\n join teams t on tu.team_id = t.id\n JOIN project_mapping pm on cdc.cicd_scope_id = pm.row_id\n and pm.`table` = 'cicd_scopes'\n WHERE\n t.name in (${team})\n and cdc.result = 'SUCCESS'\n and cdc.environment = 'PRODUCTION'\n GROUP BY\n 1\n HAVING\n $__timeFilter(max(cdc.finished_date))\n),\n_incidents_for_deployments as (\n SELECT\n i.id as incident_id,\n i.created_date as incident_create_date,\n i.resolution_date as incident_resolution_date,\n fd.deployment_id as caused_by_deployment,\n fd.deployment_finished_date,\n date_format(fd.deployment_finished_date, '%y/%m') as deployment_finished_month\n FROM\n incidents i\n left join project_incident_deployment_relationships pim on i.id = pim.id\n join _deployments fd on pim.deployment_id = fd.deployment_id\n WHERE\n $__timeFilter(i.resolution_date)\n),\n_recovery_time_ranks as (\n SELECT\n *,\n percent_rank() over(\n PARTITION BY deployment_finished_month\n order by\n TIMESTAMPDIFF(\n MINUTE,\n deployment_finished_date,\n incident_resolution_date\n )\n ) as ranks\n FROM\n _incidents_for_deployments\n),\n_median_recovery_time as (\n SELECT\n deployment_finished_month,\n max(\n TIMESTAMPDIFF(\n MINUTE,\n deployment_finished_date,\n incident_resolution_date\n )\n ) as median_recovery_time\n FROM\n _recovery_time_ranks\n WHERE\n ranks <= 0.5\n GROUP BY\n deployment_finished_month\n),\n_metric_recovery_time_2023_report as (\n SELECT\n cm.month,\n case\n when m.median_recovery_time is null then 0\n else m.median_recovery_time / 60\n end as median_recovery_time_in_hour\n FROM\n calendar_months cm\n LEFT JOIN _median_recovery_time m on cm.month = m.deployment_finished_month\n WHERE\n month_timestamp between DATE(DATE_FORMAT($__timeFrom(), '%Y-%m-01')) AND DATE(DATE_FORMAT($__timeTo(), '%Y-%m-01'))\n),\n-- ***** 2021 report ***** --\n-- Metric 4: median time to restore service - MTTR\n_incidents as (\n -- get the number of incidents created each month\n SELECT\n distinct i.id,\n date_format(i.resolution_date, '%y/%m') as month,\n cast(lead_time_minutes as signed) as lead_time_minutes\n FROM\n incidents i\n join project_mapping pm on i.scope_id = pm.row_id\n and pm.`table` = i.`table`\n join user_accounts ua on i.assignee_id = ua.account_id\n join users u on ua.user_id = u.id\n join team_users tu on u.id = tu.user_id\n join teams t on tu.team_id = t.id\n WHERE\n t.name in (${team})\n and i.lead_time_minutes is not null\n),\n_find_median_mttr_each_month_ranks as(\n SELECT\n *,\n percent_rank() over(\n PARTITION BY month\n order by\n lead_time_minutes\n ) as ranks\n FROM\n _incidents\n),\n_mttr as(\n SELECT\n month,\n max(lead_time_minutes) as median_time_to_resolve\n FROM\n _find_median_mttr_each_month_ranks\n WHERE\n ranks <= 0.5\n GROUP BY\n month\n),\n_metric_mttr_2021_report as (\n SELECT\n cm.month,\n case\n when m.median_time_to_resolve is null then 0\n else m.median_time_to_resolve / 60\n end as median_time_to_resolve_in_hour\n FROM\n calendar_months cm\n LEFT JOIN _mttr m on cm.month = m.month\n WHERE\n month_timestamp between DATE(DATE_FORMAT($__timeFrom(), '%Y-%m-01')) AND DATE(DATE_FORMAT($__timeTo(), '%Y-%m-01'))\n)\nSELECT\n cm.month,\n CASE\n WHEN '${dora_report}' = '2023' THEN mrt.median_recovery_time_in_hour\n WHEN '${dora_report}' = '2021' THEN mm.median_time_to_resolve_in_hour\n END AS '${title_value} In Hours'\nFROM\n calendar_months cm\n LEFT JOIN _metric_recovery_time_2023_report mrt ON cm.month = mrt.month\n LEFT JOIN _metric_mttr_2021_report mm ON cm.month = mm.month\nWHERE\n month_timestamp between DATE(DATE_FORMAT($__timeFrom(), '%Y-%m-01')) AND DATE(DATE_FORMAT($__timeTo(), '%Y-%m-01'))", + "rawSql": "-- ***** 2023 report ***** --\n-- Metric 4: Failed deployment recovery time\nwith _deployments as (\n SELECT\n cdc.cicd_deployment_id as deployment_id,\n max(cdc.finished_date) as deployment_finished_date\n FROM\n cicd_deployment_commits cdc\n JOIN commits c on cdc.commit_sha = c.sha\n join user_accounts ua on c.author_id = ua.account_id\n join users u on ua.user_id = u.id\n join team_users tu on u.id = tu.user_id\n join teams t on tu.team_id = t.id\n JOIN project_mapping pm on cdc.cicd_scope_id = pm.row_id\n and pm.`table` = 'cicd_scopes'\n WHERE\n t.name in (${team:singlequote})\n and cdc.result = 'SUCCESS'\n and cdc.environment = 'PRODUCTION'\n GROUP BY\n 1\n HAVING\n $__timeFilter(max(cdc.finished_date))\n),\n_incidents_for_deployments as (\n SELECT\n i.id as incident_id,\n i.created_date as incident_create_date,\n i.resolution_date as incident_resolution_date,\n fd.deployment_id as caused_by_deployment,\n fd.deployment_finished_date,\n date_format(fd.deployment_finished_date, '%y/%m') as deployment_finished_month\n FROM\n incidents i\n left join project_incident_deployment_relationships pim on i.id = pim.id\n join _deployments fd on pim.deployment_id = fd.deployment_id\n WHERE\n $__timeFilter(i.resolution_date)\n),\n_recovery_time_ranks as (\n SELECT\n *,\n percent_rank() over(\n PARTITION BY deployment_finished_month\n order by\n TIMESTAMPDIFF(\n MINUTE,\n deployment_finished_date,\n incident_resolution_date\n )\n ) as ranks\n FROM\n _incidents_for_deployments\n),\n_median_recovery_time as (\n SELECT\n deployment_finished_month,\n max(\n TIMESTAMPDIFF(\n MINUTE,\n deployment_finished_date,\n incident_resolution_date\n )\n ) as median_recovery_time\n FROM\n _recovery_time_ranks\n WHERE\n ranks <= 0.5\n GROUP BY\n deployment_finished_month\n),\n_metric_recovery_time_2023_report as (\n SELECT\n cm.month,\n case\n when m.median_recovery_time is null then 0\n else m.median_recovery_time / 60\n end as median_recovery_time_in_hour\n FROM\n calendar_months cm\n LEFT JOIN _median_recovery_time m on cm.month = m.deployment_finished_month\n WHERE\n month_timestamp between DATE(DATE_FORMAT($__timeFrom(), '%Y-%m-01')) AND DATE(DATE_FORMAT($__timeTo(), '%Y-%m-01'))\n),\n-- ***** 2021 report ***** --\n-- Metric 4: median time to restore service - MTTR\n_incidents as (\n -- get the number of incidents created each month\n SELECT\n distinct i.id,\n date_format(i.resolution_date, '%y/%m') as month,\n cast(lead_time_minutes as signed) as lead_time_minutes\n FROM\n incidents i\n join project_mapping pm on i.scope_id = pm.row_id\n and pm.`table` = i.`table`\n join user_accounts ua on i.assignee_id = ua.account_id\n join users u on ua.user_id = u.id\n join team_users tu on u.id = tu.user_id\n join teams t on tu.team_id = t.id\n WHERE\n t.name in (${team:singlequote})\n and i.lead_time_minutes is not null\n),\n_find_median_mttr_each_month_ranks as(\n SELECT\n *,\n percent_rank() over(\n PARTITION BY month\n order by\n lead_time_minutes\n ) as ranks\n FROM\n _incidents\n),\n_mttr as(\n SELECT\n month,\n max(lead_time_minutes) as median_time_to_resolve\n FROM\n _find_median_mttr_each_month_ranks\n WHERE\n ranks <= 0.5\n GROUP BY\n month\n),\n_metric_mttr_2021_report as (\n SELECT\n cm.month,\n case\n when m.median_time_to_resolve is null then 0\n else m.median_time_to_resolve / 60\n end as median_time_to_resolve_in_hour\n FROM\n calendar_months cm\n LEFT JOIN _mttr m on cm.month = m.month\n WHERE\n month_timestamp between DATE(DATE_FORMAT($__timeFrom(), '%Y-%m-01')) AND DATE(DATE_FORMAT($__timeTo(), '%Y-%m-01'))\n)\nSELECT\n cm.month,\n CASE\n WHEN '${dora_report}' = '2023' THEN mrt.median_recovery_time_in_hour\n WHEN '${dora_report}' = '2021' THEN mm.median_time_to_resolve_in_hour\n END AS '${title_value} In Hours'\nFROM\n calendar_months cm\n LEFT JOIN _metric_recovery_time_2023_report mrt ON cm.month = mrt.month\n LEFT JOIN _metric_mttr_2021_report mm ON cm.month = mm.month\nWHERE\n month_timestamp between DATE(DATE_FORMAT($__timeFrom(), '%Y-%m-01')) AND DATE(DATE_FORMAT($__timeTo(), '%Y-%m-01'))", "refId": "A", "sql": { "columns": [ diff --git a/grafana/dashboards/mysql/engineering-throughput-and-cycle-time-team-view.json b/grafana/dashboards/mysql/engineering-throughput-and-cycle-time-team-view.json index 82251d97eab..35635ebe45a 100644 --- a/grafana/dashboards/mysql/engineering-throughput-and-cycle-time-team-view.json +++ b/grafana/dashboards/mysql/engineering-throughput-and-cycle-time-team-view.json @@ -210,7 +210,7 @@ "hide": false, "metricColumn": "none", "rawQuery": true, - "rawSql": "with _prs as(\n SELECT\n pr.id,\n pr.url,\n pr.created_date,\n pr.merged_date,\n pr.author_id,\n u.id as user_id,\n u.name as user_name,\n t.id as team_id,\n t.name as team\n FROM pull_requests pr\n join user_accounts ua on pr.author_id = ua.account_id\n join users u on ua.user_id = u.id\n join team_users tu on u.id = tu.user_id\n join teams t on tu.team_id = t.id\n join project_mapping pm on pr.base_repo_id = pm.row_id and pm.table = 'repos' \n WHERE\n $__timeFilter(pr.created_date)\n and pm.project_name in (${project})\n)\n\nSELECT\n DATE_ADD(date(created_date), INTERVAL -$interval(date(created_date))+1 DAY) as time,\n count(distinct case when team_id in (${team1}) then id else null end) as \"Team1: Total PR Opened\",\n count(distinct case when team_id in (${team2}) then id else null end) as \"Team2: Total PR Opened\"\nFROM _prs\nGROUP BY 1", + "rawSql": "with _prs as(\n SELECT\n pr.id,\n pr.url,\n pr.created_date,\n pr.merged_date,\n pr.author_id,\n u.id as user_id,\n u.name as user_name,\n t.id as team_id,\n t.name as team\n FROM pull_requests pr\n join user_accounts ua on pr.author_id = ua.account_id\n join users u on ua.user_id = u.id\n join team_users tu on u.id = tu.user_id\n join teams t on tu.team_id = t.id\n join project_mapping pm on pr.base_repo_id = pm.row_id and pm.table = 'repos' \n WHERE\n $__timeFilter(pr.created_date)\n and pm.project_name in (${project})\n)\n\nSELECT\n DATE_ADD(date(created_date), INTERVAL -$interval(date(created_date))+1 DAY) as time,\n count(distinct case when team_id in (${team1:singlequote}) then id else null end) as \"Team1: Total PR Opened\",\n count(distinct case when team_id in (${team2:singlequote}) then id else null end) as \"Team2: Total PR Opened\"\nFROM _prs\nGROUP BY 1", "refId": "A", "select": [ [ @@ -380,7 +380,7 @@ "hide": false, "metricColumn": "none", "rawQuery": true, - "rawSql": "with _prs as(\n SELECT\n pr.id,\n pr.url,\n pr.created_date,\n pr.merged_date,\n pr.author_id,\n u.id as user_id,\n u.name as user_name,\n t.id as team_id,\n t.name as team\n FROM pull_requests pr\n join project_mapping pm on pr.base_repo_id = pm.row_id and pm.table = 'repos' \n join user_accounts ua on pr.author_id = ua.account_id\n join users u on ua.user_id = u.id\n join team_users tu on u.id = tu.user_id\n join teams t on tu.team_id = t.id\n WHERE\n $__timeFilter(pr.created_date)\n and pm.project_name in (${project})\n)\n\nSELECT\n DATE_ADD(date(created_date), INTERVAL -$interval(date(created_date))+1 DAY) as time,\n count(distinct case when team_id in (${team1}) then id else null end)/(select count(distinct user_id) from team_users where team_id in (${team1})) as \"Team1: PR Opened per Member\",\n count(distinct case when team_id in (${team2}) then id else null end)/(select count(distinct user_id) from team_users where team_id in (${team2})) as \"Team2: PR Opened per Member\",\n count(distinct id)/(select count(*) from users) as \"Org: PR Opened per Member\"\nFROM _prs\nGROUP BY 1", + "rawSql": "with _prs as(\n SELECT\n pr.id,\n pr.url,\n pr.created_date,\n pr.merged_date,\n pr.author_id,\n u.id as user_id,\n u.name as user_name,\n t.id as team_id,\n t.name as team\n FROM pull_requests pr\n join project_mapping pm on pr.base_repo_id = pm.row_id and pm.table = 'repos' \n join user_accounts ua on pr.author_id = ua.account_id\n join users u on ua.user_id = u.id\n join team_users tu on u.id = tu.user_id\n join teams t on tu.team_id = t.id\n WHERE\n $__timeFilter(pr.created_date)\n and pm.project_name in (${project})\n)\n\nSELECT\n DATE_ADD(date(created_date), INTERVAL -$interval(date(created_date))+1 DAY) as time,\n count(distinct case when team_id in (${team1:singlequote}) then id else null end)/(select count(distinct user_id) from team_users where team_id in (${team1:singlequote})) as \"Team1: PR Opened per Member\",\n count(distinct case when team_id in (${team2:singlequote}) then id else null end)/(select count(distinct user_id) from team_users where team_id in (${team2:singlequote})) as \"Team2: PR Opened per Member\",\n count(distinct id)/(select count(*) from users) as \"Org: PR Opened per Member\"\nFROM _prs\nGROUP BY 1", "refId": "A", "select": [ [ @@ -533,7 +533,7 @@ "hide": false, "metricColumn": "none", "rawQuery": true, - "rawSql": "with _prs as(\n SELECT\n pr.id,\n pr.url,\n pr.created_date,\n pr.merged_date,\n pr.author_id,\n u.id as user_id,\n u.name as user_name,\n t.id as team_id,\n t.name as team\n FROM pull_requests pr\n join project_mapping pm on pr.base_repo_id = pm.row_id and pm.table = 'repos' \n join user_accounts ua on pr.author_id = ua.account_id\n join users u on ua.user_id = u.id\n join team_users tu on u.id = tu.user_id\n join teams t on tu.team_id = t.id\n WHERE\n $__timeFilter(pr.created_date)\n and pm.project_name in (${project})\n)\n\nSELECT\n DATE_ADD(date(created_date), INTERVAL -$interval(date(created_date))+1 DAY) as time,\n count(distinct case \n when team_id in (${team1}) and merged_date is not null then id \n when team_id in (${team1}) and merged_date is null then null end) as \"Team1: Total PR Merged\",\n count(distinct case \n when team_id in (${team2}) and merged_date is not null then id \n when team_id in (${team2}) and merged_date is null then null end) as \"Team2: Total PR Merged\"\nFROM _prs\nGROUP BY 1", + "rawSql": "with _prs as(\n SELECT\n pr.id,\n pr.url,\n pr.created_date,\n pr.merged_date,\n pr.author_id,\n u.id as user_id,\n u.name as user_name,\n t.id as team_id,\n t.name as team\n FROM pull_requests pr\n join project_mapping pm on pr.base_repo_id = pm.row_id and pm.table = 'repos' \n join user_accounts ua on pr.author_id = ua.account_id\n join users u on ua.user_id = u.id\n join team_users tu on u.id = tu.user_id\n join teams t on tu.team_id = t.id\n WHERE\n $__timeFilter(pr.created_date)\n and pm.project_name in (${project})\n)\n\nSELECT\n DATE_ADD(date(created_date), INTERVAL -$interval(date(created_date))+1 DAY) as time,\n count(distinct case \n when team_id in (${team1:singlequote}) and merged_date is not null then id \n when team_id in (${team1:singlequote}) and merged_date is null then null end) as \"Team1: Total PR Merged\",\n count(distinct case \n when team_id in (${team2:singlequote}) and merged_date is not null then id \n when team_id in (${team2:singlequote}) and merged_date is null then null end) as \"Team2: Total PR Merged\"\nFROM _prs\nGROUP BY 1", "refId": "A", "select": [ [ @@ -686,7 +686,7 @@ "hide": false, "metricColumn": "none", "rawQuery": true, - "rawSql": "with _prs as(\n SELECT\n pr.id,\n pr.url,\n pr.created_date,\n pr.merged_date,\n pr.author_id,\n u.id as user_id,\n u.name as user_name,\n t.id as team_id,\n t.name as team\n FROM pull_requests pr\n join project_mapping pm on pr.base_repo_id = pm.row_id and pm.table = 'repos' \n join user_accounts ua on pr.author_id = ua.account_id\n join users u on ua.user_id = u.id\n join team_users tu on u.id = tu.user_id\n join teams t on tu.team_id = t.id\n WHERE\n $__timeFilter(pr.created_date)\n and pm.project_name in (${project})\n)\n\nSELECT\n DATE_ADD(date(created_date), INTERVAL -$interval(date(created_date))+1 DAY) as time,\n count(distinct case \n when team_id in (${team1}) and merged_date is not null then id \n when team_id in (${team1}) and merged_date is null then null end)/(select count(distinct user_id) from team_users where team_id in (${team1})) as \"Team1: PR Merged per Member\",\n count(distinct case \n when team_id in (${team2}) and merged_date is not null then id\n when team_id in (${team2}) and merged_date is null then null end)/(select count(distinct user_id) from team_users where team_id in (${team2})) as \"Team2: PR Merged per Member\",\n count(distinct case when merged_date is not null then id end)/(select count(*) from users) as \"Org: PR Merged per Member\"\nFROM _prs\nGROUP BY 1", + "rawSql": "with _prs as(\n SELECT\n pr.id,\n pr.url,\n pr.created_date,\n pr.merged_date,\n pr.author_id,\n u.id as user_id,\n u.name as user_name,\n t.id as team_id,\n t.name as team\n FROM pull_requests pr\n join project_mapping pm on pr.base_repo_id = pm.row_id and pm.table = 'repos' \n join user_accounts ua on pr.author_id = ua.account_id\n join users u on ua.user_id = u.id\n join team_users tu on u.id = tu.user_id\n join teams t on tu.team_id = t.id\n WHERE\n $__timeFilter(pr.created_date)\n and pm.project_name in (${project})\n)\n\nSELECT\n DATE_ADD(date(created_date), INTERVAL -$interval(date(created_date))+1 DAY) as time,\n count(distinct case \n when team_id in (${team1:singlequote}) and merged_date is not null then id \n when team_id in (${team1:singlequote}) and merged_date is null then null end)/(select count(distinct user_id) from team_users where team_id in (${team1:singlequote})) as \"Team1: PR Merged per Member\",\n count(distinct case \n when team_id in (${team2:singlequote}) and merged_date is not null then id\n when team_id in (${team2:singlequote}) and merged_date is null then null end)/(select count(distinct user_id) from team_users where team_id in (${team2:singlequote})) as \"Team2: PR Merged per Member\",\n count(distinct case when merged_date is not null then id end)/(select count(*) from users) as \"Org: PR Merged per Member\"\nFROM _prs\nGROUP BY 1", "refId": "A", "select": [ [ @@ -866,7 +866,7 @@ "hide": false, "metricColumn": "none", "rawQuery": true, - "rawSql": "with _issues as(\n SELECT\n i.id,\n i.url,\n i.created_date,\n i.status,\n i.assignee_id,\n i.story_point,\n i.priority,\n u.id as user_id,\n u.name as user_name,\n t.id as team_id,\n t.name as team\n FROM issues i\n\t join board_issues bi on i.id = bi.issue_id\n\t join boards b on bi.board_id = b.id\n\t join project_mapping pm on b.id = pm.row_id\n \tjoin user_accounts ua on i.assignee_id = ua.account_id\n join users u on ua.user_id = u.id\n join team_users tu on u.id = tu.user_id\n join teams t on tu.team_id = t.id\n WHERE\n $__timeFilter(i.created_date)\n and pm.project_name in (${project})\n)\n\nSELECT\n DATE_ADD(date(created_date), INTERVAL -$interval(date(created_date))+1 DAY) as time,\n -- count(i.id) as 'Issues Opened',\n count(distinct case when status = 'DONE' and team_id in (${team1}) then id else null end) as 'Team1: Issues Completed',\n count(distinct case when status = 'DONE' and team_id in (${team2}) then id else null end) as 'Team2: Issues Completed'\nFROM _issues\nGROUP BY 1", + "rawSql": "with _issues as(\n SELECT\n i.id,\n i.url,\n i.created_date,\n i.status,\n i.assignee_id,\n i.story_point,\n i.priority,\n u.id as user_id,\n u.name as user_name,\n t.id as team_id,\n t.name as team\n FROM issues i\n\t join board_issues bi on i.id = bi.issue_id\n\t join boards b on bi.board_id = b.id\n\t join project_mapping pm on b.id = pm.row_id\n \tjoin user_accounts ua on i.assignee_id = ua.account_id\n join users u on ua.user_id = u.id\n join team_users tu on u.id = tu.user_id\n join teams t on tu.team_id = t.id\n WHERE\n $__timeFilter(i.created_date)\n and pm.project_name in (${project})\n)\n\nSELECT\n DATE_ADD(date(created_date), INTERVAL -$interval(date(created_date))+1 DAY) as time,\n -- count(i.id) as 'Issues Opened',\n count(distinct case when status = 'DONE' and team_id in (${team1:singlequote}) then id else null end) as 'Team1: Issues Completed',\n count(distinct case when status = 'DONE' and team_id in (${team2:singlequote}) then id else null end) as 'Team2: Issues Completed'\nFROM _issues\nGROUP BY 1", "refId": "A", "select": [ [ @@ -1037,7 +1037,7 @@ "hide": false, "metricColumn": "none", "rawQuery": true, - "rawSql": "with _issues as(\n SELECT\n distinct i.id,\n i.url,\n i.created_date,\n i.status,\n i.assignee_id,\n i.story_point,\n i.priority,\n u.id as user_id,\n u.name as user_name,\n t.id as team_id,\n t.name as team\n FROM issues i\n\t join board_issues bi on i.id = bi.issue_id\n\t join boards b on bi.board_id = b.id\n\t join project_mapping pm on b.id = pm.row_id\n \tjoin user_accounts ua on i.assignee_id = ua.account_id\n join users u on ua.user_id = u.id\n join team_users tu on u.id = tu.user_id\n join teams t on tu.team_id = t.id\n WHERE\n $__timeFilter(i.created_date)\n and pm.project_name in (${project})\n ORDER BY 1\n)\n\nSELECT\n DATE_ADD(date(created_date), INTERVAL -$interval(date(created_date))+1 DAY) as time,\n count(distinct case when status = 'DONE' and team_id in (${team1}) then id else null end)/(select count(distinct user_id) from team_users where team_id in (${team1})) as 'Team1: Issues Completed per Member',\n count(distinct case when status = 'DONE' and team_id in (${team2}) then id else null end)/(select count(distinct user_id) from team_users where team_id in (${team2})) as 'Team2: Issues Completed per Member',\n count(distinct id)/(select count(*) from users) as \"Org: Issues Completed per Member\"\nFROM _issues\nGROUP BY 1", + "rawSql": "with _issues as(\n SELECT\n distinct i.id,\n i.url,\n i.created_date,\n i.status,\n i.assignee_id,\n i.story_point,\n i.priority,\n u.id as user_id,\n u.name as user_name,\n t.id as team_id,\n t.name as team\n FROM issues i\n\t join board_issues bi on i.id = bi.issue_id\n\t join boards b on bi.board_id = b.id\n\t join project_mapping pm on b.id = pm.row_id\n \tjoin user_accounts ua on i.assignee_id = ua.account_id\n join users u on ua.user_id = u.id\n join team_users tu on u.id = tu.user_id\n join teams t on tu.team_id = t.id\n WHERE\n $__timeFilter(i.created_date)\n and pm.project_name in (${project})\n ORDER BY 1\n)\n\nSELECT\n DATE_ADD(date(created_date), INTERVAL -$interval(date(created_date))+1 DAY) as time,\n count(distinct case when status = 'DONE' and team_id in (${team1:singlequote}) then id else null end)/(select count(distinct user_id) from team_users where team_id in (${team1:singlequote})) as 'Team1: Issues Completed per Member',\n count(distinct case when status = 'DONE' and team_id in (${team2:singlequote}) then id else null end)/(select count(distinct user_id) from team_users where team_id in (${team2:singlequote})) as 'Team2: Issues Completed per Member',\n count(distinct id)/(select count(*) from users) as \"Org: Issues Completed per Member\"\nFROM _issues\nGROUP BY 1", "refId": "A", "select": [ [ @@ -1234,7 +1234,7 @@ "hide": false, "metricColumn": "none", "rawQuery": true, - "rawSql": "with _issues as(\n SELECT\n distinct i.id,\n i.url,\n i.created_date,\n i.status,\n i.assignee_id,\n i.story_point,\n i.priority,\n u.id as user_id,\n u.name as user_name,\n t.id as team_id,\n t.name as team\n FROM issues i\n\t join board_issues bi on i.id = bi.issue_id\n\t join boards b on bi.board_id = b.id\n\t join project_mapping pm on b.id = pm.row_id\n \tjoin user_accounts ua on i.assignee_id = ua.account_id\n join users u on ua.user_id = u.id\n join team_users tu on u.id = tu.user_id\n join teams t on tu.team_id = t.id\n WHERE\n $__timeFilter(i.created_date)\n and pm.project_name in (${project})\n ORDER BY 1\n)\n\nSELECT\n DATE_ADD(date(created_date), INTERVAL -$interval(date(created_date))+1 DAY) as time,\n -- count(i.id) as 'Issues Opened',\n sum(case when status = 'DONE' and team_id in (${team1}) then story_point else 0 end) as 'Team1: Story Points Completed',\n sum(case when status = 'DONE' and team_id in (${team2}) then story_point else 0 end) as 'Team2: Story Points Completed'\nFROM _issues\nGROUP BY 1", + "rawSql": "with _issues as(\n SELECT\n distinct i.id,\n i.url,\n i.created_date,\n i.status,\n i.assignee_id,\n i.story_point,\n i.priority,\n u.id as user_id,\n u.name as user_name,\n t.id as team_id,\n t.name as team\n FROM issues i\n\t join board_issues bi on i.id = bi.issue_id\n\t join boards b on bi.board_id = b.id\n\t join project_mapping pm on b.id = pm.row_id\n \tjoin user_accounts ua on i.assignee_id = ua.account_id\n join users u on ua.user_id = u.id\n join team_users tu on u.id = tu.user_id\n join teams t on tu.team_id = t.id\n WHERE\n $__timeFilter(i.created_date)\n and pm.project_name in (${project})\n ORDER BY 1\n)\n\nSELECT\n DATE_ADD(date(created_date), INTERVAL -$interval(date(created_date))+1 DAY) as time,\n -- count(i.id) as 'Issues Opened',\n sum(case when status = 'DONE' and team_id in (${team1:singlequote}) then story_point else 0 end) as 'Team1: Story Points Completed',\n sum(case when status = 'DONE' and team_id in (${team2:singlequote}) then story_point else 0 end) as 'Team2: Story Points Completed'\nFROM _issues\nGROUP BY 1", "refId": "A", "select": [ [ @@ -1405,7 +1405,7 @@ "hide": false, "metricColumn": "none", "rawQuery": true, - "rawSql": "with _issues as(\n SELECT\n distinct i.id,\n i.url,\n i.created_date,\n i.status,\n i.assignee_id,\n i.story_point,\n i.priority,\n u.id as user_id,\n u.name as user_name,\n t.id as team_id,\n t.name as team\n FROM issues i\n\t join board_issues bi on i.id = bi.issue_id\n\t join boards b on bi.board_id = b.id\n\t join project_mapping pm on b.id = pm.row_id\n \tjoin user_accounts ua on i.assignee_id = ua.account_id\n join users u on ua.user_id = u.id\n join team_users tu on u.id = tu.user_id\n join teams t on tu.team_id = t.id\n WHERE\n $__timeFilter(i.created_date)\n and pm.project_name in (${project})\n ORDER BY 1\n)\n\nSELECT\n DATE_ADD(date(created_date), INTERVAL -$interval(date(created_date))+1 DAY) as time,\n sum(case when status = 'DONE' and team_id in (${team1}) then story_point else 0 end)/(select count(distinct user_id) from team_users where team_id in (${team1})) as 'Team1: Story Points Completed per Member',\n sum(case when status = 'DONE' and team_id in (${team2}) then story_point else 0 end)/(select count(distinct user_id) from team_users where team_id in (${team2})) as 'Team2: Story Points Completed per Member',\n count(distinct id)/(select count(*) FROM users) as \"Org: Story Points Completed per Member\"\nFROM _issues\nGROUP BY 1", + "rawSql": "with _issues as(\n SELECT\n distinct i.id,\n i.url,\n i.created_date,\n i.status,\n i.assignee_id,\n i.story_point,\n i.priority,\n u.id as user_id,\n u.name as user_name,\n t.id as team_id,\n t.name as team\n FROM issues i\n\t join board_issues bi on i.id = bi.issue_id\n\t join boards b on bi.board_id = b.id\n\t join project_mapping pm on b.id = pm.row_id\n \tjoin user_accounts ua on i.assignee_id = ua.account_id\n join users u on ua.user_id = u.id\n join team_users tu on u.id = tu.user_id\n join teams t on tu.team_id = t.id\n WHERE\n $__timeFilter(i.created_date)\n and pm.project_name in (${project})\n ORDER BY 1\n)\n\nSELECT\n DATE_ADD(date(created_date), INTERVAL -$interval(date(created_date))+1 DAY) as time,\n sum(case when status = 'DONE' and team_id in (${team1:singlequote}) then story_point else 0 end)/(select count(distinct user_id) from team_users where team_id in (${team1:singlequote})) as 'Team1: Story Points Completed per Member',\n sum(case when status = 'DONE' and team_id in (${team2:singlequote}) then story_point else 0 end)/(select count(distinct user_id) from team_users where team_id in (${team2:singlequote})) as 'Team2: Story Points Completed per Member',\n count(distinct id)/(select count(*) FROM users) as \"Org: Story Points Completed per Member\"\nFROM _issues\nGROUP BY 1", "refId": "A", "select": [ [ @@ -1602,7 +1602,7 @@ "hide": false, "metricColumn": "none", "rawQuery": true, - "rawSql": "with _merged_prs as(\n SELECT\n distinct pr.id,\n pr.url,\n pr.created_date,\n pr.merged_date,\n pr.author_id,\n prc.id as comment_id,\n u.id as user_id,\n u.name as user_name,\n t.id as team_id,\n t.name as team\n FROM pull_requests pr\n join project_mapping pm on pr.base_repo_id = pm.row_id and pm.table = 'repos' \n left join pull_request_comments prc on pr.id = prc.pull_request_id\n join user_accounts ua on pr.author_id = ua.account_id\n join users u on ua.user_id = u.id\n join team_users tu on u.id = tu.user_id\n join teams t on tu.team_id = t.id\n WHERE\n $__timeFilter(pr.created_date)\n and pm.project_name in (${project})\n and pr.merged_date is not null\n ORDER BY 1\n)\n\nselect\n DATE_ADD(date(created_date), INTERVAL -$interval(date(created_date))+1 DAY) as time,\n count(distinct case when team_id in (${team1}) then comment_id else null end)/(select count(distinct user_id) from team_users where team_id in (${team1})) as \"Team1: PR Review Depth\",\n count(distinct case when team_id in (${team2}) then comment_id else null end)/(select count(distinct user_id) from team_users where team_id in (${team2})) as \"Team2: PR Review Depth\",\n count(distinct comment_id)/(select count(*) FROM users) as \"Org: PR Review Depth\"\nFROM _merged_prs\nGROUP BY 1", + "rawSql": "with _merged_prs as(\n SELECT\n distinct pr.id,\n pr.url,\n pr.created_date,\n pr.merged_date,\n pr.author_id,\n prc.id as comment_id,\n u.id as user_id,\n u.name as user_name,\n t.id as team_id,\n t.name as team\n FROM pull_requests pr\n join project_mapping pm on pr.base_repo_id = pm.row_id and pm.table = 'repos' \n left join pull_request_comments prc on pr.id = prc.pull_request_id\n join user_accounts ua on pr.author_id = ua.account_id\n join users u on ua.user_id = u.id\n join team_users tu on u.id = tu.user_id\n join teams t on tu.team_id = t.id\n WHERE\n $__timeFilter(pr.created_date)\n and pm.project_name in (${project})\n and pr.merged_date is not null\n ORDER BY 1\n)\n\nselect\n DATE_ADD(date(created_date), INTERVAL -$interval(date(created_date))+1 DAY) as time,\n count(distinct case when team_id in (${team1:singlequote}) then comment_id else null end)/(select count(distinct user_id) from team_users where team_id in (${team1:singlequote})) as \"Team1: PR Review Depth\",\n count(distinct case when team_id in (${team2:singlequote}) then comment_id else null end)/(select count(distinct user_id) from team_users where team_id in (${team2:singlequote})) as \"Team2: PR Review Depth\",\n count(distinct comment_id)/(select count(*) FROM users) as \"Org: PR Review Depth\"\nFROM _merged_prs\nGROUP BY 1", "refId": "A", "select": [ [ @@ -1773,7 +1773,7 @@ "hide": false, "metricColumn": "none", "rawQuery": true, - "rawSql": "with _prs as(\n SELECT\n distinct pr.id,\n pr.url,\n pr.created_date,\n pr.merged_date,\n pr.author_id,\n pr.merge_commit_sha,\n c.additions + c.deletions as loc,\n u.id as user_id,\n u.name as user_name,\n t.id as team_id,\n t.name as team\n FROM pull_requests pr\n join project_mapping pm on pr.base_repo_id = pm.row_id and pm.table = 'repos' \n left join commits c on pr.merge_commit_sha = c.sha\n join user_accounts ua on pr.author_id = ua.account_id\n join users u on ua.user_id = u.id\n join team_users tu on u.id = tu.user_id\n join teams t on tu.team_id = t.id\n WHERE\n $__timeFilter(pr.created_date)\n and pm.project_name in (${project})\n and pr.status = 'MERGED'\n ORDER BY 1\n)\n\nselect\n DATE_ADD(date(created_date), INTERVAL -$interval(date(created_date))+1 DAY) as time,\n sum(case when team_id in (${team1}) then loc else null end)/(select count(distinct user_id) from team_users where team_id in (${team1})) as \"Team1: PR Size\",\n sum(case when team_id in (${team2}) then loc else null end)/(select count(distinct user_id) from team_users where team_id in (${team2})) as \"Team2: PR Size\",\n sum(loc)/(select count(*) FROM users) as \"Org: PR Merged Size\"\nFROM _prs\nGROUP BY 1\nORDER BY 1", + "rawSql": "with _prs as(\n SELECT\n distinct pr.id,\n pr.url,\n pr.created_date,\n pr.merged_date,\n pr.author_id,\n pr.merge_commit_sha,\n c.additions + c.deletions as loc,\n u.id as user_id,\n u.name as user_name,\n t.id as team_id,\n t.name as team\n FROM pull_requests pr\n join project_mapping pm on pr.base_repo_id = pm.row_id and pm.table = 'repos' \n left join commits c on pr.merge_commit_sha = c.sha\n join user_accounts ua on pr.author_id = ua.account_id\n join users u on ua.user_id = u.id\n join team_users tu on u.id = tu.user_id\n join teams t on tu.team_id = t.id\n WHERE\n $__timeFilter(pr.created_date)\n and pm.project_name in (${project})\n and pr.status = 'MERGED'\n ORDER BY 1\n)\n\nselect\n DATE_ADD(date(created_date), INTERVAL -$interval(date(created_date))+1 DAY) as time,\n sum(case when team_id in (${team1:singlequote}) then loc else null end)/(select count(distinct user_id) from team_users where team_id in (${team1:singlequote})) as \"Team1: PR Size\",\n sum(case when team_id in (${team2:singlequote}) then loc else null end)/(select count(distinct user_id) from team_users where team_id in (${team2:singlequote})) as \"Team2: PR Size\",\n sum(loc)/(select count(*) FROM users) as \"Org: PR Merged Size\"\nFROM _prs\nGROUP BY 1\nORDER BY 1", "refId": "A", "select": [ [ @@ -1970,7 +1970,7 @@ "hide": false, "metricColumn": "none", "rawQuery": true, - "rawSql": "with _bugs as(\n SELECT\n distinct i.id,\n i.url,\n i.created_date,\n i.status,\n i.assignee_id,\n i.story_point,\n i.priority,\n u.id as user_id,\n u.name as user_name,\n t.id as team_id,\n t.name as team\n FROM issues i\n\t join board_issues bi on i.id = bi.issue_id\n\t join boards b on bi.board_id = b.id\n\t join project_mapping pm on b.id = pm.row_id\n \tjoin user_accounts ua on i.assignee_id = ua.account_id\n join users u on ua.user_id = u.id\n join team_users tu on u.id = tu.user_id\n join teams t on tu.team_id = t.id\n WHERE\n $__timeFilter(i.created_date)\n and pm.project_name in (${project})\n and i.type = 'BUG'\n ORDER BY 1\n)\n\nSELECT\n DATE_ADD(date(created_date), INTERVAL -$interval(date(created_date))+1 DAY) as time,\n count(case when team_id in (${team1}) then id else null end) as 'Team1: P0/P1 Bugs',\n count(case when team_id in (${team2}) then id else null end) as 'Team2: P0/P1 Bugs'\nFROM _bugs\nWHERE\n -- please choose the priorities in the filter above\n priority in (${priority})\nGROUP BY 1\nORDER BY 1", + "rawSql": "with _bugs as(\n SELECT\n distinct i.id,\n i.url,\n i.created_date,\n i.status,\n i.assignee_id,\n i.story_point,\n i.priority,\n u.id as user_id,\n u.name as user_name,\n t.id as team_id,\n t.name as team\n FROM issues i\n\t join board_issues bi on i.id = bi.issue_id\n\t join boards b on bi.board_id = b.id\n\t join project_mapping pm on b.id = pm.row_id\n \tjoin user_accounts ua on i.assignee_id = ua.account_id\n join users u on ua.user_id = u.id\n join team_users tu on u.id = tu.user_id\n join teams t on tu.team_id = t.id\n WHERE\n $__timeFilter(i.created_date)\n and pm.project_name in (${project})\n and i.type = 'BUG'\n ORDER BY 1\n)\n\nSELECT\n DATE_ADD(date(created_date), INTERVAL -$interval(date(created_date))+1 DAY) as time,\n count(case when team_id in (${team1:singlequote}) then id else null end) as 'Team1: P0/P1 Bugs',\n count(case when team_id in (${team2:singlequote}) then id else null end) as 'Team2: P0/P1 Bugs'\nFROM _bugs\nWHERE\n -- please choose the priorities in the filter above\n priority in (${priority})\nGROUP BY 1\nORDER BY 1", "refId": "A", "select": [ [ @@ -2141,7 +2141,7 @@ "hide": false, "metricColumn": "none", "rawQuery": true, - "rawSql": "with _bugs as(\n SELECT\n distinct i.id,\n i.url,\n i.created_date,\n i.status,\n i.assignee_id,\n i.story_point,\n i.priority,\n u.id as user_id,\n u.name as user_name,\n t.id as team_id,\n t.name as team\n FROM issues i\n\t join board_issues bi on i.id = bi.issue_id\n\t join boards b on bi.board_id = b.id\n\t join project_mapping pm on b.id = pm.row_id\n \tjoin user_accounts ua on i.assignee_id = ua.account_id\n join users u on ua.user_id = u.id\n join team_users tu on u.id = tu.user_id\n join teams t on tu.team_id = t.id\n WHERE\n $__timeFilter(i.created_date)\n and pm.project_name in (${project})\n and i.type = 'BUG'\n ORDER BY 1\n)\n\nSELECT\n DATE_ADD(date(created_date), INTERVAL -$interval(date(created_date))+1 DAY) as time,\n count(case when team_id in (${team1}) then id else null end)/(select count(distinct user_id) from team_users where team_id in (${team1})) as 'Team1: P0/P1 Bugs per Member',\n count(case when team_id in (${team2}) then id else null end)/(select count(distinct user_id) from team_users where team_id in (${team2})) as 'Team2: P0/P1 Bugs per Member',\n count(distinct id)/(select count(*) FROM users) as \"Org: P0/P1 Bugs per Member\"\nFROM _bugs\nWHERE\n -- please choose the priorities in the filter above\n priority in (${priority})\nGROUP BY 1\nORDER BY 1", + "rawSql": "with _bugs as(\n SELECT\n distinct i.id,\n i.url,\n i.created_date,\n i.status,\n i.assignee_id,\n i.story_point,\n i.priority,\n u.id as user_id,\n u.name as user_name,\n t.id as team_id,\n t.name as team\n FROM issues i\n\t join board_issues bi on i.id = bi.issue_id\n\t join boards b on bi.board_id = b.id\n\t join project_mapping pm on b.id = pm.row_id\n \tjoin user_accounts ua on i.assignee_id = ua.account_id\n join users u on ua.user_id = u.id\n join team_users tu on u.id = tu.user_id\n join teams t on tu.team_id = t.id\n WHERE\n $__timeFilter(i.created_date)\n and pm.project_name in (${project})\n and i.type = 'BUG'\n ORDER BY 1\n)\n\nSELECT\n DATE_ADD(date(created_date), INTERVAL -$interval(date(created_date))+1 DAY) as time,\n count(case when team_id in (${team1:singlequote}) then id else null end)/(select count(distinct user_id) from team_users where team_id in (${team1:singlequote})) as 'Team1: P0/P1 Bugs per Member',\n count(case when team_id in (${team2:singlequote}) then id else null end)/(select count(distinct user_id) from team_users where team_id in (${team2:singlequote})) as 'Team2: P0/P1 Bugs per Member',\n count(distinct id)/(select count(*) FROM users) as \"Org: P0/P1 Bugs per Member\"\nFROM _bugs\nWHERE\n -- please choose the priorities in the filter above\n priority in (${priority})\nGROUP BY 1\nORDER BY 1", "refId": "A", "select": [ [ @@ -2335,7 +2335,7 @@ "hide": false, "metricColumn": "none", "rawQuery": true, - "rawSql": "with _prs as(\n SELECT\n pr.id,\n pr.merged_date as pr_merged_date,\n -- convert null to 0 if a PR has no cycle_time to make sure cycle_time equals the sum of the four metrics below\n\t\tcoalesce(prm.pr_cycle_time/60,0) as cycle_time,\n\t\tpr.author_id,\n u.id as user_id,\n u.name as user_name,\n t.id as team_id,\n t.name as team\n FROM pull_requests pr\n join project_mapping pm on pr.base_repo_id = pm.row_id and pm.table = 'repos' \n\t\tleft join project_pr_metrics prm on pr.id = prm.id\n left join user_accounts ua on pr.author_id = ua.account_id\n left join users u on ua.user_id = u.id\n left join team_users tu on u.id = tu.user_id\n left join teams t on tu.team_id = t.id\n WHERE\n $__timeFilter(pr.merged_date)\n and pm.project_name in (${project})\n GROUP BY 1,2,3,4,5,6,7,8\n)\n\nSELECT \n DATE_ADD(date(pr_merged_date), INTERVAL -$interval(date(pr_merged_date))+1 DAY) as time,\n avg(case when team_id in (${team1}) then cycle_time end) as 'Team1: Avg Cycle Time(h)',\n avg(case when team_id in (${team2}) then cycle_time end) as 'Team2: Avg Cycle Time(h)'\nFROM _prs\nGROUP BY 1\nORDER BY 1", + "rawSql": "with _prs as(\n SELECT\n pr.id,\n pr.merged_date as pr_merged_date,\n -- convert null to 0 if a PR has no cycle_time to make sure cycle_time equals the sum of the four metrics below\n\t\tcoalesce(prm.pr_cycle_time/60,0) as cycle_time,\n\t\tpr.author_id,\n u.id as user_id,\n u.name as user_name,\n t.id as team_id,\n t.name as team\n FROM pull_requests pr\n join project_mapping pm on pr.base_repo_id = pm.row_id and pm.table = 'repos' \n\t\tleft join project_pr_metrics prm on pr.id = prm.id\n left join user_accounts ua on pr.author_id = ua.account_id\n left join users u on ua.user_id = u.id\n left join team_users tu on u.id = tu.user_id\n left join teams t on tu.team_id = t.id\n WHERE\n $__timeFilter(pr.merged_date)\n and pm.project_name in (${project})\n GROUP BY 1,2,3,4,5,6,7,8\n)\n\nSELECT \n DATE_ADD(date(pr_merged_date), INTERVAL -$interval(date(pr_merged_date))+1 DAY) as time,\n avg(case when team_id in (${team1:singlequote}) then cycle_time end) as 'Team1: Avg Cycle Time(h)',\n avg(case when team_id in (${team2:singlequote}) then cycle_time end) as 'Team2: Avg Cycle Time(h)'\nFROM _prs\nGROUP BY 1\nORDER BY 1", "refId": "A", "select": [ [ @@ -2502,7 +2502,7 @@ "hide": false, "metricColumn": "none", "rawQuery": true, - "rawSql": "with _prs as(\n SELECT\n pr.id,\n pr.merged_date as pr_merged_date,\n -- convert null to 0 if a PR has no coding_time to make sure cycle_time equals the sum of the four sub-metrics\n\t\tcoalesce(prm.pr_coding_time/60,0) as coding_time,\n\t\tpr.author_id,\n u.id as user_id,\n u.name as user_name,\n t.id as team_id,\n t.name as team\n FROM pull_requests pr\n join project_mapping pm on pr.base_repo_id = pm.row_id and pm.table = 'repos' \n\t\tleft join project_pr_metrics prm on pr.id = prm.id\n left join user_accounts ua on pr.author_id = ua.account_id\n left join users u on ua.user_id = u.id\n left join team_users tu on u.id = tu.user_id\n left join teams t on tu.team_id = t.id\n WHERE\n $__timeFilter(pr.merged_date)\n and pm.project_name in (${project})\n GROUP BY 1,2,3,4,5,6,7,8\n)\n\nSELECT \n DATE_ADD(date(pr_merged_date), INTERVAL -$interval(date(pr_merged_date))+1 DAY) as time,\n avg(case when team_id in (${team1}) then coding_time end) as 'Team1: Avg Coding Time(h)',\n avg(case when team_id in (${team2}) then coding_time end) as 'Team2: Avg Coding Time(h)'\nFROM _prs\nGROUP BY 1\nORDER BY 1", + "rawSql": "with _prs as(\n SELECT\n pr.id,\n pr.merged_date as pr_merged_date,\n -- convert null to 0 if a PR has no coding_time to make sure cycle_time equals the sum of the four sub-metrics\n\t\tcoalesce(prm.pr_coding_time/60,0) as coding_time,\n\t\tpr.author_id,\n u.id as user_id,\n u.name as user_name,\n t.id as team_id,\n t.name as team\n FROM pull_requests pr\n join project_mapping pm on pr.base_repo_id = pm.row_id and pm.table = 'repos' \n\t\tleft join project_pr_metrics prm on pr.id = prm.id\n left join user_accounts ua on pr.author_id = ua.account_id\n left join users u on ua.user_id = u.id\n left join team_users tu on u.id = tu.user_id\n left join teams t on tu.team_id = t.id\n WHERE\n $__timeFilter(pr.merged_date)\n and pm.project_name in (${project})\n GROUP BY 1,2,3,4,5,6,7,8\n)\n\nSELECT \n DATE_ADD(date(pr_merged_date), INTERVAL -$interval(date(pr_merged_date))+1 DAY) as time,\n avg(case when team_id in (${team1:singlequote}) then coding_time end) as 'Team1: Avg Coding Time(h)',\n avg(case when team_id in (${team2:singlequote}) then coding_time end) as 'Team2: Avg Coding Time(h)'\nFROM _prs\nGROUP BY 1\nORDER BY 1", "refId": "A", "select": [ [ @@ -2669,7 +2669,7 @@ "hide": false, "metricColumn": "none", "rawQuery": true, - "rawSql": "with _prs as(\n SELECT\n pr.id,\n pr.merged_date as pr_merged_date,\n -- convert null to 0 if a PR has no pickup_time to make sure cycle_time equals the sum of the four sub-metrics\n\t\tcoalesce(prm.pr_pickup_time/60,0) as pickup_time,\n\t\tpr.author_id,\n u.id as user_id,\n u.name as user_name,\n t.id as team_id,\n t.name as team\n FROM pull_requests pr\n join project_mapping pm on pr.base_repo_id = pm.row_id and pm.table = 'repos' \n\t\tleft join project_pr_metrics prm on pr.id = prm.id\n left join user_accounts ua on pr.author_id = ua.account_id\n left join users u on ua.user_id = u.id\n left join team_users tu on u.id = tu.user_id\n left join teams t on tu.team_id = t.id\n WHERE\n $__timeFilter(pr.merged_date)\n and pm.project_name in (${project})\n GROUP BY 1,2,3,4,5,6,7,8\n)\n\nSELECT \n DATE_ADD(date(pr_merged_date), INTERVAL -$interval(date(pr_merged_date))+1 DAY) as time,\n avg(case when team_id in (${team1}) then pickup_time end) as 'Team1: Avg Pickup Time(h)',\n avg(case when team_id in (${team2}) then pickup_time end) as 'Team2: Avg Pickup Time(h)'\nFROM _prs\nGROUP BY 1\nORDER BY 1", + "rawSql": "with _prs as(\n SELECT\n pr.id,\n pr.merged_date as pr_merged_date,\n -- convert null to 0 if a PR has no pickup_time to make sure cycle_time equals the sum of the four sub-metrics\n\t\tcoalesce(prm.pr_pickup_time/60,0) as pickup_time,\n\t\tpr.author_id,\n u.id as user_id,\n u.name as user_name,\n t.id as team_id,\n t.name as team\n FROM pull_requests pr\n join project_mapping pm on pr.base_repo_id = pm.row_id and pm.table = 'repos' \n\t\tleft join project_pr_metrics prm on pr.id = prm.id\n left join user_accounts ua on pr.author_id = ua.account_id\n left join users u on ua.user_id = u.id\n left join team_users tu on u.id = tu.user_id\n left join teams t on tu.team_id = t.id\n WHERE\n $__timeFilter(pr.merged_date)\n and pm.project_name in (${project})\n GROUP BY 1,2,3,4,5,6,7,8\n)\n\nSELECT \n DATE_ADD(date(pr_merged_date), INTERVAL -$interval(date(pr_merged_date))+1 DAY) as time,\n avg(case when team_id in (${team1:singlequote}) then pickup_time end) as 'Team1: Avg Pickup Time(h)',\n avg(case when team_id in (${team2:singlequote}) then pickup_time end) as 'Team2: Avg Pickup Time(h)'\nFROM _prs\nGROUP BY 1\nORDER BY 1", "refId": "A", "select": [ [ @@ -2836,7 +2836,7 @@ "hide": false, "metricColumn": "none", "rawQuery": true, - "rawSql": "with _prs as(\n SELECT\n pr.id,\n pr.merged_date as pr_merged_date,\n -- convert null to 0 if a PR has no review_time to make sure cycle_time equals the sum of the four sub-metrics\n\t\tcoalesce(prm.pr_review_time/60,0) as review_time,\n\t\tpr.author_id,\n u.id as user_id,\n u.name as user_name,\n t.id as team_id,\n t.name as team\n FROM pull_requests pr\n join project_mapping pm on pr.base_repo_id = pm.row_id and pm.table = 'repos' \n\t\tleft join project_pr_metrics prm on pr.id = prm.id\n left join user_accounts ua on pr.author_id = ua.account_id\n left join users u on ua.user_id = u.id\n left join team_users tu on u.id = tu.user_id\n left join teams t on tu.team_id = t.id\n WHERE\n $__timeFilter(pr.merged_date)\n and pm.project_name in (${project})\n GROUP BY 1,2,3,4,5,6,7,8\n)\n\nSELECT \n DATE_ADD(date(pr_merged_date), INTERVAL -$interval(date(pr_merged_date))+1 DAY) as time,\n avg(case when team_id in (${team1}) then review_time end) as 'Team1: Avg Review Time(h)',\n avg(case when team_id in (${team2}) then review_time end) as 'Team2: Avg Review Time(h)'\nFROM _prs\nGROUP BY 1\nORDER BY 1", + "rawSql": "with _prs as(\n SELECT\n pr.id,\n pr.merged_date as pr_merged_date,\n -- convert null to 0 if a PR has no review_time to make sure cycle_time equals the sum of the four sub-metrics\n\t\tcoalesce(prm.pr_review_time/60,0) as review_time,\n\t\tpr.author_id,\n u.id as user_id,\n u.name as user_name,\n t.id as team_id,\n t.name as team\n FROM pull_requests pr\n join project_mapping pm on pr.base_repo_id = pm.row_id and pm.table = 'repos' \n\t\tleft join project_pr_metrics prm on pr.id = prm.id\n left join user_accounts ua on pr.author_id = ua.account_id\n left join users u on ua.user_id = u.id\n left join team_users tu on u.id = tu.user_id\n left join teams t on tu.team_id = t.id\n WHERE\n $__timeFilter(pr.merged_date)\n and pm.project_name in (${project})\n GROUP BY 1,2,3,4,5,6,7,8\n)\n\nSELECT \n DATE_ADD(date(pr_merged_date), INTERVAL -$interval(date(pr_merged_date))+1 DAY) as time,\n avg(case when team_id in (${team1:singlequote}) then review_time end) as 'Team1: Avg Review Time(h)',\n avg(case when team_id in (${team2:singlequote}) then review_time end) as 'Team2: Avg Review Time(h)'\nFROM _prs\nGROUP BY 1\nORDER BY 1", "refId": "A", "select": [ [ @@ -3003,7 +3003,7 @@ "hide": false, "metricColumn": "none", "rawQuery": true, - "rawSql": "with _prs as(\n SELECT\n pr.id,\n pr.merged_date as pr_merged_date,\n -- convert null to 0 if a PR has no deploy_time to make sure cycle_time equals the sum of the four sub-metrics\n\t\tcoalesce(prm.pr_deploy_time/60,0) as deploy_time,\n\t\tpr.author_id,\n u.id as user_id,\n u.name as user_name,\n t.id as team_id,\n t.name as team\n FROM pull_requests pr\n join project_mapping pm on pr.base_repo_id = pm.row_id and pm.table = 'repos' \n\t\tleft join project_pr_metrics prm on pr.id = prm.id\n left join user_accounts ua on pr.author_id = ua.account_id\n left join users u on ua.user_id = u.id\n left join team_users tu on u.id = tu.user_id\n left join teams t on tu.team_id = t.id\n WHERE\n $__timeFilter(pr.merged_date)\n and pm.project_name in (${project})\n GROUP BY 1,2,3,4,5,6,7,8\n)\n\nSELECT \n DATE_ADD(date(pr_merged_date), INTERVAL -$interval(date(pr_merged_date))+1 DAY) as time,\n avg(case when team_id in (${team1}) then deploy_time end) as 'Team1: Avg Deploy Time(h)',\n avg(case when team_id in (${team2}) then deploy_time end) as 'Team2: Avg Deploy Time(h)'\nFROM _prs\nGROUP BY 1\nORDER BY 1", + "rawSql": "with _prs as(\n SELECT\n pr.id,\n pr.merged_date as pr_merged_date,\n -- convert null to 0 if a PR has no deploy_time to make sure cycle_time equals the sum of the four sub-metrics\n\t\tcoalesce(prm.pr_deploy_time/60,0) as deploy_time,\n\t\tpr.author_id,\n u.id as user_id,\n u.name as user_name,\n t.id as team_id,\n t.name as team\n FROM pull_requests pr\n join project_mapping pm on pr.base_repo_id = pm.row_id and pm.table = 'repos' \n\t\tleft join project_pr_metrics prm on pr.id = prm.id\n left join user_accounts ua on pr.author_id = ua.account_id\n left join users u on ua.user_id = u.id\n left join team_users tu on u.id = tu.user_id\n left join teams t on tu.team_id = t.id\n WHERE\n $__timeFilter(pr.merged_date)\n and pm.project_name in (${project})\n GROUP BY 1,2,3,4,5,6,7,8\n)\n\nSELECT \n DATE_ADD(date(pr_merged_date), INTERVAL -$interval(date(pr_merged_date))+1 DAY) as time,\n avg(case when team_id in (${team1:singlequote}) then deploy_time end) as 'Team1: Avg Deploy Time(h)',\n avg(case when team_id in (${team2:singlequote}) then deploy_time end) as 'Team2: Avg Deploy Time(h)'\nFROM _prs\nGROUP BY 1\nORDER BY 1", "refId": "A", "select": [ [ @@ -3196,7 +3196,7 @@ "hide": false, "metricColumn": "none", "rawQuery": true, - "rawSql": "with _merged_prs as(\n SELECT\n distinct pr.id,\n pr.url,\n pr.created_date,\n pr.merged_date,\n pr.author_id,\n u.id as user_id,\n u.name as user_name,\n t.id as team_id,\n t.name as team\n FROM pull_requests pr\n join project_mapping pm on pr.base_repo_id = pm.row_id and pm.table = 'repos' \n join user_accounts ua on pr.author_id = ua.account_id\n join users u on ua.user_id = u.id\n join team_users tu on u.id = tu.user_id\n join teams t on tu.team_id = t.id\n WHERE\n $__timeFilter(pr.created_date)\n and pm.project_name in (${project})\n and pr.merged_date is not null\n ORDER BY 1\n)\n\nSELECT\n DATE_ADD(date(created_date), INTERVAL -$interval(date(created_date))+1 DAY) as time,\n count(distinct case when team_id in (${team1}) and id not in (SELECT pull_request_id FROM pull_request_comments) then id else null end) as \"Team1: PRs Merged w/o Review\",\n count(distinct case when team_id in (${team2}) and id not in (SELECT pull_request_id FROM pull_request_comments) then id else null end) as \"Team2: PRs Merged w/o Review\"\nFROM _merged_prs\nGROUP BY 1", + "rawSql": "with _merged_prs as(\n SELECT\n distinct pr.id,\n pr.url,\n pr.created_date,\n pr.merged_date,\n pr.author_id,\n u.id as user_id,\n u.name as user_name,\n t.id as team_id,\n t.name as team\n FROM pull_requests pr\n join project_mapping pm on pr.base_repo_id = pm.row_id and pm.table = 'repos' \n join user_accounts ua on pr.author_id = ua.account_id\n join users u on ua.user_id = u.id\n join team_users tu on u.id = tu.user_id\n join teams t on tu.team_id = t.id\n WHERE\n $__timeFilter(pr.created_date)\n and pm.project_name in (${project})\n and pr.merged_date is not null\n ORDER BY 1\n)\n\nSELECT\n DATE_ADD(date(created_date), INTERVAL -$interval(date(created_date))+1 DAY) as time,\n count(distinct case when team_id in (${team1:singlequote}) and id not in (SELECT pull_request_id FROM pull_request_comments) then id else null end) as \"Team1: PRs Merged w/o Review\",\n count(distinct case when team_id in (${team2:singlequote}) and id not in (SELECT pull_request_id FROM pull_request_comments) then id else null end) as \"Team2: PRs Merged w/o Review\"\nFROM _merged_prs\nGROUP BY 1", "refId": "A", "select": [ [ diff --git a/grafana/dashboards/mysql/work-logs.json b/grafana/dashboards/mysql/work-logs.json index ba2da4761e8..6125c71a7be 100644 --- a/grafana/dashboards/mysql/work-logs.json +++ b/grafana/dashboards/mysql/work-logs.json @@ -216,7 +216,7 @@ "editorMode": "code", "format": "table", "rawQuery": true, - "rawSql": "with _accounts as (\n select ua.account_id, ua.user_id, u.name\n from accounts a \n join user_accounts ua on a.id = ua.account_id\n join users u on ua.user_id = u.id\n where ua.user_id in ($users)\n),\n\n_activities as (\n SELECT \n *,\n ROW_NUMBER() OVER (PARTITION BY `Date` ORDER BY `Time` desc) AS _row_number\n FROM (\n SELECT DATE_FORMAT(created_date, '%Y-%m-%d | %W') as Date, created_date as Time, 'Create an issue' as Activity, concat('#', issue_key, ' ', title) as Details, a.name as Name\n FROM issues i\n join _accounts a on i.creator_id = a.account_id\n where $__timeFilter(created_date)\n\n union\n\n SELECT DATE_FORMAT(resolution_date, '%Y-%m-%d | %W') as Date, resolution_date as Time, 'Issue resolved' as Activity, concat('#', issue_key, ' ', title) as Details, a.name as Name \n FROM issues i\n join _accounts a on i.assignee_id = a.account_id\n where $__timeFilter(resolution_date)\n\n union\n\n SELECT DATE_FORMAT(authored_date, '%Y-%m-%d | %W') as Date, authored_date as Time, 'Finish a commit' as Activity, concat(message, ' #', sha) as Details, a.name as Name \n FROM commits c\n join _accounts a on c.author_id = a.account_id\n where $__timeFilter(authored_date)\n\n union\n\n SELECT DATE_FORMAT(created_date, '%Y-%m-%d | %W') as Date, created_date as Time, 'Open a PR' as Activity, concat('#', pull_request_key, ' ', title) as Details, a.name as Name\n FROM pull_requests pr\n join _accounts a on pr.author_id = a.account_id\n where $__timeFilter(created_date)\n\n union\n\n SELECT DATE_FORMAT(merged_date, '%Y-%m-%d | %W') as Date, merged_date as Time, 'PR gets merged' as Activity, concat('#', pull_request_key, ' ', title) as Details, a.name as Name \n FROM pull_requests pr\n join _accounts a on pr.author_id = a.account_id\n where $__timeFilter(merged_date)\n\n union\n\n SELECT DATE_FORMAT(prc.created_date, '%Y-%m-%d | %W') as Date, prc.created_date as Time, 'Comment on PR' as Activity, concat('#', pr.pull_request_key, ' ', pr.title) as Details, a.name as Name \n FROM pull_request_comments prc\n left join pull_requests pr on prc.pull_request_id = pr.id\n join _accounts a on prc.account_id = a.account_id\n WHERE \n prc.type = 'NORMAL'\n and $__timeFilter(prc.created_date)\n\n union\n\n SELECT DATE_FORMAT(prc.created_date, '%Y-%m-%d | %W') as Date, prc.created_date as Time, 'Review PR' as Activity, concat('#', pr.pull_request_key, ' ', pr.title) as Details, a.name as Name \n FROM pull_request_comments prc\n left join pull_requests pr on prc.pull_request_id = pr.id\n join _accounts a on prc.account_id = a.account_id\n WHERE \n prc.type in ('REVIEW', 'DIFF')\n and $__timeFilter(prc.created_date)\n ) t\n\n ORDER BY Time desc\n)\n\nSELECT \n CASE WHEN _row_number = 1 THEN `Date` ELSE NULL END AS `Date`, `Time`, Activity, Details, Name\nFROM _activities", + "rawSql": "with _accounts as (\n select ua.account_id, ua.user_id, u.name\n from accounts a \n join user_accounts ua on a.id = ua.account_id\n join users u on ua.user_id = u.id\n where ua.user_id in (${users:singlequote})\n),\n\n_activities as (\n SELECT \n *,\n ROW_NUMBER() OVER (PARTITION BY `Date` ORDER BY `Time` desc) AS _row_number\n FROM (\n SELECT DATE_FORMAT(created_date, '%Y-%m-%d | %W') as Date, created_date as Time, 'Create an issue' as Activity, concat('#', issue_key, ' ', title) as Details, a.name as Name\n FROM issues i\n join _accounts a on i.creator_id = a.account_id\n where $__timeFilter(created_date)\n\n union\n\n SELECT DATE_FORMAT(resolution_date, '%Y-%m-%d | %W') as Date, resolution_date as Time, 'Issue resolved' as Activity, concat('#', issue_key, ' ', title) as Details, a.name as Name \n FROM issues i\n join _accounts a on i.assignee_id = a.account_id\n where $__timeFilter(resolution_date)\n\n union\n\n SELECT DATE_FORMAT(authored_date, '%Y-%m-%d | %W') as Date, authored_date as Time, 'Finish a commit' as Activity, concat(message, ' #', sha) as Details, a.name as Name \n FROM commits c\n join _accounts a on c.author_id = a.account_id\n where $__timeFilter(authored_date)\n\n union\n\n SELECT DATE_FORMAT(created_date, '%Y-%m-%d | %W') as Date, created_date as Time, 'Open a PR' as Activity, concat('#', pull_request_key, ' ', title) as Details, a.name as Name\n FROM pull_requests pr\n join _accounts a on pr.author_id = a.account_id\n where $__timeFilter(created_date)\n\n union\n\n SELECT DATE_FORMAT(merged_date, '%Y-%m-%d | %W') as Date, merged_date as Time, 'PR gets merged' as Activity, concat('#', pull_request_key, ' ', title) as Details, a.name as Name \n FROM pull_requests pr\n join _accounts a on pr.author_id = a.account_id\n where $__timeFilter(merged_date)\n\n union\n\n SELECT DATE_FORMAT(prc.created_date, '%Y-%m-%d | %W') as Date, prc.created_date as Time, 'Comment on PR' as Activity, concat('#', pr.pull_request_key, ' ', pr.title) as Details, a.name as Name \n FROM pull_request_comments prc\n left join pull_requests pr on prc.pull_request_id = pr.id\n join _accounts a on prc.account_id = a.account_id\n WHERE \n prc.type = 'NORMAL'\n and $__timeFilter(prc.created_date)\n\n union\n\n SELECT DATE_FORMAT(prc.created_date, '%Y-%m-%d | %W') as Date, prc.created_date as Time, 'Review PR' as Activity, concat('#', pr.pull_request_key, ' ', pr.title) as Details, a.name as Name \n FROM pull_request_comments prc\n left join pull_requests pr on prc.pull_request_id = pr.id\n join _accounts a on prc.account_id = a.account_id\n WHERE \n prc.type in ('REVIEW', 'DIFF')\n and $__timeFilter(prc.created_date)\n ) t\n\n ORDER BY Time desc\n)\n\nSELECT \n CASE WHEN _row_number = 1 THEN `Date` ELSE NULL END AS `Date`, `Time`, Activity, Details, Name\nFROM _activities", "refId": "A", "sql": { "columns": [ @@ -359,7 +359,7 @@ "editorMode": "code", "format": "table", "rawQuery": true, - "rawSql": "with _accounts as (\n select ua.account_id, ua.user_id, u.name\n from accounts a \n join user_accounts ua on a.id = ua.account_id\n join users u on ua.user_id = u.id\n where ua.user_id in ($users)\n),\n\n_activities as (\n SELECT \n *,\n ROW_NUMBER() OVER (PARTITION BY `Date` ORDER BY `Time` desc) AS _row_number\n FROM (\n SELECT DATE(created_date) as Date, created_date as Time, 'Create an issue' as Activity, concat('#', issue_key, ' ', title) as Details, a.name as Name\n FROM issues i\n join _accounts a on i.creator_id = a.account_id\n where $__timeFilter(created_date)\n\n union\n\n SELECT DATE(resolution_date) as Date, resolution_date as Time, 'Issue resolved' as Activity, concat('#', issue_key, ' ', title) as Details, a.name as Name \n FROM issues i\n join _accounts a on i.assignee_id = a.account_id\n where $__timeFilter(resolution_date)\n\n union\n\n SELECT DATE(authored_date) as Date, authored_date as Time, 'Finish a commit' as Activity, concat(message, ' #', sha) as Details, a.name as Name \n FROM commits c\n join _accounts a on c.author_id = a.account_id\n where $__timeFilter(authored_date)\n\n union\n\n SELECT DATE(created_date) as Date, created_date as Time, 'Open a PR' as Activity, concat('#', pull_request_key, ' ', title) as Details, a.name as Name\n FROM pull_requests pr\n join _accounts a on pr.author_id = a.account_id\n where $__timeFilter(created_date)\n\n union\n\n SELECT DATE(merged_date) as Date, merged_date as Time, 'PR gets merged' as Activity, concat('#', pull_request_key, ' ', title) as Details, a.name as Name \n FROM pull_requests pr\n join _accounts a on pr.author_id = a.account_id\n where $__timeFilter(merged_date)\n\n union\n\n SELECT DATE(prc.created_date) as Date, prc.created_date as Time, 'Comment on PR' as Activity, concat('#', pr.pull_request_key, ' ', pr.title) as Details, a.name as Name \n FROM pull_request_comments prc\n left join pull_requests pr on prc.pull_request_id = pr.id\n join _accounts a on prc.account_id = a.account_id\n WHERE \n prc.type = 'NORMAL'\n and $__timeFilter(prc.created_date)\n\n union\n\n SELECT DATE(prc.created_date) as Date, prc.created_date as Time, 'Review PR' as Activity, concat('#', pr.pull_request_key, ' ', pr.title) as Details, a.name as Name \n FROM pull_request_comments prc\n left join pull_requests pr on prc.pull_request_id = pr.id\n join _accounts a on prc.account_id = a.account_id\n WHERE \n prc.type in ('REVIEW', 'DIFF')\n and $__timeFilter(prc.created_date)\n ) t\n\n ORDER BY Time desc\n),\n\n_activity_count_per_day as (\n SELECT \n Date,\n count(*) as value\n FROM _activities\n GROUP BY 1\n),\n\nlast_few_calendar_months as(\n-- construct the last few calendar months within the selected time period in the top-right corner\n\tSELECT \n CAST(($__timeTo()-INTERVAL (H+T+U) DAY) AS date) as d, \n DATE_FORMAT(CAST(($__timeTo()-INTERVAL (H+T+U) DAY) AS date), 'w%u %Y') as week_name,\n DATE_FORMAT(CAST(($__timeTo()-INTERVAL (H+T+U) DAY) AS date), '%Y%u') as week_number\n\tFROM ( SELECT 0 H\n\t\t\tUNION ALL SELECT 100 UNION ALL SELECT 200 UNION ALL SELECT 300\n\t\t) H CROSS JOIN ( SELECT 0 T\n\t\t\tUNION ALL SELECT 10 UNION ALL SELECT 20 UNION ALL SELECT 30\n\t\t\tUNION ALL SELECT 40 UNION ALL SELECT 50 UNION ALL SELECT 60\n\t\t\tUNION ALL SELECT 70 UNION ALL SELECT 80 UNION ALL SELECT 90\n\t\t) T CROSS JOIN ( SELECT 0 U\n\t\t\tUNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3\n\t\t\tUNION ALL SELECT 4 UNION ALL SELECT 5 UNION ALL SELECT 6\n\t\t\tUNION ALL SELECT 7 UNION ALL SELECT 8 UNION ALL SELECT 9\n\t\t) U\n\tWHERE\n\t\t($__timeTo()-INTERVAL (H+T+U) DAY) > $__timeFrom()\n),\n\n_calendar_months_with_rank as (\n SELECT \n d, \n concat(week_name, ' (', DATE_FORMAT(DATE_SUB(d, INTERVAL WEEKDAY(d) DAY), '%m/%d'), ' ~ ', DATE_FORMAT(DATE_ADD(DATE_SUB(d, INTERVAL WEEKDAY(d) DAY), INTERVAL 6 DAY), '%m/%d'), ')') as week_name,\n week_number,\n DATE_FORMAT(d, '%W') as weekday,\n dense_rank() over(ORDER BY week_number desc) as week_rank\n FROM last_few_calendar_months\n ORDER BY 1 desc\n),\n\n_final_dataset as (\n SELECT \n _calendar_months_with_rank.*, \n case when _activity_count_per_day.value is null then 0 else _activity_count_per_day.value end as activity_count \n from _calendar_months_with_rank left join _activity_count_per_day on _calendar_months_with_rank.d = _activity_count_per_day.Date\n),\n\nWeekSummary AS (\n SELECT\n week_name,\n SUM(CASE WHEN weekday = 'Monday' THEN activity_count END) AS Mon,\n SUM(CASE WHEN weekday = 'Tuesday' THEN activity_count END) AS Tue,\n SUM(CASE WHEN weekday = 'Wednesday' THEN activity_count END) AS Wed,\n SUM(CASE WHEN weekday = 'Thursday' THEN activity_count END) AS Thur,\n SUM(CASE WHEN weekday = 'Friday' THEN activity_count END) AS Fri,\n SUM(CASE WHEN weekday = 'Saturday' THEN activity_count END) AS Sat,\n SUM(CASE WHEN weekday = 'Sunday' THEN activity_count END) AS Sun\n FROM\n _final_dataset\n WHERE\n week_rank BETWEEN 1 AND 52\n GROUP BY\n week_name\n)\n\nSELECT \n week_name, \n Mon, \n Tue, \n Wed, \n Thur, \n Fri, \n Sat, \n Sun\nFROM WeekSummary\nORDER BY\n CAST(SUBSTRING(week_name, LOCATE(' ', week_name) + 1, 4) AS UNSIGNED) DESC, \n CAST(SUBSTRING(week_name, 2, LOCATE(' ', week_name) - 2) AS UNSIGNED) DESC;", + "rawSql": "with _accounts as (\n select ua.account_id, ua.user_id, u.name\n from accounts a \n join user_accounts ua on a.id = ua.account_id\n join users u on ua.user_id = u.id\n where ua.user_id in (${users:singlequote})\n),\n\n_activities as (\n SELECT \n *,\n ROW_NUMBER() OVER (PARTITION BY `Date` ORDER BY `Time` desc) AS _row_number\n FROM (\n SELECT DATE(created_date) as Date, created_date as Time, 'Create an issue' as Activity, concat('#', issue_key, ' ', title) as Details, a.name as Name\n FROM issues i\n join _accounts a on i.creator_id = a.account_id\n where $__timeFilter(created_date)\n\n union\n\n SELECT DATE(resolution_date) as Date, resolution_date as Time, 'Issue resolved' as Activity, concat('#', issue_key, ' ', title) as Details, a.name as Name \n FROM issues i\n join _accounts a on i.assignee_id = a.account_id\n where $__timeFilter(resolution_date)\n\n union\n\n SELECT DATE(authored_date) as Date, authored_date as Time, 'Finish a commit' as Activity, concat(message, ' #', sha) as Details, a.name as Name \n FROM commits c\n join _accounts a on c.author_id = a.account_id\n where $__timeFilter(authored_date)\n\n union\n\n SELECT DATE(created_date) as Date, created_date as Time, 'Open a PR' as Activity, concat('#', pull_request_key, ' ', title) as Details, a.name as Name\n FROM pull_requests pr\n join _accounts a on pr.author_id = a.account_id\n where $__timeFilter(created_date)\n\n union\n\n SELECT DATE(merged_date) as Date, merged_date as Time, 'PR gets merged' as Activity, concat('#', pull_request_key, ' ', title) as Details, a.name as Name \n FROM pull_requests pr\n join _accounts a on pr.author_id = a.account_id\n where $__timeFilter(merged_date)\n\n union\n\n SELECT DATE(prc.created_date) as Date, prc.created_date as Time, 'Comment on PR' as Activity, concat('#', pr.pull_request_key, ' ', pr.title) as Details, a.name as Name \n FROM pull_request_comments prc\n left join pull_requests pr on prc.pull_request_id = pr.id\n join _accounts a on prc.account_id = a.account_id\n WHERE \n prc.type = 'NORMAL'\n and $__timeFilter(prc.created_date)\n\n union\n\n SELECT DATE(prc.created_date) as Date, prc.created_date as Time, 'Review PR' as Activity, concat('#', pr.pull_request_key, ' ', pr.title) as Details, a.name as Name \n FROM pull_request_comments prc\n left join pull_requests pr on prc.pull_request_id = pr.id\n join _accounts a on prc.account_id = a.account_id\n WHERE \n prc.type in ('REVIEW', 'DIFF')\n and $__timeFilter(prc.created_date)\n ) t\n\n ORDER BY Time desc\n),\n\n_activity_count_per_day as (\n SELECT \n Date,\n count(*) as value\n FROM _activities\n GROUP BY 1\n),\n\nlast_few_calendar_months as(\n-- construct the last few calendar months within the selected time period in the top-right corner\n\tSELECT \n CAST(($__timeTo()-INTERVAL (H+T+U) DAY) AS date) as d, \n DATE_FORMAT(CAST(($__timeTo()-INTERVAL (H+T+U) DAY) AS date), 'w%u %Y') as week_name,\n DATE_FORMAT(CAST(($__timeTo()-INTERVAL (H+T+U) DAY) AS date), '%Y%u') as week_number\n\tFROM ( SELECT 0 H\n\t\t\tUNION ALL SELECT 100 UNION ALL SELECT 200 UNION ALL SELECT 300\n\t\t) H CROSS JOIN ( SELECT 0 T\n\t\t\tUNION ALL SELECT 10 UNION ALL SELECT 20 UNION ALL SELECT 30\n\t\t\tUNION ALL SELECT 40 UNION ALL SELECT 50 UNION ALL SELECT 60\n\t\t\tUNION ALL SELECT 70 UNION ALL SELECT 80 UNION ALL SELECT 90\n\t\t) T CROSS JOIN ( SELECT 0 U\n\t\t\tUNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3\n\t\t\tUNION ALL SELECT 4 UNION ALL SELECT 5 UNION ALL SELECT 6\n\t\t\tUNION ALL SELECT 7 UNION ALL SELECT 8 UNION ALL SELECT 9\n\t\t) U\n\tWHERE\n\t\t($__timeTo()-INTERVAL (H+T+U) DAY) > $__timeFrom()\n),\n\n_calendar_months_with_rank as (\n SELECT \n d, \n concat(week_name, ' (', DATE_FORMAT(DATE_SUB(d, INTERVAL WEEKDAY(d) DAY), '%m/%d'), ' ~ ', DATE_FORMAT(DATE_ADD(DATE_SUB(d, INTERVAL WEEKDAY(d) DAY), INTERVAL 6 DAY), '%m/%d'), ')') as week_name,\n week_number,\n DATE_FORMAT(d, '%W') as weekday,\n dense_rank() over(ORDER BY week_number desc) as week_rank\n FROM last_few_calendar_months\n ORDER BY 1 desc\n),\n\n_final_dataset as (\n SELECT \n _calendar_months_with_rank.*, \n case when _activity_count_per_day.value is null then 0 else _activity_count_per_day.value end as activity_count \n from _calendar_months_with_rank left join _activity_count_per_day on _calendar_months_with_rank.d = _activity_count_per_day.Date\n),\n\nWeekSummary AS (\n SELECT\n week_name,\n SUM(CASE WHEN weekday = 'Monday' THEN activity_count END) AS Mon,\n SUM(CASE WHEN weekday = 'Tuesday' THEN activity_count END) AS Tue,\n SUM(CASE WHEN weekday = 'Wednesday' THEN activity_count END) AS Wed,\n SUM(CASE WHEN weekday = 'Thursday' THEN activity_count END) AS Thur,\n SUM(CASE WHEN weekday = 'Friday' THEN activity_count END) AS Fri,\n SUM(CASE WHEN weekday = 'Saturday' THEN activity_count END) AS Sat,\n SUM(CASE WHEN weekday = 'Sunday' THEN activity_count END) AS Sun\n FROM\n _final_dataset\n WHERE\n week_rank BETWEEN 1 AND 52\n GROUP BY\n week_name\n)\n\nSELECT \n week_name, \n Mon, \n Tue, \n Wed, \n Thur, \n Fri, \n Sat, \n Sun\nFROM WeekSummary\nORDER BY\n CAST(SUBSTRING(week_name, LOCATE(' ', week_name) + 1, 4) AS UNSIGNED) DESC, \n CAST(SUBSTRING(week_name, 2, LOCATE(' ', week_name) - 2) AS UNSIGNED) DESC;", "refId": "A", "sql": { "columns": [ @@ -580,7 +580,7 @@ "editorMode": "code", "format": "table", "rawQuery": true, - "rawSql": "with _accounts as (\n select ua.account_id, ua.user_id, u.name\n from accounts a \n join user_accounts ua on a.id = ua.account_id\n join users u on ua.user_id = u.id\n where ua.user_id in ($users)\n),\n\n_activities as (\n SELECT \n *,\n ROW_NUMBER() OVER (PARTITION BY `Date` ORDER BY `Time` desc) AS _row_number\n FROM (\n SELECT DATE(created_date) as Date, created_date as Time, 'Create an issue' as Activity, concat('#', issue_key, ' ', title) as Details, a.name as Name\n FROM issues i\n join _accounts a on i.creator_id = a.account_id\n where $__timeFilter(created_date)\n\n union\n\n SELECT DATE(resolution_date) as Date, resolution_date as Time, 'Issue resolved' as Activity, concat('#', issue_key, ' ', title) as Details, a.name as Name \n FROM issues i\n join _accounts a on i.assignee_id = a.account_id\n where $__timeFilter(resolution_date)\n\n union\n\n SELECT DATE(authored_date) as Date, authored_date as Time, 'Finish a commit' as Activity, concat(message, ' #', sha) as Details, a.name as Name \n FROM commits c\n join _accounts a on c.author_id = a.account_id\n where $__timeFilter(authored_date)\n\n union\n\n SELECT DATE(created_date) as Date, created_date as Time, 'Open a PR' as Activity, concat('#', pull_request_key, ' ', title) as Details, a.name as Name\n FROM pull_requests pr\n join _accounts a on pr.author_id = a.account_id\n where $__timeFilter(created_date)\n\n union\n\n SELECT DATE(merged_date) as Date, merged_date as Time, 'PR gets merged' as Activity, concat('#', pull_request_key, ' ', title) as Details, a.name as Name \n FROM pull_requests pr\n join _accounts a on pr.author_id = a.account_id\n where $__timeFilter(merged_date)\n\n union\n\n SELECT DATE(prc.created_date) as Date, prc.created_date as Time, 'Comment on PR' as Activity, concat('#', pr.pull_request_key, ' ', pr.title) as Details, a.name as Name \n FROM pull_request_comments prc\n left join pull_requests pr on prc.pull_request_id = pr.id\n join _accounts a on prc.account_id = a.account_id\n WHERE \n prc.type = 'NORMAL'\n and $__timeFilter(prc.created_date)\n\n union\n\n SELECT DATE(prc.created_date) as Date, prc.created_date as Time, 'Review PR' as Activity, concat('#', pr.pull_request_key, ' ', pr.title) as Details, a.name as Name \n FROM pull_request_comments prc\n left join pull_requests pr on prc.pull_request_id = pr.id\n join _accounts a on prc.account_id = a.account_id\n WHERE \n prc.type in ('REVIEW', 'DIFF')\n and $__timeFilter(prc.created_date)\n ) t\n\n ORDER BY Time desc\n),\n\n_activities_per_day as (\n SELECT \n Date,\n sum(case when Activity = 'Create an issue' then 1 else 0 end) as 'Create an issue',\n sum(case when Activity = 'Issue resolved' then 1 else 0 end) as 'Issue resolved',\n sum(case when Activity = 'Finish a commit' then 1 else 0 end) as 'Finish a commit',\n sum(case when Activity = 'Open a PR' then 1 else 0 end) as 'Open a PR',\n sum(case when Activity = 'PR gets merged' then 1 else 0 end) as 'PR gets merged',\n sum(case when Activity = 'Comment on PR' then 1 else 0 end) as 'Comment on PR',\n sum(case when Activity = 'Review PR' then 1 else 0 end) as 'Review PR'\n FROM _activities\n GROUP BY 1\n),\n\n_calendar_dates as(\n-- construct the last few calendar months within the selected time period in the top-right corner\n\tSELECT \n CAST(($__timeTo()-INTERVAL (H+T+U) DAY) AS date) as Date\n\tFROM ( SELECT 0 H\n\t\t\tUNION ALL SELECT 100 UNION ALL SELECT 200 UNION ALL SELECT 300\n\t\t) H CROSS JOIN ( SELECT 0 T\n\t\t\tUNION ALL SELECT 10 UNION ALL SELECT 20 UNION ALL SELECT 30\n\t\t\tUNION ALL SELECT 40 UNION ALL SELECT 50 UNION ALL SELECT 60\n\t\t\tUNION ALL SELECT 70 UNION ALL SELECT 80 UNION ALL SELECT 90\n\t\t) T CROSS JOIN ( SELECT 0 U\n\t\t\tUNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3\n\t\t\tUNION ALL SELECT 4 UNION ALL SELECT 5 UNION ALL SELECT 6\n\t\t\tUNION ALL SELECT 7 UNION ALL SELECT 8 UNION ALL SELECT 9\n\t\t) U\n\tWHERE\n\t\t($__timeTo()-INTERVAL (H+T+U) DAY) > $__timeFrom()\n),\n\n_last_7_days as (\n SELECT * FROM _calendar_dates\n ORDER BY Date desc\n limit 7\n)\n\nSELECT \n date_format(_last_7_days.Date, '%d/%m %a') as d,\n _activities_per_day.*\nFROM \n _last_7_days LEFT JOIN _activities_per_day ON _last_7_days.Date = _activities_per_day.Date\nORDER by _last_7_days.Date asc", + "rawSql": "with _accounts as (\n select ua.account_id, ua.user_id, u.name\n from accounts a \n join user_accounts ua on a.id = ua.account_id\n join users u on ua.user_id = u.id\n where ua.user_id in (${users:singlequote})\n),\n\n_activities as (\n SELECT \n *,\n ROW_NUMBER() OVER (PARTITION BY `Date` ORDER BY `Time` desc) AS _row_number\n FROM (\n SELECT DATE(created_date) as Date, created_date as Time, 'Create an issue' as Activity, concat('#', issue_key, ' ', title) as Details, a.name as Name\n FROM issues i\n join _accounts a on i.creator_id = a.account_id\n where $__timeFilter(created_date)\n\n union\n\n SELECT DATE(resolution_date) as Date, resolution_date as Time, 'Issue resolved' as Activity, concat('#', issue_key, ' ', title) as Details, a.name as Name \n FROM issues i\n join _accounts a on i.assignee_id = a.account_id\n where $__timeFilter(resolution_date)\n\n union\n\n SELECT DATE(authored_date) as Date, authored_date as Time, 'Finish a commit' as Activity, concat(message, ' #', sha) as Details, a.name as Name \n FROM commits c\n join _accounts a on c.author_id = a.account_id\n where $__timeFilter(authored_date)\n\n union\n\n SELECT DATE(created_date) as Date, created_date as Time, 'Open a PR' as Activity, concat('#', pull_request_key, ' ', title) as Details, a.name as Name\n FROM pull_requests pr\n join _accounts a on pr.author_id = a.account_id\n where $__timeFilter(created_date)\n\n union\n\n SELECT DATE(merged_date) as Date, merged_date as Time, 'PR gets merged' as Activity, concat('#', pull_request_key, ' ', title) as Details, a.name as Name \n FROM pull_requests pr\n join _accounts a on pr.author_id = a.account_id\n where $__timeFilter(merged_date)\n\n union\n\n SELECT DATE(prc.created_date) as Date, prc.created_date as Time, 'Comment on PR' as Activity, concat('#', pr.pull_request_key, ' ', pr.title) as Details, a.name as Name \n FROM pull_request_comments prc\n left join pull_requests pr on prc.pull_request_id = pr.id\n join _accounts a on prc.account_id = a.account_id\n WHERE \n prc.type = 'NORMAL'\n and $__timeFilter(prc.created_date)\n\n union\n\n SELECT DATE(prc.created_date) as Date, prc.created_date as Time, 'Review PR' as Activity, concat('#', pr.pull_request_key, ' ', pr.title) as Details, a.name as Name \n FROM pull_request_comments prc\n left join pull_requests pr on prc.pull_request_id = pr.id\n join _accounts a on prc.account_id = a.account_id\n WHERE \n prc.type in ('REVIEW', 'DIFF')\n and $__timeFilter(prc.created_date)\n ) t\n\n ORDER BY Time desc\n),\n\n_activities_per_day as (\n SELECT \n Date,\n sum(case when Activity = 'Create an issue' then 1 else 0 end) as 'Create an issue',\n sum(case when Activity = 'Issue resolved' then 1 else 0 end) as 'Issue resolved',\n sum(case when Activity = 'Finish a commit' then 1 else 0 end) as 'Finish a commit',\n sum(case when Activity = 'Open a PR' then 1 else 0 end) as 'Open a PR',\n sum(case when Activity = 'PR gets merged' then 1 else 0 end) as 'PR gets merged',\n sum(case when Activity = 'Comment on PR' then 1 else 0 end) as 'Comment on PR',\n sum(case when Activity = 'Review PR' then 1 else 0 end) as 'Review PR'\n FROM _activities\n GROUP BY 1\n),\n\n_calendar_dates as(\n-- construct the last few calendar months within the selected time period in the top-right corner\n\tSELECT \n CAST(($__timeTo()-INTERVAL (H+T+U) DAY) AS date) as Date\n\tFROM ( SELECT 0 H\n\t\t\tUNION ALL SELECT 100 UNION ALL SELECT 200 UNION ALL SELECT 300\n\t\t) H CROSS JOIN ( SELECT 0 T\n\t\t\tUNION ALL SELECT 10 UNION ALL SELECT 20 UNION ALL SELECT 30\n\t\t\tUNION ALL SELECT 40 UNION ALL SELECT 50 UNION ALL SELECT 60\n\t\t\tUNION ALL SELECT 70 UNION ALL SELECT 80 UNION ALL SELECT 90\n\t\t) T CROSS JOIN ( SELECT 0 U\n\t\t\tUNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3\n\t\t\tUNION ALL SELECT 4 UNION ALL SELECT 5 UNION ALL SELECT 6\n\t\t\tUNION ALL SELECT 7 UNION ALL SELECT 8 UNION ALL SELECT 9\n\t\t) U\n\tWHERE\n\t\t($__timeTo()-INTERVAL (H+T+U) DAY) > $__timeFrom()\n),\n\n_last_7_days as (\n SELECT * FROM _calendar_dates\n ORDER BY Date desc\n limit 7\n)\n\nSELECT \n date_format(_last_7_days.Date, '%d/%m %a') as d,\n _activities_per_day.*\nFROM \n _last_7_days LEFT JOIN _activities_per_day ON _last_7_days.Date = _activities_per_day.Date\nORDER by _last_7_days.Date asc", "refId": "A", "sql": { "columns": [ @@ -716,7 +716,7 @@ "editorMode": "code", "format": "table", "rawQuery": true, - "rawSql": "with _accounts as (\n select ua.account_id, ua.user_id, u.name\n from accounts a \n join user_accounts ua on a.id = ua.account_id\n join users u on ua.user_id = u.id\n where ua.user_id in ($users)\n),\n\n\n_issues as (\n SELECT DATE_FORMAT(created_date, '%d/%m/%Y') as Date, created_date as Time, 'Create an issue' as Activity, concat('#', issue_key, ' ', title) as Details, status, a.name as Name\n FROM issues i\n join _accounts a on i.creator_id = a.account_id\n where $__timeFilter(created_date)\n)\n\nSELECT status, count(*) FROM _issues\nGROUP BY 1", + "rawSql": "with _accounts as (\n select ua.account_id, ua.user_id, u.name\n from accounts a \n join user_accounts ua on a.id = ua.account_id\n join users u on ua.user_id = u.id\n where ua.user_id in (${users:singlequote})\n),\n\n\n_issues as (\n SELECT DATE_FORMAT(created_date, '%d/%m/%Y') as Date, created_date as Time, 'Create an issue' as Activity, concat('#', issue_key, ' ', title) as Details, status, a.name as Name\n FROM issues i\n join _accounts a on i.creator_id = a.account_id\n where $__timeFilter(created_date)\n)\n\nSELECT status, count(*) FROM _issues\nGROUP BY 1", "refId": "A", "sql": { "columns": [ @@ -787,7 +787,7 @@ "editorMode": "code", "format": "table", "rawQuery": true, - "rawSql": "with _accounts as (\n select ua.account_id, ua.user_id, u.name, u.email\n from accounts a \n join user_accounts ua on a.id = ua.account_id\n join users u on ua.user_id = u.id\n where ua.user_id in ($users)\n)\n\nSELECT count(distinct c.sha)\nFROM commits c\njoin _accounts a on c.author_id = a.email\nwhere $__timeFilter(authored_date)\n", + "rawSql": "with _accounts as (\n select ua.account_id, ua.user_id, u.name, u.email\n from accounts a \n join user_accounts ua on a.id = ua.account_id\n join users u on ua.user_id = u.id\n where ua.user_id in (${users:singlequote})\n)\n\nSELECT count(distinct c.sha)\nFROM commits c\njoin _accounts a on c.author_id = a.email\nwhere $__timeFilter(authored_date)\n", "refId": "A", "sql": { "columns": [ @@ -859,7 +859,7 @@ "editorMode": "code", "format": "table", "rawQuery": true, - "rawSql": "with _accounts as (\n select ua.account_id, ua.user_id, u.name\n from accounts a \n join user_accounts ua on a.id = ua.account_id\n join users u on ua.user_id = u.id\n where ua.user_id in ($users)\n),\n\n\n_commits as (\n SELECT distinct DATE_FORMAT(authored_date, '%d/%m/%Y') as Date, authored_date as Time, 'Finish a commit' as Activity, concat(message, ' #', sha) as Details, a.name as Name, c.additions, c.deletions\n FROM commits c\n join _accounts a on c.author_id = a.account_id\n where $__timeFilter(authored_date)\n)\n\nSELECT sum(additions + deletions) FROM _commits\n", + "rawSql": "with _accounts as (\n select ua.account_id, ua.user_id, u.name\n from accounts a \n join user_accounts ua on a.id = ua.account_id\n join users u on ua.user_id = u.id\n where ua.user_id in (${users:singlequote})\n),\n\n\n_commits as (\n SELECT distinct DATE_FORMAT(authored_date, '%d/%m/%Y') as Date, authored_date as Time, 'Finish a commit' as Activity, concat(message, ' #', sha) as Details, a.name as Name, c.additions, c.deletions\n FROM commits c\n join _accounts a on c.author_id = a.account_id\n where $__timeFilter(authored_date)\n)\n\nSELECT sum(additions + deletions) FROM _commits\n", "refId": "A", "sql": { "columns": [ @@ -931,7 +931,7 @@ "editorMode": "code", "format": "table", "rawQuery": true, - "rawSql": "with _accounts as (\n select ua.account_id, ua.user_id, u.name\n from accounts a \n join user_accounts ua on a.id = ua.account_id\n join users u on ua.user_id = u.id\n where ua.user_id in ($users)\n),\n\n\n_prs as (\n SELECT pr.id as pr_id, pr.merged_date, concat('#', pr.pull_request_key, ' ', pr.title) as details, prc.id as comment_id, prc.created_date as comment_date, a.name, prc.type as comment_type\n FROM pull_requests pr\n left join pull_request_comments prc on pr.id = prc.pull_request_id\n left join _accounts a on prc.account_id = a.account_id\n WHERE \n $__timeFilter(pr.created_date)\n)\n\nSELECT \n concat(count(distinct case when name is not null then pr_id end), '/', count(distinct pr_id)) as text\nFROM _prs\n", + "rawSql": "with _accounts as (\n select ua.account_id, ua.user_id, u.name\n from accounts a \n join user_accounts ua on a.id = ua.account_id\n join users u on ua.user_id = u.id\n where ua.user_id in (${users:singlequote})\n),\n\n\n_prs as (\n SELECT pr.id as pr_id, pr.merged_date, concat('#', pr.pull_request_key, ' ', pr.title) as details, prc.id as comment_id, prc.created_date as comment_date, a.name, prc.type as comment_type\n FROM pull_requests pr\n left join pull_request_comments prc on pr.id = prc.pull_request_id\n left join _accounts a on prc.account_id = a.account_id\n WHERE \n $__timeFilter(pr.created_date)\n)\n\nSELECT \n concat(count(distinct case when name is not null then pr_id end), '/', count(distinct pr_id)) as text\nFROM _prs\n", "refId": "A", "sql": { "columns": [ @@ -1003,7 +1003,7 @@ "editorMode": "code", "format": "table", "rawQuery": true, - "rawSql": "with _accounts as (\n select ua.account_id, ua.user_id, u.name\n from accounts a \n join user_accounts ua on a.id = ua.account_id\n join users u on ua.user_id = u.id\n where ua.user_id in ($users)\n),\n\n\n_prs as (\n SELECT distinct DATE_FORMAT(created_date, '%d/%m/%Y') as Date, created_date as Time, 'Open a PR' as Activity, concat('#', pull_request_key, ' ', title) as Details, a.name as Name, pr.id, pr.merged_date\n FROM pull_requests pr\n join _accounts a on pr.author_id = a.account_id\n where \n $__timeFilter(created_date)\n)\n\nSELECT \n concat(count(case when merged_date is not null then id else null end), '/', count(distinct id)) FROM _prs\n", + "rawSql": "with _accounts as (\n select ua.account_id, ua.user_id, u.name\n from accounts a \n join user_accounts ua on a.id = ua.account_id\n join users u on ua.user_id = u.id\n where ua.user_id in (${users:singlequote})\n),\n\n\n_prs as (\n SELECT distinct DATE_FORMAT(created_date, '%d/%m/%Y') as Date, created_date as Time, 'Open a PR' as Activity, concat('#', pull_request_key, ' ', title) as Details, a.name as Name, pr.id, pr.merged_date\n FROM pull_requests pr\n join _accounts a on pr.author_id = a.account_id\n where \n $__timeFilter(created_date)\n)\n\nSELECT \n concat(count(case when merged_date is not null then id else null end), '/', count(distinct id)) FROM _prs\n", "refId": "A", "sql": { "columns": [ @@ -1121,7 +1121,7 @@ "hide": false, "metricColumn": "none", "rawQuery": true, - "rawSql": "with _accounts as (\n select ua.account_id, ua.user_id, u.name\n from accounts a \n join user_accounts ua on a.id = ua.account_id\n join users u on ua.user_id = u.id\n where ua.user_id in ($users)\n),\n\n_prs as (\n SELECT \n DATE_ADD(date(created_date), INTERVAL -DAY(date(created_date))+1 DAY) as time,\n count(distinct pr.id) as pr_count\n FROM pull_requests pr\n join _accounts a on pr.author_id = a.account_id\n where \n $__timeFilter(created_date)\n -- and created_date >= DATE_ADD(DATE_ADD($__timeFrom(), INTERVAL -DAY($__timeFrom())+1 DAY), INTERVAL +1 MONTH)\n and pr.merged_date is not null\n GROUP BY 1\n)\n\nSELECT \n date_format(time,'%M %Y') as month,\n pr_count as \"Pull Request Count\"\nFROM _prs\nORDER BY time\n", + "rawSql": "with _accounts as (\n select ua.account_id, ua.user_id, u.name\n from accounts a \n join user_accounts ua on a.id = ua.account_id\n join users u on ua.user_id = u.id\n where ua.user_id in (${users:singlequote})\n),\n\n_prs as (\n SELECT \n DATE_ADD(date(created_date), INTERVAL -DAY(date(created_date))+1 DAY) as time,\n count(distinct pr.id) as pr_count\n FROM pull_requests pr\n join _accounts a on pr.author_id = a.account_id\n where \n $__timeFilter(created_date)\n -- and created_date >= DATE_ADD(DATE_ADD($__timeFrom(), INTERVAL -DAY($__timeFrom())+1 DAY), INTERVAL +1 MONTH)\n and pr.merged_date is not null\n GROUP BY 1\n)\n\nSELECT \n date_format(time,'%M %Y') as month,\n pr_count as \"Pull Request Count\"\nFROM _prs\nORDER BY time\n", "refId": "A", "select": [ [ @@ -1226,7 +1226,7 @@ "editorMode": "code", "format": "table", "rawQuery": true, - "rawSql": "with _accounts as (\n select ua.account_id, ua.user_id, u.name\n from accounts a \n join user_accounts ua on a.id = ua.account_id\n join users u on ua.user_id = u.id\n where ua.user_id in ($users)\n),\n\n\n_commits as (\n SELECT distinct DATE_FORMAT(authored_date, '%d/%m/%Y') as Date, authored_date as Time, 'Finish a commit' as Activity, concat(message, ' #', sha) as Details, a.name as Name, c.additions, c.deletions, c.sha\n FROM commits c\n join _accounts a on c.author_id = a.account_id\n where $__timeFilter(authored_date)\n),\n\n_pr_commits_data as(\n SELECT\n pr.id as pr_id,\n pr.merge_commit_sha,\n sum(c.additions)+sum(c.deletions) as loc\n FROM \n pull_requests pr\n left join _commits c on pr.merge_commit_sha = c.sha\n WHERE\n $__timeFilter(pr.created_date)\n and pr.status = 'MERGED'\n group by 1,2\n)\n\nSELECT \n avg(loc) as 'PR Merged Size'\nFROM _pr_commits_data\n", + "rawSql": "with _accounts as (\n select ua.account_id, ua.user_id, u.name\n from accounts a \n join user_accounts ua on a.id = ua.account_id\n join users u on ua.user_id = u.id\n where ua.user_id in (${users:singlequote})\n),\n\n\n_commits as (\n SELECT distinct DATE_FORMAT(authored_date, '%d/%m/%Y') as Date, authored_date as Time, 'Finish a commit' as Activity, concat(message, ' #', sha) as Details, a.name as Name, c.additions, c.deletions, c.sha\n FROM commits c\n join _accounts a on c.author_id = a.account_id\n where $__timeFilter(authored_date)\n),\n\n_pr_commits_data as(\n SELECT\n pr.id as pr_id,\n pr.merge_commit_sha,\n sum(c.additions)+sum(c.deletions) as loc\n FROM \n pull_requests pr\n left join _commits c on pr.merge_commit_sha = c.sha\n WHERE\n $__timeFilter(pr.created_date)\n and pr.status = 'MERGED'\n group by 1,2\n)\n\nSELECT \n avg(loc) as 'PR Merged Size'\nFROM _pr_commits_data\n", "refId": "A", "sql": { "columns": [ @@ -1298,7 +1298,7 @@ "editorMode": "code", "format": "table", "rawQuery": true, - "rawSql": "with _accounts as (\n select ua.account_id, ua.user_id, u.name\n from accounts a \n join user_accounts ua on a.id = ua.account_id\n join users u on ua.user_id = u.id\n where ua.user_id in ($users)\n),\n\n\n_prs as (\n SELECT DATE_FORMAT(prc.created_date, '%d/%m/%Y') as Date, prc.created_date as Time, 'Comment on PR' as Activity, concat('#', pr.pull_request_key, ' ', pr.title) as Details, a.name as Name, pr.id as pr_id, prc.id as prc_id\n FROM pull_request_comments prc\n left join pull_requests pr on prc.pull_request_id = pr.id\n join _accounts a on prc.account_id = a.account_id\n WHERE \n $__timeFilter(prc.created_date)\n)\n\nSELECT \n round(count(distinct prc_id)/count(distinct pr_id) , 1) FROM _prs\n", + "rawSql": "with _accounts as (\n select ua.account_id, ua.user_id, u.name\n from accounts a \n join user_accounts ua on a.id = ua.account_id\n join users u on ua.user_id = u.id\n where ua.user_id in (${users:singlequote})\n),\n\n\n_prs as (\n SELECT DATE_FORMAT(prc.created_date, '%d/%m/%Y') as Date, prc.created_date as Time, 'Comment on PR' as Activity, concat('#', pr.pull_request_key, ' ', pr.title) as Details, a.name as Name, pr.id as pr_id, prc.id as prc_id\n FROM pull_request_comments prc\n left join pull_requests pr on prc.pull_request_id = pr.id\n join _accounts a on prc.account_id = a.account_id\n WHERE \n $__timeFilter(prc.created_date)\n)\n\nSELECT \n round(count(distinct prc_id)/count(distinct pr_id) , 1) FROM _prs\n", "refId": "A", "sql": { "columns": [ @@ -1371,7 +1371,7 @@ "editorMode": "code", "format": "table", "rawQuery": true, - "rawSql": "with _accounts as (\n select ua.account_id, ua.user_id, u.name\n from accounts a \n join user_accounts ua on a.id = ua.account_id\n join users u on ua.user_id = u.id\n where ua.user_id in ($users)\n)\n\n\nSELECT avg(TIMESTAMPDIFF(Minute,pr.created_date,pr.merged_date)/60) as 'Time to merge'\nFROM \n pull_requests pr\n join _accounts a on pr.author_id = a.account_id\nWHERE \n $__timeFilter(pr.created_date)\n", + "rawSql": "with _accounts as (\n select ua.account_id, ua.user_id, u.name\n from accounts a \n join user_accounts ua on a.id = ua.account_id\n join users u on ua.user_id = u.id\n where ua.user_id in (${users:singlequote})\n)\n\n\nSELECT avg(TIMESTAMPDIFF(Minute,pr.created_date,pr.merged_date)/60) as 'Time to merge'\nFROM \n pull_requests pr\n join _accounts a on pr.author_id = a.account_id\nWHERE \n $__timeFilter(pr.created_date)\n", "refId": "A", "sql": { "columns": [ @@ -1437,14 +1437,14 @@ ] }, "datasource": "mysql", - "definition": "select concat(users.name, '--', users.id) from users left join team_users on users.id = team_users.user_id where team_users.team_id in ($team)", + "definition": "select concat(users.name, '--', users.id) from users left join team_users on users.id = team_users.user_id where team_users.team_id in (${team:singlequote})", "hide": 0, "includeAll": true, "label": "User", "multi": true, "name": "users", "options": [], - "query": "select concat(users.name, '--', users.id) from users left join team_users on users.id = team_users.user_id where team_users.team_id in ($team)", + "query": "select concat(users.name, '--', users.id) from users left join team_users on users.id = team_users.user_id where team_users.team_id in (${team:singlequote})", "refresh": 1, "regex": "/^(?.*)--(?.*)$/", "skipUrlSync": false,