Skip to content

Commit 3fe1744

Browse files
committed
Refine and clean up view #1467
1 parent 9f109bc commit 3fe1744

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

backend/src/main/resources/db/migration/V3_6_0__add_evaluation_view.sql

+8-7
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ WITH team_quarters AS (
2323
SELECT DISTINCT ON (kr.id)
2424
kr.id as key_result_id,
2525
ci.value_metric,
26+
COALESCE(((value_metric - baseline) / NULLIF(stretch_goal - baseline, 0)),0) as progress,
2627
ci.zone,
2728
kr.key_result_type,
2829
kr.stretch_goal,
@@ -31,8 +32,8 @@ WITH team_quarters AS (
3132
sub_o.quarter_id
3233
FROM key_result kr
3334
LEFT JOIN CHECK_IN ci ON KR.ID = ci.KEY_RESULT_ID AND ci.MODIFIED_ON = (SELECT MAX(CC.MODIFIED_ON)
34-
FROM CHECK_IN CC
35-
WHERE CC.KEY_RESULT_ID = ci.KEY_RESULT_ID)
35+
FROM CHECK_IN CC
36+
WHERE CC.KEY_RESULT_ID = ci.KEY_RESULT_ID)
3637
INNER JOIN objective sub_o ON kr.objective_id = sub_o.id
3738
ORDER BY kr.id, ci.modified_on DESC
3839
),
@@ -45,23 +46,23 @@ WITH team_quarters AS (
4546
COUNT(*) FILTER (WHERE key_result_type = 'metric') AS key_results_metric_amount,
4647
COUNT(*) FILTER (
4748
WHERE (key_result_type = 'ordinal' AND zone IN ('TARGET', 'STRETCH'))
48-
OR (key_result_type = 'metric' AND COALESCE(((value_metric - baseline) / NULLIF(stretch_goal - baseline, 0)),0)>= 0.7)
49+
OR (key_result_type = 'metric' AND progress >= 0.7)
4950
) AS key_results_in_target_or_stretch_amount,
5051
COUNT(*) FILTER (
5152
WHERE (key_result_type = 'ordinal' AND zone = 'FAIL')
52-
OR (key_result_type = 'metric' AND COALESCE(((value_metric - baseline) / NULLIF(stretch_goal - baseline, 0)),0) < 0.3)
53+
OR (key_result_type = 'metric' AND progress > 0 AND progress < 0.3)
5354
) AS key_results_in_fail_amount,
5455
COUNT(*) FILTER (
5556
WHERE (key_result_type = 'ordinal' AND zone = 'COMMIT')
56-
OR (key_result_type = 'metric' AND COALESCE(((value_metric - baseline) / NULLIF(stretch_goal - baseline, 0)),0) BETWEEN 0.3 AND 0.7)
57+
OR (key_result_type = 'metric' AND progress >= 0.3 AND progress < 0.7)
5758
) AS key_results_in_commit_amount,
5859
COUNT(*) FILTER (
5960
WHERE (key_result_type = 'ordinal' AND zone = 'TARGET')
60-
OR (key_result_type = 'metric' AND COALESCE(((value_metric - baseline) / NULLIF(stretch_goal - baseline, 0)),0) BETWEEN 0.7 AND 1)
61+
OR (key_result_type = 'metric' AND progress >= 0.7 AND progress < 1)
6162
) AS key_results_in_target_amount,
6263
COUNT(*) FILTER (
6364
WHERE (key_result_type = 'ordinal' AND zone = 'STRETCH')
64-
OR (key_result_type = 'metric' AND COALESCE(((value_metric - baseline) / NULLIF(stretch_goal - baseline, 0)),0) >= 1)
65+
OR (key_result_type = 'metric' AND progress >= 1)
6566
) AS key_results_in_stretch_amount
6667
FROM kr_latest_check_in
6768
GROUP BY team_id, quarter_id

0 commit comments

Comments
 (0)