Skip to content

Commit

Permalink
Price data is now using https://nwmp.gaming.tools instead of https://…
Browse files Browse the repository at this point in the history
  • Loading branch information
josdemmers committed Oct 29, 2024
1 parent 63eba09 commit c6cd57f
Show file tree
Hide file tree
Showing 10 changed files with 208 additions and 264 deletions.
38 changes: 38 additions & 0 deletions NewWorldCompanion.Entities/Nwmarketprice.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Text.Json;
using System.Text.Json.Nodes;
using System.Text.Json.Serialization;
using System.Threading.Tasks;
using System.Windows;

namespace NewWorldCompanion.Entities
{
public class Nwmarketprice
{
public string ItemId { get; set; } = string.Empty;
public string ItemName { get; set; } = string.Empty;

public int Days { get; set; } = 0;
public DateTime LastUpdated { get; set; } = DateTime.MinValue;
public string LastUpdatedString
{
get
{
return LastUpdated.ToString();
}
}
/// <summary>
/// Lowest price seen in the most recent scan compared to the lowest price seen the previous day
/// </summary>
public int PriceChange { get; set; }
public double RecentLowestPrice { get; set; } = 0.0;
/// <summary>
/// RollingAverage
/// </summary>
public double RecentLowestPriceAvg { get; set; } = 0.0;
}
}
87 changes: 0 additions & 87 deletions NewWorldCompanion.Entities/NwmarketpriceJson.cs

This file was deleted.

45 changes: 45 additions & 0 deletions NewWorldCompanion.Entities/ServerPriceData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.Json.Serialization;
using System.Threading.Tasks;

namespace NewWorldCompanion.Entities
{
public class ServerPriceData
{
[JsonPropertyName("server_id")]
public string ServerId { get; set; } = string.Empty;

[JsonPropertyName("daily")]
public Dictionary<string, List<PriceData>> Daily { get; set; } = new();

[JsonPropertyName("hourly")]
public Dictionary<string, List<PriceData>> Hourly { get; set; } = new();
}

public class PriceData
{
[JsonPropertyName("timestamp")]
public int Timestamp { get; set; } = 0;

[JsonPropertyName("min_price")]
public int MinPrice { get; set; } = 0;

[JsonPropertyName("max_price")]
public int MaxPrice { get; set; } = 0;

[JsonPropertyName("mean_price")]
public int MeanPrice { get; set; } = 0;

[JsonPropertyName("median_price")]
public int MedianPrice { get; set; } = 0;

[JsonPropertyName("quantity")]
public int Quantity { get; set; } = 0;

[JsonPropertyName("means")]
public List<List<double>> Means { get; set; } = new();
}
}
4 changes: 4 additions & 0 deletions NewWorldCompanion.Events/PriceServerEvents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,8 @@ public class PriceServerListUpdatedEvent : PubSubEvent
public class PriceCacheUpdatedEvent : PubSubEvent
{
}

public class SelectedServerChanged : PubSubEvent
{
}
}
5 changes: 2 additions & 3 deletions NewWorldCompanion.Interfaces/IPriceManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@ public interface IPriceManager
{
List<PriceServer> Servers { get; }

NwmarketpriceJson GetPriceData(string itemName);
Nwmarketprice GetPriceData(string itemName);
double GetCraftingCosts(string itemId);
List<NwmarketpriceJson> GetExtendedPriceData(string itemName);
void UpdatePriceData(string itemName);
List<Nwmarketprice> GetExtendedPriceData(string itemName);
}
}
39 changes: 19 additions & 20 deletions NewWorldCompanion.Services/OverlayHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,25 +140,25 @@ private void DrawGraphics(object? sender, DrawGraphicsEventArgs e)

