Esempio n. 1
0
        public void WorkUnit_DefaultPropertyValues()
        {
            var workUnit = new WorkUnit();

            Assert.AreEqual(DateTime.MinValue, workUnit.UnitRetrievalTime);
            Assert.IsNull(workUnit.FoldingID);
            Assert.AreEqual(0, workUnit.Team);
            Assert.AreEqual(DateTime.MinValue, workUnit.Assigned);
            Assert.AreEqual(DateTime.MinValue, workUnit.Timeout);
            Assert.AreEqual(TimeSpan.Zero, workUnit.UnitStartTimeStamp);
            Assert.AreEqual(DateTime.MinValue, workUnit.Finished);
            Assert.AreEqual(0.0f, workUnit.CoreVersion);
            Assert.AreEqual(0, workUnit.ProjectID);
            Assert.AreEqual(0, workUnit.ProjectRun);
            Assert.AreEqual(0, workUnit.ProjectClone);
            Assert.AreEqual(0, workUnit.ProjectGen);
            Assert.IsNull(workUnit.ProteinName);
            Assert.IsNull(workUnit.ProteinTag);
            Assert.AreEqual(WorkUnitResult.Unknown, workUnit.UnitResult);
            Assert.AreEqual(0, workUnit.FramesObserved);
            Assert.IsNull(workUnit.CurrentFrame);
            Assert.IsNull(workUnit.LogLines);
            Assert.IsNull(workUnit.Frames);
            Assert.IsNull(workUnit.CoreID);
            Assert.AreEqual(-1, workUnit.QueueIndex);
        }
Esempio n. 2
0
        /// <summary>
        /// Returns a shallow copy of this <see cref="WorkUnit"/>.
        /// </summary>
        public WorkUnit Copy()
        {
            var u = new WorkUnit
            {
                UnitRetrievalTime = UnitRetrievalTime,
                FoldingID         = FoldingID,
                Team               = Team,
                Assigned           = Assigned,
                Timeout            = Timeout,
                UnitStartTimeStamp = UnitStartTimeStamp,
                Finished           = Finished,
                CoreVersion        = CoreVersion,
                ProjectID          = ProjectID,
                ProjectRun         = ProjectRun,
                ProjectClone       = ProjectClone,
                ProjectGen         = ProjectGen,
                ProteinName        = ProteinName,
                ProteinTag         = ProteinTag,
                UnitResult         = UnitResult,
                FramesObserved     = FramesObserved,
                LogLines           = LogLines,
                CoreID             = CoreID,
                QueueIndex         = QueueIndex
            };

            return(u);
        }
Esempio n. 3
0
        public void WorkUnit_GetFrame_ReturnsNullIfRequestedIdDoesNotExist_Test()
        {
            // Arrange
            var workUnit = new WorkUnit();

            // Act & Assert
            Assert.IsNull(workUnit.GetFrame(0));
        }
Esempio n. 4
0
        public void WorkUnit_CurrentFrame_DefaultValueIsNull_Test()
        {
            // Arrange
            var workUnit = new WorkUnit();

            // Act & Assert
            Assert.IsNull(workUnit.CurrentFrame);
        }
Esempio n. 5
0
        public void WorkUnitModel_TimeoutTest5()
        {
            var workUnit = new WorkUnit {
                Timeout = DateTime.MinValue
            };
            var workUnitModel = CreateWorkUnitModel(new Protein(), workUnit);

            Assert.AreEqual(workUnit.Timeout, workUnitModel.Timeout);
        }
Esempio n. 6
0
        public void WorkUnitModel_FinishedTest1()
        {
            var workUnit = new WorkUnit {
                Finished = DateTime.UtcNow
            };
            var workUnitModel = CreateWorkUnitModel(new Protein(), workUnit);

            Assert.AreEqual(workUnit.Finished.ToLocalTime(), workUnitModel.Finished);
        }
Esempio n. 7
0
        public void WorkUnitModel_FinalDeadlineTest3()
        {
            var workUnit = new WorkUnit {
                Assigned = DateTime.MinValue
            };
            var workUnitModel = CreateWorkUnitModel(new Protein(), workUnit);

            Assert.AreEqual(workUnit.Assigned, workUnitModel.FinalDeadline);
        }
