Skip to content

Commit d907d77

Browse files
committed
Add Evaluation Services #1467
1 parent c3457f1 commit d907d77

File tree

5 files changed

+74
-17
lines changed

5 files changed

+74
-17
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package ch.puzzle.okr.repository;
2+
3+
import ch.puzzle.okr.models.evaluation.EvaluationView;
4+
import ch.puzzle.okr.models.evaluation.EvaluationViewId;
5+
import org.springframework.data.repository.CrudRepository;
6+
7+
8+
public interface EvaluationViewRepository extends CrudRepository<EvaluationView, EvaluationViewId> {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package ch.puzzle.okr.service.business;
2+
3+
import ch.puzzle.okr.models.evaluation.EvaluationView;
4+
import ch.puzzle.okr.service.persistence.EvaluationViewPersistenceService;
5+
import org.springframework.stereotype.Service;
6+
7+
import java.util.List;
8+
9+
@Service
10+
public class EvaluationViewBusinessService {
11+
private final EvaluationViewPersistenceService evaluationViewPersistenceService;
12+
13+
public EvaluationViewBusinessService(EvaluationViewPersistenceService evaluationViewPersistenceService) {
14+
this.evaluationViewPersistenceService = evaluationViewPersistenceService;
15+
}
16+
17+
public List<EvaluationView> findByTeamIdsAndQuarterId(List<Long> teamIds, Long quarterId) {
18+
return evaluationViewPersistenceService.findByTeamIdsAndQuarterId(teamIds, quarterId);
19+
}
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package ch.puzzle.okr.service.persistence;
2+
3+
import ch.puzzle.okr.exception.OkrResponseStatusException;
4+
import ch.puzzle.okr.models.evaluation.EvaluationView;
5+
import ch.puzzle.okr.models.evaluation.EvaluationViewId;
6+
import ch.puzzle.okr.repository.EvaluationViewRepository;
7+
import org.springframework.data.repository.CrudRepository;
8+
import org.springframework.stereotype.Service;
9+
10+
import java.util.List;
11+
12+
@Service
13+
public class EvaluationViewPersistenceService
14+
extends PersistenceBase<EvaluationView, EvaluationViewId, EvaluationViewRepository> {
15+
protected EvaluationViewPersistenceService(CrudRepository<EvaluationView, EvaluationViewId> repository) {
16+
super(repository);
17+
}
18+
19+
public List<EvaluationView> findByTeamIdsAndQuarterId(List<Long> teamIds, Long quarterId)
20+
throws OkrResponseStatusException {
21+
List<EvaluationViewId> list = teamIds.stream().map(teamId -> new EvaluationViewId(teamId, quarterId)).toList();
22+
return iteratorToList(getRepository().findAllById(list));
23+
}
24+
25+
@Override
26+
public String getModelName() {
27+
return "EvaluationView";
28+
}
29+
}

backend/src/main/java/ch/puzzle/okr/service/persistence/PersistenceBase.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public void deleteById(I id) {
7474

7575
public abstract String getModelName();
7676

77-
private List<T> iteratorToList(Iterable<T> iterable) {
77+
protected List<T> iteratorToList(Iterable<T> iterable) {
7878
return StreamSupport
7979
.stream(Spliterators.spliteratorUnknownSize(iterable.iterator(), Spliterator.ORDERED), false)
8080
.toList();

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

+16-16
Original file line numberDiff line numberDiff line change
@@ -40,29 +40,29 @@ WITH team_quarters AS (
4040
SELECT
4141
team_id,
4242
quarter_id,
43-
COUNT(*) AS amount_key_results,
44-
COUNT(*) FILTER (WHERE key_result_type = 'ordinal') AS amount_key_results_ordinal,
45-
COUNT(*) FILTER (WHERE key_result_type = 'metric') AS amount_key_results_metric,
43+
COUNT(*) AS key_result_amount,
44+
COUNT(*) FILTER (WHERE key_result_type = 'ordinal') AS key_results_ordinal_amount,
45+
COUNT(*) FILTER (WHERE key_result_type = 'metric') AS key_results_metric_amount,
4646
COUNT(*) FILTER (
4747
WHERE (key_result_type = 'ordinal' AND zone IN ('TARGET', 'STRETCH'))
4848
OR (key_result_type = 'metric' AND COALESCE(((value_metric - baseline) / NULLIF(stretch_goal - baseline, 0)),0)>= 0.7)
49-
) AS amount_key_results_in_target_or_stretch,
49+
) AS key_results_in_target_or_stretch_amount,
5050
COUNT(*) FILTER (
5151
WHERE (key_result_type = 'ordinal' AND zone = 'FAIL')
5252
OR (key_result_type = 'metric' AND COALESCE(((value_metric - baseline) / NULLIF(stretch_goal - baseline, 0)),0) < 0.3)
53-
) AS amount_key_results_in_fail,
53+
) AS key_results_in_fail_amount,
5454
COUNT(*) FILTER (
5555
WHERE (key_result_type = 'ordinal' AND zone = 'COMMIT')
5656
OR (key_result_type = 'metric' AND COALESCE(((value_metric - baseline) / NULLIF(stretch_goal - baseline, 0)),0) BETWEEN 0.3 AND 0.7)
57-
) AS amount_key_results_in_commit,
57+
) AS key_results_in_commit_amount,
5858
COUNT(*) FILTER (
5959
WHERE (key_result_type = 'ordinal' AND zone = 'TARGET')
6060
OR (key_result_type = 'metric' AND COALESCE(((value_metric - baseline) / NULLIF(stretch_goal - baseline, 0)),0) BETWEEN 0.7 AND 1)
61-
) AS amount_key_results_in_target,
61+
) AS key_results_in_target_amount,
6262
COUNT(*) FILTER (
6363
WHERE (key_result_type = 'ordinal' AND zone = 'STRETCH')
6464
OR (key_result_type = 'metric' AND COALESCE(((value_metric - baseline) / NULLIF(stretch_goal - baseline, 0)),0) >= 1)
65-
) AS amount_key_results_in_stretch
65+
) AS key_results_in_stretch_amount
6666
FROM kr_latest_check_in
6767
GROUP BY team_id, quarter_id
6868
)
@@ -74,14 +74,14 @@ SELECT
7474
o.objective_amount,
7575
o.completed_objectives_amount ,
7676
o.successfully_completed_objectives_amount,
77-
kr.amount_key_results,
78-
kr.amount_key_results_ordinal,
79-
kr.amount_key_results_metric,
80-
kr.amount_key_results_in_target_or_stretch,
81-
kr.amount_key_results_in_fail,
82-
kr.amount_key_results_in_commit,
83-
kr.amount_key_results_in_target,
84-
kr.amount_key_results_in_stretch
77+
kr.key_result_amount,
78+
kr.key_results_ordinal_amount,
79+
kr.key_results_metric_amount,
80+
kr.key_results_in_target_or_stretch_amount,
81+
kr.key_results_in_fail_amount,
82+
kr.key_results_in_commit_amount,
83+
kr.key_results_in_target_amount,
84+
kr.key_results_in_stretch_amount
8585
FROM team_quarters tq
8686
LEFT JOIN objectives o
8787
ON tq.team_id = o.team_id

0 commit comments

Comments
 (0)