Skip to content

Commit

Permalink
Merge pull request #194 from Sidekick-Poe/feature/poe-ninja-updates
Browse files Browse the repository at this point in the history
Add Coffin pricing from poe.ninja
  • Loading branch information
domialex committed Apr 7, 2024
2 parents 21beb2b + 2274762 commit ad75ec3
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 21 deletions.
1 change: 1 addition & 0 deletions src/Sidekick.Apis.Poe/Parser/ItemParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ private Properties ParseSanctumProperties(ParsingItem parsingItem)
return new Properties
{
AreaLevel = GetInt(patterns.AreaLevel, parsingItem),
ItemLevel = GetInt(patterns.ItemLevel, parsingItem),
};
}

Expand Down
6 changes: 6 additions & 0 deletions src/Sidekick.Apis.PoeNinja/Api/ItemType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ public enum ItemType
[EnumValue("artifacts")]
Artifact,

[EnumValue("coffins")]
Coffin,

[EnumValue("unique-relics")]
UniqueRelic,

// BaseType, // This is ~13mb of raw data, in memory it eats ~40mb.
// HelmetEnchant,
}
Expand Down
7 changes: 3 additions & 4 deletions src/Sidekick.Apis.PoeNinja/IPoeNinjaClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@ public interface IPoeNinjaClient
string? englishName,
string? englishType,
Category category,
int? gemLevel = null,
int? mapTier = null,
bool? isRelic = false,
int? numberOfLinks = null);
Properties properties,
int? numberOfLinks = null,
string? firstModifierLine = null);

Task<NinjaPrice?> GetClusterPrice(
string englishGrantText,
Expand Down
2 changes: 0 additions & 2 deletions src/Sidekick.Apis.PoeNinja/Models/NinjaPrice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ public record NinjaPrice

public SparkLine? SparkLine { get; init; }

public bool IsRelic { get; init; }

public int Links { get; init; }

public int ItemLevel { get; init; }
Expand Down
40 changes: 28 additions & 12 deletions src/Sidekick.Apis.PoeNinja/PoeNinjaClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,29 +58,41 @@ private HttpClient GetHttpClient()
string? englishName,
string? englishType,
Category category,
int? gemLevel = null,
int? mapTier = null,
bool? isRelic = false,
int? numberOfLinks = null)
Properties properties,
int? numberOfLinks = null,
string? firstModifierLine = null)
{
await ClearCacheIfExpired();

var prices = await GetPrices(category);

var query = prices.Where(x => x.Name == englishName || x.Name == englishType);
IEnumerable<NinjaPrice> query;

if (category == Category.Gem && gemLevel != null)
// Currencies can have 1 modifier, the Name or BaseType will be the modifier.
if (category == Category.Currency && firstModifierLine != null)
{
query = prices.Where(x => x.Name == firstModifierLine);
}
else if (properties.Blighted || properties.BlightRavaged)
{
query = query.Where(x => x.GemLevel == gemLevel);
var itemTypeToSearch = properties.Blighted ? ItemType.BlightedMap : ItemType.BlightRavagedMap;
var nameToSearch = englishName ?? englishType ?? string.Empty;
query = prices.Where(x => x.ItemType == itemTypeToSearch)
.Where(x => x.Name?.Contains(nameToSearch) == true);
}
else
{
query = prices.Where(x => x.Name == englishName || x.Name == englishType);
}

if (isRelic != null)
if (category == Category.Gem)
{
query = query.Where(x => x.IsRelic == isRelic);
query = query.Where(x => x.GemLevel == properties.GemLevel);
}

if (category == Category.Map && mapTier != null)
if (category == Category.Map)
{
query = query.Where(x => x.MapTier == mapTier);
query = query.Where(x => x.MapTier == properties.MapTier);
}

if (numberOfLinks != null)
Expand Down Expand Up @@ -237,7 +249,6 @@ private async Task<IEnumerable<NinjaPrice>> FetchItems(ItemType itemType)
DetailsId = x.DetailsId,
ItemType = itemType,
SparkLine = x.SparkLine ?? x.LowConfidenceSparkLine,
IsRelic = x.ItemClass == 9, // 3 for Unique, 9 for Relic Unique.
Links = x.Links,
BaseType = x.BaseType,
ItemLevel = x.ItemLevel,
Expand Down Expand Up @@ -326,6 +337,7 @@ private IEnumerable<ItemType> GetApiItemTypes(Category category)
yield return ItemType.Essence;
yield return ItemType.Resonator;
yield return ItemType.Artifact;
yield return ItemType.Coffin;
yield break;

case Category.DivinationCard:
Expand All @@ -349,6 +361,10 @@ private IEnumerable<ItemType> GetApiItemTypes(Category category)
case Category.ItemisedMonster:
yield return ItemType.Beast;
yield break;

case Category.Sanctum:
yield return ItemType.UniqueRelic;
yield break;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ else if (Price != null)
Item.Invariant.Name,
Item.Invariant.Type,
Item.Metadata.Category,
gemLevel: Item.Properties.GemLevel,
mapTier: Item.Properties.MapTier,
numberOfLinks: Item.GetMaximumNumberOfLinks());
Item.Properties,
numberOfLinks: Item.GetMaximumNumberOfLinks(),
firstModifierLine: Item.ModifierLines.FirstOrDefault()?.Text);
}

ChartOptions = new ChartOptions()
Expand Down

0 comments on commit ad75ec3

Please sign in to comment.