Esempio n. 8
0
        public void WorkUnitModel_FinishedTest5()
        {
            var workUnit = new WorkUnit {
                Finished = DateTime.MinValue
            };
            var workUnitModel = CreateWorkUnitModel(new Protein(), workUnit);

            Assert.AreEqual(workUnit.Finished, workUnitModel.Finished);
        }
Esempio n. 9
0
        public void WorkUnitModel_TimeoutTest1()
        {
            var workUnit = new WorkUnit {
                Timeout = DateTime.UtcNow
            };
            var workUnitModel = CreateWorkUnitModel(new Protein(), workUnit);

            Assert.AreEqual(workUnit.Timeout.ToLocalTime(), workUnitModel.Timeout);
        }
Esempio n. 10
0
        public void WorkUnitModel_AllFramesCompleted1()
        {
            var workUnit = new WorkUnit();
            var frames   = new Dictionary <int, LogLineFrameData>().With(CreateFrame(TimeSpan.Zero, 100));

            workUnit.Frames = frames;
            var workUnitModel = CreateWorkUnitModel(null, workUnit);

            Assert.IsTrue(workUnitModel.AllFramesCompleted);
        }
Esempio n. 11
0
        public void WorkUnitModel_PreferredDeadlineTest2()
        {
            var workUnit = new WorkUnit {
                Assigned = DateTime.UtcNow, Timeout = DateTime.UtcNow.Add(TimeSpan.FromDays(5))
            };
            var workUnitModel = CreateWorkUnitModel(new Protein(), workUnit);

            // PreferredDeadline comes from DueTime when ProteinIsUnknown
            Assert.AreEqual(workUnit.Assigned.AddDays(5).ToLocalTime(), workUnitModel.PreferredDeadline);
        }
Esempio n. 12
0
        public void WorkUnitModel_FinalDeadlineTest1()
        {
            var protein = new Protein {
                ProjectNumber = 1, MaximumDays = 6
            };
            var workUnit = new WorkUnit {
                Assigned = DateTime.UtcNow
            };
            var workUnitModel = CreateWorkUnitModel(protein, workUnit);

            Assert.AreEqual(workUnit.Assigned.AddDays(6).ToLocalTime(), workUnitModel.FinalDeadline);
        }
Esempio n. 13
0
        public void WorkUnit_CurrentFrame_ReturnsNullIfMaximumFrameDataIdIsNotZeroOrGreater_Test()
        {
            // Arrange
            var workUnit = new WorkUnit();
            var frames   = new Dictionary <int, LogLineFrameData>().With(new LogLineFrameData {
                ID = -1
            });

            workUnit.Frames = frames;
            // Act & Assert
            Assert.IsNull(workUnit.CurrentFrame);
        }
Esempio n. 14
0
        public void WorkUnit_CurrentFrame_IsSourcedFromFrameDataDictionary_Test()
        {
            // Arrange
            var workUnit = new WorkUnit();
            var frames   = new Dictionary <int, LogLineFrameData>().With(new LogLineFrameData {
                ID = 0
            });

            workUnit.Frames = frames;
            // Act & Assert
            Assert.AreSame(frames[0], workUnit.CurrentFrame);
        }
Esempio n. 15
0
        public void WorkUnit_GetFrame_ReturnsObjectIfRequestedIdExists_Test()
        {
            // Arrange
            var workUnit = new WorkUnit();
            var frames   = new Dictionary <int, LogLineFrameData>().With(new LogLineFrameData {
                ID = 0
            });

            workUnit.Frames = frames;
            // Act & Assert
            Assert.IsNotNull(workUnit.GetFrame(0));
        }
Esempio n. 16
0
        private static WorkUnitModel CreateWorkUnitModel(Protein protein, WorkUnit workUnit, IProteinBenchmarkService benchmarkService = null)
        {
            var slotModel = new SlotModel(new NullClient(null, null, benchmarkService)
            {
                Settings = new ClientSettings()
            });

            return(new WorkUnitModel(slotModel, workUnit)
            {
                CurrentProtein = protein ?? new Protein()
            });
        }
