This commit is contained in:
Chomp 2023-02-05 11:57:03 +00:00
parent 2737cb6fc7
commit dc75a68226
9 changed files with 313537 additions and 251110 deletions

View File

@ -11,5 +11,6 @@
public string Currency { get; set; } public string Currency { get; set; }
public string TemplateId { get; set; } public string TemplateId { get; set; }
public int TraderPrice { get; set; } public int TraderPrice { get; set; }
public string Trader { get; set; }
} }
} }

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,8 @@
namespace MarketPriceLookup.Common
{
public class HandbookCategory
{
public string Id { get; set; }
public string ParentId { get; set; }
}
}

View File

@ -0,0 +1,48 @@
using System;
using System.IO;
using System.Linq;
using System.Text.Json;
namespace MarketPriceLookup.Common.Helpers
{
public static class HandbookHelper
{
private static Handbook _handbook;
public static Handbook Items
{
get
{
if (_handbook == null)
{
var itemsFilePath = $"{Directory.GetCurrentDirectory()}\\Assets\\handbook.json";
if (!File.Exists(itemsFilePath))
{
throw new Exception($"Missing handbook.json under assets ({itemsFilePath})");
}
var handbookJson = File.ReadAllText(itemsFilePath);
_handbook = JsonSerializer.Deserialize<Handbook>(handbookJson);
}
return _handbook;
}
}
public static HandbookItem GetItem(string id)
{
return Items.Items.FirstOrDefault(x => x.Id == id);
}
public static HandbookCategory GetCategory(string id)
{
return Items.Categories.FirstOrDefault(x => x.Id == id);
}
}
public class Handbook
{
public HandbookCategory[] Categories { get; set; }
public HandbookItem[] Items { get; set; }
}
}

View File

@ -0,0 +1,9 @@
namespace MarketPriceLookup.Common
{
public class HandbookItem
{
public string Id { get; set; }
public string ParentId { get; set; }
public int Price { get;set;}
}
}

View File

@ -11,10 +11,33 @@ namespace MarketPriceLookup.Common.Helpers
{ {
private static readonly Dictionary<string, Prices> priceFile = new Dictionary<string, Prices>(); private static readonly Dictionary<string, Prices> priceFile = new Dictionary<string, Prices>();
public static Dictionary<string, Prices> GetAllPrices()
{
if (priceFile.Count == 0)
{
HydrateDictionary();
}
return priceFile;
}
public static Prices GetItemPrice(string key) public static Prices GetItemPrice(string key)
{ {
// parse csv if dictionary is empty // parse csv if dictionary is empty
if (priceFile.Count == 0) if (priceFile.Count == 0)
{
HydrateDictionary();
}
if (!priceFile.ContainsKey(key))
{
return null;
}
return priceFile[key];
}
private static void HydrateDictionary()
{ {
var workingPath = Directory.GetCurrentDirectory(); var workingPath = Directory.GetCurrentDirectory();
var inputPath = $"{workingPath}//input"; var inputPath = $"{workingPath}//input";
@ -40,27 +63,33 @@ namespace MarketPriceLookup.Common.Helpers
int price = int.Parse(fields[2]); int price = int.Parse(fields[2]);
int avg24hPrice = int.Parse(fields[3]); int avg24hPrice = int.Parse(fields[3]);
int avg7daysPrice = int.Parse(fields[4]); int avg7daysPrice = int.Parse(fields[4]);
//string trader = fields[5]; string trader = fields[5];
//int buyBackPrice = int.Parse(fields[6]); //int buyBackPrice = int.Parse(fields[6]);
string currency = GetCurrencyType(fields[7]); string currency = GetCurrencyType(fields[7]);
string bsgId = fields[8]; string bsgId = fields[8];
int traderPrice = int.Parse(fields[9]); int traderPrice = int.Parse(fields[9]);
//if (avg7daysPrice == 0) if (avg7daysPrice == 0)
//{ {
// LoggingHelpers.LogError($"unable to add bad item with price average of 0, ignoring: {bsgId} {name}"); LoggingHelpers.LogError($"unable to add item {bsgId} {name} with average price of 0, ignoring");
// continue; continue;
//} }
if (name.Contains(" (0/"))
{
LoggingHelpers.LogWarning($"Skipping 0 durability item: {bsgId} {name}");
continue;
}
if (priceFile.ContainsKey(bsgId)) if (priceFile.ContainsKey(bsgId))
{ {
//oh no, item already exists in the csv //oh no, item already exists in the csv
var existingItem = priceFile[bsgId]; var existingItem = priceFile[bsgId];
LoggingHelpers.LogError($"Unable to add item: {bsgId} {name}. existing item: {existingItem.TemplateId} {existingItem.Name}"); LoggingHelpers.LogError($"Unable to add item: {bsgId} {name}. existing item: {existingItem.TemplateId} {existingItem.Name}");
if (existingItem.Average7DaysPrice != avg7daysPrice) if (existingItem.Average7DaysPrice < avg7daysPrice)
{ {
LoggingHelpers.LogError($"Price diff found: already existing item price: {existingItem.Average7DaysPrice} new item price: {avg7daysPrice}"); LoggingHelpers.LogError($"Price diff found: existing item price: {existingItem.Average7DaysPrice} new item price: {avg7daysPrice}, using larger price");
continue; priceFile.Remove(bsgId);
} }
} }
if (!priceFile.ContainsKey(bsgId)) if (!priceFile.ContainsKey(bsgId))
@ -71,7 +100,7 @@ namespace MarketPriceLookup.Common.Helpers
Price = price, Price = price,
Average24hPrice = avg24hPrice, Average24hPrice = avg24hPrice,
Average7DaysPrice = avg7daysPrice, Average7DaysPrice = avg7daysPrice,
//Trader = trader, Trader = trader,
//BuyPackPrice = buyBackPrice, //BuyPackPrice = buyBackPrice,
Currency = currency, Currency = currency,
TemplateId = bsgId, TemplateId = bsgId,
@ -85,14 +114,6 @@ namespace MarketPriceLookup.Common.Helpers
} }
} }
if (!priceFile.ContainsKey(key))
{
return null;
}
return priceFile[key];
}
private static string GetCurrencyType(string input) private static string GetCurrencyType(string input)
{ {
return input switch return input switch

View File

@ -14,6 +14,7 @@ namespace MarketPriceLookup.Common.Models
public string _parent { get; set; } public string _parent { get; set; }
public string _type { get; set; } public string _type { get; set; }
public Props _props { get; set; } public Props _props { get; set; }
public string BackgroundColor { get; set; }
} }
public class Props public class Props
@ -24,6 +25,9 @@ namespace MarketPriceLookup.Common.Models
public List<Chamber> Chambers { get; set; } public List<Chamber> Chambers { get; set; }
public List<Slot> Slots { get; set; } public List<Slot> Slots { get; set; }
public string defAmmo { get; set; } public string defAmmo { get; set; }
public int LootExperience { get; set; }
public int ExamineExperience { get; set; }
public bool CanSellOnRagfair { get;set;}
} }
public class Chamber public class Chamber

