Skip to content

Commit

Permalink
Update to return the days the requests occur on for Requests Per Day (#…
Browse files Browse the repository at this point in the history
…1985)

* Update to return the days the requests occur on for Requests Per Day

Signed-off-by: Aindriu Lavelle <aindriu.lavelle@aiven.io>

* remove log line

Signed-off-by: Aindriu Lavelle <aindriu.lavelle@aiven.io>

---------

Signed-off-by: Aindriu Lavelle <aindriu.lavelle@aiven.io>
  • Loading branch information
aindriu-aiven authored Nov 16, 2023
1 parent f67c060 commit e24ce82
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 24 deletions.
3 changes: 3 additions & 0 deletions core/src/main/java/io/aiven/klaw/helpers/KwConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -150,4 +150,7 @@ public class KwConstants {

public static final DateTimeFormatter DATE_TIME_DDMMMYYYY_HHMMSS_FORMATTER =
DateTimeFormatter.ofPattern("dd-MMM-yyyy HH:mm:ss").withZone(ZoneId.systemDefault());

public static final DateTimeFormatter DATE_DDMMMYYYY_FORMATTER =
DateTimeFormatter.ofPattern("dd-MMM-yyyy").withZone(ZoneId.systemDefault());
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.aiven.klaw.helpers.db.rdbms;

import static io.aiven.klaw.helpers.KwConstants.DATE_TIME_DDMMMYYYY_HHMMSS_FORMATTER;
import static io.aiven.klaw.helpers.KwConstants.REQUESTOR_SUBSCRIPTIONS;
import static io.aiven.klaw.helpers.KwConstants.*;
import static org.reflections.Reflections.log;

import com.google.common.collect.Lists;
import io.aiven.klaw.dao.*;
Expand All @@ -15,24 +15,15 @@
import io.aiven.klaw.model.response.DashboardStats;
import io.aiven.klaw.repository.*;
import io.aiven.klaw.service.CommonUtilsService;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.TreeSet;
import java.util.*;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.commons.lang3.tuple.Pair;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.stereotype.Component;
Expand Down Expand Up @@ -1101,12 +1092,11 @@ public List<CommonUtilsService.ChartsOverviewItem<String, Integer>> selectActivi
Integer teamId, int numberOfDays, int tenantId) {
try {
List<CommonUtilsService.ChartsOverviewItem<String, Integer>> res = new ArrayList<>();
List<Integer> fromDb =
List<Pair<String, Integer>> fromDb =
gatherActivityList(
activityLogRepo.findActivityLogForTeamIdForLastNDays(teamId, tenantId, numberOfDays));
for (int elem : fromDb) {

res.add(CommonUtilsService.ChartsOverviewItem.of("activitycount", elem));
for (Pair<String, Integer> elem : fromDb) {
res.add(CommonUtilsService.ChartsOverviewItem.of(elem.getKey(), elem.getValue()));
}
return res;
} catch (Exception e) {
Expand All @@ -1119,11 +1109,11 @@ public List<CommonUtilsService.ChartsOverviewItem<String, Integer>> selectActivi
int numberOfDays, String[] envIdList, int tenantId) {
try {
List<CommonUtilsService.ChartsOverviewItem<String, Integer>> res = new ArrayList<>();
List<Integer> fromDb =
List<Pair<String, Integer>> fromDb =
gatherActivityList(
activityLogRepo.findActivityLogForLastNDays(envIdList, tenantId, numberOfDays));
for (int elem : fromDb) {
res.add(CommonUtilsService.ChartsOverviewItem.of("activitycount", elem));
for (Pair<String, Integer> elem : fromDb) {
res.add(CommonUtilsService.ChartsOverviewItem.of(elem.getKey(), elem.getValue()));
}
return res;
} catch (Exception e) {
Expand All @@ -1146,10 +1136,14 @@ public static ActivityCountItem of(String dateOfActivity, int activityCount) {
}
}

private List<Integer> gatherActivityList(List<Object[]> activityCount) {
List<Integer> res = new ArrayList<>(activityCount.size());
private List<Pair<String, Integer>> gatherActivityList(List<Object[]> activityCount) {
List<Pair<String, Integer>> res = new ArrayList<>(activityCount.size());
for (Object[] activity : activityCount) {
res.add((((Long) activity[1]).intValue()));

res.add(
new ImmutablePair<>(
DATE_DDMMMYYYY_FORMATTER.format(((java.sql.Date) activity[0]).toLocalDate()),
((Long) activity[1]).intValue()));
}
return res;
}
Expand Down Expand Up @@ -1287,6 +1281,7 @@ public List<CommonUtilsService.ChartsOverviewItem<Integer, Integer>> selectAclsC
Map<String, Integer> envIds =
topics.stream()
.collect(Collectors.toMap(e -> (String) e[0], e -> ((Long) e[1]).intValue()));

Map<String, Env> name2envsFromDb =
StreamSupport.stream(selectEnvsDetails(envIds.keySet(), tenantId).spliterator(), false)
.collect(Collectors.toMap(Env::getName, Function.identity()));
Expand Down

0 comments on commit e24ce82

Please sign in to comment.