Skip to content

Fix for when prediction breakdown does not contain main label #182

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main/java/com/botdetector/BotDetectorPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,7 @@ private void processPlayer(Player player)

String rawName = player.getName();

boolean invalidName = rawName == null || rawName.length() == 0 || rawName.charAt(0) == '#' || rawName.charAt(0) == '[';
boolean invalidName = rawName == null || rawName.isEmpty() || rawName.charAt(0) == '#' || rawName.charAt(0) == '[';

if (player == client.getLocalPlayer())
{
Expand Down
14 changes: 13 additions & 1 deletion src/main/java/com/botdetector/http/BotDetectorClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,19 @@ public void onResponse(Call call, Response response)
{
try
{
future.complete(processResponse(gson, response, Prediction.class));
Prediction p = processResponse(gson, response, Prediction.class);
// Sanity check for if the primary label does not appear in the breakdown
if (p != null
&& p.getConfidence() != null // Some 'debug' labels such as 'Stats_Too_Low' will have null confidence, ignore these!
&& p.getPredictionBreakdown() != null
&& !p.getPredictionBreakdown().isEmpty()
&& p.getPredictionBreakdown().keySet().stream().noneMatch(x -> x.equalsIgnoreCase(p.getPredictionLabel())))
{
p.getPredictionBreakdown().put(p.getPredictionLabel(), p.getConfidence());
log.warn(String.format("Primary prediction label missing from breakdown! Added missing label. (pl:'%s', id:'%d', lb:'%s', cf:'%.4f')",
p.getPlayerName(), p.getPlayerId(), p.getPredictionLabel(), p.getConfidence()));
}
future.complete(p);
}
catch (IOException e)
{
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/com/botdetector/ui/BotDetectorPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -1107,7 +1107,7 @@ public void setPrediction(Prediction pred, PlayerSighting sighting)
feedbackLabelComboBox.setSelectedItem(UNSURE_PREDICTION_LABEL);
feedbackLabelComboBox.addItem(SOMETHING_ELSE_PREDICTION_LABEL);

if (pred.getPredictionBreakdown() == null || pred.getPredictionBreakdown().size() == 0)
if (pred.getPredictionBreakdown() == null || pred.getPredictionBreakdown().isEmpty())
{
predictionBreakdownLabel.setText(EMPTY_LABEL);
predictionBreakdownPanel.setVisible(false);
Expand All @@ -1133,7 +1133,7 @@ public void setPrediction(Prediction pred, PlayerSighting sighting)
entry ->
{
FeedbackPredictionLabel pLabel = new FeedbackPredictionLabel(entry.getKey(), entry.getValue(),
entry.getKey().equals(primaryLabel) ? FeedbackValue.POSITIVE : FeedbackValue.NEGATIVE);
entry.getKey().equalsIgnoreCase(primaryLabel) ? FeedbackValue.POSITIVE : FeedbackValue.NEGATIVE);
feedbackLabelComboBox.addItem(pLabel);
if (pLabel.getFeedbackValue() == FeedbackValue.POSITIVE)
{
Expand Down Expand Up @@ -1253,7 +1253,7 @@ private void predictPlayer()
{
String target = sanitize(searchBar.getText());

if (target.length() <= 0)
if (target.isEmpty())
{
return;
}
Expand Down Expand Up @@ -1654,7 +1654,7 @@ private static String toColoredPercentSpan(double percent)
*/
private static String toPredictionBreakdownString(Map<String, Double> predictionMap)
{
if (predictionMap == null || predictionMap.size() == 0)
if (predictionMap == null || predictionMap.isEmpty())
{
return null;
}
Expand Down