Commit 2a7b2470 authored by Cristian Aguirre's avatar Cristian Aguirre

OperativeDashboardService

parent b9b888c3
...@@ -20,14 +20,14 @@ public class BotSessionJDCBRepository { ...@@ -20,14 +20,14 @@ public class BotSessionJDCBRepository {
@Qualifier("sqlSessionFactory") @Qualifier("sqlSessionFactory")
private SqlSessionFactory sqlSessionFactory; private SqlSessionFactory sqlSessionFactory;
public List<SessionByClientBean> countSessionInRange(OffsetDateTime startDate, OffsetDateTime endDate) { public int countSessionInRange(OffsetDateTime startDate, OffsetDateTime endDate) {
SqlSession session = sqlSessionFactory.openSession(); SqlSession session = sqlSessionFactory.openSession();
try { try {
Map<String, Object> params = new HashMap<>(); Map<String, Object> params = new HashMap<>();
params.put("startDate", startDate); params.put("startDate", startDate);
params.put("endDate", endDate); params.put("endDate", endDate);
return session.selectList("com.bytesw.bytebot.dao.jdbc.SessionMapper.countSessionsInRange", params); return session.selectOne("com.bytesw.bytebot.dao.jdbc.SessionMapper.countSessionsInRange", params);
} finally { } finally {
session.close(); session.close();
} }
......
package com.bytesw.bytebot.model.enums;
import lombok.Getter;
import java.util.HashMap;
import java.util.Map;
@Getter
public enum MetricMessageTypeEnum {
RECEIVED("received"),
SENT("sent"),
SESSION("session");
private static final Map<String, MetricMessageTypeEnum> map = new HashMap<>();
private String name;
MetricMessageTypeEnum(String name){ this.name = name;}
public String getName() {return name;}
static {
for (MetricMessageTypeEnum type : MetricMessageTypeEnum.values()) {
map.put(type.name, type);
}
}
public static MetricMessageTypeEnum fromString(String name) {
return map.get(name);
}
}
...@@ -46,7 +46,7 @@ public class SchedulerTaskService extends XDFService<SchedulerTask, SchedulerTas ...@@ -46,7 +46,7 @@ public class SchedulerTaskService extends XDFService<SchedulerTask, SchedulerTas
if (!calendarOptional.isPresent()) { if (!calendarOptional.isPresent()) {
throw new NotFoundException("Calendar not found " + bean.getCalendarID()); throw new NotFoundException("Calendar not found " + bean.getCalendarID());
} }
model.setCalendar(calendarOptional.get()); // model.setCalendar(calendarOptional.get());
return model; return model;
} }
......
...@@ -47,7 +47,7 @@ public class WeekSchedulerService extends XDFService<WeekScheduler, WeekSchedule ...@@ -47,7 +47,7 @@ public class WeekSchedulerService extends XDFService<WeekScheduler, WeekSchedule
if (bean.getCalendarID() == null) { if (bean.getCalendarID() == null) {
throw new NotFoundException("Calendar can not be null"); throw new NotFoundException("Calendar can not be null");
} }
bean.setCalendarID(bean.getCalendarID().trim());
Optional<Calendar> calendarOptional = calendarRepository.findById(bean.getCalendarID().trim()); Optional<Calendar> calendarOptional = calendarRepository.findById(bean.getCalendarID().trim());
if (!calendarOptional.isPresent()) { if (!calendarOptional.isPresent()) {
throw new NotFoundException("Calendar not found " + bean.getCalendarID()); throw new NotFoundException("Calendar not found " + bean.getCalendarID());
......
...@@ -11,7 +11,7 @@ import com.bytesw.xdf.exception.NotFoundException; ...@@ -11,7 +11,7 @@ import com.bytesw.xdf.exception.NotFoundException;
import lombok.extern.log4j.Log4j2; import lombok.extern.log4j.Log4j2;
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 com.bytesw.bytebot.model.enums.MetricMessageTypeEnum;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.math.BigInteger; import java.math.BigInteger;
import java.sql.Timestamp; import java.sql.Timestamp;
...@@ -43,13 +43,14 @@ public class OperativeDashboardService extends DashboardService { ...@@ -43,13 +43,14 @@ public class OperativeDashboardService extends DashboardService {
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<Object[]> sessions = generateDataVariablePeriod(rangeMinutsList, MetricMessageTypeEnum.SESSION.getName());
int totalSessions = botSessionJDCBRepository.countSessionInRange(startDate, endDate);
// Mensajes recibidos // Mensajes recibidos
List<Object[]> recivedMessages = generateDataVariablePeriod(rangeMinutsList, true); List<Object[]> recivedMessages = generateDataVariablePeriod(rangeMinutsList, MetricMessageTypeEnum.RECEIVED.getName());
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, MetricMessageTypeEnum.SENT.getName());
int totalresponseMessages = responseJDBCRepository.countSessionInRange(startDate, endDate); int totalresponseMessages = responseJDBCRepository.countSessionInRange(startDate, endDate);
//Promedio primera respuesta en mili //Promedio primera respuesta en mili
...@@ -61,9 +62,12 @@ public class OperativeDashboardService extends DashboardService { ...@@ -61,9 +62,12 @@ public class OperativeDashboardService extends DashboardService {
avgFirstResponse = (Double) avgFRObject; avgFirstResponse = (Double) avgFRObject;
} }
double avgSessionsByCustomerRaw = botSessionJDCBRepository.getAvgSessionByCustomerInRange(startDate, endDate); Double avgSessionsByCustomerRaw = botSessionJDCBRepository.getAvgSessionByCustomerInRange(startDate, endDate);
// Tomar solo parte entera // Tomar solo parte entera
int avgSessionsByCustomer = (int) avgSessionsByCustomerRaw; if (avgSessionsByCustomerRaw == null){
avgSessionsByCustomerRaw = 0.0;
}
int avgSessionsByCustomer = avgSessionsByCustomerRaw.intValue();
Timestamp timestamp = botSessionJDCBRepository.getLastDateInRage(startDate, endDate); Timestamp timestamp = botSessionJDCBRepository.getLastDateInRage(startDate, endDate);
...@@ -80,23 +84,11 @@ public class OperativeDashboardService extends DashboardService { ...@@ -80,23 +84,11 @@ public class OperativeDashboardService extends DashboardService {
BigInteger value = new BigInteger(String.valueOf(difference.getSeconds())); BigInteger value = new BigInteger(String.valueOf(difference.getSeconds()));
sessionInactivity.setValue(value); sessionInactivity.setValue(value);
// Adjutando el total de sesiones por cliente // Adjutando las sesiones totales
SummaryBean totalSessions = new SummaryBean(); Map<String,Object> totalSession = new HashMap<>();
totalSessions.setHistory(new ArrayList<>()); totalSession.put("value",totalSessions);
ArrayList<BigInteger> totalsessions = new ArrayList<BigInteger>(); // Total de sesiones totalSession.put("history",sessions);
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];
session.add(sender_id);
session.add(x.getCount());
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 // Adjuntamos los mensajes recibidos
Map<String, Object> recivedMessage = new HashMap<>(); Map<String, Object> recivedMessage = new HashMap<>();
recivedMessage.put("value", totalrecivedMessages); recivedMessage.put("value", totalrecivedMessages);
...@@ -109,7 +101,7 @@ public class OperativeDashboardService extends DashboardService { ...@@ -109,7 +101,7 @@ public class OperativeDashboardService extends DashboardService {
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", totalSession);
summary.put("totalSentMessages", responseMessage); summary.put("totalSentMessages", responseMessage);
summary.put("totalReceivedMessages", recivedMessage); summary.put("totalReceivedMessages", recivedMessage);
...@@ -125,16 +117,18 @@ public class OperativeDashboardService extends DashboardService { ...@@ -125,16 +117,18 @@ 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, String metric) {
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 (metric.equals(MetricMessageTypeEnum.RECEIVED.getName())) {
cant = messageJDBCRepository.countMessageInRangeHour(range.getStartDate(), range.getEndDate()); cant = messageJDBCRepository.countMessageInRangeHour(range.getStartDate(), range.getEndDate());
} else { } else if (metric.equals(MetricMessageTypeEnum.SENT.getName())) {
cant = responseJDBCRepository.countSessionInRange(range.getStartDate(), range.getEndDate()); cant = responseJDBCRepository.countSessionInRange(range.getStartDate(), range.getEndDate());
}else if (metric.equals(MetricMessageTypeEnum.SESSION.getName())){
cant = botSessionJDCBRepository.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();
......
...@@ -12,14 +12,10 @@ ...@@ -12,14 +12,10 @@
ORDER BY SESSION_LEDAT DESC LIMIT 1 ORDER BY SESSION_LEDAT DESC LIMIT 1
</select> </select>
<select id="countSessionsInRange" resultType="SessionByClient" flushCache="true"> <select id="countSessionsInRange" resultType="int" flushCache="true">
select au.user_ident as sender_id, select count(session_id) from avb_session
count(session_id) as count
FROM AVB_SESSION bas
join avb_user au on au.user_id=bas.user_id
WHERE SESSION_LEDAT &lt;= #{endDate} WHERE SESSION_LEDAT &lt;= #{endDate}
AND SESSION_LEDAT &gt;= #{startDate} AND SESSION_LEDAT &gt;= #{startDate}
group by au.user_ident
</select> </select>
<select id="avgSessionsByCustomerInRange" resultType="Double" flushCache="true"> <select id="avgSessionsByCustomerInRange" resultType="Double" flushCache="true">
......
...@@ -12,14 +12,10 @@ ...@@ -12,14 +12,10 @@
ORDER BY SESSION_LEDAT DESC LIMIT 1 ORDER BY SESSION_LEDAT DESC LIMIT 1
</select> </select>
<select id="countSessionsInRange" resultType="SessionByClient" flushCache="true"> <select id="countSessionsInRange" resultType="int" flushCache="true">
select au.user_ident as sender_id, select count(session_id) from avb_session
count(session_id) as count
FROM AVB_SESSION bas
join avb_user au on au.user_id=bas.user_id
WHERE SESSION_LEDAT &lt;= #{endDate} WHERE SESSION_LEDAT &lt;= #{endDate}
AND SESSION_LEDAT &gt;= #{startDate} AND SESSION_LEDAT &gt;= #{startDate}
group by au.user_ident
</select> </select>
<select id="avgSessionsByCustomerInRange" resultType="Double" flushCache="true"> <select id="avgSessionsByCustomerInRange" resultType="Double" flushCache="true">
......
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