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

DashboardController

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