Fixes exception in market averages

This commit is contained in:
benbierens 2024-04-12 09:12:51 +02:00
parent 2cf5a26934
commit ae25b58610
No known key found for this signature in database
GPG Key ID: 877D2C2E09A22F3A
3 changed files with 7 additions and 5 deletions

View File

@ -16,7 +16,7 @@
public class MarketAverage
{
public int NumberOfFinished { get; set; }
public TimeSpan TimeRange { get; set; }
public int TimeRangeSeconds { get; set; }
public float Price { get; set; }
public float Size { get; set; }
public float Duration { get; set; }

View File

@ -31,7 +31,8 @@ namespace BiblioTech.Commands
private string[] GetInsight(MarketAverage avg)
{
var headerLine = $"[Last {Time.FormatDuration(avg.TimeRange)}] ({avg.NumberOfFinished} Contracts finished)";
var timeRange = TimeSpan.FromSeconds(avg.TimeRangeSeconds);
var headerLine = $"[Last {Time.FormatDuration(timeRange)}] ({avg.NumberOfFinished} Contracts finished)";
if (avg.NumberOfFinished == 0)
{

View File

@ -53,7 +53,7 @@ namespace TestNetRewarder
return new MarketAverage
{
NumberOfFinished = CountNumberOfFinishedRequests(states),
TimeRange = GetTotalTimeRange(states),
TimeRangeSeconds = GetTotalTimeRange(states),
Price = Average(states, s => s.Request.Ask.Reward),
Duration = Average(states, s => s.Request.Ask.Duration),
Size = Average(states, s => GetTotalSize(s.Request.Ask)),
@ -93,12 +93,13 @@ namespace TestNetRewarder
}
}
if (count < 1.0f) return 0.0f;
return sum / count;
}
private TimeSpan GetTotalTimeRange(ChainState[] states)
private int GetTotalTimeRange(ChainState[] states)
{
return Program.Config.Interval * states.Length;
return Convert.ToInt32((Program.Config.Interval * states.Length).TotalSeconds);
}
private int CountNumberOfFinishedRequests(ChainState[] states)