BarrageScoreCurvePlugin 插件api

This commit is contained in:
userA
2023-10-13 17:46:53 +08:00
parent 384d4fefea
commit 47f78c0c26
4 changed files with 118 additions and 1 deletions

View File

@@ -0,0 +1,83 @@
package org.example.api;
import org.example.bean.BarrageCurveVO;
import org.example.bean.LiverKeyword;
import org.example.config.BarrageModuleConfig;
import org.example.core.bgevnet.BarrageEvent;
import org.example.core.bgevnet.bgscore.BarragePoint;
import org.example.core.bgevnet.bgscore.BarrageScoreCurvePlugin;
import org.example.service.LiverKeywordService;
import org.example.util.ConfigFileUtil;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
* @author Genius
* @date 2023/10/13 16:45
**/
@Component
public class BarrageScoreCurvePluginApi {
@Resource
private BarrageScoreCurvePlugin barrageScoreCurvePlugin;
@Resource
private LiverKeywordService keywordService;
public List<BarrageCurveVO> curveVOList(){
List<BarrageCurveVO> curveVOList = new ArrayList<>();
barrageScoreCurvePlugin.getBarragePointMap().forEach(
(k,v)->{
curveVOList.add(new BarrageCurveVO(k,v));
}
);
return curveVOList;
}
public BarrageCurveVO generateCurve(String filePath){
BarrageEvent event = new BarrageEvent();
event.setFileName(filePath);
List<BarragePoint> points = barrageScoreCurvePlugin.generateCurve(event);
return new BarrageCurveVO(filePath,points);
}
public BarrageCurveVO generateCurve(String filePath,String liver){
BarrageEvent event = new BarrageEvent();
event.setFileName(filePath);
event.setLiver(liver);
List<BarragePoint> points = barrageScoreCurvePlugin.generateCurve(event);
return new BarrageCurveVO(filePath,points);
}
public List<LiverKeyword> getKeyWords(String anchor){
return barrageScoreCurvePlugin.getKetWords(anchor);
}
public List<LiverKeyword> getKeyWords(){
return keywordService.getGlobalKeyWords();
}
public boolean updateKeyWord(LiverKeyword keyword){
return keywordService.updateKeyWord(keyword);
}
public boolean addKeyWord(LiverKeyword keyword){
return keywordService.addKeyWord(keyword);
}
public boolean deleteKeyWord(String anchor,String keyword){
return keywordService.deleteKeyWord(anchor,keyword);
}
public void changeSetting(Map<String,Object> settings){
ConfigFileUtil.changeSetting(settings,BarrageModuleConfig.getFullFilePath(),"barrageScoreCurve");
}
public Object getSetting(){
return ConfigFileUtil.getSetting(BarrageModuleConfig.getFullFilePath(),"barrageScoreCurve");
}
}

View File

@@ -0,0 +1,21 @@
package org.example.bean;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.example.core.bgevnet.bgscore.BarragePoint;
import org.springframework.stereotype.Component;
import java.util.List;
/**
* @author Genius
* @date 2023/10/13 16:46
**/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class BarrageCurveVO {
private String filePath;
private List<BarragePoint> points;
}

View File

@@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.example.bean.Barrage;
import org.example.constpool.BarrageModuleConstPool;
import org.example.constpool.FileNameBuilder;
@@ -24,6 +25,7 @@ import java.util.stream.Collectors;
* @date 2023/09/13 18:21
**/
@Data
@NoArgsConstructor
public class BarrageEvent {
private String platform;
@@ -63,6 +65,9 @@ public class BarrageEvent {
}
public String getBarrageFilePath(){
if(platform==null||action==null){
return fileName;
}
return Paths.get(BarrageSaveFile.fileRoot(action,platform), fileName).toString();
}

View File

@@ -14,6 +14,7 @@ import org.example.core.bgevnet.bgscore.split.SplitStrategyFactory;
import org.example.plugin.SpringBootPlugin;
import org.example.service.LiverKeywordService;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
import javax.annotation.Resource;
import java.util.*;
@@ -55,12 +56,15 @@ public class BarrageScoreCurvePlugin extends SpringBootPlugin {
String liver = event.getLiver();
String path = event.getBarrageFilePath();
long duration = Long.parseLong(fileCache.get("barrageScoreCurve", "duration").toString());
List<LiverKeyword> liverKeyWords = service.getLiverKeyWords(liver);
List<LiverKeyword> liverKeyWords = getKetWords(liver);
Map<String, LiverKeyword> liverKeywordMap = generateKeyMap(liverKeyWords);
String splitType = (String) fileCache.get("barrageScoreCurve", "splitStrategy");
String scoreType = (String) fileCache.get("barrageScoreCurve", "scoreStrategy");
AbstractScoreStrategy scoreStrategy = ScoreStrategyFactory.build(scoreType, liverKeywordMap);
if(scoreType!=null){
AbstractSplitStrategy splitStrategy = SplitStrategyFactory.build(splitType, scoreStrategy, barrages, duration,liverKeywordMap);
if(splitStrategy!=null){
@@ -112,4 +116,8 @@ public class BarrageScoreCurvePlugin extends SpringBootPlugin {
public static boolean isBan(String barrage,Map<String, LiverKeyword> map){
return isBan0(barrage,globalKeywordMap)||isBan0(barrage,map);
}
public List<LiverKeyword> getKetWords(String liver){
return StringUtils.hasText(liver)?service.getLiverKeyWords(liver):new ArrayList<>();
}
}