Remaining time estimate
This commit is contained in:
@@ -58,6 +58,10 @@
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\References\log4net.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="MathNet.Numerics, Version=3.17.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\MathNet.Numerics.3.17.0\lib\net40\MathNet.Numerics.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="MlkPwgen, Version=0.2.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\MlkPwgen.0.2.0.0\lib\net45\MlkPwgen.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
@@ -84,6 +88,7 @@
|
||||
<Compile Include="DAL\DataService.cs" />
|
||||
<Compile Include="DAL\LeafWebContext.cs" />
|
||||
<Compile Include="DAL\LeafWebInitializer.cs" />
|
||||
<Compile Include="Entities\ILeafInput.cs" />
|
||||
<Compile Include="Entities\LeafGasComparisonPhotosyntheticInfo.cs" />
|
||||
<Compile Include="Entities\LeafGasComparisonFittingInfo.cs" />
|
||||
<Compile Include="Entities\LeafGasComparison.cs" />
|
||||
@@ -139,6 +144,7 @@
|
||||
<Compile Include="Utility\BoolTypeConverter.cs" />
|
||||
<Compile Include="Parsers\CsvParserBase.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Utility\TimeInProgressEstimater.cs" />
|
||||
<Compile Include="Utility\FileUtility.cs" />
|
||||
<Compile Include="Utility\Memoizer.cs" />
|
||||
<Compile Include="Utility\ParseInfoAttribute.cs" />
|
||||
|
||||
+13
-2
@@ -57,8 +57,19 @@ namespace LeafWeb.Core.DAL
|
||||
public IQueryable<LeafInput> GetLeafInputsOrdered()
|
||||
{
|
||||
return _db.LeafInputs
|
||||
.OrderByDescending(li => li.CurrentStatus == LeafInputStatusType.Pending)
|
||||
.ThenByDescending(li => li.PendingPriority)
|
||||
// first by in-progress items
|
||||
.OrderByDescending(li =>
|
||||
li.CurrentStatus == LeafInputStatusType.Running ||
|
||||
li.CurrentStatus == LeafInputStatusType.Starting ||
|
||||
li.CurrentStatus == LeafInputStatusType.Finishing ||
|
||||
li.CurrentStatus == LeafInputStatusType.Cancelling ||
|
||||
li.CurrentStatus == LeafInputStatusType.CancelPending)
|
||||
// then by pending, by priority
|
||||
.ThenByDescending(li =>
|
||||
li.CurrentStatus == LeafInputStatusType.Pending
|
||||
? (int)li.PendingPriority
|
||||
: int.MinValue)
|
||||
// then the rest by the order they're added in
|
||||
.ThenByDescending(li => li.Id);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace LeafWeb.Core.Entities
|
||||
{
|
||||
public interface ILeafInput
|
||||
{
|
||||
int Id { get; set; }
|
||||
ICollection<LeafInputFile> InputFiles { get; set; }
|
||||
ICollection<LeafInputData> LeafInputData { get; set; }
|
||||
ICollection<LeafOutputFile> OutputFiles { get; set; }
|
||||
string Name { get; set; }
|
||||
string Email { get; set; }
|
||||
string Identifier { get; set; }
|
||||
string SiteId { get; set; }
|
||||
string UniqueToken { get; set; }
|
||||
PhotosynthesisType PhotosynthesisType { get; set; }
|
||||
DateTime Added { get; set; }
|
||||
LeafInputStatusType CurrentStatus { get; set; }
|
||||
ICollection<LeafInputStatus> StatusHistory { get; set; }
|
||||
Priority PendingPriority { get; set; }
|
||||
LeafOutputFile OutputErrorMessage { get; }
|
||||
LeafOutputFile OutputWarningMessage { get; }
|
||||
TimeSpan TimeInProgress { get; }
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,7 @@ using System.Linq;
|
||||
|
||||
namespace LeafWeb.Core.Entities
|
||||
{
|
||||
public class LeafInput
|
||||
public class LeafInput : ILeafInput
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using LeafWeb.Core.Entities;
|
||||
using MathNet.Numerics;
|
||||
|
||||
namespace LeafWeb.Core.Utility
|
||||
{
|
||||
public class TimeInProgressEstimater
|
||||
{
|
||||
private readonly double[] _xData;
|
||||
private readonly double[] _yData;
|
||||
|
||||
public TimeInProgressEstimater(IEnumerable<ILeafInput> leafInputs)
|
||||
{
|
||||
var xData = new List<double>();
|
||||
var yData = new List<double>();
|
||||
foreach (var leafInput in leafInputs)
|
||||
{
|
||||
xData.Add(leafInput.InputFiles.Count);
|
||||
yData.Add(ConvertFromTimeSpan(leafInput.TimeInProgress));
|
||||
}
|
||||
_xData = xData.ToArray();
|
||||
_yData = yData.ToArray();
|
||||
}
|
||||
|
||||
public TimeSpan EstimateTimeInProgress(ILeafInput leafInput)
|
||||
{
|
||||
//var lineFunc = Fit.LineFunc(_xData, _yData);
|
||||
var lineFunc = Fit.PolynomialFunc(_xData, _yData, 3);
|
||||
var estimate = lineFunc(leafInput.InputFiles.Count);
|
||||
return ConvertToTimeSpan(estimate);
|
||||
}
|
||||
|
||||
private static double ConvertFromTimeSpan(TimeSpan timeSpan)
|
||||
{
|
||||
return timeSpan.TotalSeconds;
|
||||
}
|
||||
|
||||
private static TimeSpan ConvertToTimeSpan(double estimate)
|
||||
{
|
||||
int int32;
|
||||
try
|
||||
{
|
||||
int32 = Convert.ToInt32(estimate);
|
||||
}
|
||||
catch (OverflowException)
|
||||
{
|
||||
int32 = int.MaxValue;
|
||||
}
|
||||
return TimeSpan.FromSeconds(int32);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -25,6 +25,8 @@ namespace LeafWeb.Core.Utility
|
||||
{
|
||||
Func<int, string> pluralize = i => i > 1 ? "s" : string.Empty;
|
||||
Func<int, string, string> formatTime = (i, s) => $"{i:0} {s}{pluralize(i)}";
|
||||
if (span.Duration().Days > 90)
|
||||
return formatTime(span.Days/30, "month");
|
||||
if (span.Duration().Days > 0)
|
||||
return formatTime(span.Days, "day");
|
||||
if (span.Duration().Hours > 0)
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
<package id="EntityFramework" version="6.1.3" targetFramework="net45" />
|
||||
<package id="fasterflect" version="2.1.3" targetFramework="net45" />
|
||||
<package id="log4net" version="1.2.10" targetFramework="net45" />
|
||||
<package id="MathNet.Numerics" version="3.17.0" targetFramework="net45" />
|
||||
<package id="MlkPwgen" version="0.2.0.0" targetFramework="net45" />
|
||||
<package id="SSH.NET" version="2013.4.7" targetFramework="net45" />
|
||||
</packages>
|
||||
Reference in New Issue
Block a user