mirror of
https://github.com/tencentmusic/supersonic.git
synced 2025-12-20 06:34:55 +00:00
[improvement][project]Use DatePeriodEnum to replace DAY/MONTH/YEAR period constants.
This commit is contained in:
@@ -6,6 +6,7 @@ import com.tencent.supersonic.chat.api.pojo.request.ChatParseReq;
|
||||
import com.tencent.supersonic.chat.api.pojo.response.QueryResult;
|
||||
import com.tencent.supersonic.chat.server.service.AgentService;
|
||||
import com.tencent.supersonic.chat.server.service.ChatQueryService;
|
||||
import com.tencent.supersonic.common.pojo.enums.DatePeriodEnum;
|
||||
import com.tencent.supersonic.headless.api.pojo.SchemaElement;
|
||||
import com.tencent.supersonic.headless.api.pojo.SemanticParseInfo;
|
||||
import com.tencent.supersonic.headless.api.pojo.response.ParseResp;
|
||||
@@ -22,9 +23,9 @@ import static org.junit.Assert.assertEquals;
|
||||
public class BaseTest extends BaseApplication {
|
||||
|
||||
protected final int unit = 7;
|
||||
protected final String startDay = LocalDate.now().plusDays(-unit).toString();
|
||||
protected final String endDay = LocalDate.now().plusDays(-1).toString();
|
||||
protected final String period = "DAY";
|
||||
protected final String startDay = LocalDate.now().minusDays(unit).toString();
|
||||
protected final String endDay = LocalDate.now().toString();
|
||||
protected final DatePeriodEnum period = DatePeriodEnum.DAY;
|
||||
|
||||
@Autowired protected ChatQueryService chatQueryService;
|
||||
@Autowired protected AgentService agentService;
|
||||
|
||||
@@ -2,13 +2,13 @@ package com.tencent.supersonic.chat;
|
||||
|
||||
import com.tencent.supersonic.chat.api.pojo.response.QueryResult;
|
||||
import com.tencent.supersonic.common.pojo.DateConf;
|
||||
import com.tencent.supersonic.common.pojo.enums.DatePeriodEnum;
|
||||
import com.tencent.supersonic.common.pojo.enums.FilterOperatorEnum;
|
||||
import com.tencent.supersonic.common.pojo.enums.QueryType;
|
||||
import com.tencent.supersonic.headless.api.pojo.SemanticParseInfo;
|
||||
import com.tencent.supersonic.headless.api.pojo.request.QueryFilter;
|
||||
import com.tencent.supersonic.headless.chat.query.rule.metric.MetricFilterQuery;
|
||||
import com.tencent.supersonic.headless.chat.query.rule.metric.MetricGroupByQuery;
|
||||
import com.tencent.supersonic.headless.chat.query.rule.metric.MetricModelQuery;
|
||||
import com.tencent.supersonic.headless.chat.query.rule.metric.MetricTopNQuery;
|
||||
import com.tencent.supersonic.util.DataUtils;
|
||||
import org.junit.jupiter.api.Order;
|
||||
@@ -45,25 +45,7 @@ public class MetricTest extends BaseTest {
|
||||
"user_name", FilterOperatorEnum.EQUALS, "alice", "用户", 2L));
|
||||
|
||||
expectedParseInfo.setDateInfo(
|
||||
DataUtils.getDateConf(DateConf.DateMode.RECENT, unit, period, startDay, endDay));
|
||||
expectedParseInfo.setQueryType(QueryType.METRIC);
|
||||
|
||||
assertQueryResult(expectedResult, actualResult);
|
||||
}
|
||||
|
||||
// @Test
|
||||
public void testMetricDomain() throws Exception {
|
||||
QueryResult actualResult = submitNewChat("超音数总访问次数", DataUtils.metricAgentId);
|
||||
|
||||
QueryResult expectedResult = new QueryResult();
|
||||
SemanticParseInfo expectedParseInfo = new SemanticParseInfo();
|
||||
expectedResult.setChatContext(expectedParseInfo);
|
||||
|
||||
expectedResult.setQueryMode(MetricModelQuery.QUERY_MODE);
|
||||
expectedParseInfo.setAggType(NONE);
|
||||
expectedParseInfo.getMetrics().add(DataUtils.getSchemaElement("访问次数"));
|
||||
expectedParseInfo.setDateInfo(
|
||||
DataUtils.getDateConf(DateConf.DateMode.RECENT, unit, period, startDay, endDay));
|
||||
DataUtils.getDateConf(DateConf.DateMode.BETWEEN, unit, period, startDay, endDay));
|
||||
expectedParseInfo.setQueryType(QueryType.METRIC);
|
||||
|
||||
assertQueryResult(expectedResult, actualResult);
|
||||
@@ -84,7 +66,8 @@ public class MetricTest extends BaseTest {
|
||||
expectedParseInfo.getDimensions().add(DataUtils.getSchemaElement("部门"));
|
||||
|
||||
expectedParseInfo.setDateInfo(
|
||||
DataUtils.getDateConf(DateConf.DateMode.RECENT, unit, period, startDay, endDay));
|
||||
DataUtils.getDateConf(
|
||||
DateConf.DateMode.BETWEEN, 7, DatePeriodEnum.DAY, startDay, endDay));
|
||||
expectedParseInfo.setQueryType(QueryType.METRIC);
|
||||
|
||||
assertQueryResult(expectedResult, actualResult);
|
||||
@@ -110,7 +93,7 @@ public class MetricTest extends BaseTest {
|
||||
expectedParseInfo.getDimensionFilters().add(dimensionFilter);
|
||||
|
||||
expectedParseInfo.setDateInfo(
|
||||
DataUtils.getDateConf(DateConf.DateMode.RECENT, unit, period, startDay, endDay));
|
||||
DataUtils.getDateConf(DateConf.DateMode.BETWEEN, unit, period, startDay, endDay));
|
||||
expectedParseInfo.setQueryType(QueryType.METRIC);
|
||||
|
||||
assertQueryResult(expectedResult, actualResult);
|
||||
@@ -131,7 +114,8 @@ public class MetricTest extends BaseTest {
|
||||
expectedParseInfo.getMetrics().add(DataUtils.getSchemaElement("访问次数"));
|
||||
expectedParseInfo.getDimensions().add(DataUtils.getSchemaElement("用户"));
|
||||
|
||||
expectedParseInfo.setDateInfo(DataUtils.getDateConf(3, DateConf.DateMode.RECENT, "DAY"));
|
||||
expectedParseInfo.setDateInfo(
|
||||
DataUtils.getDateConf(3, DateConf.DateMode.BETWEEN, DatePeriodEnum.DAY));
|
||||
expectedParseInfo.setQueryType(QueryType.METRIC);
|
||||
|
||||
assertQueryResult(expectedResult, actualResult);
|
||||
@@ -151,7 +135,7 @@ public class MetricTest extends BaseTest {
|
||||
expectedParseInfo.getDimensions().add(DataUtils.getSchemaElement("部门"));
|
||||
|
||||
expectedParseInfo.setDateInfo(
|
||||
DataUtils.getDateConf(DateConf.DateMode.RECENT, unit, period, startDay, endDay));
|
||||
DataUtils.getDateConf(DateConf.DateMode.BETWEEN, unit, period, startDay, endDay));
|
||||
expectedParseInfo.setQueryType(QueryType.METRIC);
|
||||
|
||||
assertQueryResult(expectedResult, actualResult);
|
||||
|
||||
@@ -37,7 +37,7 @@ public class MultiTurnsTest extends BaseTest {
|
||||
"user_name", FilterOperatorEnum.EQUALS, "alice", "用户", 2L));
|
||||
|
||||
expectedParseInfo.setDateInfo(
|
||||
DataUtils.getDateConf(DateConf.DateMode.RECENT, unit, period, startDay, endDay));
|
||||
DataUtils.getDateConf(DateConf.DateMode.BETWEEN, unit, period, startDay, endDay));
|
||||
expectedParseInfo.setQueryType(QueryType.METRIC);
|
||||
|
||||
assertQueryResult(expectedResult, actualResult);
|
||||
@@ -66,7 +66,7 @@ public class MultiTurnsTest extends BaseTest {
|
||||
"user_name", FilterOperatorEnum.EQUALS, "alice", "用户", 2L));
|
||||
|
||||
expectedParseInfo.setDateInfo(
|
||||
DataUtils.getDateConf(DateConf.DateMode.RECENT, unit, period, startDay, endDay));
|
||||
DataUtils.getDateConf(DateConf.DateMode.BETWEEN, unit, period, startDay, endDay));
|
||||
expectedParseInfo.setQueryType(QueryType.METRIC);
|
||||
|
||||
assertQueryResult(expectedResult, actualResult);
|
||||
@@ -93,7 +93,7 @@ public class MultiTurnsTest extends BaseTest {
|
||||
.add(DataUtils.getFilter("user_name", FilterOperatorEnum.EQUALS, "lucy", "用户", 2L));
|
||||
|
||||
expectedParseInfo.setDateInfo(
|
||||
DataUtils.getDateConf(DateConf.DateMode.RECENT, unit, period, startDay, endDay));
|
||||
DataUtils.getDateConf(DateConf.DateMode.BETWEEN, unit, period, startDay, endDay));
|
||||
expectedParseInfo.setQueryType(QueryType.METRIC);
|
||||
|
||||
assertQueryResult(expectedResult, actualResult);
|
||||
|
||||
@@ -1,15 +1,9 @@
|
||||
package com.tencent.supersonic.util;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.tencent.supersonic.auth.api.authentication.pojo.User;
|
||||
import com.tencent.supersonic.chat.api.pojo.request.ChatParseReq;
|
||||
import com.tencent.supersonic.chat.server.agent.Agent;
|
||||
import com.tencent.supersonic.chat.server.agent.AgentConfig;
|
||||
import com.tencent.supersonic.chat.server.agent.AgentToolType;
|
||||
import com.tencent.supersonic.chat.server.agent.PluginTool;
|
||||
import com.tencent.supersonic.chat.server.agent.RuleParserTool;
|
||||
import com.tencent.supersonic.common.pojo.DateConf;
|
||||
import com.tencent.supersonic.common.pojo.enums.DatePeriodEnum;
|
||||
import com.tencent.supersonic.common.pojo.enums.FilterOperatorEnum;
|
||||
import com.tencent.supersonic.headless.api.pojo.SchemaElement;
|
||||
import com.tencent.supersonic.headless.api.pojo.request.QueryFilter;
|
||||
@@ -51,15 +45,6 @@ public class DataUtils {
|
||||
return chatParseReq;
|
||||
}
|
||||
|
||||
public static ChatParseReq getChatParseReqWithAgent(Integer id, String query, Integer agentId) {
|
||||
ChatParseReq queryReq = new ChatParseReq();
|
||||
queryReq.setQueryText(query);
|
||||
queryReq.setChatId(id);
|
||||
queryReq.setUser(user_test);
|
||||
queryReq.setAgentId(agentId);
|
||||
return queryReq;
|
||||
}
|
||||
|
||||
public static SchemaElement getSchemaElement(String name) {
|
||||
return SchemaElement.builder().name(name).build();
|
||||
}
|
||||
@@ -79,20 +64,21 @@ public class DataUtils {
|
||||
return filter;
|
||||
}
|
||||
|
||||
public static DateConf getDateConf(Integer unit, DateConf.DateMode dateMode, String period) {
|
||||
public static DateConf getDateConf(
|
||||
Integer unit, DateConf.DateMode dateMode, DatePeriodEnum period) {
|
||||
DateConf dateInfo = new DateConf();
|
||||
dateInfo.setUnit(unit);
|
||||
dateInfo.setDateMode(dateMode);
|
||||
dateInfo.setPeriod(period);
|
||||
dateInfo.setStartDate(now().plusDays(-unit).toString());
|
||||
dateInfo.setEndDate(now().plusDays(-1).toString());
|
||||
dateInfo.setStartDate(now().minusDays(unit).toString());
|
||||
dateInfo.setEndDate(now().toString());
|
||||
return dateInfo;
|
||||
}
|
||||
|
||||
public static DateConf getDateConf(
|
||||
DateConf.DateMode dateMode,
|
||||
Integer unit,
|
||||
String period,
|
||||
DatePeriodEnum period,
|
||||
String startDate,
|
||||
String endDate) {
|
||||
DateConf dateInfo = new DateConf();
|
||||
@@ -104,69 +90,6 @@ public class DataUtils {
|
||||
return dateInfo;
|
||||
}
|
||||
|
||||
public static DateConf getDateConf(
|
||||
DateConf.DateMode dateMode, String startDate, String endDate) {
|
||||
DateConf dateInfo = new DateConf();
|
||||
dateInfo.setDateMode(dateMode);
|
||||
dateInfo.setStartDate(startDate);
|
||||
dateInfo.setEndDate(endDate);
|
||||
return dateInfo;
|
||||
}
|
||||
|
||||
public static DateConf getDateConf(
|
||||
DateConf.DateMode dateMode, String startDate, String endDate, int unit) {
|
||||
DateConf dateInfo = new DateConf();
|
||||
dateInfo.setDateMode(dateMode);
|
||||
dateInfo.setStartDate(startDate);
|
||||
dateInfo.setEndDate(endDate);
|
||||
dateInfo.setUnit(unit);
|
||||
return dateInfo;
|
||||
}
|
||||
|
||||
public static Agent getMetricAgent() {
|
||||
Agent agent = new Agent();
|
||||
agent.setId(1);
|
||||
agent.setName("查信息");
|
||||
agent.setDescription("查信息");
|
||||
AgentConfig agentConfig = new AgentConfig();
|
||||
agentConfig.getTools().add(getRuleQueryTool());
|
||||
agent.setAgentConfig(JSONObject.toJSONString(agentConfig));
|
||||
return agent;
|
||||
}
|
||||
|
||||
public static Agent getTagAgent() {
|
||||
Agent agent = new Agent();
|
||||
agent.setId(2);
|
||||
agent.setName("标签圈选");
|
||||
agent.setDescription("标签圈选");
|
||||
AgentConfig agentConfig = new AgentConfig();
|
||||
agentConfig.getTools().add(getRuleQueryTool());
|
||||
agent.setAgentConfig(JSONObject.toJSONString(agentConfig));
|
||||
return agent;
|
||||
}
|
||||
|
||||
private static RuleParserTool getRuleQueryTool() {
|
||||
RuleParserTool ruleQueryTool = new RuleParserTool();
|
||||
ruleQueryTool.setType(AgentToolType.NL2SQL_RULE);
|
||||
ruleQueryTool.setDataSetIds(Lists.newArrayList(-1L));
|
||||
ruleQueryTool.setQueryModes(
|
||||
Lists.newArrayList(
|
||||
"METRIC_ID",
|
||||
"METRIC_FILTER",
|
||||
"METRIC_MODEL",
|
||||
"TAG_DETAIL",
|
||||
"TAG_LIST_FILTER",
|
||||
"TAG_ID"));
|
||||
return ruleQueryTool;
|
||||
}
|
||||
|
||||
private static PluginTool getPluginTool() {
|
||||
PluginTool pluginTool = new PluginTool();
|
||||
pluginTool.setType(AgentToolType.PLUGIN);
|
||||
pluginTool.setPlugins(Lists.newArrayList(1L));
|
||||
return pluginTool;
|
||||
}
|
||||
|
||||
public static Set<Long> getMetricAgentIModelIds() {
|
||||
Set<Long> result = new HashSet<>();
|
||||
result.add(1L);
|
||||
|
||||
Reference in New Issue
Block a user