View File

@ -1,13 +1,17 @@
 
Microsoft Visual Studio Solution File, Format Version 12.00 Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16 # Visual Studio Version 17
VisualStudioVersion = 16.0.31624.102 VisualStudioVersion = 17.0.32112.339
MinimumVisualStudioVersion = 10.0.40219.1 MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MarketPriceLookup", "MarketPriceLookup\MarketPriceLookup.csproj", "{8E1A2B84-F63E-45DE-8C27-710A4E85F897}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MarketPriceLookup", "MarketPriceLookup\MarketPriceLookup.csproj", "{8E1A2B84-F63E-45DE-8C27-710A4E85F897}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MarketPriceLookup.Common", "MarketPriceLookup.Common\MarketPriceLookup.Common.csproj", "{7A93F68F-ACFE-4950-B3DE-2A9DE2DC47FA}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MarketPriceLookup.Common", "MarketPriceLookup.Common\MarketPriceLookup.Common.csproj", "{7A93F68F-ACFE-4950-B3DE-2A9DE2DC47FA}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MarketPriceLookup.Common.Models", "MarketPriceLookup.Common.Models\MarketPriceLookup.Common.Models.csproj", "{4F371EC5-29D2-4B99-823D-0866FC51A030}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MarketPriceLookup.Common.Models", "MarketPriceLookup.Common.Models\MarketPriceLookup.Common.Models.csproj", "{4F371EC5-29D2-4B99-823D-0866FC51A030}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TraderAllowedSellTypeGenerator", "TraderAllowedSellTypeGenerator\TraderAllowedSellTypeGenerator.csproj", "{53387C27-EB44-4F4E-A304-BEB988AA478B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RarityValueGenerator", "RarityValueGenerator\RarityValueGenerator.csproj", "{BAF78315-E253-4739-85D4-4183103335BA}"
EndProject EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -27,6 +31,14 @@ Global
{4F371EC5-29D2-4B99-823D-0866FC51A030}.Debug|Any CPU.Build.0 = Debug|Any CPU {4F371EC5-29D2-4B99-823D-0866FC51A030}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4F371EC5-29D2-4B99-823D-0866FC51A030}.Release|Any CPU.ActiveCfg = Release|Any CPU {4F371EC5-29D2-4B99-823D-0866FC51A030}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4F371EC5-29D2-4B99-823D-0866FC51A030}.Release|Any CPU.Build.0 = Release|Any CPU {4F371EC5-29D2-4B99-823D-0866FC51A030}.Release|Any CPU.Build.0 = Release|Any CPU
{53387C27-EB44-4F4E-A304-BEB988AA478B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{53387C27-EB44-4F4E-A304-BEB988AA478B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{53387C27-EB44-4F4E-A304-BEB988AA478B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{53387C27-EB44-4F4E-A304-BEB988AA478B}.Release|Any CPU.Build.0 = Release|Any CPU
{BAF78315-E253-4739-85D4-4183103335BA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BAF78315-E253-4739-85D4-4183103335BA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BAF78315-E253-4739-85D4-4183103335BA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BAF78315-E253-4739-85D4-4183103335BA}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE

View File

@ -10,21 +10,17 @@ namespace MarketPriceLookup
static void Main(string[] args) static void Main(string[] args)
{ {
// loop over all items and get a price for each // loop over all items and get a price for each
var priceList = new Dictionary<string, OutputPrices>(); var priceList = new Dictionary<string, int>();
foreach (var item in ItemTemplateHelper.Items) foreach (var item in ItemTemplateHelper.Items)
{ {
var priceData = MarketPricesHelper.GetItemPrice(item.Key); var priceData = MarketPricesHelper.GetItemPrice(item.Key);
if (priceData != null && priceData.Price != 0) if (priceData != null && priceData.Price != 0)
{ {
priceList.Add(item.Key, new OutputPrices priceList.Add(item.Key, priceData.Average7DaysPrice);
{
LivePrice = priceData.Average7DaysPrice,
TraderPrice = priceData.TraderPrice,
TraderCurrency = priceData.Currency
});
} }
} }
// save found prices to json // save found prices to json
JsonWriter.WriteJson(priceList, "output", Directory.GetCurrentDirectory(), "prices"); JsonWriter.WriteJson(priceList, "output", Directory.GetCurrentDirectory(), "prices");
} }