Esempio n. 17
0
        public void WorkUnitModel_PreferredDeadlineTest1()
        {
            var protein = new Protein {
                ProjectNumber = 1, PreferredDays = 3
            };
            var workUnit = new WorkUnit {
                Assigned = DateTime.UtcNow
            };
            var workUnitModel = CreateWorkUnitModel(protein, workUnit);

            Assert.AreEqual(workUnit.Assigned.AddDays(3).ToLocalTime(), workUnitModel.PreferredDeadline);
        }
Esempio n. 18
0
        public void WorkUnitModel_PreferredDeadlineTest4()
        {
            // daylight savings time test (in DST => Standard Time)
            var protein = new Protein {
                ProjectNumber = 1, PreferredDays = 7
            };
            var workUnit = new WorkUnit {
                Assigned = new DateTime(2011, 11, 1)
            };
            var workUnitModel = CreateWorkUnitModel(protein, workUnit);

            Assert.AreEqual(workUnit.Assigned.AddDays(7).ToLocalTime(), workUnitModel.PreferredDeadline);
        }
Esempio n. 19
0
        public void WorkUnitModel_FinalDeadlineTest5()
        {
            // daylight savings time test (in Standard Time => DST)
            var protein = new Protein {
                ProjectNumber = 1, MaximumDays = 7
            };
            var workUnit = new WorkUnit {
                Assigned = new DateTime(2011, 3, 9)
            };
            var workUnitModel = CreateWorkUnitModel(protein, workUnit);

            Assert.AreEqual(workUnit.Assigned.AddDays(7).ToLocalTime(), workUnitModel.FinalDeadline);
        }
Esempio n. 20
0
        public void WorkUnitModel_PercentCompleteTest1()
        {
            var workUnit = new WorkUnit();
            var frames   = new Dictionary <int, LogLineFrameData>()
                           .With(new LogLineFrameData {
                ID = 5
            });

            workUnit.Frames = frames;
            var workUnitModel = CreateWorkUnitModel(null, workUnit);

            Assert.AreEqual(5, workUnitModel.PercentComplete);
        }
Esempio n. 21
0
        public void WorkUnitModel_PerUnitDownloadTest4()
        {
            var workUnit = new WorkUnit {
                Assigned = DateTime.UtcNow, FramesObserved = 4
            };
            var frames = new Dictionary <int, LogLineFrameData>()
                         .With(CreateFrame(TimeSpan.Zero, -1));

            workUnit.Frames = frames;
            var workUnitModel = CreateWorkUnitModel(null, workUnit);

            Assert.AreEqual(0, workUnitModel.GetRawTime(PPDCalculation.EffectiveRate));
            Assert.AreEqual(TimeSpan.FromSeconds(0), workUnitModel.GetFrameTime(PPDCalculation.EffectiveRate));
            Assert.AreEqual(0, workUnitModel.GetPPD(SlotStatus.Unknown, PPDCalculation.EffectiveRate, BonusCalculation.None));
        }
Esempio n. 22
0
        public void WorkUnitModel_EtaTest1()
        {
            var workUnit = new WorkUnit {
                FramesObserved = 4
            };
            var frames = new Dictionary <int, LogLineFrameData>()
                         .With(CreateFrame(TimeSpan.Zero, 0),
                               CreateFrame(TimeSpan.FromMinutes(4), 1),
                               CreateFrame(TimeSpan.FromMinutes(5), 2),
                               CreateFrame(TimeSpan.FromMinutes(6), 3));

            workUnit.Frames = frames;
            var workUnitModel = CreateWorkUnitModel(null, workUnit);

            Assert.AreEqual(TimeSpan.FromMinutes(582), workUnitModel.GetEta(PPDCalculation.LastFrame));
        }
Esempio n. 23
0
        public void WorkUnitModel_PercentCompleteTest2()
        {
            var protein = new Protein {
                Frames = 200
            };
            var workUnit = new WorkUnit();
            var frames   = new Dictionary <int, LogLineFrameData>()
                           .With(new LogLineFrameData {
                ID = 5
            });

            workUnit.Frames = frames;
            var workUnitModel = CreateWorkUnitModel(protein, workUnit);

            Assert.AreEqual(2, workUnitModel.PercentComplete);
        }
