Commit 5b30c81e authored by Cristian Aguirre's avatar Cristian Aguirre

DashboardController

parent 6f35ea6c
......@@ -29,7 +29,6 @@ public class DashboardController {
@PostMapping("/operative")
public ResponseEntity<String> getOperativeInfo(@RequestBody Map<String, Object> body) {
Map<String, Object> info = operativeDashboardService.generateInfo(body);
return new ResponseEntity<>(gson.toJson(info), HttpStatus.OK);
}
......
......@@ -8,13 +8,10 @@ import com.bytesw.bytebot.jdbc.BotSessionJDCBRepository;
import com.bytesw.bytebot.jdbc.MessageJDBCRepository;
import com.bytesw.bytebot.jdbc.ResponseJDBCRepository;
import com.bytesw.xdf.exception.NotFoundException;
import io.swagger.models.auth.In;
import lombok.extern.log4j.Log4j2;
import org.apache.commons.collections.ArrayStack;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.management.ObjectName;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.sql.Timestamp;
......@@ -35,31 +32,38 @@ public class OperativeDashboardService extends DashboardService {
private ResponseJDBCRepository responseJDBCRepository;
@Override
protected void completeData(OffsetDateTime startDate, OffsetDateTime endDate, Integer rangeMinutes,Map<String, Object> info) {
protected void completeData(OffsetDateTime startDate, OffsetDateTime endDate, Integer rangeMinutes, Map<String, Object> info) {
if (startDate.isAfter(endDate)) {
throw new NotFoundException("Invalid data range");
}
List<RangeBean> rangeList = calculateRangeList(startDate, endDate);
List<RangeBean> rangeMinutsList = calculateMinutesRangeList(startDate,endDate,rangeMinutes);
List<RangeBean> rangeMinutsList = calculateMinutesRangeList(startDate, endDate, rangeMinutes);
List<Object[]> messageByActivity = generateData(rangeList);
//Cantidad de sesiones
List<SessionByClientBean> sessions_by_user = botSessionJDCBRepository.countSessionInRange(startDate, endDate);
// Mensajes recibidos
List<Object[]> recivedMessages = generateDataVariablePeriod(rangeMinutsList,true);
List<Object[]> recivedMessages = generateDataVariablePeriod(rangeMinutsList, true);
int totalrecivedMessages = messageJDBCRepository.countSessionInRange(startDate, endDate);
// Mensajes enviados
List<Object[]> responseMessages = generateDataVariablePeriod(rangeMinutsList,false);
List<Object[]> responseMessages = generateDataVariablePeriod(rangeMinutsList, false);
int totalresponseMessages = responseJDBCRepository.countSessionInRange(startDate, endDate);
//Promedio primera respuesta en mili
Object avgFRObject = botSessionJDCBRepository.getAvgFirstResponseTime(startDate, endDate);
Double avgFirstResponse;
if (avgFRObject instanceof Long) {
avgFirstResponse = new Double((Long)avgFRObject);
avgFirstResponse = new Double((Long) avgFRObject);
} else {
avgFirstResponse = (Double) avgFRObject;
}
Double avgSessionsByCustomer = botSessionJDCBRepository.getAvgSessionByCustomerInRange(startDate, endDate);
double avgSessionsByCustomerRaw = botSessionJDCBRepository.getAvgSessionByCustomerInRange(startDate, endDate);
// Tomar solo parte entera
int avgSessionsByCustomer = (int) avgSessionsByCustomerRaw;
Timestamp timestamp = botSessionJDCBRepository.getLastDateInRage(startDate, endDate);
......@@ -73,13 +77,14 @@ public class OperativeDashboardService extends DashboardService {
// Adjuntando tiempo de inactividad
SummaryBean sessionInactivity = new SummaryBean();
sessionInactivity.setValue(new BigInteger(String.valueOf(difference.getSeconds())));
BigInteger value = new BigInteger(String.valueOf(difference.getSeconds()));
sessionInactivity.setValue(value);
// Adjutando el total de sesiones por cliente
SummaryBean totalSessions = new SummaryBean();
totalSessions.setHistory(new ArrayList<>());
ArrayList<BigInteger> totalsessions = new ArrayList<BigInteger>(); // Total de sesiones
sessions_by_user.stream().forEach(x ->{
sessions_by_user.stream().forEach(x -> {
ArrayList<Object> session = new ArrayList<Object>();
// Split de la data para obtener el número
String sender_id = x.getSender_id().split(":")[1];
......@@ -88,24 +93,25 @@ public class OperativeDashboardService extends DashboardService {
totalsessions.add(x.getCount());
totalSessions.getHistory().add(session);
});
int sum = totalsessions.stream().mapToInt(BigInteger::intValue).sum();
BigInteger total = BigInteger.valueOf(sum);
totalSessions.setValue(total);
// Adjuntamos los mensajes recibidos
Map<String,Object> recivedMessage = new HashMap<>();
recivedMessage.put("value",totalrecivedMessages);
recivedMessage.put("history",recivedMessages);
Map<String, Object> recivedMessage = new HashMap<>();
recivedMessage.put("value", totalrecivedMessages);
recivedMessage.put("history", recivedMessages);
// Adjuntamos los mensajes enviados
Map<String,Object> responseMessage = new HashMap<>();
responseMessage.put("value",totalresponseMessages);
responseMessage.put("history",responseMessages);
Map<String, Object> responseMessage = new HashMap<>();
responseMessage.put("value", totalresponseMessages);
responseMessage.put("history", responseMessages);
Map<String, Object> summary = new HashMap<>();
summary.put("sessionInactivity", sessionInactivity);
summary.put("totalSessions", totalSessions);
summary.put("totalSentMessages",responseMessage);
summary.put("totalReceivedMessages",recivedMessage);
summary.put("totalSentMessages", responseMessage);
summary.put("totalReceivedMessages", recivedMessage);
AverageBean averageBean = new AverageBean();
if (avgFirstResponse == null) {
......@@ -119,32 +125,33 @@ public class OperativeDashboardService extends DashboardService {
info.put("customerMessageDetail", messageByActivity);
}
private List<Object[]> generateDataVariablePeriod(List<RangeBean> rangeList, boolean recieved){
private List<Object[]> generateDataVariablePeriod(List<RangeBean> rangeList, boolean recieved) {
List<Object[]> data = new ArrayList<>();
Map<Long,Map<Integer,Integer>> accumulated = new HashMap<>();
Map<Long, Map<Integer, Integer>> accumulated = new HashMap<>();
int cont = 0;
for (RangeBean range: rangeList){
for (RangeBean range : rangeList) {
int cant = 0;
if(recieved){
cant = messageJDBCRepository.countMessageInRangeHour(range.getStartDate(),range.getEndDate());
}else{
cant = responseJDBCRepository.countSessionInRange(range.getStartDate(),range.getEndDate());
if (recieved) {
cant = messageJDBCRepository.countMessageInRangeHour(range.getStartDate(), range.getEndDate());
} else {
cant = responseJDBCRepository.countSessionInRange(range.getStartDate(), range.getEndDate());
}
LocalDateTime times = range.getStartDate().toLocalDateTime();
Long timestamp = Timestamp.valueOf(times).getTime();
if(!accumulated.containsKey(timestamp)){
if (!accumulated.containsKey(timestamp)) {
accumulated.put(timestamp, new HashMap<>());
}
accumulated.get(timestamp).put(cont,cant);
accumulated.get(timestamp).put(cont, cant);
cont++;
}
accumulated.keySet().stream().forEach(x ->{
accumulated.get(x).keySet().stream().forEach(y ->{
accumulated.keySet().stream().forEach(x -> {
accumulated.get(x).keySet().stream().forEach(y -> {
data.add(new Object[]{x, accumulated.get(x).get(y)});
});
});
return data;
}
private List<Object[]> generateData(List<RangeBean> rangeList) {
List<Object[]> data = new ArrayList<>();
Map<Long, Map<Integer, Integer>> accumulated = new HashMap<>();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment