using System;
using System.Linq;
using LeafWeb.Core.Entities;
using LeafWeb.Core.Utility;
using Moq;
using NUnit.Framework;

namespace LeafWeb.Core.Tests.Utility
{
	[TestFixture]
	public class TimeInProgressEstimaterTests
	{
		[Test]
		public void EstimateTest()
		{
			Func<int, int> scaleFunc = i => i*60*10;

			//var obervations = 
			//	from i in Enumerable.Range(1, 10)
			//	let time = scaleFunc(i)
			//	select Mock.Of<ILeafInput>(li =>
			//		li.InputFiles.Count == i &&
			//		li.TimeInProgress == TimeSpan.FromMinutes(time));

			var obervations =
				from d in data
				select Mock.Of<ILeafInput>(li =>
					li.InputFiles.Count == d.Item1 &&
					li.TimeInProgress == TimeSpan.FromSeconds(d.Item2)
					);

			var estimater = new TimeInProgressEstimater(obervations.ToArray());

			Action<int> est = i =>
			{
				var query = Mock.Of<ILeafInput>(li => li.InputFiles.Count == i);
				var estimate = estimater.EstimateTimeInProgress(query);
				Console.WriteLine($"{i} => {estimate}.  {TimeSpan.FromMinutes(scaleFunc(i))}");
			};

			for (var i = 1; i < 100; i++)
				est(i);
		}

		private Tuple<int,double>[] data =
		{
			Tuple.Create(3, 990.347),
			Tuple.Create(11, 5688.136),
			Tuple.Create(166, 243433.25),
			Tuple.Create(156, 96585.35),
			Tuple.Create(23, 205828.927),
			Tuple.Create(10, 4679.583),
			Tuple.Create(20, 28568.39),
			Tuple.Create(3, 1456.104),
			Tuple.Create(3, 1144.78),
			Tuple.Create(23, 12356.24),
			Tuple.Create(5, 10149.49),
			Tuple.Create(10, 4832.93),
			Tuple.Create(4, 1770.086),
			Tuple.Create(8, 4727.98),
			Tuple.Create(20, 35137.31),
			Tuple.Create(20, 38265.414),
			Tuple.Create(20, 23023.103),
			Tuple.Create(20, 28994.213),
			Tuple.Create(8, 6755.817),
			Tuple.Create(20, 11458.047),
			Tuple.Create(20, 13239.973),
			Tuple.Create(1, 155.907),
			Tuple.Create(1, 198.236),
			Tuple.Create(4, 6171.793),
			Tuple.Create(13, 6036.343),
			Tuple.Create(13, 6287.683),
			Tuple.Create(1, 230.48),
			Tuple.Create(2, 3134.58),
			Tuple.Create(15, 26254.85),
			Tuple.Create(17, 10140.037),
			Tuple.Create(10, 7622.307),
			Tuple.Create(8, 9016.327),
			Tuple.Create(9, 8037.403),
			Tuple.Create(18, 14819.907),
			Tuple.Create(4, 2744.767),
			Tuple.Create(30, 26198.996),
			Tuple.Create(27, 25819.637),
			Tuple.Create(30, 17456.014),
			Tuple.Create(28, 17611.16),
			Tuple.Create(24, 8778.873),
			Tuple.Create(1, 343.343),
			Tuple.Create(2, 797.004),
			Tuple.Create(1, 199.92),
			Tuple.Create(24, 13000.967),
			Tuple.Create(18, 15778.11),
			Tuple.Create(5, 3511.834),
			Tuple.Create(5, 1211.593),
			Tuple.Create(5, 8895.523),
			Tuple.Create(5, 3537.074),
			Tuple.Create(5, 2411.197),
			Tuple.Create(5, 11243.546),
			Tuple.Create(6, 3967.287),
			Tuple.Create(6, 3912.07),
			Tuple.Create(5, 2406.013),
			Tuple.Create(5, 11237.71),
			Tuple.Create(35, 16774.884),
			Tuple.Create(31, 12828.044),
			Tuple.Create(30, 15379.2),
			Tuple.Create(30, 15139.8),
			Tuple.Create(36, 59509.324),
			Tuple.Create(33, 36650.247),
			Tuple.Create(35, 17443.134),
			Tuple.Create(32, 17103.803),
			Tuple.Create(32, 23901.747),
			Tuple.Create(31, 17996.223),
			Tuple.Create(36, 35667.134),
			Tuple.Create(33, 25839.96),
			Tuple.Create(30, 30598.057),
			Tuple.Create(1, 559.94),
			Tuple.Create(30, 37881.45),
			Tuple.Create(1, 1536.64),
			Tuple.Create(1, 1635.797),
			Tuple.Create(6, 5198.684),
			Tuple.Create(30, 33436.844),
			Tuple.Create(30, 46370.277),
			Tuple.Create(29, 2054.907),
			Tuple.Create(24, 1898.857),
			Tuple.Create(24, 2658.23),
			Tuple.Create(40, 3984.13),
			Tuple.Create(29, 4258.67),
			Tuple.Create(24, 3210.917),
			Tuple.Create(24, 2931.43)
		};
	}
}