Skip to content

Commit

Permalink
Merge branch 'AvarageItemPrices'
Browse files Browse the repository at this point in the history
  • Loading branch information
Triky313 committed Jan 1, 2021
2 parents 6fb4c93 + cdd1681 commit 975b7ca
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -313,4 +313,6 @@
<translation name="HAS_BEEN_UNDERCUT">ist unterboten worden</translation>
<translation name="IS_ALERT_ACTIVATE">Ist Alarm aktiv</translation>
<translation name="UNDERCUTTING_PRICE">Zu unterbietender Preis</translation>
<translation name="AVERAGE_PRICES">Durchschnittspreise</translation>
<translation name="AVERAGE_PRICES_TOOLTIP">Verk.-Preis min | Verk.-Preis max | Kauf-Preis min | Kauf-Preis max</translation>
</translations>
Original file line number Diff line number Diff line change
Expand Up @@ -314,4 +314,6 @@
<translation name="HAS_BEEN_UNDERCUT">has been undercut</translation>
<translation name="IS_ALERT_ACTIVATE">Is alert activate</translation>
<translation name="UNDERCUTTING_PRICE">Undercutting price</translation>
<translation name="AVERAGE_PRICES">Average prices</translation>
<translation name="AVERAGE_PRICES_TOOLTIP">Sell price min | Sell price max | Buy price min | Buy price max</translation>
</translations>
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,7 @@ public class ItemWindowTranslation
public string ItemPower => LanguageController.Translation("ITEM_POWER");
public string Durability => LanguageController.Translation("DURABILITY");
public string RealMoneyPrice => LanguageController.Translation("REAL_MONEY_PRICE");
public string AveragePrices => LanguageController.Translation("AVERAGE_PRICES");
public string AveragePricesTooltip => LanguageController.Translation("AVERAGE_PRICES_TOOLTIP");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public class ItemWindowViewModel : INotifyPropertyChanged
private Visibility _loadingImageVisibility;
private FontAwesomeIcon _loadingImageIcon;
private bool _loadingImageSpin;
private string _differentCalculation;
private string _averagePrices;
private List<MarketQualityObject> _realMoneyPriceList;
private GoldResponseModel _currentGoldPrice;
private List<MarketResponse> _currentCityPrices;
Expand Down Expand Up @@ -463,7 +463,7 @@ public void GetMainPriceStats()
}

MarketCurrentPricesItemList = marketCurrentPricesItemList;
SetDifferenceCalculationText(statsPricesTotalList);
SetAveragePricesString();

HasItemPrices = true;
RefreshIconTooltipText = $"{LanguageController.Translation("LAST_UPDATE")}: {Formatting.CurrentDateTimeFormat(DateTime.Now)}";
Expand Down Expand Up @@ -583,22 +583,47 @@ private static ulong GetMinPrice(List<MarketResponseTotal> list)
return min;
}

private void SetDifferenceCalculationText(List<MarketResponseTotal> statsPricesTotalList)
private void SetAveragePricesString()
{
ulong? bestBuyMaxPrice = 0UL;
ulong? bestSellMinPrice = 0UL;
var cityPrices = GetFilteredCityPrices(false, false, true, false, false);

if (statsPricesTotalList?.Count > 0)
var sellPriceMin = new List<ulong>();
var sellPriceMax = new List<ulong>();
var buyPriceMin = new List<ulong>();
var buyPriceMax = new List<ulong>();

foreach (var price in cityPrices)
{
bestBuyMaxPrice = statsPricesTotalList.FirstOrDefault(s => s.BestBuyMaxPrice)?.BuyPriceMax ?? 0UL;
bestSellMinPrice = statsPricesTotalList.FirstOrDefault(s => s.BestSellMinPrice)?.SellPriceMin ?? 0UL;
}
if (price.SellPriceMin != 0)
{
sellPriceMin.Add(price.SellPriceMin);
}

var diffPrice = (int)bestBuyMaxPrice - (int)bestSellMinPrice;
if (price.SellPriceMax != 0)
{
sellPriceMax.Add(price.SellPriceMax);
}

DifferentCalculation = $"{LanguageController.Translation("BOUGHT_FOR")} {string.Format(LanguageController.CurrentCultureInfo, "{0:n0}", bestSellMinPrice)} | " +
$"{LanguageController.Translation("SELL_FOR")} {string.Format(LanguageController.CurrentCultureInfo, "{0:n0}", bestBuyMaxPrice)} | " +
$"{LanguageController.Translation("PROFIT")} {string.Format(LanguageController.CurrentCultureInfo, "{0:n0}", diffPrice)}";
if (price.BuyPriceMin != 0)
{
buyPriceMin.Add(price.BuyPriceMin);
}

if (price.BuyPriceMax != 0)
{
buyPriceMax.Add(price.BuyPriceMax);
}
}

