Пример #1
0
 /// <summary>
 /// Gets all production measurements based the given frame time, work unit information, and the unit completion time.
 /// </summary>
 /// <param name="frameTime">The work unit frame time.</param>
 /// <param name="protein">The work unit information.</param>
 /// <param name="unitTimeByDownloadTime">The overall unit completion time based on the unit's download time.</param>
 /// <param name="unitTimeByFrameTime">The overall unit completion time based on the unit's current frame time.</param>
 /// <returns>The production measurements for the work unit.</returns>
 public static ProductionValues GetProductionValues(TimeSpan frameTime, Protein protein, TimeSpan unitTimeByDownloadTime, TimeSpan unitTimeByFrameTime)
 {
     return(GetProductionValues(frameTime,
                                protein.Frames,
                                protein.Credit,
                                protein.KFactor,
                                protein.PreferredDays,
                                protein.MaximumDays,
                                unitTimeByDownloadTime,
                                unitTimeByFrameTime));
 }
        public void ProteinProductionExtensions_GetProductionValues_WithBonus_Test()
        {
            var protein = new Protein {
                Credit = 700.0, KFactor = 26.4, PreferredDays = 3.0, MaximumDays = 5.0
            };
            var frameTime = TimeSpan.FromMinutes(5);
            var unitTime  = TimeSpan.FromMinutes(5 * 100);
            var values    = protein.GetProductionValues(frameTime, unitTime);

            Assert.AreEqual(2.88, values.UPD);
            Assert.AreEqual(19.5, values.Multiplier, 0.01);
            Assert.AreEqual(13648.383, values.Credit);
            Assert.AreEqual(39307.35, values.PPD, 0.01);
        }
        public void Protein_DefaultValues_Test()
        {
            var protein = new Protein();

            Assert.AreEqual(0, protein.ProjectNumber);
            Assert.AreEqual("0.0.0.0", protein.ServerIP);
            Assert.AreEqual("Unknown", protein.WorkUnitName);
            Assert.AreEqual(0, protein.NumberOfAtoms);
            Assert.AreEqual(0, protein.PreferredDays);
            Assert.AreEqual(0, protein.MaximumDays);
            Assert.AreEqual(0, protein.Credit);
            Assert.AreEqual(100, protein.Frames);
            Assert.AreEqual("Unknown", protein.Core);
            Assert.AreEqual("Unassigned Description", protein.Description);
            Assert.AreEqual("Unknown", protein.Contact);
            Assert.AreEqual(0, protein.KFactor);
        }
Пример #4
0
        public void Protein_DefaultPropertyValues()
        {
            var protein = new Protein();

            Assert.AreEqual(0, protein.ProjectNumber);
            Assert.AreEqual(null, protein.ServerIP);
            Assert.AreEqual(null, protein.WorkUnitName);
            Assert.AreEqual(0, protein.NumberOfAtoms);
            Assert.AreEqual(0, protein.PreferredDays);
            Assert.AreEqual(0, protein.MaximumDays);
            Assert.AreEqual(0, protein.Credit);
            Assert.AreEqual(100, protein.Frames);
            Assert.AreEqual(null, protein.Core);
            Assert.AreEqual(null, protein.Description);
            Assert.AreEqual(null, protein.Contact);
            Assert.AreEqual(0, protein.KFactor);
        }
        internal async Task <ICollection <Protein> > DeserializeAsyncOld(Stream stream)
        {
            var collection = new List <Protein>();

            using var reader = new StreamReader(stream);

            string line;

            while ((line = await reader.ReadLineAsync().ConfigureAwait(false)) != null)
            {
                var p = ParseProteinOld(line);
                if (Protein.IsValid(p))
                {
                    collection.Add(p);
                }
            }

            return(collection);
        }
        internal ICollection <Protein> DeserializeOld(Stream stream)
        {
            var collection = new List <Protein>();

            using var reader = new StreamReader(stream);

            string line;

            while ((line = reader.ReadLine()) != null)
            {
                var p = ParseProteinOld(line);
                if (Protein.IsValid(p))
                {
                    collection.Add(p);
                }
            }

            return(collection);
        }
Пример #7
0
        private static string WriteProtein(Protein protein)
        {
            // Project Number, Server IP, Work Unit Name, Number of Atoms, Preferred (days),
            // Final Deadline (days), Credit, Frames, Code, Description, Contact, KFactor

            string line = String.Format(CultureInfo.InvariantCulture,
                                        "{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}\t{7}\t{8}\t{9}\t{10}\t{11}",
                                        /*  0 */ protein.ProjectNumber,
                                        /*  1 */ protein.ServerIP,
                                        /*  2 */ protein.WorkUnitName,
                                        /*  3 */ protein.NumberOfAtoms,
                                        /*  4 */ protein.PreferredDays,
                                        /*  5 */ protein.MaximumDays,
                                        /*  6 */ protein.Credit,
                                        /*  7 */ protein.Frames,
                                        /*  8 */ protein.Core,
                                        /*  9 */ protein.Description,
                                        /* 10 */ protein.Contact,
                                        /* 11 */ protein.KFactor);

            return(line);
        }
