Skip to content

Commit

Permalink
Manager: Add default weekly clears account detection
Browse files Browse the repository at this point in the history
  • Loading branch information
Sejsel committed Mar 12, 2024
1 parent c8ebbaa commit 994c2bf
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 2 deletions.
52 changes: 52 additions & 0 deletions ArcdpsLogManager/ManagerForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
using GW2Scratch.EVTCAnalytics.GameData;
using GW2Scratch.EVTCAnalytics.Processing;
using Gw2Sharp;
using System.Runtime.InteropServices;

namespace GW2Scratch.ArcdpsLogManager
{
Expand Down Expand Up @@ -173,6 +174,57 @@ public ManagerForm(LogCache logCache, ApiData apiData)
new ProcessingUpdateDialog(LogDataProcessor, updates).ShowModal(this);
}
};
LogSearchFinished += (_, _) =>
{
// We want to set default player account names from logs.
// This is quite tricky as people might have some logs that are not theirs.
// Furthermore, they might have renamed their account at some point.
if (Settings.PlayerAccountNames.Count == 0)
{
var povsByCount = new Dictionary<string, int>();
int totalLogs = 0;
foreach (var log in logs)
{
if (log.ParsingStatus != ParsingStatus.Parsed) continue;
if (log.PointOfView == null) continue;
if (log.PointOfView.AccountName == "Unknown") continue;
povsByCount.TryAdd(log.PointOfView.AccountName, 0);
povsByCount[log.PointOfView.AccountName]++;
totalLogs += 1;
}

// If more than 200 logs => any PoV that has appeared at least 50 times.
// If there are fewer => any PoV that has appeared at least 20 times.
// If there are not any such PoVs (most likely if there are only very few logs),
// take the most common PoV.
// We do not really want to use log percentage even for users
// with more logs as they may have a fairly recent new account.
if (totalLogs >= 200 && povsByCount.Any(x => x.Value >= 50))
{
Settings.PlayerAccountNames = povsByCount
.Where(x => x.Value >= 100)
.OrderByDescending(x => x.Value)
.Select(x => x.Key)
.ToList();
}
else if (totalLogs < 200 && povsByCount.Any(x => x.Value >= 20))
{
Settings.PlayerAccountNames = povsByCount
.OrderByDescending(x => x.Value)
.Where(x => x.Value >= 20)
.Select(x => x.Key)
.ToList();
}
else
{
Settings.PlayerAccountNames = povsByCount
.OrderByDescending(x => x.Value)
.Take(1)
.Select(x => x.Key)
.ToList();
}
}
};

// Collection initialization
logsFiltered = new FilterCollection<LogData>(logs);
Expand Down
10 changes: 8 additions & 2 deletions ArcdpsLogManager/Sections/WeeklyClears.cs
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,14 @@ public WeeklyClears(ImageProvider imageProvider)
DataUpdated?.Invoke(this, EventArgs.Empty);
};

Settings.PlayerAccountNamesChanged += (_, _) =>
{
accountFilterBox.SelectedIndex = -1;
accountFilterBox.DataStore = Settings.PlayerAccountNames.Select(x => x.TrimStart(':'));
accountFilterBox.SelectedIndex = Settings.PlayerAccountNames.Count > 0 ? 0 : -1;
DataUpdated?.Invoke(this, EventArgs.Empty);
};

var addNewAccountButton = new Button { Text = "Add account" };
var removeAccountButton = new Button { Text = "Remove", Enabled = accountFilterBox.SelectedIndex != -1 };
addNewAccountButton.Click += (_, _) =>
Expand All @@ -212,8 +220,6 @@ public WeeklyClears(ImageProvider imageProvider)
{
Settings.PlayerAccountNames = Settings.PlayerAccountNames.Append(selectedAccount).ToList();
}

accountFilterBox.DataStore = Settings.PlayerAccountNames.Select(x => x.TrimStart(':'));
accountFilterBox.SelectedIndex = Settings.PlayerAccountNames.Count - 1;
AccountFilter = selectedAccount;
removeAccountButton.Enabled = true;
Expand Down

0 comments on commit 994c2bf

Please # to comment.