Exemplo 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);
        }
Exemplo 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);
        }
Exemplo n.º 3
0
        public void WorkUnit_GetFrame_ReturnsNullIfRequestedIdDoesNotExist_Test()
        {
            // Arrange
            var workUnit = new WorkUnit();

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

            // Act & Assert
            Assert.IsNull(workUnit.CurrentFrame);
        }
Exemplo 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);
        }
Exemplo 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);
        }
Exemplo 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);
        }
Exemplo 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);
        }
Exemplo 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);
        }
Exemplo 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);
        }
Exemplo 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);
        }
Exemplo 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);
        }
Exemplo 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);
        }
Exemplo 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);
        }
Exemplo 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));
        }
Exemplo 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()
            });
        }
Exemplo 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);
        }
Exemplo 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);
        }
Exemplo 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);
        }
Exemplo 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);
        }
Exemplo 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));
        }
Exemplo 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));
        }
Exemplo 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);
        }
Exemplo 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));
        }
Exemplo 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));
        }
Exemplo 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));
        }
Exemplo 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);
        }
Exemplo 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));
        }
Exemplo 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));
        }
Exemplo 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));
        }