private void DrawGraphicsItem(DrawGraphicsEventArgs e, string itemName)
{
NwmarketpriceJson nwmarketpriceJson = _priceManager.GetPriceData(itemName);
List<NwmarketpriceJson> extendedNwmarketpriceJson = _priceManager.GetExtendedPriceData(itemName);
Nwmarketprice nwmarketprice = _priceManager.GetPriceData(itemName);
List<Nwmarketprice> extendedNwmarketprice = _priceManager.GetExtendedPriceData(itemName);

string infoItemName = itemName;
string infoPrice = "Loading...";
string infoPriceAvg = string.Empty;

if (!string.IsNullOrWhiteSpace(nwmarketpriceJson.item_name))
if (!string.IsNullOrWhiteSpace(nwmarketprice.ItemName))
{
var priceChange = nwmarketpriceJson.price_change >= 0 ? $"+{nwmarketpriceJson.price_change}" : $"{nwmarketpriceJson.price_change}";
infoPrice = $"{nwmarketpriceJson.recent_lowest_price.ToString("F2")} ({priceChange}%) ({nwmarketpriceJson.last_checked_string})";
infoPriceAvg = nwmarketpriceJson.RecentLowestPriceAvg;
infoPriceAvg = string.IsNullOrWhiteSpace(infoPriceAvg) ? infoPriceAvg : $"{infoPriceAvg} (15-day avg) ({nwmarketpriceJson.last_checked_string})";
var priceChange = nwmarketprice.PriceChange >= 0 ? $"+{nwmarketprice.PriceChange}" : $"{nwmarketprice.PriceChange}";
infoPrice = $"{nwmarketprice.RecentLowestPrice.ToString("F2")} ({priceChange}%) ({nwmarketprice.LastUpdatedString})";
infoPriceAvg = nwmarketprice.RecentLowestPriceAvg.ToString("F2");
infoPriceAvg = string.IsNullOrWhiteSpace(infoPriceAvg) ? infoPriceAvg : $"{infoPriceAvg} ({nwmarketprice.Days}-day avg) ({nwmarketprice.LastUpdatedString})";
}

// Do not show Bind on pickup items.
if (!_newWorldDataStore.IsBindOnPickup(itemName))
{
int ExtendedTooltipOffset = _settingsManager.Settings.ExtendedTooltipEnabled ? Math.Min(extendedNwmarketpriceJson.Count, 3) * 20 : 0;
int ExtendedTooltipOffset = _settingsManager.Settings.ExtendedTooltipEnabled ? Math.Min(extendedNwmarketprice.Count, 3) * 20 : 0;
// Add some extra margin
ExtendedTooltipOffset = ExtendedTooltipOffset == 0 ? 0 : ExtendedTooltipOffset + 40;

Expand All @@ -177,13 +177,13 @@ private void DrawGraphicsItem(DrawGraphicsEventArgs e, string itemName)
// Extended text
if (ExtendedTooltipOffset > 0)
{
for (int i = 0; i < Math.Min(extendedNwmarketpriceJson.Count, 3); i++)
for (int i = 0; i < Math.Min(extendedNwmarketprice.Count, 3); i++)
{
var craftingCosts = _priceManager.GetCraftingCosts(extendedNwmarketpriceJson[i].nwdb_id);
gfx.DrawText(_fonts["consolas"], _brushes["text"], 20, ((i+1)*20), $"{extendedNwmarketpriceJson[i].item_name} " +
$"{extendedNwmarketpriceJson[i].recent_lowest_price.ToString("F2")} (Sell) " +
var craftingCosts = _priceManager.GetCraftingCosts(extendedNwmarketprice[i].ItemId);
gfx.DrawText(_fonts["consolas"], _brushes["text"], 20, ((i+1)*20), $"{extendedNwmarketprice[i].ItemName} " +
$"{extendedNwmarketprice[i].RecentLowestPrice.ToString("F2")} (Sell) " +
$"{craftingCosts.ToString("F2")} (Craft) " +
$"{extendedNwmarketpriceJson[i].recent_lowest_price - craftingCosts:F2} (Profit)");
$"{extendedNwmarketprice[i].RecentLowestPrice - craftingCosts:F2} (Profit)");
}
gfx.DrawRectangle(_brushes["border"], 0, 0, _overlayWidth, ExtendedTooltipOffset, 1);
}
Expand Down Expand Up @@ -214,20 +214,20 @@ private void DrawGraphicsNamedItem(DrawGraphicsEventArgs e, string itemName)

private void DrawGraphicsRecipe(DrawGraphicsEventArgs e, CraftingRecipe craftingRecipe)
{
NwmarketpriceJson nwmarketpriceJson = _priceManager.GetPriceData(craftingRecipe.LocalisationUserFriendly);
Nwmarketprice nwmarketprice = _priceManager.GetPriceData(craftingRecipe.LocalisationUserFriendly);

bool learnedStatus = craftingRecipe.Learned;
string infoItemName = craftingRecipe.LocalisationUserFriendly;
string infoLearned = $"Learned: {learnedStatus}";
string infoPrice = "Loading...";
string infoPriceAvg = string.Empty;

if (!string.IsNullOrWhiteSpace(nwmarketpriceJson.item_name))
if (!string.IsNullOrWhiteSpace(nwmarketprice.ItemName))
{
var priceChange = nwmarketpriceJson.price_change >= 0 ? $"+{nwmarketpriceJson.price_change}" : $"{nwmarketpriceJson.price_change}";
infoPrice = $"{nwmarketpriceJson.recent_lowest_price.ToString("F2")} ({priceChange}%) ({nwmarketpriceJson.last_checked_string})";
infoPriceAvg = nwmarketpriceJson.RecentLowestPriceAvg;
infoPriceAvg = string.IsNullOrWhiteSpace(infoPriceAvg) ? infoPriceAvg : $"{infoPriceAvg} (15-day avg) ({nwmarketpriceJson.last_checked_string})";
var priceChange = nwmarketprice.PriceChange >= 0 ? $"+{nwmarketprice.PriceChange}" : $"{nwmarketprice.PriceChange}";
infoPrice = $"{nwmarketprice.RecentLowestPrice.ToString("F2")} ({priceChange}%) ({nwmarketprice.LastUpdatedString})";
infoPriceAvg = nwmarketprice.RecentLowestPriceAvg.ToString("F2");
infoPriceAvg = string.IsNullOrWhiteSpace(infoPriceAvg) ? infoPriceAvg : $"{infoPriceAvg} (15-day avg) ({nwmarketprice.LastUpdatedString})";
}

_window.X = _overlayX;
Expand Down Expand Up @@ -273,7 +273,6 @@ private void HandleOcrTextReadyEvent()
_itemName = _ocrHandler.OcrText;
if (!_itemName.Equals(_itemNamePrevious))
{
_priceManager.UpdatePriceData(_itemName);
_itemNamePrevious = _itemName;
}
}
Expand Down
Loading

0 comments on commit c6cd57f

Please sign in to comment.