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

OperativeDashboardService

parent b9b888c3
......@@ -20,14 +20,14 @@ public class BotSessionJDCBRepository {
@Qualifier("sqlSessionFactory")
private SqlSessionFactory sqlSessionFactory;
public List<SessionByClientBean> countSessionInRange(OffsetDateTime startDate, OffsetDateTime endDate) {
public int countSessionInRange(OffsetDateTime startDate, OffsetDateTime endDate) {
SqlSession session = sqlSessionFactory.openSession();
try {
Map<String, Object> params = new HashMap<>();
params.put("startDate", startDate);
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 {
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
if (!calendarOptional.isPresent()) {
throw new NotFoundException("Calendar not found " + bean.getCalendarID());
}
model.setCalendar(calendarOptional.get());
// model.setCalendar(calendarOptional.get());
return model;
}
......
......@@ -47,7 +47,7 @@ public class WeekSchedulerService extends XDFService<WeekScheduler, WeekSchedule
if (bean.getCalendarID() == null) {
throw new NotFoundException("Calendar can not be null");
}
bean.setCalendarID(bean.getCalendarID().trim());
Optional<Calendar> calendarOptional = calendarRepository.findById(bean.getCalendarID().trim());
if (!calendarOptional.isPresent()) {
throw new NotFoundException("Calendar not found " + bean.getCalendarID());
......
......@@ -11,7 +11,7 @@ import com.bytesw.xdf.exception.NotFoundException;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.bytesw.bytebot.model.enums.MetricMessageTypeEnum;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.sql.Timestamp;
......@@ -43,13 +43,14 @@ public class OperativeDashboardService extends DashboardService {
List<Object[]> messageByActivity = generateData(rangeList);
//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
List<Object[]> recivedMessages = generateDataVariablePeriod(rangeMinutsList, true);
List<Object[]> recivedMessages = generateDataVariablePeriod(rangeMinutsList, MetricMessageTypeEnum.RECEIVED.getName());
int totalrecivedMessages = messageJDBCRepository.countSessionInRange(startDate, endDate);
// Mensajes enviados
List<Object[]> responseMessages = generateDataVariablePeriod(rangeMinutsList, false);
List<Object[]> responseMessages = generateDataVariablePeriod(rangeMinutsList, MetricMessageTypeEnum.SENT.getName());
int totalresponseMessages = responseJDBCRepository.countSessionInRange(startDate, endDate);
//Promedio primera respuesta en mili
......@@ -61,9 +62,12 @@ public class OperativeDashboardService extends DashboardService {
avgFirstResponse = (Double) avgFRObject;
}
double avgSessionsByCustomerRaw = botSessionJDCBRepository.getAvgSessionByCustomerInRange(startDate, endDate);
Double avgSessionsByCustomerRaw = botSessionJDCBRepository.getAvgSessionByCustomerInRange(startDate, endDate);
// Tomar solo parte entera
int avgSessionsByCustomer = (int) avgSessionsByCustomerRaw;
if (avgSessionsByCustomerRaw == null){
avgSessionsByCustomerRaw = 0.0;
}
int avgSessionsByCustomer = avgSessionsByCustomerRaw.intValue();
Timestamp timestamp = botSessionJDCBRepository.getLastDateInRage(startDate, endDate);
......@@ -80,23 +84,11 @@ public class OperativeDashboardService extends DashboardService {
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 -> {
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);
});
// Adjutando las sesiones totales
Map<String,Object> totalSession = new HashMap<>();
totalSession.put("value",totalSessions);
totalSession.put("history",sessions);
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);
......@@ -109,7 +101,7 @@ public class OperativeDashboardService extends DashboardService {
Map<String, Object> summary = new HashMap<>();
summary.put("sessionInactivity", sessionInactivity);
summary.put("totalSessions", totalSessions);
summary.put("totalSessions", totalSession);
summary.put("totalSentMessages", responseMessage);
summary.put("totalReceivedMessages", recivedMessage);
......@@ -125,16 +117,18 @@ 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, String metric) {
List<Object[]> data = new ArrayList<>();
Map<Long, Map<Integer, Integer>> accumulated = new HashMap<>();
int cont = 0;
for (RangeBean range : rangeList) {
int cant = 0;
if (recieved) {
if (metric.equals(MetricMessageTypeEnum.RECEIVED.getName())) {
cant = messageJDBCRepository.countMessageInRangeHour(range.getStartDate(), range.getEndDate());
} else {
} else if (metric.equals(MetricMessageTypeEnum.SENT.getName())) {
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();
Long timestamp = Timestamp.valueOf(times).getTime();
......
......@@ -12,14 +12,10 @@
ORDER BY SESSION_LEDAT DESC LIMIT 1
</select>
<select id="countSessionsInRange" resultType="SessionByClient" flushCache="true">
select au.user_ident as sender_id,
count(session_id) as count
FROM AVB_SESSION bas
join avb_user au on au.user_id=bas.user_id
<select id="countSessionsInRange" resultType="int" flushCache="true">
select count(session_id) from avb_session
WHERE SESSION_LEDAT &lt;= #{endDate}
AND SESSION_LEDAT &gt;= #{startDate}
group by au.user_ident
</select>
<select id="avgSessionsByCustomerInRange" resultType="Double" flushCache="true">
......
......@@ -12,14 +12,10 @@
ORDER BY SESSION_LEDAT DESC LIMIT 1
</select>
<select id="countSessionsInRange" resultType="SessionByClient" flushCache="true">
select au.user_ident as sender_id,
count(session_id) as count
FROM AVB_SESSION bas
join avb_user au on au.user_id=bas.user_id
<select id="countSessionsInRange" resultType="int" flushCache="true">
select count(session_id) from avb_session
WHERE SESSION_LEDAT &lt;= #{endDate}
AND SESSION_LEDAT &gt;= #{startDate}
group by au.user_ident
</select>
<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