Esempio n. 24
0
        public void WorkUnitModel_EtaTest2()
        {
            var workUnit = new WorkUnit {
                Assigned = DateTime.UtcNow, FramesObserved = 4
            };
            var frames = new Dictionary <int, LogLineFrameData>()
                         .With(CreateFrame(TimeSpan.Zero, 0),
                               CreateFrame(TimeSpan.FromMinutes(4), 1),
                               CreateFrame(TimeSpan.FromMinutes(5), 2),
                               CreateFrame(TimeSpan.FromMinutes(6), 3));

            workUnit.Frames            = frames;
            workUnit.UnitRetrievalTime = workUnit.Assigned.Add(TimeSpan.FromMinutes(30));
            var workUnitModel = CreateWorkUnitModel(null, workUnit);

            Assert.AreEqual(workUnit.Assigned.Add(TimeSpan.FromMinutes(612)), workUnitModel.GetEtaDate(PPDCalculation.LastFrame));
        }
Esempio n. 25
0
        public void WorkUnitModel_CreditUPDAndPPDTest4()
        {
            var workUnit = new WorkUnit {
                FramesObserved = 4
            };
            var frames = new Dictionary <int, LogLineFrameData>()
                         .With(CreateFrame(TimeSpan.Zero, 0),
                               CreateFrame(TimeSpan.FromMinutes(4), 1),
                               CreateFrame(TimeSpan.FromMinutes(5), 2),
                               CreateFrame(TimeSpan.FromMinutes(6), 3));

            workUnit.Frames = frames;
            var workUnitModel = CreateWorkUnitModel(null, workUnit);

            Assert.AreEqual(0, workUnitModel.GetCredit(SlotStatus.Unknown, PPDCalculation.LastFrame, BonusCalculation.None));
            Assert.AreEqual(2.4, workUnitModel.GetUPD(PPDCalculation.LastFrame));
            Assert.AreEqual(0, workUnitModel.GetPPD(SlotStatus.Unknown, PPDCalculation.LastFrame, BonusCalculation.None));
        }
Esempio n. 26
0
        public void WorkUnitModel_TimePerSectionTest3()
        {
            var workUnit = new WorkUnit {
                FramesObserved = 5
            };
            var frames = new Dictionary <int, LogLineFrameData>()
                         .With(CreateFrame(TimeSpan.Zero, 0),
                               CreateFrame(new TimeSpan(0, 5, 10), 1),
                               CreateFrame(new TimeSpan(0, 6, 20), 2),
                               CreateFrame(new TimeSpan(0, 6, 10), 3),
                               CreateFrame(new TimeSpan(0, 6, 20), 4));

            workUnit.Frames = frames;
            var workUnitModel = CreateWorkUnitModel(null, workUnit);

            Assert.AreEqual(360, workUnitModel.GetRawTime(PPDCalculation.AllFrames));
            Assert.AreEqual(TimeSpan.FromSeconds(360), workUnitModel.GetFrameTime(PPDCalculation.AllFrames));
        }
Esempio n. 27
0
        internal bool EqualsProjectAndDownloadTime(WorkUnit other)
        {
            if (other == null)
            {
                return(false);
            }

            // if the Projects are known
            if (this.HasProject() && other.HasProject())
            {
                // equals the Project and Assigned
                if (this.EqualsProject(other) && Assigned.Equals(other.Assigned))
                {
                    return(true);
                }
            }

            return(false);
        }