var sellPriceMinAverage = Average(sellPriceMin.ToArray());
var sellPriceMaxAverage = Average(sellPriceMax.ToArray());
var buyPriceMinAverage = Average(buyPriceMin.ToArray());
var buyPriceMaxAverage = Average(buyPriceMax.ToArray());

AveragePrices = $"{string.Format(LanguageController.CurrentCultureInfo, "{0:n0}", sellPriceMinAverage)} | " +
$"{string.Format(LanguageController.CurrentCultureInfo, "{0:n0}", sellPriceMaxAverage)} | " +
$"{string.Format(LanguageController.CurrentCultureInfo, "{0:n0}", buyPriceMinAverage)} | " +
$"{string.Format(LanguageController.CurrentCultureInfo, "{0:n0}", buyPriceMaxAverage)}";
}

#endregion Prices
Expand Down Expand Up @@ -653,10 +678,10 @@ public List<MarketResponse> CurrentCityPrices {
}
}

public string DifferentCalculation {
get => _differentCalculation;
public string AveragePrices {
get => _averagePrices;
set {
_differentCalculation = value;
_averagePrices = value;
OnPropertyChanged();
}
}
Expand Down Expand Up @@ -869,5 +894,26 @@ protected virtual void OnPropertyChanged([CallerMemberName] string propertyName
}

#endregion Bindings

#region Helper

public ulong Sum(params ulong[] values)
{
return values.Aggregate(0UL, (current, t) => current + t);
}

public ulong Average(params ulong[] values)
{
if (values.Length == 0)
{
return 0;
}

var sum = Sum(values);
var result = sum / (ulong) values.Length;
return result;
}

#endregion
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -379,8 +379,8 @@
<GradientStop Color="{StaticResource Background.Second}" Offset="1" />
</LinearGradientBrush>
</Grid.Background>
<Label Content="{Binding Translation.DifferentCalculation, FallbackValue=DIFFERENT__CALCULATION}" HorizontalAlignment="Left" Margin="10,0,0,4" VerticalAlignment="Bottom" Width="150" Foreground="{StaticResource SolidColorBrush.Foreground.First}" Background="{x:Null}" />
<Label Content="{Binding DifferentCalculation}" Margin="160,0,0,4" Foreground="{StaticResource SolidColorBrush.Foreground.First}" Height="26" VerticalAlignment="Bottom" HorizontalAlignment="Left" Width="485" />
<Label Content="{Binding Translation.AveragePrices, FallbackValue=AVERAGE__PRICES}" ToolTip="{Binding Translation.AveragePricesTooltip}" HorizontalAlignment="Left" Margin="10,0,0,4" VerticalAlignment="Bottom" Width="150" Foreground="{StaticResource SolidColorBrush.Foreground.First}" Background="{x:Null}" />
<Label Content="{Binding AveragePrices, FallbackValue=0.000.00 | 0.000.000 | 0.000.000 | 0.000.000}" Margin="160,0,0,4" Foreground="{StaticResource SolidColorBrush.Foreground.First}" Height="26" VerticalAlignment="Bottom" HorizontalAlignment="Left" Width="400" />
<TextBlock Margin="0,0,10,4" Foreground="{StaticResource SolidColorBrush.Foreground.First}" Height="21" VerticalAlignment="Bottom" HorizontalAlignment="Right" Width="293">
Prices are provided by the
<Hyperlink NavigateUri="https://www.albion-online-data.com/" Foreground="{StaticResource SolidColorBrush.Hyperlink.First}" FontWeight="Bold" BaselineAlignment="Center" RequestNavigate="Hyperlink_RequestNavigate">Albion Online Data Project</Hyperlink>
Expand Down

0 comments on commit 975b7ca

Please sign in to comment.