Time estimation work
This commit is contained in:
@@ -80,6 +80,16 @@ namespace LeafWeb.Core.DAL
|
||||
select s).Max(s => s.DateTime));
|
||||
}
|
||||
|
||||
public IEnumerable<LeafInput> GetLeafInputRecentlyCompleted(int count)
|
||||
{
|
||||
return
|
||||
_db.LeafInputs
|
||||
.Where(li => li.CurrentStatus == LeafInputStatusType.Complete)
|
||||
.Take(count)
|
||||
.ToList()
|
||||
.Where(li => li.OutputErrorMessage == null);
|
||||
}
|
||||
|
||||
public LeafInput GetLeafInput(int id)
|
||||
{
|
||||
return _db.LeafInputs.FirstOrDefault(li => li.Id == id);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using LeafWeb.Core.Entities;
|
||||
using MathNet.Numerics;
|
||||
|
||||
@@ -23,7 +24,15 @@ namespace LeafWeb.Core.Utility
|
||||
_yData = yData.ToArray();
|
||||
}
|
||||
|
||||
private Func<double, double> FitFunc => Fit.PolynomialFunc(_xData, _yData, 3);
|
||||
private static Func<double, double> Positivize => i => i <= 0 ? 1 : i;
|
||||
|
||||
private IEnumerable<double> Div => _xData.Zip(_yData, (x, y) => y/x);
|
||||
|
||||
private Func<double, double> AverageFitFunc => i => Div.Average()*i;
|
||||
|
||||
private Func<double, double> LineFitFunc => Fit.LineFunc(_xData, _yData);
|
||||
|
||||
private Func<double, double> FitFunc => i => (Positivize(LineFitFunc(i)) + AverageFitFunc(i))/2;
|
||||
|
||||
public TimeSpan EstimateTimeInProgress(ILeafInput leafInput)
|
||||
{
|
||||
@@ -32,7 +41,10 @@ namespace LeafWeb.Core.Utility
|
||||
|
||||
public TimeSpan EstimateTimeInProgress(int inputFileCount)
|
||||
{
|
||||
return ConvertToTimeSpan(FitFunc(inputFileCount));
|
||||
var estimate = FitFunc(inputFileCount);
|
||||
if (estimate <= 0)
|
||||
estimate = 1;
|
||||
return ConvertToTimeSpan(estimate);
|
||||
}
|
||||
|
||||
private static double ConvertFromTimeSpan(TimeSpan timeSpan)
|
||||
@@ -42,16 +54,19 @@ namespace LeafWeb.Core.Utility
|
||||
|
||||
private static TimeSpan ConvertToTimeSpan(double estimate)
|
||||
{
|
||||
int int32;
|
||||
return TimeSpan.FromSeconds(ConvertToInt32Guarded(estimate));
|
||||
}
|
||||
|
||||
private static Func<double, int> ConvertToInt32Guarded => d =>
|
||||
{
|
||||
try
|
||||
{
|
||||
int32 = Convert.ToInt32(estimate);
|
||||
return Convert.ToInt32(d);
|
||||
}
|
||||
catch (OverflowException)
|
||||
{
|
||||
int32 = int.MaxValue;
|
||||
return int.MaxValue;
|
||||
}
|
||||
return TimeSpan.FromSeconds(int32);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user