Esempio n. 28
0
        public void ShowProductionTrace(ILogger logger, string slotName, SlotStatus status, PPDCalculation ppdCalculation, BonusCalculation bonusCalculation)
        {
            // test the level
            if (!logger.IsDebugEnabled)
            {
                return;
            }

            if (ProteinIsUnknown(CurrentProtein))
            {
                logger.Debug(String.Format(Logger.NameFormat, slotName, "Protein is unknown... 0 PPD."));
                return;
            }

            switch (bonusCalculation)
            {
            case BonusCalculation.DownloadTime:
                logger.Debug(String.Format(Logger.NameFormat, slotName,
                                           status == SlotStatus.RunningNoFrameTimes
                            ? "Calculate Bonus PPD by Frame Time."
                            : "Calculate Bonus PPD by Download Time."));
                break;

            case BonusCalculation.FrameTime:
                logger.Debug(String.Format(Logger.NameFormat, slotName, "Calculate Bonus PPD by Frame Time."));
                break;

            default:
                logger.Debug(String.Format(Logger.NameFormat, slotName, "Calculate Standard PPD."));
                break;
            }

            TimeSpan frameTime = GetFrameTime(ppdCalculation);
            var      noBonus   = CurrentProtein.GetProteinProduction(frameTime, TimeSpan.Zero);
            TimeSpan unitTimeByDownloadTime = GetUnitTimeByDownloadTime(frameTime);
            var      bonusByDownload        = CurrentProtein.GetProteinProduction(frameTime, unitTimeByDownloadTime);
            TimeSpan unitTimeByFrameTime    = GetUnitTimeByFrameTime(frameTime);
            var      bonusByFrame           = CurrentProtein.GetProteinProduction(frameTime, unitTimeByFrameTime);

            logger.Debug(CreateProductionDebugOutput(WorkUnit.ToShortProjectString(), frameTime, CurrentProtein, noBonus,
                                                     unitTimeByDownloadTime, bonusByDownload,
                                                     unitTimeByFrameTime, bonusByFrame));
        }
Esempio n. 29
0
        public void WorkUnitModel_TimePerSectionTest4()
        {
            var protein = new Protein {
                ProjectNumber = 1, Credit = 100
            };
            var workUnit = new WorkUnit {
                Assigned = DateTime.UtcNow, FramesObserved = 4
            };
            var frames = new Dictionary <int, LogLineFrameData>()
                         .With(CreateFrame(TimeSpan.Zero, 0),
                               CreateFrame(TimeSpan.FromMinutes(4), 1),
                               CreateFrame(TimeSpan.FromMinutes(5), 2),
                               CreateFrame(TimeSpan.FromMinutes(6), 3));

            workUnit.Frames            = frames;
            workUnit.UnitRetrievalTime = workUnit.Assigned.ToLocalTime().Add(TimeSpan.FromMinutes(30));
            var workUnitModel = CreateWorkUnitModel(protein, workUnit);

            Assert.AreEqual(600, workUnitModel.GetRawTime(PPDCalculation.EffectiveRate));
            Assert.AreEqual(TimeSpan.FromSeconds(600), workUnitModel.GetFrameTime(PPDCalculation.EffectiveRate));
        }
Esempio n. 30
0
        public void WorkUnitModel_CreditUPDAndPPDTest2()
        {
            var protein = new Protein {
                ProjectNumber = 1, Credit = 100, KFactor = 5, PreferredDays = 3, MaximumDays = 6
            };
            var utcNow   = DateTime.UtcNow;
            var workUnit = new WorkUnit {
                Finished = utcNow, Assigned = utcNow.Subtract(TimeSpan.FromHours(2)), FramesObserved = 4
            };
            var frames = new Dictionary <int, LogLineFrameData>()
                         .With(CreateFrame(TimeSpan.Zero, 0),
                               CreateFrame(TimeSpan.FromMinutes(4), 1),
                               CreateFrame(TimeSpan.FromMinutes(5), 2),
                               CreateFrame(TimeSpan.FromMinutes(6), 3));

            workUnit.Frames = frames;
            var workUnitModel = CreateWorkUnitModel(protein, workUnit);

            Assert.AreEqual(1897.367, workUnitModel.GetCredit(SlotStatus.Running, PPDCalculation.LastFrame, BonusCalculation.DownloadTime));
            Assert.AreEqual(2.4, workUnitModel.GetUPD(PPDCalculation.LastFrame));
            Assert.AreEqual(4553.6808, workUnitModel.GetPPD(SlotStatus.Running, PPDCalculation.LastFrame, BonusCalculation.DownloadTime));
        }