Skip to content

Commit

Permalink
Merge pull request #151 from Lixuhuilll/closeTime
Browse files Browse the repository at this point in the history
地图信息新增服务器认为的关闭时间。作业热度惩罚仅限首次上传时间于地图关闭前。
  • Loading branch information
dragove authored Dec 25, 2023
2 parents 429d418 + aba8761 commit 13781ad
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import org.jetbrains.annotations.Nullable;

import java.io.Serializable;

Expand All @@ -26,7 +25,4 @@ public class ArkLevelInfo implements Serializable {
private String name;
private int width;
private int height;
// 当前版本地图是否开放
@Nullable
private Boolean isOpen;
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import org.springframework.data.mongodb.core.index.Indexed;
import org.springframework.data.mongodb.core.mapping.Document;

import java.time.LocalDateTime;

/**
* 地图数据
*
Expand Down Expand Up @@ -39,7 +41,10 @@ public class ArkLevel {
private String name;
private int width;
private int height;
// 当前版本地图是否开放
// 只是服务器认为的当前版本地图是否开放
@Nullable
private Boolean isOpen;
// 非实际意义上的活动地图关闭时间,只是服务器认为的关闭时间
@Nullable
private LocalDateTime closeTime;
}
27 changes: 22 additions & 5 deletions src/main/java/plus/maa/backend/service/ArkLevelService.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
Expand Down Expand Up @@ -77,7 +79,7 @@ public class ArkLevelService {

private final List<String> bypassFileNames = List.of("overview.json");

@Cacheable("arkLevels")
@Cacheable("arkLevelInfos")
public List<ArkLevelInfo> getArkLevelInfos() {
return arkLevelRepo.findAll()
.stream()
Expand All @@ -86,13 +88,12 @@ public List<ArkLevelInfo> getArkLevelInfos() {
}

@Cacheable("arkLevel")
public ArkLevelInfo findByLevelIdFuzzy(String levelId) {
ArkLevel level = arkLevelRepo.findByLevelIdFuzzy(levelId).findAny().orElse(null);
return arkLevelConverter.convert(level);
public ArkLevel findByLevelIdFuzzy(String levelId) {
return arkLevelRepo.findByLevelIdFuzzy(levelId).findAny().orElse(null);
}


public List<ArkLevelInfo> queryLevelByKeyword(String keyword) {
public List<ArkLevelInfo> queryLevelInfosByKeyword(String keyword) {
List<ArkLevel> levels = arkLevelRepo.queryLevelByKeyword(keyword).collect(Collectors.toList());
return arkLevelConverter.convert(levels);
}
Expand Down Expand Up @@ -220,16 +221,26 @@ public void updateActivitiesOpenStatus() {
// 分页修改
Pageable pageable = Pageable.ofSize(1000);
Page<ArkLevel> arkLevelPage = arkLevelRepo.findAllByCatOne(catOne, pageable);

// 获取当前时间
LocalDateTime nowTime = LocalDateTime.now();

while (arkLevelPage.hasContent()) {

arkLevelPage.forEach(arkLevel -> {
// 只考虑地图系列的唯一标识
if (keyInfos.contains(ArkLevelUtil.getKeyInfoById(arkLevel.getStageId()))) {

arkLevel.setIsOpen(true);
// 如果一个旧地图重新开放,关闭时间也需要另算
arkLevel.setCloseTime(null);
} else if (arkLevel.getIsOpen() != null) {
// 数据可能存在部分缺失,因此地图此前必须被匹配过,才会认为其关闭
arkLevel.setIsOpen(false);
// 不能每天都变更关闭时间
if (arkLevel.getCloseTime() == null) {
arkLevel.setCloseTime(nowTime);
}
}
});

Expand Down Expand Up @@ -265,6 +276,7 @@ public void updateCrisisV2OpenStatus() {

// 获取当前时间
Instant nowInstant = Instant.now();
LocalDateTime nowTime = LocalDateTime.ofInstant(nowInstant, ZoneId.systemDefault());

while (arkCrisisV2Page.hasContent()) {

Expand All @@ -275,6 +287,11 @@ public void updateCrisisV2OpenStatus() {
.map(crisisV2Info -> Instant.ofEpochSecond(crisisV2Info.getEndTs()))
.ifPresent(endInstant -> arkCrisisV2.setIsOpen(endInstant.isAfter(nowInstant)));

if (arkCrisisV2.getCloseTime() == null &&
Boolean.FALSE.equals(arkCrisisV2.getIsOpen())) {
// 危机合约应该不存在赛季重新开放的问题,只要不每天变动关闭时间即可
arkCrisisV2.setCloseTime(nowTime);
}
});

arkLevelRepo.saveAll(arkCrisisV2Page);
Expand Down
9 changes: 3 additions & 6 deletions src/main/java/plus/maa/backend/service/CopilotService.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,7 @@
import plus.maa.backend.controller.response.copilot.CopilotInfo;
import plus.maa.backend.controller.response.copilot.CopilotPageInfo;
import plus.maa.backend.repository.*;
import plus.maa.backend.repository.entity.CommentsArea;
import plus.maa.backend.repository.entity.Copilot;
import plus.maa.backend.repository.entity.MaaUser;
import plus.maa.backend.repository.entity.Rating;
import plus.maa.backend.repository.entity.*;
import plus.maa.backend.service.model.RatingCache;
import plus.maa.backend.service.model.RatingType;

Expand Down Expand Up @@ -119,7 +116,7 @@ private CopilotDTO correctCopilot(CopilotDTO copilotDTO) {
.setName(action.getName() == null ? null : action.getName().replaceAll("[\"“”]", "")));
}
// 使用stageId存储作业关卡信息
ArkLevelInfo level = levelService.findByLevelIdFuzzy(copilotDTO.getStageName());
ArkLevel level = levelService.findByLevelIdFuzzy(copilotDTO.getStageName());
if (level != null) {
copilotDTO.setStageName(level.getStageId());
}
Expand Down Expand Up @@ -286,7 +283,7 @@ public CopilotPageInfo queriesCopilot(@Nullable String userId, CopilotQueriesReq

//关卡名、关卡类型、关卡编号
if (StringUtils.isNotBlank(request.getLevelKeyword())) {
List<ArkLevelInfo> levelInfo = levelService.queryLevelByKeyword(request.getLevelKeyword());
List<ArkLevelInfo> levelInfo = levelService.queryLevelInfosByKeyword(request.getLevelKeyword());
if (levelInfo.isEmpty()) {
andQueries.add(Criteria.where("stageName").regex(caseInsensitive(request.getLevelKeyword())));
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/plus/maa/backend/task/CopilotBackupTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
import org.springframework.stereotype.Component;
import plus.maa.backend.config.external.CopilotBackup;
import plus.maa.backend.config.external.MaaCopilotProperties;
import plus.maa.backend.controller.response.copilot.ArkLevelInfo;
import plus.maa.backend.repository.CopilotRepository;
import plus.maa.backend.repository.entity.ArkLevel;
import plus.maa.backend.repository.entity.Copilot;
import plus.maa.backend.service.ArkLevelService;

Expand Down Expand Up @@ -107,7 +107,7 @@ public void backupCopilots() {
File baseDirectory = git.getRepository().getWorkTree();
List<Copilot> copilots = copilotRepository.findAll();
copilots.forEach(copilot -> {
ArkLevelInfo level = levelService.findByLevelIdFuzzy(copilot.getStageName());
ArkLevel level = levelService.findByLevelIdFuzzy(copilot.getStageName());
if (Objects.isNull(level)) {
return;
}
Expand Down
12 changes: 9 additions & 3 deletions src/main/java/plus/maa/backend/task/CopilotScoreRefreshTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import plus.maa.backend.controller.response.copilot.ArkLevelInfo;
import plus.maa.backend.repository.CopilotRepository;
import plus.maa.backend.repository.RedisCache;
import plus.maa.backend.repository.entity.ArkLevel;
import plus.maa.backend.repository.entity.Copilot;
import plus.maa.backend.repository.entity.Rating;
import plus.maa.backend.service.ArkLevelService;
Expand Down Expand Up @@ -109,8 +109,14 @@ private void refresh(Collection<String> copilotIdSTRs, Iterable<Copilot> copilot
long dislikeCount = dislikeCountMap.getOrDefault(Long.toString(copilot.getCopilotId()), 0L);
double hotScore = CopilotService.getHotScore(copilot, likeCount, dislikeCount);
// 判断关卡是否开放
ArkLevelInfo arkLevelInfo = arkLevelService.findByLevelIdFuzzy(copilot.getStageName());
if (arkLevelInfo != null && Boolean.FALSE.equals(arkLevelInfo.getIsOpen())) {
ArkLevel level = arkLevelService.findByLevelIdFuzzy(copilot.getStageName());
// 关卡已关闭,且作业在关闭前上传
if (level != null &&
level.getCloseTime() != null &&
copilot.getFirstUploadTime() != null &&
Boolean.FALSE.equals(level.getIsOpen()) &&
copilot.getFirstUploadTime().isBefore(level.getCloseTime())) {

// 非开放关卡打入冷宫
hotScore /= 3;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ spring:
check-template-location: false
# 缓存配置,使用caffeine缓存框架,缓存时长为5分钟,最大缓存数量500
cache:
cache-names: arkLevel, arkLevels, copilotPage
cache-names: arkLevel, arkLevelInfos, copilotPage
type: caffeine
caffeine:
spec: maximumSize=500,expireAfterWrite=300s
Expand Down

0 comments on commit 13781ad

Please sign in to comment.