Пример #8
0
        public void Protein_Copy_ReturnsNewInstance()
        {
            // Arrange
            var protein = new Protein
            {
                ProjectNumber = 1,
                ServerIP      = nameof(Protein.ServerIP),
                WorkUnitName  = nameof(Protein.WorkUnitName),
                NumberOfAtoms = 2,
                PreferredDays = 3,
                MaximumDays   = 4,
                Credit        = 5,
                Frames        = 6,
                Core          = nameof(Protein.Core),
                Description   = nameof(Protein.Description),
                Contact       = nameof(Protein.Contact),
                KFactor       = 7
            };
            // Act
            var copy = protein.Copy();

            // Assert
            Assert.AreNotSame(protein, copy);
            Assert.AreEqual(1, copy.ProjectNumber);
            Assert.AreEqual(nameof(Protein.ServerIP), copy.ServerIP);
            Assert.AreEqual(nameof(Protein.WorkUnitName), copy.WorkUnitName);
            Assert.AreEqual(2, copy.NumberOfAtoms);
            Assert.AreEqual(3, copy.PreferredDays);
            Assert.AreEqual(4, copy.MaximumDays);
            Assert.AreEqual(5, copy.Credit);
            Assert.AreEqual(6, copy.Frames);
            Assert.AreEqual(nameof(Protein.Core), copy.Core);
            Assert.AreEqual(nameof(Protein.Description), copy.Description);
            Assert.AreEqual(nameof(Protein.Contact), copy.Contact);
            Assert.AreEqual(7, copy.KFactor);
        }
 /// <summary>
 /// Gets the credit measurement based the given work unit information and the unit completion time.
 /// </summary>
 /// <param name="protein"></param>
 /// <param name="unitTime">The overall unit completion time.</param>
 /// <returns>The credit for the work unit.</returns>
 public static double GetBonusCredit(this Protein protein, TimeSpan unitTime)
 {
     return(ProductionCalculator.GetBonusCredit(protein.Credit, protein.KFactor, protein.PreferredDays, protein.MaximumDays, unitTime));
 }
Пример #10
0
 /// <summary>
 /// Gets the points per day measurement based the given frame time, work unit information, and the unit completion time.
 /// </summary>
 /// <param name="frameTime">The work unit frame time.</param>
 /// <param name="protein">The work unit information.</param>
 /// <returns>The points per day for the work unit.</returns>
 public static double GetPPD(TimeSpan frameTime, Protein protein)
 {
     return(GetPPD(frameTime, protein, false));
 }
Пример #11
0
 /// <summary>
 /// Gets the units per day measurement based the given frame time and number of frames.
 /// </summary>
 /// <param name="protein"></param>
 /// <param name="frameTime">The work unit frame time.</param>
 /// <returns>The units per day for the work unit.</returns>
 public static double GetUPD(this Protein protein, TimeSpan frameTime) =>
 ProductionCalculator.GetUPD(frameTime, protein.Frames);
Пример #12
0
        public void ProteinValidator_IsValid_ReturnsFalseWhenAllRequiredPropertiesAreNotPopulated_Test()
        {
            var protein = new Protein();

            Assert.IsFalse(ProteinValidator.IsValid(protein));
        }
 /// <summary>
 /// Gets all production measurements based the given frame time, work unit information, and the unit completion time.
 /// </summary>
 /// <param name="protein"></param>
 /// <param name="frameTime">The work unit frame time.</param>
 /// <param name="unitTime">The overall unit completion time.</param>
 /// <returns>The production measurements for the work unit.</returns>
 public static ProductionValues GetProductionValues(this Protein protein, TimeSpan frameTime, TimeSpan unitTime)
 {
     return(ProductionCalculator.GetProductionValues(frameTime, protein.Frames, protein.Credit, protein.KFactor, protein.PreferredDays, protein.MaximumDays, unitTime));
 }
 /// <summary>
 /// Gets the points per day measurement based the given frame time and work unit credit.
 /// </summary>
 /// <param name="protein"></param>
 /// <param name="frameTime">The work unit frame time.</param>
 /// <returns>The points per day for the work unit.</returns>
 public static double GetPPD(this Protein protein, TimeSpan frameTime)
 {
     return(ProductionCalculator.GetPPD(frameTime, protein.Frames, protein.Credit));
 }
Пример #15
0
 public void Protein_IsValid_ReturnsFalseWhenProteinIsNull_Test()
 {
     Assert.IsFalse(Protein.IsValid(null));
 }
Пример #16
0
 /// <summary>
 /// Gets all production measurements based the given frame time, work unit information, and the unit completion time.
 /// </summary>
 /// <param name="protein"></param>
 /// <param name="frameTime">The work unit frame time.</param>
 /// <param name="unitTime">The overall unit completion time.</param>
 /// <returns>The production measurements for the work unit.</returns>
 public static ProteinProduction GetProteinProduction(this Protein protein, TimeSpan frameTime, TimeSpan unitTime) =>
 ProductionCalculator.GetProteinProduction(frameTime, protein.Frames, protein.Credit, protein.KFactor, protein.PreferredDays, protein.MaximumDays, unitTime);
Пример #17
0
 /// <summary>
 /// Gets the production bonus multiplier.
 /// </summary>
 /// <param name="protein"></param>
 /// <param name="unitTime">The overall unit completion time.</param>
 /// <returns>The production bonus multiplier.</returns>
 public static double GetBonusMultiplier(this Protein protein, TimeSpan unitTime) =>
 ProductionCalculator.GetBonusMultiplier(protein.KFactor, protein.PreferredDays, protein.MaximumDays, unitTime);