Advertisement
LuNa2713

Задачи тестируют dev

Oct 23rd, 2024
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 3.83 KB | None | 0 0
  1. WITH
  2. tested_issues AS (
  3.     SELECT
  4.         iss.id AS issue_id,
  5.         iss.closed_on,
  6.         iss.project_id
  7.     FROM issues iss
  8.     LEFT JOIN projects p ON p.id = iss.project_id
  9.     WHERE
  10.         $__timeFilter(iss.closed_on)
  11.         AND iss.tracker_id in (83, 85) -- трекер DevTask или Bug
  12.         AND iss.status_id IN (4) -- задача завершена
  13.         AND p.lft >= (SELECT lft FROM projects WHERE id = 4) -- проект внутри w1
  14.         AND p.rgt <= (SELECT rgt FROM projects WHERE id = 4)
  15. ),
  16. issues_assigned_changes AS (
  17.     SELECT
  18.         j.journalized_id AS issue_id,
  19.         j.created_on AS event_on,
  20.         jd.value AS assigned_to_id,
  21.         ROW_NUMBER() OVER (PARTITION BY j.journalized_id ORDER BY j.created_on) AS rnk
  22.     FROM journal_details jd
  23.     INNER JOIN journals j ON j.id = jd.journal_id
  24.     WHERE
  25.         j.journalized_id IN (SELECT issue_id FROM tested_issues)
  26.         AND j.journalized_type = 'Issue'
  27.         AND jd.prop_key = 'assigned_to_id'
  28. ),
  29. issues_assigned_periods AS (
  30.     SELECT
  31.         s.issue_id,
  32.         s.event_on AS started_at,
  33.         COALESCE(f.event_on, NOW()) AS finished_at,
  34.         s.assigned_to_id
  35.     FROM issues_assigned_changes s
  36.     LEFT JOIN issues_assigned_changes f ON f.issue_id = s.issue_id AND f.rnk = s.rnk + 1
  37. ),
  38. result AS (
  39.     SELECT
  40.         m.month AS mmonth,
  41.         iss.issue_id AS quantity_tasks,
  42.         -- QA Нагишева, Романова, Тюренкова и Сухорукова
  43.         COUNT(
  44.             CASE WHEN
  45.                     jd.old_value IN (41, 87, 103)
  46.                     AND jd.value IN (70, 15, 72, 88)
  47.                     AND u.id IN (1478, 1536, 2306, 2433)
  48.                 THEN j.id
  49.                 ELSE NULL
  50.             END
  51.         ) AS cnt_qa,
  52.         -- старый статус "Внутреннее тестирование", "Тестирование на препроде", “Тестирование на проде”, новый статус "Запланировано", "Готово", "Перенести на препрод", “Перенести на прод”
  53.         COUNT(
  54.             CASE WHEN
  55.                     jd.old_value IN (41, 87, 103)
  56.                     AND jd.value IN (70, 15, 72, 88)
  57.                     AND u.id NOT IN (1478, 1536, 2306, 2433)
  58.                     AND iap.assigned_to_id != u.id
  59.                 THEN j.id
  60.                 ELSE NULL
  61.             END
  62.         ) AS cnt_dev,
  63.         COUNT(
  64.             CASE WHEN
  65.                     jd.old_value IN (41, 87, 103)
  66.                     AND jd.value IN (70, 15, 72, 88)
  67.                     AND u.id NOT IN (1478, 1536, 2306, 2433)
  68.                     AND iap.assigned_to_id = u.id
  69.                 THEN j.id
  70.                 ELSE NULL
  71.             END
  72.         ) AS cnt_self
  73.     FROM nag_monthes m
  74.     LEFT JOIN tested_issues iss ON DATE_FORMAT(iss.closed_on, '%Y-%m-01') = DATE_FORMAT(m.month, '%Y-%m-01')
  75.     LEFT JOIN projects p ON p.id = iss.project_id
  76.     LEFT JOIN journals j ON j.journalized_id = iss.issue_id AND j.journalized_type = 'Issue'
  77.     LEFT JOIN journal_details jd ON jd.journal_id = j.id AND jd.prop_key = 'status_id'
  78.     LEFT JOIN users u ON u.id = j.user_id
  79.     LEFT JOIN issues_assigned_periods iap ON
  80.         iap.issue_id = iss.issue_id
  81.         AND iap.assigned_to_id IS NOT NULL
  82.         AND iap.started_at <= j.created_on
  83.         AND iap.finished_at >= j.created_on
  84.     WHERE
  85.         $__timeFilter(m.month)
  86.     GROUP BY 1, iss.issue_id
  87.     ORDER BY 1
  88. )
  89. SELECT
  90.     t.mmonth,
  91.     COUNT(DISTINCT CASE WHEN t.cnt_qa > 0 AND t.cnt_dev = 0 AND t.cnt_self = 0 THEN t.quantity_tasks END) AS "не Dev",
  92.     COUNT(DISTINCT CASE WHEN t.cnt_dev > 0 THEN t.quantity_tasks END) AS "Dev",
  93.     COUNT(DISTINCT CASE WHEN t.cnt_self > 0 THEN t.quantity_tasks END) AS "Self"
  94. FROM result t
  95. GROUP BY 1
  96. ORDER BY 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement