Skip to content

Commit

Permalink
Fixed avg price data
Browse files Browse the repository at this point in the history
  • Loading branch information
josdemmers committed May 27, 2022
1 parent 9823cd3 commit ba2842f
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 16 deletions.
20 changes: 9 additions & 11 deletions NewWorldCompanion.Entities/NwmarketpriceJson.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class NwmarketpriceJson
public string last_checked { get; set; } = string.Empty;
//public string recent_lowest_price { get; set; } = string.Empty;
public double recent_lowest_price { get; set; } = 0.0;
public List<object> avg_graph_data { get; set; } = new List<object>();
public List<AvgGraph> avg_graph_data { get; set; } = new List<AvgGraph>();

[JsonIgnore]
public string RecentLowestPriceAvg
Expand All @@ -30,16 +30,8 @@ public string RecentLowestPriceAvg
{
if (avg_graph_data.Count() > 0)
{
JsonElement priceData = (JsonElement)avg_graph_data.Last();
switch (priceData.ValueKind)
{
case JsonValueKind.Number:
price = decimal.Parse(priceData.ToString(), style, CultureInfo.InvariantCulture).ToString("F2");
break;
case JsonValueKind.Array:
price = decimal.Parse(priceData[1].ToString(), style, CultureInfo.InvariantCulture).ToString("F2");
break;
}
AvgGraph priceData = avg_graph_data.Last();
price = priceData.price.ToString("F2");
}
}
catch (Exception){}
Expand All @@ -48,4 +40,10 @@ public string RecentLowestPriceAvg
}
}
}

public class AvgGraph
{
public DateTime datetime { get; set; }
public double price { get; set; }
}
}
4 changes: 2 additions & 2 deletions NewWorldCompanion.Services/OverlayHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ private void DrawGraphicsItem(DrawGraphicsEventArgs e, string itemName)
// $"{nwmarketpriceJson.recent_lowest_price} lowest ({nwmarketpriceJson.last_checked})";
infoPrice = nwmarketpriceJson.recent_lowest_price.Equals(nwmarketpriceJson.last_checked) ?
decimal.Parse(nwmarketpriceJson.recent_lowest_price.ToString(), style, CultureInfo.InvariantCulture).ToString("F2"):
$"{nwmarketpriceJson.recent_lowest_price} lowest ({nwmarketpriceJson.last_checked})";
$"{nwmarketpriceJson.recent_lowest_price.ToString("F2")} lowest ({nwmarketpriceJson.last_checked})";
infoPriceAvg = string.IsNullOrWhiteSpace(recentLowestPriceAvgList) ?
infoPriceAvg :
$"{recentLowestPriceAvgList} lowest avg ({nwmarketpriceJson.last_checked})";
Expand Down Expand Up @@ -186,7 +186,7 @@ private void DrawGraphicsRecipe(DrawGraphicsEventArgs e, CraftingRecipe crafting
// $"{nwmarketpriceJson.recent_lowest_price} lowest ({nwmarketpriceJson.last_checked})";
infoPrice = nwmarketpriceJson.recent_lowest_price.Equals(nwmarketpriceJson.last_checked) ?
decimal.Parse(nwmarketpriceJson.recent_lowest_price.ToString(), style, CultureInfo.InvariantCulture).ToString("F2") :
$"{nwmarketpriceJson.recent_lowest_price} lowest ({nwmarketpriceJson.last_checked})";
$"{nwmarketpriceJson.recent_lowest_price.ToString("F2")} lowest ({nwmarketpriceJson.last_checked})";
infoPriceAvg = string.IsNullOrWhiteSpace(recentLowestPriceAvgList) ?
infoPriceAvg :
$"{recentLowestPriceAvgList} lowest avg ({nwmarketpriceJson.last_checked})";
Expand Down
2 changes: 1 addition & 1 deletion NewWorldCompanion/ViewModels/Tabs/CraftingViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ public string SelectedCraftingRecipePrice
// $"{nwmarketpriceJson.recent_lowest_price} lowest ({nwmarketpriceJson.last_checked})";
_selectedCraftingRecipePrice = nwmarketpriceJson.recent_lowest_price.Equals(nwmarketpriceJson.last_checked) ?
decimal.Parse(nwmarketpriceJson.recent_lowest_price.ToString(), style, CultureInfo.InvariantCulture).ToString("F2") :
$"{nwmarketpriceJson.recent_lowest_price} lowest ({nwmarketpriceJson.last_checked})";
$"{nwmarketpriceJson.recent_lowest_price.ToString("F2")} lowest ({nwmarketpriceJson.last_checked})";
}
}
return _selectedCraftingRecipePrice;
Expand Down
4 changes: 2 additions & 2 deletions NewWorldCompanion/common.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project>
<PropertyGroup>
<FileVersion>1.0.6.0</FileVersion>
<Version>1.0.6.0</Version>
<FileVersion>1.0.6.1</FileVersion>
<Version>1.0.6.1</Version>
<Copyright>Copyright © 2022</Copyright>
<TargetFramework>net6.0-windows</TargetFramework>
</PropertyGroup>
Expand Down

0 comments on commit ba2842f

Please sign in to comment.