Skip to content

Commit

Permalink
fix deck matching by id, not name + total games played
Browse files Browse the repository at this point in the history
  • Loading branch information
icetbr committed Jul 4, 2020
1 parent 5bb0895 commit ed3fc10
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 7 deletions.
12 changes: 9 additions & 3 deletions Advisor/Advisor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,8 @@ internal async void UpdateCardList()
// Some unreproducable bug threw an exception here. System.InvalidOperationException: Sequence contains no elements @ IEnumerable.Max() => should be fixed by DefaultIfEmpty() now!
var maxSim = dict.Values.DefaultIfEmpty(0).Max();

Log.Info($"decksFound: { dict.Count }, opponent: {CoreAPI.Game.Opponent.Class}, maxSim: { maxSim }");

// If any archetype deck matches more than MinimumSimilarity (as percentage) show the deck with the highest similarity (important: we need at least 1 deck in dict, otherwise we can't show any results.)
if (dict.Count > 0 && maxSim >= Settings.Default.MinimumSimilarity * 0.01)
{
Expand All @@ -255,8 +257,9 @@ internal async void UpdateCardList()
_advisorOverlay.LblArchetype.Text = $"{matchedDeck.Key.Name} ({Math.Round(matchedDeck.Value * 100, 2)}%)";
}

_advisorOverlay.LblStats.Text = matchedDeck.Key.Note;
var deck = DeckList.Instance.Decks.Where(d => d.TagList.ToLowerInvariant().Contains("archetype")).First(d => d.Name == matchedDeck.Key.Name);
string[] infos = matchedDeck.Key.Note.Split('-');
_advisorOverlay.LblStats.Text = $"{ infos[1] }/{ infos[2] }%";
var deck = DeckList.Instance.Decks.Where(d => d.TagList.ToLowerInvariant().Contains("archetype")).First(d => d.Note.Split('-')[0] == matchedDeck.Key.Note.Split('-')[0]);

var predictedCards = ((Deck) deck.Clone()).Cards.ToList();

Expand Down Expand Up @@ -308,9 +311,12 @@ internal async void UpdateCardList()
}

// Update overlay cards.
isNewArchetypeDeck = true;
_advisorOverlay.Update(predictedCards.ToSortedCardList(), isNewArchetypeDeck);
// Remember current archetype deck guid with highest similarity to opponent's played cards.
_currentArchetypeDeckGuid = matchedDeck.Key.DeckId;

Log.Info($"Deck: { matchedDeck.Key.DeckId } , { infos[0] }, { matchedDeck.Key.Class }, { isNewArchetypeDeck }");
}
else
{
Expand Down Expand Up @@ -352,7 +358,7 @@ public static void Notify(string title, string message, int autoClose, string ic

public static async Task ImportMetastatsDecks()
{
//construct Progress<T>, passing ReportProgress as the Action<T>
//construct Progress<T>, passing ReportProgress as the Action<T>
var progressIndicator = new Progress<Tuple<int, int>>(ReportProgress);
try
{
Expand Down
2 changes: 1 addition & 1 deletion Advisor/AdvisorPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public void OnUpdate()
{
}

public Version Version => new Version(1, 0, 14);
public Version Version => new Version(1, 2, 0);

public async Task CheckForUpdate()
{
Expand Down
3 changes: 2 additions & 1 deletion Advisor/ExtensionMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ public static int CountUnion(this Deck thisDeck, IList<Card> cards)
/// <returns>Number of played games with the given deck. If no info is found or parse is unsuccessful, return 0.</returns>
public static int GetPlayedGames(this Deck thisDeck)
{
var success = int.TryParse(Regex.Match(thisDeck.Note, @"Games: ([0-9]+)").Groups[1].Value, out var result);
string[] infos = thisDeck.Note.Split('-');
var success = int.TryParse(infos[1], out int result);
return success ? result : 0;
}
}
Expand Down
4 changes: 2 additions & 2 deletions Advisor/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.1.0.0")]
[assembly: AssemblyFileVersion("1.1.0.0")]
[assembly: AssemblyVersion("1.2.0.0")]
[assembly: AssemblyFileVersion("1.2.0.0")]
7 changes: 7 additions & 0 deletions Advisor/Services/HsReplay/HsReplaySnapshotImporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ private Deck GetDeck(JToken deckJson, Dictionary<string, HsReplayArchetype> allA
deck.Class = hsReplayClassToDeckTrackerClass[archetype.Class];
deck.Cards = GetCardsFromHsReplayDeckList(hsReplayDeck.DeckList);
deck.LastEdited = DateTime.Now;
deck.Note = hsReplayDeck.DeckId + "-" + hsReplayDeck.TotalGames + "-" + hsReplayDeck.WinRate;

return deck;
}
Expand Down Expand Up @@ -183,6 +184,12 @@ class HsReplayDeck
[JsonProperty("deck_list")]
public string DeckList { get; set; }

[JsonProperty("total_games")]
public string TotalGames { get; set; }

[JsonProperty("win_rate")]
public string WinRate { get; set; }

public string Name { get; set; }
public string ClassId { get; set; }
}
Expand Down

0 comments on commit ed3fc10

Please sign in to comment.