From b46f08938e4fd6f26e3c2c5f30c87b3eb98bf372 Mon Sep 17 00:00:00 2001 From: Keir Nellyer Date: Tue, 21 Jun 2016 17:46:52 +0100 Subject: [PATCH] Implement age decay algorithm as supplied by @alexthecoder --- .../mineplex/core/report/ReportManager.java | 25 ++++++++++++++----- .../mineplex/core/report/ReportMessage.java | 23 +++++++++++------ .../core/report/ReportRepository.java | 2 +- 3 files changed, 36 insertions(+), 14 deletions(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/report/ReportManager.java b/Plugins/Mineplex.Core/src/mineplex/core/report/ReportManager.java index 93bb993c6..c6cbf3efe 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/report/ReportManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/report/ReportManager.java @@ -225,13 +225,26 @@ public class ReportManager return calculatePriority(report).thenApply(priority -> priority > 0); } - public CompletableFuture calculatePriority(Report report) + public CompletableFuture calculatePriority(Report report) { - // todo take into account age of report - return UtilFuture.sequence(_reportProfileRepository.getProfiles(report.getReporterIds())).thenApply(reportProfiles -> reportProfiles.stream() - .mapToInt(profile -> profile.getReputation(report.getCategory())) - .map(operand -> operand * 100) - .sum()); + return CompletableFuture.supplyAsync(() -> + { + double priority = 0; + + for (Map.Entry entry : report.getMessages().entrySet()) + { + int accountId = entry.getKey(); + ReportProfile profile = _reportProfileRepository.getProfile(accountId).join(); + int categoryReputation = profile.getReputation(report.getCategory()); + + ReportMessage message = entry.getValue(); + int serverWeight = message.getServerWeight(); + double ageImpact = Math.pow(1 - 0.066666666666667, message.getDurationSinceCreation().toMinutes()); + // TODO do something with all these values + } + + return priority; + }); } public void publishChatSnap(Report report, boolean updateChat) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/report/ReportMessage.java b/Plugins/Mineplex.Core/src/mineplex/core/report/ReportMessage.java index 183b8ddde..2c007f343 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/report/ReportMessage.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/report/ReportMessage.java @@ -1,5 +1,9 @@ package mineplex.core.report; +import java.time.Duration; +import java.time.LocalDateTime; +import java.time.ZoneId; +import java.time.temporal.TemporalUnit; import java.util.Date; import static com.google.common.base.Preconditions.*; @@ -14,15 +18,15 @@ public class ReportMessage private int _reporterId; private String _message; private String _server; - private int _weight; + private int _serverWeight; private Date _time; - public ReportMessage(int reporterId, String message, String server, int weight) + public ReportMessage(int reporterId, String message, String server, int serverWeight) { - this(reporterId, message, server, weight, new Date()); + this(reporterId, message, server, serverWeight, new Date()); } - public ReportMessage(int reporterId, String message, String server, int weight, Date time) + public ReportMessage(int reporterId, String message, String server, int serverWeight, Date time) { checkNotNull(message); checkNotNull(server); @@ -31,7 +35,7 @@ public class ReportMessage _reporterId = reporterId; _message = message; _server = server; - _weight = weight; + _serverWeight = serverWeight; _time = time; } @@ -50,13 +54,18 @@ public class ReportMessage return _server; } - public int getWeight() + public int getServerWeight() { - return _weight; + return _serverWeight; } public Date getTimeCreated() { return _time; } + + public Duration getDurationSinceCreation() + { + return Duration.between(_time.toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime(), LocalDateTime.now()); + } } \ No newline at end of file diff --git a/Plugins/Mineplex.Core/src/mineplex/core/report/ReportRepository.java b/Plugins/Mineplex.Core/src/mineplex/core/report/ReportRepository.java index 7bd918757..941d0c8f2 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/report/ReportRepository.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/report/ReportRepository.java @@ -365,7 +365,7 @@ public class ReportRepository extends MinecraftRepository preparedStatement.setInt(2, entry.getKey()); // reporter id preparedStatement.setString(3, reportMessage.getMessage()); // reason preparedStatement.setString(4, reportMessage.getServer()); // server - preparedStatement.setInt(5, reportMessage.getWeight()); // weight + preparedStatement.setInt(5, reportMessage.getServerWeight()); // weight preparedStatement.setTimestamp(6, new Timestamp(reportMessage.getTimeCreated().getTime())); // time preparedStatement.execute(); }