示例#1
0
        public bool Update(string codec, double compressionSpeed, double decompressionSpeed, long inputBytes, long outputBytes)
        {
            var item   = Items.FirstOrDefault(r => r.Codec == codec);
            var result = false;

            if (item == null)
            {
                item                           = new ResultsItem();
                item.Codec                     = codec;
                item.CompressionSpeed          = compressionSpeed;
                item.DecompressionSpeed        = decompressionSpeed;
                item.Age                       = 0;
                item.AverageCompressionSpeed   = compressionSpeed;
                item.AverageDecompressionSpeed = decompressionSpeed;
                item.Cycles                    = 1;
                item.InputBytes                = inputBytes;
                item.OutputBytes               = outputBytes;
                item.Ratio                     = item.OutputBytes * 100 / item.InputBytes;
                Items.Add(item);
                result = true;
            }
            else
            {
                item.Age++;
                if (compressionSpeed > item.CompressionSpeed)
                {
                    item.CompressionSpeed = compressionSpeed;
                    item.Age = 0;
                    result   = true;
                }
                if (decompressionSpeed > item.DecompressionSpeed)
                {
                    item.DecompressionSpeed = decompressionSpeed;
                    item.Age = 0;
                    result   = true;
                }

                var cycles = item.Cycles;
                item.AverageCompressionSpeed   = (item.AverageCompressionSpeed * cycles + compressionSpeed) / (cycles + 1);
                item.AverageDecompressionSpeed = (item.AverageDecompressionSpeed * cycles + decompressionSpeed) / (cycles + 1);
                item.Cycles       = cycles + 1;
                item.InputBytes  += inputBytes;
                item.OutputBytes += outputBytes;
                item.Ratio        = item.OutputBytes * 100 / item.InputBytes;
            }

            if (result)
            {
                LastImprovement = DateTime.Now;
            }
            return(result);
        }
示例#2
0
		public bool Update(string codec, double compressionSpeed, double decompressionSpeed, long inputBytes, long outputBytes)
		{
			var item = Items.FirstOrDefault(r => r.Codec == codec);
			var result = false;

			if (item == null)
			{
				item = new ResultsItem();
				item.Codec = codec;
				item.CompressionSpeed = compressionSpeed;
				item.DecompressionSpeed = decompressionSpeed;
				item.Age = 0;
				item.AverageCompressionSpeed = compressionSpeed;
				item.AverageDecompressionSpeed = decompressionSpeed;
				item.Cycles = 1;
				item.InputBytes = inputBytes;
				item.OutputBytes = outputBytes;
				item.Ratio = item.OutputBytes * 100 / item.InputBytes;
				Items.Add(item);
				result = true;
			}
			else
			{
				item.Age++;
				if (compressionSpeed > item.CompressionSpeed)
				{
					item.CompressionSpeed = compressionSpeed;
					item.Age = 0;
					result = true;
				}
				if (decompressionSpeed > item.DecompressionSpeed)
				{
					item.DecompressionSpeed = decompressionSpeed;
					item.Age = 0;
					result = true;
				}

				var cycles = item.Cycles;
				item.AverageCompressionSpeed = (item.AverageCompressionSpeed * cycles + compressionSpeed) / (cycles + 1);
				item.AverageDecompressionSpeed = (item.AverageDecompressionSpeed * cycles + decompressionSpeed) / (cycles + 1);
				item.Cycles = cycles + 1;
				item.InputBytes += inputBytes;
				item.OutputBytes += outputBytes;
				item.Ratio = item.OutputBytes * 100 / item.InputBytes;
			}

			if (result) LastImprovement = DateTime.Now;
			return result;
		}