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 TemplateId { 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,78 +11,22 @@ namespace MarketPriceLookup.Common.Helpers
{
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)
{
// parse csv if dictionary is empty
if (priceFile.Count == 0)
{
var workingPath = Directory.GetCurrentDirectory();
var inputPath = $"{workingPath}//input";
var filePath = $"{inputPath}//marketPrices.csv";
DiskHelpers.CreateDirIfDoesntExist(inputPath);
using (TextFieldParser csvParser = new TextFieldParser(filePath))
{
csvParser.CommentTokens = new string[] { "#" };
csvParser.SetDelimiters(new string[] { "," });
csvParser.HasFieldsEnclosedInQuotes = true;
// Skip the row with the column names
csvParser.ReadLine();
csvParser.ReadLine();
while (!csvParser.EndOfData)
{
// Read current line fields, pointer moves to the next line.
string[] fields = csvParser.ReadFields();
//string uid = fields[0];
string name = fields[1];
int price = int.Parse(fields[2]);
int avg24hPrice = int.Parse(fields[3]);
int avg7daysPrice = int.Parse(fields[4]);
//string trader = fields[5];
//int buyBackPrice = int.Parse(fields[6]);
string currency = GetCurrencyType(fields[7]);
string bsgId = fields[8];
int traderPrice = int.Parse(fields[9]);
//if (avg7daysPrice == 0)
//{
// LoggingHelpers.LogError($"unable to add bad item with price average of 0, ignoring: {bsgId} {name}");
// continue;
//}
if (priceFile.ContainsKey(bsgId))
{
//oh no, item already exists in the csv
var existingItem = priceFile[bsgId];
LoggingHelpers.LogError($"Unable to add item: {bsgId} {name}. existing item: {existingItem.TemplateId} {existingItem.Name}");
if (existingItem.Average7DaysPrice != avg7daysPrice)
{
LoggingHelpers.LogError($"Price diff found: already existing item price: {existingItem.Average7DaysPrice} new item price: {avg7daysPrice}");
continue;
}
}
if (!priceFile.ContainsKey(bsgId))
{
priceFile.Add(bsgId, new Prices
{
Name = name,
Price = price,
Average24hPrice = avg24hPrice,
Average7DaysPrice = avg7daysPrice,
//Trader = trader,
//BuyPackPrice = buyBackPrice,
Currency = currency,
TemplateId = bsgId,
TraderPrice = traderPrice,
});
}
LoggingHelpers.LogSuccess($"Adding item: {bsgId} {name}");
}
}
HydrateDictionary();
}
if (!priceFile.ContainsKey(key))
@ -93,6 +37,83 @@ namespace MarketPriceLookup.Common.Helpers
return priceFile[key];
}
private static void HydrateDictionary()
{
var workingPath = Directory.GetCurrentDirectory();
var inputPath = $"{workingPath}//input";
var filePath = $"{inputPath}//marketPrices.csv";
DiskHelpers.CreateDirIfDoesntExist(inputPath);
using (TextFieldParser csvParser = new TextFieldParser(filePath))
{
csvParser.CommentTokens = new string[] { "#" };
csvParser.SetDelimiters(new string[] { "," });
csvParser.HasFieldsEnclosedInQuotes = true;
// Skip the row with the column names
csvParser.ReadLine();
csvParser.ReadLine();
while (!csvParser.EndOfData)
{
// Read current line fields, pointer moves to the next line.
string[] fields = csvParser.ReadFields();
//string uid = fields[0];
string name = fields[1];
int price = int.Parse(fields[2]);
int avg24hPrice = int.Parse(fields[3]);
int avg7daysPrice = int.Parse(fields[4]);
string trader = fields[5];
//int buyBackPrice = int.Parse(fields[6]);
string currency = GetCurrencyType(fields[7]);
string bsgId = fields[8];
int traderPrice = int.Parse(fields[9]);
if (avg7daysPrice == 0)
{
LoggingHelpers.LogError($"unable to add item {bsgId} {name} with average price of 0, ignoring");
continue;
}
if (name.Contains(" (0/"))
{
LoggingHelpers.LogWarning($"Skipping 0 durability item: {bsgId} {name}");
continue;
}
if (priceFile.ContainsKey(bsgId))
{
//oh no, item already exists in the csv
var existingItem = priceFile[bsgId];
LoggingHelpers.LogError($"Unable to add item: {bsgId} {name}. existing item: {existingItem.TemplateId} {existingItem.Name}");
if (existingItem.Average7DaysPrice < avg7daysPrice)
{
LoggingHelpers.LogError($"Price diff found: existing item price: {existingItem.Average7DaysPrice} new item price: {avg7daysPrice}, using larger price");
priceFile.Remove(bsgId);
}
}
if (!priceFile.ContainsKey(bsgId))
{
priceFile.Add(bsgId, new Prices
{
Name = name,
Price = price,
Average24hPrice = avg24hPrice,
Average7DaysPrice = avg7daysPrice,
Trader = trader,
//BuyPackPrice = buyBackPrice,
Currency = currency,
TemplateId = bsgId,
TraderPrice = traderPrice,
});
}
LoggingHelpers.LogSuccess($"Adding item: {bsgId} {name}");
}
}
}
private static string GetCurrencyType(string input)
{
return input switch

View File

@ -14,6 +14,7 @@ namespace MarketPriceLookup.Common.Models
public string _parent { get; set; }
public string _type { get; set; }
public Props _props { get; set; }
public string BackgroundColor { get; set; }
}
public class Props
@ -24,6 +25,9 @@ namespace MarketPriceLookup.Common.Models
public List<Chamber> Chambers { get; set; }
public List<Slot> Slots { 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

View File

@ -1,13 +1,17 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.31624.102
# Visual Studio Version 17
VisualStudioVersion = 17.0.32112.339
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
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
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
Global
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}.Release|Any CPU.ActiveCfg = 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
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View File

@ -10,21 +10,17 @@ namespace MarketPriceLookup
static void Main(string[] args)
{
// 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)
{
var priceData = MarketPricesHelper.GetItemPrice(item.Key);
if (priceData != null && priceData.Price != 0)
{
priceList.Add(item.Key, new OutputPrices
{
LivePrice = priceData.Average7DaysPrice,
TraderPrice = priceData.TraderPrice,
TraderCurrency = priceData.Currency
});
priceList.Add(item.Key, priceData.Average7DaysPrice);
}
}
// save found prices to json
JsonWriter.WriteJson(priceList, "output", Directory.GetCurrentDirectory(), "prices");
}