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

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/dev-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,4 @@ jobs:
script: |
docker rm -f taskflow
docker image rm ${{ secrets.DOCKER_REPO }} -f
docker run --name taskflow --network host -d -p 9090:9090 ${{ secrets.DOCKER_REPO }} --restart on-failure
docker run --name taskflow -d -p 9090:9090 ${{ secrets.DOCKER_REPO }} --restart on-failure
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package clap.server.adapter.inbound.web.statistics;

import clap.server.application.port.inbound.statistics.FindCategoryTaskRequestUsecase;
import clap.server.application.port.inbound.statistics.FindPeriodTaskProcessUsecase;
import clap.server.application.port.inbound.statistics.FindPeriodTaskRequestUsecase;
import clap.server.application.port.inbound.statistics.FindSubCategoryTaskRequestUsecase;
import clap.server.application.port.inbound.statistics.*;
import clap.server.common.annotation.architecture.WebAdapter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
Expand All @@ -23,7 +20,7 @@ public class FindStatisticsController {
private final FindPeriodTaskProcessUsecase findPeriodTaskProcessUsecase;
private final FindCategoryTaskRequestUsecase findCategoryTaskRequestUsecase;
private final FindSubCategoryTaskRequestUsecase findSubCategoryTaskRequestUsecase;
// private final ManagerTaskProcessUsecase managerTaskProcessUsecase;
private final ManagerTaskProcessUsecase managerTaskProcessUsecase;

@GetMapping(value = "/task-requests-by-period")
public ResponseEntity<Map<String, Long>> aggregatePeriodTaskRequest(@RequestParam String period) {
Expand All @@ -34,6 +31,7 @@ public ResponseEntity<Map<String, Long>> aggregatePeriodTaskRequest(@RequestPara
public ResponseEntity<Map<String, Long>> aggregatePeriodTaskProcess(@RequestParam String period) {
return ResponseEntity.ok(findPeriodTaskProcessUsecase.aggregatePeriodTaskProcess(period));
}

@GetMapping("/task-requests-by-category")
public ResponseEntity<Map<String, Long>> aggregateCategoryTaskRequest(@RequestParam String period) {
return ResponseEntity.ok(findCategoryTaskRequestUsecase.aggregateCategoryTaskRequest(period));
Expand All @@ -43,5 +41,9 @@ public ResponseEntity<Map<String, Long>> aggregateCategoryTaskRequest(@RequestPa
public ResponseEntity<Map<String, Long>> aggregateSubCategoryTaskRequest(@RequestParam String period, @RequestParam String mainCategory) {
return ResponseEntity.ok(findSubCategoryTaskRequestUsecase.aggregateSubCategoryTaskRequest(period, mainCategory));
}
// @GetMapping("/task/statistics/tasks-processed-by-manager")

@GetMapping("/tasks-processed-by-manager")
public ResponseEntity<Map<String, Long>> aggregateSubCategoryTaskRequest(@RequestParam String period) {
return ResponseEntity.ok(managerTaskProcessUsecase.aggregateManagerTaskProcess(period));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ public Map<String, Long> findSubCategoryTaskRequestByPeriod(String period, Strin
return getCategoryTaskResults(executeQuery(query));
}

@Override
public Map<String, Long> findManagerTaskProcessByPeriod(String period) {
PeriodConfig periodConfig = PeriodConfig.valueOf(period.toUpperCase());

NativeQuery query = buildManagerTaskProcessQuery(periodConfig);
return getManagerTaskResults(executeQuery(query));
}

private NativeQuery buildPeriodTaskRequestQuery(PeriodConfig config) {
return NativeQuery.builder()
.withQuery(q -> q
Expand Down Expand Up @@ -141,6 +149,20 @@ private NativeQuery buildSubCategoryTaskRequestQuery(PeriodConfig config, String
.build();
}

private NativeQuery buildManagerTaskProcessQuery(PeriodConfig config) {
return NativeQuery.builder()
.withQuery(q -> q
.range(r -> r
.date(d -> d
.field("created_at")
.gte(String.valueOf(LocalDate.now().minusDays(config.getDaysToSubtract()))))))
.withAggregation("manager_task", AggregationBuilders.terms()
.field("processor")
.build()._toAggregation())
.withMaxResults(0)
.build();
}

private ElasticsearchAggregations executeQuery(NativeQuery query) {
return (ElasticsearchAggregations) elasticsearchOperations
.search(query, TaskDocument.class)
Expand Down Expand Up @@ -181,4 +203,20 @@ private Map<String, Long> getCategoryTaskResults(ElasticsearchAggregations aggre
))
);
}

private Map<String, Long> getManagerTaskResults(ElasticsearchAggregations aggregations) {
return new TreeMap<>(
aggregations.get("manager_task")
.aggregation()
.getAggregate()
.sterms()
.buckets()
.array()
.stream()
.collect(Collectors.toMap(
bucket -> bucket.key().stringValue(),
MultiBucketBase::docCount
))
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package clap.server.application.port.inbound.statistics;

import java.util.Map;

public interface ManagerTaskProcessUsecase {
Map<String, Long> aggregateManagerTaskProcess(String period);
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@ public interface TaskDocumentPort {
Map<String, Long> findCategoryTaskRequestByPeriod(String period);

Map<String, Long> findSubCategoryTaskRequestByPeriod(String period, String mainCategory);

Map<String, Long> findManagerTaskProcessByPeriod(String period);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package clap.server.application.statistics;

import clap.server.application.port.inbound.statistics.ManagerTaskProcessUsecase;
import clap.server.application.port.outbound.task.TaskDocumentPort;
import clap.server.common.annotation.architecture.ApplicationService;
import lombok.RequiredArgsConstructor;

import java.util.Map;

@ApplicationService
@RequiredArgsConstructor
public class ManagerTaskProcessService implements ManagerTaskProcessUsecase {
private final TaskDocumentPort taskDocumentPort;

@Override
public Map<String, Long> aggregateManagerTaskProcess(String period) {
return taskDocumentPort.findManagerTaskProcessByPeriod(period);
}
}
Loading