Implement age decay algorithm as supplied by @alexthecoder

This commit is contained in:
Keir Nellyer 2016-06-21 17:46:52 +01:00
parent b4f10531cb
commit b46f08938e
3 changed files with 36 additions and 14 deletions

View File

@ -225,13 +225,26 @@ public class ReportManager
return calculatePriority(report).thenApply(priority -> priority > 0);
}
public CompletableFuture<Integer> calculatePriority(Report report)
public CompletableFuture<Double> 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<Integer, ReportMessage> 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)

View File

@ -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());
}
}

View File

@ -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();
}