|
@ -25,6 +25,7 @@ namespace Biskilog_Accounting.Client.Pages.Dashboard.Elements |
|
|
private Timer m_timer { get; set; } |
|
|
private Timer m_timer { get; set; } |
|
|
private ApexChart<ProductPriceChange> chart; |
|
|
private ApexChart<ProductPriceChange> chart; |
|
|
private Random m_random = new Random(); |
|
|
private Random m_random = new Random(); |
|
|
|
|
|
private int tries = 10; |
|
|
protected override void OnInitialized() |
|
|
protected override void OnInitialized() |
|
|
{ |
|
|
{ |
|
|
base.OnInitialized(); |
|
|
base.OnInitialized(); |
|
@ -37,35 +38,61 @@ namespace Biskilog_Accounting.Client.Pages.Dashboard.Elements |
|
|
|
|
|
|
|
|
private void TimerElapsed(object sender, ElapsedEventArgs e) |
|
|
private void TimerElapsed(object sender, ElapsedEventArgs e) |
|
|
{ |
|
|
{ |
|
|
|
|
|
tries = 0; |
|
|
// Code to execute every 10 seconds
|
|
|
// Code to execute every 10 seconds
|
|
|
InvokeAsync(async () => |
|
|
InvokeAsync(async () => |
|
|
{ |
|
|
{ |
|
|
if (m_productHistory.Count > 0) |
|
|
await GetPriceChange(); |
|
|
{ |
|
|
StateHasChanged(); |
|
|
int randomNumber = m_random.Next(ProductHistory.Count); |
|
|
await chart.RenderAsync(); |
|
|
m_currentProduct = ProductHistory[randomNumber].Pcode; |
|
|
}); |
|
|
m_productHistory = ProductHistory.Where(t => t.Pcode == m_currentProduct).ToList(); |
|
|
} |
|
|
|
|
|
private async Task GetPriceChange() |
|
|
|
|
|
{ |
|
|
|
|
|
tries++; |
|
|
|
|
|
if (m_productHistory.Count > 0) |
|
|
|
|
|
{ |
|
|
|
|
|
int randomNumber = m_random.Next(ProductHistory.Count); |
|
|
|
|
|
|
|
|
ProductPriceChange change = m_productHistory.First(); |
|
|
m_productHistory = ProductHistory.Where(t => t.Pcode == m_currentProduct).ToList(); |
|
|
|
|
|
|
|
|
|
|
|
ProductPriceChange change = m_productHistory.First(); |
|
|
|
|
|
double actualChange = (double)((change.CurrentPrice - change.PreviousPrice)); |
|
|
|
|
|
if (actualChange == 0) |
|
|
|
|
|
{ |
|
|
|
|
|
// if randomly selected doesn't have any product change history
|
|
|
|
|
|
if (!string.IsNullOrEmpty(m_currentProduct)) |
|
|
|
|
|
{ |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
else |
|
|
|
|
|
{ |
|
|
|
|
|
if (tries < 3) |
|
|
|
|
|
{ |
|
|
|
|
|
GetPriceChange(); |
|
|
|
|
|
} |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
else |
|
|
|
|
|
{ |
|
|
m_percentage = (double)((change.CurrentPrice - change.PreviousPrice) / change.PreviousPrice > 0 ? change.PreviousPrice * 100 : 1); |
|
|
m_percentage = (double)((change.CurrentPrice - change.PreviousPrice) / change.PreviousPrice > 0 ? change.PreviousPrice * 100 : 1); |
|
|
m_increase = change.CurrentPrice > change.PreviousPrice; |
|
|
|
|
|
m_currentPrice = (double)change.CurrentPrice; |
|
|
|
|
|
m_productName = change.ProductName; |
|
|
|
|
|
m_subtitle = $"Price :{m_calculator.GetCurrencyCode().CurrencySymbol}"; |
|
|
|
|
|
m_title = $"{m_productName} Price Changes"; |
|
|
|
|
|
StateHasChanged(); |
|
|
|
|
|
await chart.RenderAsync(); |
|
|
|
|
|
} |
|
|
} |
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
m_increase = change.CurrentPrice > change.PreviousPrice; |
|
|
|
|
|
m_currentPrice = (double)change.CurrentPrice; |
|
|
|
|
|
m_productName = change.ProductName; |
|
|
|
|
|
m_subtitle = $"Price :{m_calculator.GetCurrencyCode().CurrencySymbol}"; |
|
|
|
|
|
m_title = $"{m_productName} Price Changes"; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
public void Dispose() |
|
|
public void Dispose() |
|
|
{ |
|
|
{ |
|
|
// Dispose of the timer when the component is disposed
|
|
|
// Dispose of the timer when the component is disposed
|
|
|
m_timer?.Stop(); |
|
|
m_timer?.Stop(); |
|
|
m_timer?.Dispose(); |
|
|
m_timer?.Dispose(); |
|
|
} |
|
|
} |
|
|
protected override void OnParametersSet() |
|
|
protected override async void OnParametersSet() |
|
|
{ |
|
|
{ |
|
|
if (!IsLoading) |
|
|
if (!IsLoading) |
|
|
{ |
|
|
{ |
|
@ -101,21 +128,8 @@ namespace Biskilog_Accounting.Client.Pages.Dashboard.Elements |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
}; |
|
|
}; |
|
|
Random random = new Random(); |
|
|
|
|
|
int randomNumber = random.Next(ProductHistory.Count); |
|
|
|
|
|
m_currentProduct = ProductHistory[randomNumber].Pcode; |
|
|
|
|
|
m_productHistory = ProductHistory.Where(t => t.Pcode == m_currentProduct).ToList(); |
|
|
|
|
|
|
|
|
|
|
|
if (m_productHistory.Count > 0) |
|
|
await GetPriceChange(); |
|
|
{ |
|
|
|
|
|
ProductPriceChange change = m_productHistory.First(); |
|
|
|
|
|
m_percentage = (double)((change.CurrentPrice - change.PreviousPrice) / change.PreviousPrice > 0 ? change.PreviousPrice * 100 : 1); |
|
|
|
|
|
m_increase = change.CurrentPrice > change.PreviousPrice; |
|
|
|
|
|
m_currentPrice = (double)change.CurrentPrice; |
|
|
|
|
|
m_productName = change.ProductName; |
|
|
|
|
|
m_subtitle = $"Price :{m_calculator.GetCurrencyCode().CurrencySymbol}"; |
|
|
|
|
|
m_title = $"{m_productName} Price Changes"; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
base.OnParametersSet(); |
|
|
base.OnParametersSet(); |
|
|
} |
|
|
} |
|
|